Loading...
Searching...
No Matches
ml::MouseEvents Class Reference

Static helpers for mouse hit-testing against framework objects. More...

#include <MouseEvents.h>

Static Public Member Functions

static bool isClicked (const sf::FloatRect &bounds, const sf::RenderWindow &window)
 Return true if the left mouse button is held over a rect.
template<typename T>
static bool isClicked (const T &obj, const sf::RenderWindow &window)
 Return true if the left mouse button is held over a framework object.
static bool isHovered (const sf::FloatRect &bounds, const sf::RenderWindow &window)
 Return true if the mouse is currently over a rect.
template<typename T>
static bool isHovered (const T &obj, const sf::RenderWindow &window)
 Return true if the mouse is currently over a framework object.

Detailed Description

Static helpers for mouse hit-testing against framework objects.

MouseEvents provides the low-level spatial queries that UIManager uses each frame to determine which component the mouse is hovering over or clicking on. Each method is overloaded to accept either a framework object (queried via getGlobalBounds()) or a raw sf::FloatRect.

Both isHovered and isClicked convert the current mouse position from screen space to world space before testing, so they work correctly with any view transform.

Note
User code rarely calls these directly. The preferred approach is to use the Subscribable event callbacks (onClick, onHover) which are fired automatically by UIManager.
See also
UIManager, Subscribable, Positionable

Definition at line 33 of file MouseEvents.h.

Member Function Documentation

◆ isClicked() [1/2]

bool ml::MouseEvents::isClicked ( const sf::FloatRect & bounds,
const sf::RenderWindow & window )
static

Return true if the left mouse button is held over a rect.

Combines sf::Mouse::isButtonPressed(Left) with a hover test against bounds.

Parameters
boundsThe rectangle to test in world coordinates.
Window moduleThe render window providing the view transform.
Returns
true if the left button is down and the mouse is inside bounds.

◆ isClicked() [2/2]

template<typename T>
bool ml::MouseEvents::isClicked ( const T & obj,
const sf::RenderWindow & window )
inlinestatic

Return true if the left mouse button is held over a framework object.

Delegates to isClicked(obj.getGlobalBounds(), window).

Template Parameters
TAny type with a getGlobalBounds() method returning sf::FloatRect.
Parameters
objThe object to test.
Window moduleThe render window used to map mouse coordinates.
Returns
true if the left button is down and the mouse is inside obj's bounds.

Definition at line 79 of file MouseEvents.h.

◆ isHovered() [1/2]

bool ml::MouseEvents::isHovered ( const sf::FloatRect & bounds,
const sf::RenderWindow & window )
static

Return true if the mouse is currently over a rect.

Maps sf::Mouse::getPosition(window) to world space via the window's current view, then tests containment against bounds.

Parameters
boundsThe rectangle to test in world coordinates.
Window moduleThe render window providing the view transform.
Returns
true if the mapped mouse position is inside bounds.

◆ isHovered() [2/2]

template<typename T>
bool ml::MouseEvents::isHovered ( const T & obj,
const sf::RenderWindow & window )
inlinestatic

Return true if the mouse is currently over a framework object.

Delegates to isHovered(obj.getGlobalBounds(), window).

Template Parameters
TAny type with a getGlobalBounds() method returning sf::FloatRect.
Parameters
objThe object to test.
Window moduleThe render window used to map mouse coordinates to world space.
Returns
true if the mouse position is inside obj's bounds.

Definition at line 49 of file MouseEvents.h.


The documentation for this class was generated from the following file: