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

Commit

Permalink
Changed the game controller enum types to match SDL naming conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 25, 2013
1 parent 8e6e234 commit 1802193
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions include/SDL_events.h
Expand Up @@ -314,7 +314,7 @@ typedef struct SDL_ControllerAxisEvent
Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */
Uint32 timestamp;
Uint8 which; /**< The joystick instance id */
SDL_CONTROLLER_AXIS axis; /**< The joystick axis index */
SDL_GameControllerAxis axis; /**< The joystick axis index */
int value; /**< The axis value (range: -32768 to 32767) */
} SDL_ControllerAxisEvent;

Expand All @@ -327,7 +327,7 @@ typedef struct SDL_ControllerButtonEvent
Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
Uint32 timestamp;
Uint8 which; /**< The joystick instance id */
SDL_CONTROLLER_BUTTON button; /**< The joystick button index */
SDL_GameControllerButton button; /**< The joystick button index */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
} SDL_ControllerButtonEvent;

Expand Down
21 changes: 11 additions & 10 deletions include/SDL_gamecontroller.h
Expand Up @@ -59,7 +59,8 @@ typedef enum
SDL_CONTROLLER_BINDTYPE_BUTTON,
SDL_CONTROLLER_BINDTYPE_AXIS,
SDL_CONTROLLER_BINDTYPE_HAT
} SDL_CONTROLLER_BINDTYPE;
} SDL_GameControllerBindType;

/**
* get the sdl joystick layer binding for this controller button/axis mapping
*/
Expand All @@ -71,7 +72,7 @@ struct _SDL_GameControllerHatBind

typedef struct _SDL_GameControllerButtonBind
{
SDL_CONTROLLER_BINDTYPE m_eBindType;
SDL_GameControllerBindType m_eBindType;
union
{
int button;
Expand Down Expand Up @@ -172,19 +173,19 @@ typedef enum
SDL_CONTROLLER_AXIS_TRIGGERLEFT,
SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
SDL_CONTROLLER_AXIS_MAX
} SDL_CONTROLLER_AXIS;
} SDL_GameControllerAxis;

/**
* turn this string into a axis mapping
*/
extern DECLSPEC SDL_CONTROLLER_AXIS SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);

/**
* get the sdl joystick layer binding for this controller button mapping
*/
extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
SDL_CONTROLLER_AXIS button);
SDL_GameControllerAxis axis);

/**
* Get the current state of an axis control on a game controller.
Expand All @@ -195,7 +196,7 @@ SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
*/
extern DECLSPEC Sint16 SDLCALL
SDL_GameControllerGetAxis(SDL_GameController *gamecontroller,
SDL_CONTROLLER_AXIS axis);
SDL_GameControllerAxis axis);

/**
* The list of buttons available from a controller
Expand All @@ -219,20 +220,20 @@ typedef enum
SDL_CONTROLLER_BUTTON_DPAD_LEFT,
SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
SDL_CONTROLLER_BUTTON_MAX
} SDL_CONTROLLER_BUTTON;
} SDL_GameControllerButton;

/**
* turn this string into a button mapping
*/
extern DECLSPEC SDL_CONTROLLER_BUTTON SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);


/**
* get the sdl joystick layer binding for this controller button mapping
*/
extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
SDL_CONTROLLER_BUTTON button);
SDL_GameControllerButton button);


/**
Expand All @@ -241,7 +242,7 @@ SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
* The button indices start at index 0.
*/
extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
SDL_CONTROLLER_BUTTON button);
SDL_GameControllerButton button);

