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

SDL2 game controller interface. More...

#include <GameController.hpp>

Public Types

enum  Axis : int8 {
  AXIS_INVALID = -1 , AXIS_LEFT_X , AXIS_LEFT_Y , AXIS_RIGHT_X ,
  AXIS_RIGHT_Y , AXIS_TRIGGER_LEFT , AXIS_TRIGGER_RIGHT , AXIS_MAX
}
 Game controller axis definitions. More...
enum  Button : int8 {
  BUTTON_INVALID = -1 , BUTTON_A , BUTTON_B , BUTTON_X ,
  BUTTON_Y , BUTTON_BACK , BUTTON_GUIDE , BUTTON_START ,
  BUTTON_LEFT_STICK , BUTTON_RIGHT_STICK , BUTTON_LEFT_SHOULDER , BUTTON_RIGHT_SHOULDER ,
  BUTTON_DPAD_UP , BUTTON_DPAD_DOWN , BUTTON_DPAD_LEFT , BUTTON_DPAD_RIGHT ,
  BUTTON_MAX = SDL_CONTROLLER_BUTTON_MAX
}
 Game controller button definitions. More...
typedef GameController 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 game controller.
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.
std::string mapping_string ()

Static Public Member Functions

static NOM_EXPORT std::string name (JoystickIndex device_index)
 Get the implementation-dependent name of the joystick.
static NOM_EXPORT int set_event_state (int state)
 Toggle the game controller's event polling state.
static NOM_EXPORT void update ()
 Update the current state of the opened game controllers.
static NOM_EXPORT std::string mapping_string (JoystickGUID guid)
static NOM_EXPORT int load_mapping_memory (const char *buffer, int buffer_size)
static NOM_EXPORT int load_mapping_file (const std::string &filename)
static NOM_EXPORT int load_mapping_string (const std::string &mapping)
static NOM_EXPORT JoystickID device_id (JoystickIndex device_index)
 Get the instance ID of a joystick device.
static NOM_EXPORT bool compatible_joystick (JoystickIndex device_index)
 Check to see if the joystick is supported by SDL's game controller interface.

Static Public Attributes

static NOM_EXPORT bool device_closed_

Private Types

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

Private Attributes

joystick_dev device_

Detailed Description

SDL2 game controller interface.

   [DESCRIPTION STUB]

Definition at line 56 of file GameController.hpp.

Member Typedef Documentation

◆ joystick_dev

typedef std::unique_ptr<SDL_GameController, void (*)(SDL_GameController*)> nom::GameController::joystick_dev
private

Definition at line 215 of file GameController.hpp.

◆ self_type

typedef GameController nom::GameController::self_type

Definition at line 101 of file GameController.hpp.

Member Enumeration Documentation

◆ Axis

Game controller axis definitions.

Definition at line 60 of file GameController.hpp.

◆ Button

Game controller button definitions.

Definition at line 73 of file GameController.hpp.

Member Function Documentation

◆ attached()

bool nom::GameController::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::GameController::close ( )

Close an opened joystick.

Remarks
This effectively frees the resources of the joystick.

◆ device()

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

Get the underlying implementation pointer.

Returns
A non-owned pointer to the underlying implementation.

◆ device_id() [1/2]

JoystickID nom::GameController::device_id ( ) const

Get the instance ID of an opened game controller.

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

◆ device_id() [2/2]

NOM_EXPORT JoystickID nom::GameController::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

◆ load_mapping_file()

NOM_EXPORT int nom::GameController::load_mapping_file ( const std::string & filename)
static
Todo
This function call leaks memory from within SDL!

◆ load_mapping_memory()

NOM_EXPORT int nom::GameController::load_mapping_memory ( const char * buffer,
int buffer_size )
static
Todo
Implement this function

◆ mapping_string()

NOM_EXPORT std::string nom::GameController::mapping_string ( JoystickGUID guid)
static
Remarks
This function can be called before any joysticks are accessed.

◆ name() [1/2]

std::string nom::GameController::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]

NOM_EXPORT std::string nom::GameController::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

◆ open()

bool nom::GameController::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()

NOM_EXPORT int nom::GameController::set_event_state ( int state)
static

Toggle the game controller's event polling state.

Parameters
stateOne of the following: SDL_QUERY, SDL_IGNORE or SDL_ENABLE.
Returns
One (1) if enabled, zero (0) if disabled or 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 game controller events are disabled, you must call GameController::update and manually check the state of the joystick when event data is needed.
Note
This does not disable the underlying joystick events.
See also
Joystick::set_event_state

◆ update()

NOM_EXPORT void nom::GameController::update ( )
static

Update the current state of the opened game controllers.

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::GameController::device_
private

Definition at line 217 of file GameController.hpp.

◆ device_closed_

NOM_EXPORT bool nom::GameController::device_closed_
static

Definition at line 99 of file GameController.hpp.


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