Public Types | Public Member Functions | Static Public Member Functions | List of all members
ime::input::Mouse Class Reference

Captures mouse inputs from the user. More...

#include <Mouse.h>

Public Types

enum  Button {
  Button::Left, Button::Right, Button::Middle, Button::XButton1,
  Button::XButton2
}
 Mouse buttons. More...
 
enum  Wheel { Wheel::VerticalWheel, Wheel::HorizontalWheel }
 Mouse wheels. More...
 

Public Member Functions

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)
 Handle a system event. More...
 

Static Public Member Functions

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...
 
static void setPosition (const Vector2i &position, const Window &window)
 Set the current position of the mouse in window coordinates. More...
 
static Vector2i getPosition (const Window &window)
 Get the current position of the mouse in window coordinates. More...
 

Detailed Description

Captures mouse inputs from the user.

You usually don't instantiate this class directly, you either use the input manager that is local to a Scene or the global input manager that from the Engine class

Definition at line 54 of file Mouse.h.

Member Enumeration Documentation

◆ Button

Mouse buttons.

Enumerator
Left 

The left mouse button.

Right 

The right mouse button.

Middle 

The middle (wheel) mouse button.

XButton1 

The first extra mouse button.

XButton2 

The second extra mouse button.

Definition at line 59 of file Mouse.h.

◆ Wheel

Mouse wheels.

Enumerator
VerticalWheel 

The vertical mouse wheel.

HorizontalWheel 

The horizontal mouse wheel.

Definition at line 70 of file Mouse.h.

Member Function Documentation

◆ getPosition() [1/2]

static Vector2i ime::input::Mouse::getPosition ( )
static

Get the current position of the mouse in desktop coordinates.

Returns
The current position of the mouse

This function returns the global position of the mouse cursor on the desktop.

◆ getPosition() [2/2]

static Vector2i ime::input::Mouse::getPosition ( const Window window)
static

Get the current position of the mouse in window coordinates.

Parameters
windowReference window
Returns
The current position of the mouse

This function returns the current position of the mouse cursor, relative to the given window

◆ handleEvent()

void ime::input::Mouse::handleEvent ( Event  event)

Handle a system event.

Parameters
eventEvent to be handled

◆ isButtonPressed()

static bool ime::input::Mouse::isButtonPressed ( Button  button)
static

Check if a mouse button is pressed or not.

Parameters
buttonMouse button to be checked
Returns
True if a mouse button is pressed, otherwise false

This function checks the state of a mouse button in real time, unlike all the other function which are event-based

◆ onButtonDown() [1/2]

int ime::input::Mouse::onButtonDown ( Callback< Button callback)

Add an event listener to a mouse button down event.

Parameters
callbackThe function to be executed when the mouse button is depressed
Returns
The event listeners identification number

The callback is passed the button that was depressed

Note
This event does Not fire repetitively while the mouse button is depressed

◆ onButtonDown() [2/2]

int ime::input::Mouse::onButtonDown ( Callback< Button, int, int >  callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the event a mouse button is released
Returns
The event listeners identification number

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

Note
This event does Not fire repetitively while the mouse button is depressed

◆ onButtonUp() [1/2]

int ime::input::Mouse::onButtonUp ( Callback< Button callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the mouse button is released
Returns
The event listeners identification number

The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released

◆ onButtonUp() [2/2]

int ime::input::Mouse::onButtonUp ( Callback< Button, int, int >  callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the mouse button is released
Returns
The event listeners identification number

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

◆ onMouseMove()

int ime::input::Mouse::onMouseMove ( Callback< int, int >  callback)

Add an event listener to a mouse move event.

Parameters
callbackFunction to execute when the mouse moves
Returns
The event listeners identification number

The callback function will be passed the new position of the mouse cursor

◆ onWheelScroll()

int ime::input::Mouse::onWheelScroll ( Callback< Wheel, float, int, int >  callback)

Add an event listener to a mouse wheel scroll event.

Parameters
callbackFunction to be executed when the mouse wheel is scrolled
Returns
The event listeners identification number

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

◆ setPosition() [1/2]

static void ime::input::Mouse::setPosition ( const Vector2i position)
static

Set the current position of the mouse in desktop coordinates.

Parameters
positionNew position of the mouse

This function sets the global position of the mouse cursor on the desktop

◆ setPosition() [2/2]

static void ime::input::Mouse::setPosition ( const Vector2i position,
const Window window 
)
static

Set the current position of the mouse in window coordinates.

Parameters
positionNew position of the mouse
windowReference window

This function sets the current position of the mouse cursor, relative to the given window

◆ unsubscribe()

bool ime::input::Mouse::unsubscribe ( MouseEvent  event,
int  id 
)

Remove an event listener from a mouse event.

Parameters
eventThe event to remove the event listener from
idThe id of the event listener
Returns
True if the event listener was removed or false if the given event does not have the specified event listener

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