/**
* Close a controller previously opened with SDL_GameControllerOpen().
Expand Down
34 changes: 17 additions & 17 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -64,12 +64,12 @@ struct _SDL_ControllerMapping
struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX];

// reverse mapping, joystick indices to buttons
SDL_CONTROLLER_AXIS raxes[k_nMaxReverseEntries];
SDL_CONTROLLER_AXIS rbuttonasaxis[k_nMaxReverseEntries];
SDL_GameControllerAxis raxes[k_nMaxReverseEntries];
SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries];

SDL_CONTROLLER_BUTTON rbuttons[k_nMaxReverseEntries];
SDL_CONTROLLER_BUTTON raxesasbutton[k_nMaxReverseEntries];
SDL_CONTROLLER_BUTTON rhatasbutton[k_nMaxHatEntries];
SDL_GameControllerButton rbuttons[k_nMaxReverseEntries];
SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries];
SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries];

};

Expand Down Expand Up @@ -118,8 +118,8 @@ struct _SDL_GameController
};


int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value);
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state);
int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);

/*
* Event filter to fire controller events from joystick ones
Expand Down Expand Up @@ -296,7 +296,7 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
/*
* convert a string to its enum equivalent
*/
SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString )
SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString )
{
if ( !pchString || !pchString[0] )
return SDL_CONTROLLER_AXIS_INVALID;
Expand All @@ -321,7 +321,7 @@ SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString )
/*
* convert a string to its enum equivalent
*/
SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchString )
SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString )
{
if ( !pchString || !pchString[0] )
return SDL_CONTROLLER_BUTTON_INVALID;
Expand Down Expand Up @@ -367,8 +367,8 @@ SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchStri
void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping )
{
int iSDLButton = 0;
SDL_CONTROLLER_BUTTON button;
SDL_CONTROLLER_AXIS axis;
SDL_GameControllerButton button;
SDL_GameControllerAxis axis;
button = SDL_GameControllerGetButtonFromString( szGameButton );
axis = SDL_GameControllerGetAxisFromString( szGameButton );
iSDLButton = SDL_atoi( &szJoystickButton[1] );
Expand Down Expand Up @@ -829,7 +829,7 @@ SDL_GameControllerOpen(int device_index)
* Get the current state of an axis control on a controller
*/
Sint16
SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis)
SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
{
if ( !gamecontroller )
return 0;
Expand All @@ -854,7 +854,7 @@ SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AX
* Get the current state of a button on a controller
*/
Uint8
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button)
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
{
if ( !gamecontroller )
return 0;
Expand Down Expand Up @@ -925,7 +925,7 @@ SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
/**
* get the sdl joystick layer binding for this controller axi mapping
*/
SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis )
SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
{
SDL_GameControllerButtonBind bind;
SDL_memset( &bind, 0x0, sizeof(bind) );
Expand All @@ -951,7 +951,7 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameControlle
/**
* get the sdl joystick layer binding for this controller button mapping
*/
SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button )
SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
{
SDL_GameControllerButtonBind bind;
SDL_memset( &bind, 0x0, sizeof(bind) );
Expand Down Expand Up @@ -1053,7 +1053,7 @@ SDL_GameControllerQuit(void)
* Event filter to transform joystick events into appropriate game controller ones
*/
int
SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value)
SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value)
{
int posted;

Expand All @@ -1077,7 +1077,7 @@ SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLE
* Event filter to transform joystick events into appropriate game controller ones
*/
int
SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state)
SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state)
{
int posted;
#if !SDL_EVENTS_DISABLED
Expand Down
4 changes: 2 additions & 2 deletions test/testgamecontroller.c
Expand Up @@ -41,7 +41,7 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
}

static const char *
ControllerAxisName(const SDL_CONTROLLER_AXIS axis)
ControllerAxisName(const SDL_GameControllerAxis axis)
{
switch (axis)
{
Expand All @@ -59,7 +59,7 @@ ControllerAxisName(const SDL_CONTROLLER_AXIS axis)
}

static const char *
ControllerButtonName(const SDL_CONTROLLER_BUTTON button)
ControllerButtonName(const SDL_GameControllerButton button)
{
switch (button)
{
Expand Down

0 comments on commit 1802193

Please sign in to comment.