mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-21 04:08:27 +00:00
Automatically assign player indexes to game controllers, and allow changing the player index for game controllers and joysticks.
Added the functions SDL_JoystickFromPlayerIndex(), SDL_JoystickSetPlayerIndex(), SDL_GameControllerFromPlayerIndex(), and SDL_GameControllerSetPlayerIndex()
This commit is contained in:
parent
f050309ee9
commit
46e1377d49
26 changed files with 405 additions and 67 deletions
|
@ -1765,6 +1765,15 @@ SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
|
|||
return SDL_JoystickGetPlayerIndex(SDL_GameControllerGetJoystick(gamecontroller));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the player index of an opened game controller
|
||||
*/
|
||||
void
|
||||
SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index)
|
||||
{
|
||||
SDL_JoystickSetPlayerIndex(SDL_GameControllerGetJoystick(gamecontroller), player_index);
|
||||
}
|
||||
|
||||
Uint16
|
||||
SDL_GameControllerGetVendor(SDL_GameController * gamecontroller)
|
||||
{
|
||||
|
@ -1809,7 +1818,7 @@ SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
|
|||
|
||||
|
||||
/*
|
||||
* Find the SDL_GameController that owns this instance id
|
||||
* Return the SDL_GameController associated with an instance id.
|
||||
*/
|
||||
SDL_GameController *
|
||||
SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
|
||||
|
@ -1830,6 +1839,19 @@ SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the SDL_GameController associated with a player index.
|
||||
*/
|
||||
SDL_GameController *SDL_GameControllerFromPlayerIndex(int player_index)
|
||||
{
|
||||
SDL_Joystick *joystick = SDL_JoystickFromPlayerIndex(player_index);
|
||||
if (joystick) {
|
||||
return SDL_GameControllerFromInstanceID(joystick->instance_id);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the SDL joystick layer binding for this controller axis mapping
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue