Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
add new gamecontroller APIs
Browse files Browse the repository at this point in the history
- add mappings after init (or even before w/o using the hint)
- get string for axis
- get string for button
- get mapping string for controller or for GUID
- new event to notify when a controller is remapped. (e.g. mapping was changed via the AddMapping method)
  • Loading branch information
urkle committed Mar 5, 2013
1 parent 6e6ce9e commit 1d9f710
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 131 deletions.
7 changes: 4 additions & 3 deletions include/SDL_events.h
Expand Up @@ -100,6 +100,7 @@ typedef enum
SDL_CONTROLLERBUTTONUP, /**< Game controller button released */
SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */
SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */
SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */

/* Touch events */
SDL_FINGERDOWN = 0x700,
Expand Down Expand Up @@ -358,9 +359,9 @@ typedef struct SDL_ControllerButtonEvent
*/
typedef struct SDL_ControllerDeviceEvent
{
Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */
Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
Uint32 timestamp;
Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
Uint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
} SDL_ControllerDeviceEvent;


Expand Down Expand Up @@ -484,7 +485,7 @@ typedef union SDL_Event
SDL_JoyHatEvent jhat; /**< Joystick hat event data */
SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
SDL_ControllerAxisEvent caxis; /**< Game Controller button event data */
SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */
SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */
SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */
SDL_QuitEvent quit; /**< Quit request event data */
Expand Down
31 changes: 30 additions & 1 deletion include/SDL_gamecontroller.h
Expand Up @@ -90,7 +90,7 @@ typedef struct SDL_GameControllerButtonBind
* }
* }
*
* Using the SDL_HINT_GAMECONTROLLERCONFIG hint you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
* Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
* guid,name,mappings
*
* Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
Expand All @@ -106,6 +106,26 @@ typedef struct SDL_GameControllerButtonBind
*
*/

/**
* Add or update an existing mapping configuration
*
* \return 1 if mapping is added, 0 if updated, -1 on error
*/
extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping( const char* mappingSring );

/**
* Get a mapping string for a GUID
*
* \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
*/
extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid );

/**
* Get a mapping string for an open GameController
*
* \return the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
*/
extern DECLSPEC char * SDLCALL SDL_GameControllerMapping( SDL_GameController * gamecontroller );

/**
* Is the joystick on this index supported by the game controller interface?
Expand Down Expand Up @@ -186,6 +206,11 @@ typedef enum
*/
extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);

/**
* turn this axis enum into a string mapping
*/
extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);

/**
* Get the SDL joystick layer binding for this controller button mapping
*/
Expand Down Expand Up @@ -233,6 +258,10 @@ typedef enum
*/
extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);

/**
* turn this button enum into a string mapping
*/
extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);

/**
* Get the SDL joystick layer binding for this controller button mapping
Expand Down

0 comments on commit 1d9f710

Please sign in to comment.