CODE
/* The SDL joystick structure */
struct _SDL_Joystick {
Uint8 index; /* Device index */
const char *name; /* Joystick name - system dependent */
int naxes; /* Number of axis controls on the joystick */
Sint16 *axes; /* Current axis states */
int nhats; /* Number of hats on the joystick */
Uint8 *hats; /* Current hat states */
int nballs; /* Number of trackballs on the joystick */
struct balldelta {
int dx;
int dy;
} *balls; /* Current ball motion deltas */
int nbuttons; /* Number of buttons on the joystick */
Uint8 *buttons; /* Current button states */
struct joystick_hwdata *hwdata; /* Driver dependent information */
int ref_count; /* Reference count for multiple opens */
};
CODE
typedef struct GamePad
{
// The following members are inherited from XINPUT_GAMEPAD:
WORD wButtons;
BYTE bAnalogButtons[8];
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
// Thumb stick values converted to range [-1,+1]
FLOAT fX1;
FLOAT fY1;
FLOAT fX2;
FLOAT fY2;
// State of buttons tracked since last poll
WORD wLastButtons;
BOOL bLastAnalogButtons[8];
WORD wPressedButtons;
BOOL bPressedAnalogButtons[8];
// Rumble properties
XINPUT_RUMBLE Rumble;
XINPUT_FEEDBACK Feedback;
// Device properties
XINPUT_CAPABILITIES caps;
HANDLE hDevice;
// Flags for whether game pad was just inserted or removed
BOOL bInserted;
BOOL bRemoved;
} XBGAMEPAD;
CODE
// Get the analog buttons that have been pressed or released since
// the last call.
for( b=0; b<8; b++ )
{
// Turn the 8-bit polled value into a boolean value
BOOL bPressed = ( joystick->hwdata->pGamepads.bAnalogButtons > XINPUT_GAMEPAD_MAX_CROSSTALK );
if( bPressed )
joystick->hwdata->pGamepads.bAnalogButtons = !joystick->hwdata->pGamepads.bLastAnalogButtons;
else
joystick->hwdata->pGamepads.bAnalogButtons = FALSE;
// Store the current state for the next time
joystick->hwdata->pGamepads.bLastAnalogButtons = bPressed;
if ( bPressed ) {
if ( !joystick->buttons ) {
SDL_PrivateJoystickButton(joystick, (Uint8)b, SDL_PRESSED);
}
} else {
if ( joystick->buttons ) {
SDL_PrivateJoystickButton(joystick, (Uint8)b, SDL_RELEASED);
}
}
}