Classes | Public Types | Public Member Functions | List of all members
ime::input::Joystick Class Reference

Give access to the state of the joysticks. More...

#include <Joystick.h>

Classes

struct  Identification
 Stores a joystick's identification. More...
 

Public Types

enum  { Count = 8 , ButtonCount = 32 , AxisCount = 8 }
 Joystick related constants. More...
 
enum class  Axis {
  X , Y , Z , R ,
  U , V , PovX , PovY
}
 Axes supported by IME joysticks. More...
 

Public Member Functions

 Joystick (unsigned int index)
 
bool isConnected () const
 Check if the joystick is connected or not. More...
 
void setEnable (bool enable)
 Enable or disable the joystick. More...
 
bool isEnabled () const
 Check if the joystick is enabled or not. More...
 
unsigned int getIndex () const
 Get the id of the joystick. More...
 
unsigned int getButtonCount () const
 Get the number of buttons supported by the joystick. More...
 
bool hasAxis (Axis axis) const
 Check if a joystick supports a given axis. More...
 
bool isButtonPressed (unsigned int button) const
 Check if a button is pressed or not. More...
 
float getAxisPosition (Axis axis) const
 Get the current position of an axis. More...
 
Identification getIdentification () const
 Get the joystick's identification information. More...
 
int onConnect (const Callback<> &callback)
 Add an event listener to a connection event. More...
 
int onDisconnect (const Callback<> &callback)
 Add an event listener to a disconnection event. More...
 
int onButtonPress (const Callback< unsigned int > &callback)
 Add an event listener to a button press event. More...
 
int onButtonRelease (const Callback< unsigned int > &callback)
 Add an event listener to button release event. More...
 
int onButtonHeld (const Callback< unsigned int > &callback)
 Add an event listener to button held event. More...
 
int onAxisMove (const Callback< Axis, float > &callback)
 Add an event listener to an axis move event. More...
 
bool unsubscribe (JoystickEvent event, int id)
 Remove an event listener from a joystick event. More...
 
void handleEvent (Event event)
 
void update ()
 

Detailed Description

Give access to the state of the joysticks.

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

Definition at line 53 of file Joystick.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Joystick related constants.

Enumerator
Count 

Maximum number of supported joysticks.

ButtonCount 

Maximum number of supported buttons.

AxisCount 

Maximum number of supported axes.

Definition at line 58 of file Joystick.h.

◆ Axis

enum class ime::input::Joystick::Axis
strong

Axes supported by IME joysticks.

Enumerator

The X axis.

The Y axis.

The Z axis.

The R axis.

The U axis.

The V axis.

PovX 

The X axis of the point-of-view hat.

PovY 

The Y axis of the point-of-view hat.

Definition at line 67 of file Joystick.h.

Member Function Documentation

◆ getAxisPosition()

float ime::input::Joystick::getAxisPosition ( Axis  axis) const

Get the current position of an axis.

Parameters
axisThe axis to get the position of
Returns
The current position of the axis, in range [-100 .. 100]

If the joystick is not connected, this function returns 0

This function checks the position in real time, unlike all the other function which are event-based

◆ getButtonCount()

unsigned int ime::input::Joystick::getButtonCount ( ) const

Get the number of buttons supported by the joystick.

Returns
The number of buttons supported by the joystick

If the joystick is not connected, this function returns 0.

◆ getIdentification()

Identification ime::input::Joystick::getIdentification ( ) const

Get the joystick's identification information.

Parameters
joystickIndex of the joystick
Returns
A joystick's identification information

◆ getIndex()

unsigned int ime::input::Joystick::getIndex ( ) const

Get the id of the joystick.

Returns
The id of the joystick

◆ hasAxis()

bool ime::input::Joystick::hasAxis ( Axis  axis) const

Check if a joystick supports a given axis.

Parameters
axisThe axis to be checked
Returns
True if the joystick supports the axis, otherwise false

If the joystick is not connected, this function returns false

◆ isButtonPressed()

bool ime::input::Joystick::isButtonPressed ( unsigned int  button) const

Check if a button is pressed or not.

Parameters
buttonButton to be checked
Returns
True if the button is pressed, otherwise false

If the joystick is not connected, this function returns false

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

◆ isConnected()

bool ime::input::Joystick::isConnected ( ) const

Check if the joystick is connected or not.

Returns
True if the joystick is connected, otherwise false

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

◆ isEnabled()

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

Check if the joystick is enabled or not.

Returns
True if enabled, otherwise false
See also
setEnabled

◆ onAxisMove()

int ime::input::Joystick::onAxisMove ( const Callback< Axis, float > &  callback)

Add an event listener to an axis move event.

Parameters
callbackThe function to be executed when an axis is moved
Returns
The event listeners identification number

The callback is passed the axis that was moved and its new position respectively

◆ onButtonHeld()

int ime::input::Joystick::onButtonHeld ( const Callback< unsigned int > &  callback)

Add an event listener to button held event.

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

The callback is passed the button that is held

Warning
This function is experimental
See also
onButtonPress, onButtonRelease

◆ onButtonPress()

int ime::input::Joystick::onButtonPress ( const Callback< unsigned int > &  callback)

Add an event listener to a button press event.

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

A button press event does not fire while the button is held down

The callback is passed the button that was pressed

See also
onButtonRelease, onButtonHeld

◆ onButtonRelease()

int ime::input::Joystick::onButtonRelease ( const Callback< unsigned int > &  callback)

Add an event listener to button release event.

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

The callback is passed the button that was released

See also
onButtonPress, onButtonHeld

◆ onConnect()

int ime::input::Joystick::onConnect ( const Callback<> &  callback)

Add an event listener to a connection event.

Parameters
callbackFunction to be executed when the joystick is connected
Returns
The event listeners identification number
Note
If the joystick is already connected by the time the Engine starts running, then this event will not be dispatched
See also
ime::Engine::run

◆ onDisconnect()

int ime::input::Joystick::onDisconnect ( const Callback<> &  callback)

Add an event listener to a disconnection event.

Parameters
callbackFunction to be executed when a joystick is disconnected
Returns
The event listeners identification number

◆ setEnable()

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

Enable or disable the joystick.

Parameters
enableTrue to enabled or false to disable

When disabled, the joystick will no longer generate button press, button release and axis move events. Connect and disconnect events are dispatched regardless of the 'enable' state of the joystick

By default the joystick is enabled

See also
isEnabled

◆ unsubscribe()

bool ime::input::Joystick::unsubscribe ( JoystickEvent  event,
int  id 
)

Remove an event listener from a joystick event.

Parameters
eventThe event to remove the event listener from
idThe event listeners identification number
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: