Captures mouse inputs from the user. More...
#include <Mouse.h>
Public Types | |
enum class | Button { Left , Right , Middle , XButton1 , XButton2 } |
Mouse buttons. More... | |
enum class | Wheel { VerticalWheel , HorizontalWheel } |
Mouse wheels. More... | |
Public Member Functions | |
void | setEnable (bool enable) |
Enable or disable the mouse. More... | |
bool | isEnabled () const |
Check if the mouse is enabled or not. More... | |
int | onButtonUp (Callback< Button, int, int > callback) |
Add an event listener to a mouse button up event. More... | |
int | onButtonUp (Callback< Button > callback) |
Add an event listener to a mouse button up event. More... | |
int | onButtonDown (Callback< Button, int, int > callback) |
Add an event listener to a mouse button up event. More... | |
int | onButtonDown (Callback< Button > callback) |
Add an event listener to a mouse button down event. More... | |
int | onMouseMove (Callback< int, int > callback) |
Add an event listener to a mouse move event. More... | |
int | onWheelScroll (Callback< Wheel, float, int, int > callback) |
Add an event listener to a mouse wheel scroll event. More... | |
bool | unsubscribe (MouseEvent event, int id) |
Remove an event listener from a mouse event. More... | |
void | handleEvent (Event event) |
Static Public Member Functions | |
static std::string | buttonToString (Button button) |
Convert an enum Button value to its string representation. More... | |
static Button | stringToButton (const std::string &button) |
Convert a string representation of a button to enum value. More... | |
static bool | isButtonPressed (Button button) |
Check if a mouse button is pressed or not. More... | |
static void | setPosition (const Vector2i &position) |
Set the current position of the mouse in desktop coordinates. More... | |
static Vector2i | getPosition () |
Get the current position of the mouse in desktop coordinates. More... | |
Captures mouse inputs from the user.
This class is not meant to be instantiated directly, use ime::Scene::getInput or ime::Engine::getInputManager
|
strong |
|
strong |
|
static |
Convert an enum Button value to its string representation.
button | The button to be converted |
The returned string is the same as the enum value, that is, if button is Button::Left then the function will return "Left"
|
static |
Get the current position of the mouse in desktop coordinates.
This function returns the global position of the mouse cursor on the desktop. To get the position of the mouse cursor relative to the game window, use ime::Window::getRelativeMousePosition
|
static |
Check if a mouse button is pressed or not.
button | Mouse button to be checked |
This function checks the state of a mouse button in real time, unlike all the other function which are event-based
bool ime::input::Mouse::isEnabled | ( | ) | const |
Check if the mouse is enabled or not.
Add an event listener to a mouse button down event.
callback | The function to be executed when the mouse button is depressed |
The callback is passed the button that was depressed
Add an event listener to a mouse button up event.
callback | The function to be executed when the event a mouse button is released |
The mouse button down event is fired when a mouse button is depressed. The callback is passed the button that was depressed and the coordinates of the mouse cursor when the button was depressed. The mouse cursor coordinates are relative to the game window
Add an event listener to a mouse button up event.
callback | The function to be executed when the mouse button is released |
The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released
Add an event listener to a mouse button up event.
callback | The function to be executed when the mouse button is released |
The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released and the coordinates of the mouse cursor when the button was released. The mouse cursor coordinates are relative to the game window
int ime::input::Mouse::onMouseMove | ( | Callback< int, int > | callback | ) |
Add an event listener to a mouse move event.
callback | Function to execute when the mouse moves |
The callback function will be passed the new position of the mouse cursor
Add an event listener to a mouse wheel scroll event.
callback | Function to be executed when the mouse wheel is scrolled |
The callback is passed the scrolled wheel and the wheel offset (positive is up/left, negative is down/right), and the mouse coordinates relative to the game window
void ime::input::Mouse::setEnable | ( | bool | enable | ) |
Enable or disable the mouse.
enable | True to enabled or false to disable |
When disabled, the mouse will no longer generate mouse up, down move and scroll events
By default the mouse is enabled
|
static |
Set the current position of the mouse in desktop coordinates.
position | New position of the mouse |
This function sets the global position of the mouse cursor on the desktop. To set the position of the mouse cursor relative to the game window, use ime::Window::setRelativeMousePosition
|
static |
Convert a string representation of a button to enum value.
button | The button to be converted |
The returned enum button value is the same as the string value, that is, if button is "Left" then the function will return Button::Left
bool ime::input::Mouse::unsubscribe | ( | MouseEvent | event, |
int | id | ||
) |
Remove an event listener from a mouse event.
event | The event to remove the event listener from |
id | The id of the event listener |