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 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...
 

Detailed Description

Captures mouse inputs from the user.

This class is not meant to be instantiated directly, use ime::Scene::getInput or ime::Engine::getInputManager

Definition at line 52 of file Mouse.h.

Member Enumeration Documentation

◆ Button

enum class ime::input::Mouse::Button
strong

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 57 of file Mouse.h.

◆ Wheel

enum class ime::input::Mouse::Wheel
strong

Mouse wheels.

Enumerator
VerticalWheel 

The vertical mouse wheel.

HorizontalWheel 

The horizontal mouse wheel.

Definition at line 68 of file Mouse.h.

Member Function Documentation

◆ buttonToString()

static std::string ime::input::Mouse::buttonToString ( Button  button)
static

Convert an enum Button value to its string representation.

Parameters
buttonThe button to be converted
Returns
The given button as a string

The returned string is the same as the enum value, that is, if button is Button::Left then the function will return "Left"

◆ getPosition()

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. To get the position of the mouse cursor relative to the game window, use ime::Window::getRelativeMousePosition

See also
setPosition

◆ 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

◆ isEnabled()

bool ime::input::Mouse::isEnabled ( ) const

Check if the mouse is enabled or not.

Returns
True if enabled, otherwise false
See also
setEnabled

◆ 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

◆ setEnable()

void ime::input::Mouse::setEnable ( bool  enable)

Enable or disable the mouse.

Parameters
enableTrue 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

See also
isEnabled

◆ setPosition()

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. To set the position of the mouse cursor relative to the game window, use ime::Window::setRelativeMousePosition

See also
getPosition

◆ stringToButton()

static Button ime::input::Mouse::stringToButton ( const std::string &  button)
static

Convert a string representation of a button to enum value.

Parameters
buttonThe button to be converted
Returns
The given key as an enum key value

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

Warning
If the given string is not convertible to an enum button value, them the program will exit with an error

◆ 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: