nomlib
Loading...
Searching...
No Matches
nom::Joystick Class Reference

SDL2 joystick interface. More...

#include <Joystick.hpp>

Public Types

enum  Axis : uint8 {
  AXIS_ZERO = 0 , AXIS_ONE , AXIS_TWO , AXIS_THREE ,
  AXIS_FOUR , AXIS_FIVE , AXIS_SIX , AXIS_SEVEN ,
  AXIS_EIGHT , AXIS_MAX
}
 Joystick axis definitions. More...
enum  Button : uint8 {
  BUTTON_ZERO = 0 , BUTTON_ONE , BUTTON_TWO , BUTTON_THREE ,
  BUTTON_FOUR , BUTTON_FIVE , BUTTON_SIX , BUTTON_SEVEN ,
  BUTTON_EIGHT , BUTTON_NINE , BUTTON_TEN , BUTTON_ELEVEN ,
  BUTTON_TWELVE , BUTTON_FOURTEEN , BUTTON_FIFTEEN , BUTTON_SIXTEEN ,
  BUTTON_MAX
}
 Joystick button definitions. More...
enum  Hat : uint8 {
  HAT_ZERO = 0 , HAT_ONE , HAT_TWO , HAT_THREE ,
  HAT_FOUR , HAT_MAX
}
 Joystick hat definitions. More...
enum  HatPosition : uint8 {
  HAT_CENTERED = 0x00 , HAT_UP = 0x01 , HAT_RIGHT = 0x02 , HAT_DOWN = 0x04 ,
  HAT_LEFT = 0x08 , HAT_RIGHTUP = (HAT_RIGHT | HAT_UP) , HAT_RIGHTDOWN = (HAT_RIGHT | HAT_DOWN) , HAT_LEFTUP = (HAT_LEFT | HAT_UP) ,
  HAT_LEFTDOWN = (HAT_LEFT | HAT_DOWN)
}
 Joystick hat position definitions. More...
typedef Joystick self_type

Public Member Functions

SDL_Joystick * device () const
 Get the underlying implementation pointer.
bool attached () const
 Get the status of the joystick.
JoystickID device_id () const
 Get the instance ID of an opened joystick.
std::string name () const
 Get the implementation-dependent name of the joystick.
bool open (JoystickIndex device_index)
 Open a joystick for use.
void close ()
 Close an opened joystick.
int num_axes ()
 Get the number of axes for this joystick.
int num_track_balls ()
 Get the number of track balls for this joystick.
int num_buttons ()
 Get the number of buttons for this joystick.
int num_hats ()
 Get the number of POV hats for this joystick.
JoystickGUID device_guid () const
 Get the implementation-dependent GUID for this joystick instance.
std::string device_guid_string () const
 Get the ASCII string representation of this joystick instance GUID.

Static Public Member Functions

static int set_event_state (int state)
 Toggle the joystick event polling state.
static void update ()
 Update the current state of the opened joysticks.
static int num_joysticks ()
 Get the number of joysticks attached to the system.
static std::string name (JoystickIndex device_index)
 Get the implementation-dependent name of the joystick.
static JoystickGUID device_guid (JoystickIndex device_index)
 Get the implementation-dependent GUID for a joystick.
static std::string device_guid_string (JoystickGUID guid)
 Get the ASCII string representation of a joystick GUID.
static JoystickID device_id (JoystickIndex device_index)
 Get the instance ID of a joystick device.

Private Types

typedef std::unique_ptr< SDL_Joystick, void(*)(SDL_Joystick *)> joystick_dev

Private Attributes

joystick_dev device_

Detailed Description

SDL2 joystick interface.

   [DESCRIPTION STUB]

Definition at line 83 of file Joystick.hpp.

Member Typedef Documentation

◆ joystick_dev

typedef std::unique_ptr<SDL_Joystick, void (*)(SDL_Joystick*)> nom::Joystick::joystick_dev
private

Definition at line 324 of file Joystick.hpp.

◆ self_type

typedef Joystick nom::Joystick::self_type

Definition at line 148 of file Joystick.hpp.

Member Enumeration Documentation

◆ Axis

enum nom::Joystick::Axis : uint8

Joystick axis definitions.

Definition at line 87 of file Joystick.hpp.

◆ Button

enum nom::Joystick::Button : uint8

Joystick button definitions.

Definition at line 102 of file Joystick.hpp.

◆ Hat

enum nom::Joystick::Hat : uint8

Joystick hat definitions.

Definition at line 124 of file Joystick.hpp.

◆ HatPosition

Joystick hat position definitions.

Definition at line 135 of file Joystick.hpp.

Member Function Documentation

◆ attached()

bool nom::Joystick::attached ( ) const

Get the status of the joystick.

Returns
Boolean TRUE if the joystick has been opened, and boolean FALSE if it has not been opened.

◆ close()

void nom::Joystick::close ( )

Close an opened joystick.

Remarks
This effectively frees the resources of the joystick.

◆ device()

SDL_Joystick * nom::Joystick::device ( ) const

Get the underlying implementation pointer.

Returns
A non-owned pointer to the underlying implementation.

◆ device_guid() [1/2]

JoystickGUID nom::Joystick::device_guid ( ) const

Get the implementation-dependent GUID for this joystick instance.

Returns
The GUID of the joystick on success, and a zero-length GUID on failure, such as when the device state is invalid.
Remarks
This function requires an opened joystick.
See also
Joystick::attached

◆ device_guid() [2/2]

JoystickGUID nom::Joystick::device_guid ( JoystickIndex device_index)
static

Get the implementation-dependent GUID for a joystick.

Parameters
device_indexThe index of the joystick device, as recognized by SDL.
Returns
The GUID of the joystick on success, and a zero-length GUID on failure, such as when an invalid index is passed.
Remarks
This function can be called before any joysticks are accessed.
See also
Joystick::num_joysticks

◆ device_guid_string() [1/2]

std::string nom::Joystick::device_guid_string ( ) const

Get the ASCII string representation of this joystick instance GUID.

Returns
The GUID string of the joystick on success, and a zero-length GUID on failure, such as when the device state is invalid.
Remarks
This function requires an opened joystick.
See also
Joystick::attached

◆ device_guid_string() [2/2]

std::string nom::Joystick::device_guid_string ( JoystickGUID guid)
static

Get the ASCII string representation of a joystick GUID.

Returns
The GUID string of the joystick on success, and a zero-length GUID on failure, such as when an invalid GUID has been passed.
Remarks
This function can be called before any joysticks are accessed.

◆ device_id() [1/2]

JoystickID nom::Joystick::device_id ( ) const

Get the instance ID of an opened joystick.

Returns
The device instance ID for the joystick device on success, and a negative error code on failure.

◆ device_id() [2/2]

JoystickID nom::Joystick::device_id ( JoystickIndex device_index)
static

Get the instance ID of a joystick device.

Parameters
device_indexThe index of the joystick device, as recognized by SDL.
Returns
The device instance ID for the joystick device on success, and a negative error code on failure.
Remarks
This function can be called before any joysticks are accessed.
See also
Joystick::num_joysticks

◆ name() [1/2]

std::string nom::Joystick::name ( ) const

Get the implementation-dependent name of the joystick.

Returns
The name of the joystick on success, and a null-terminated string on failure, such as an invalid device state.

◆ name() [2/2]

std::string nom::Joystick::name ( JoystickIndex device_index)
static

Get the implementation-dependent name of the joystick.

Parameters
device_indexThe index of the joystick device, as recognized by SDL.
Returns
The name of the indexed joystick on success, and a zero-length string on failure, such as when no name for the device index can be found.
Remarks
This function can be called before any joysticks are accessed.
See also
Joystick::num_joysticks

◆ num_axes()

int nom::Joystick::num_axes ( )

Get the number of axes for this joystick.

Returns
The number of axes on success, and a negative error code on failure.
Remarks
This function requires an opened joystick.

◆ num_buttons()

int nom::Joystick::num_buttons ( )

Get the number of buttons for this joystick.

Returns
The number of buttons on success, and a negative error code on failure.
Remarks
This function requires an opened joystick.

◆ num_hats()

int nom::Joystick::num_hats ( )

Get the number of POV hats for this joystick.

Returns
The number of POV hats on success, and a negative error code on failure.
Remarks
This function requires an opened joystick.

◆ num_joysticks()

int nom::Joystick::num_joysticks ( )
static

Get the number of joysticks attached to the system.

Returns
The number of attached joysticks on success, and a negative error code on failure.

◆ num_track_balls()

int nom::Joystick::num_track_balls ( )

Get the number of track balls for this joystick.

Returns
The number of track balls on success, and a negative error code on failure.
Remarks
This function requires an opened joystick.

◆ open()

bool nom::Joystick::open ( JoystickIndex device_index)

Open a joystick for use.

Parameters
device_indexThe device index of the joystick as recognized by SDL.
Remarks
The device index is not the same as the instance ID of the joystick, which is used to identify the joystick in future events.
See also
Joystick::num_joysticks

◆ set_event_state()

int nom::Joystick::set_event_state ( int state)
static

Toggle the joystick event polling state.

Parameters
stateOne of the following: SDL_QUERY, SDL_IGNORE or SDL_ENABLE.
Returns
One (1) if enabled, zero (0) if disabled and a negative error code on failure. If the state was SDL_QUERY, then the current state is returned, otherwise the new processing state is returned.
Remarks
If joystick events are disabled, you must call Joystick::update and manually check the state of the joystick when event data is needed.
Note
Calling this method may delete all events currently in SDL's event queue.

◆ update()

void nom::Joystick::update ( )
static

Update the current state of the opened joysticks.

Remarks
This method is automatically called by the internal event loop of SDL if any joystick events are enabled.

Member Data Documentation

◆ device_

joystick_dev nom::Joystick::device_
private

Definition at line 326 of file Joystick.hpp.


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