mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-27 23:19:11 +00:00
Added SDL_GetGamepadPowerLevel() to get the power level directly from a gamepad
This commit is contained in:
parent
9885f4d245
commit
2e3404db01
6 changed files with 26 additions and 1 deletions
|
@ -623,6 +623,18 @@ extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepa
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
|
extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the battery level of a gamepad, if available.
|
||||||
|
*
|
||||||
|
* \param gamepad a gamepad identifier previously returned by
|
||||||
|
* SDL_OpenGamepad()
|
||||||
|
* \returns the current battery level as SDL_JoystickPowerLevel on success or
|
||||||
|
* `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*/
|
||||||
|
extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a gamepad has been opened and is currently connected.
|
* Check if a gamepad has been opened and is currently connected.
|
||||||
*
|
*
|
||||||
|
|
|
@ -870,6 +870,7 @@ SDL3_0.0.0 {
|
||||||
SDL_wcstol;
|
SDL_wcstol;
|
||||||
SDL_ClearClipboardData;
|
SDL_ClearClipboardData;
|
||||||
SDL_GetGamepadInstanceID;
|
SDL_GetGamepadInstanceID;
|
||||||
|
SDL_GetGamepadPowerLevel;
|
||||||
# extra symbols go here (don't modify this line)
|
# extra symbols go here (don't modify this line)
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
|
|
@ -896,3 +896,4 @@
|
||||||
/* New API symbols are added at the end */
|
/* New API symbols are added at the end */
|
||||||
#define SDL_ClearClipboardData SDL_ClearClipboardData_REAL
|
#define SDL_ClearClipboardData SDL_ClearClipboardData_REAL
|
||||||
#define SDL_GetGamepadInstanceID SDL_GetGamepadInstanceID_REAL
|
#define SDL_GetGamepadInstanceID SDL_GetGamepadInstanceID_REAL
|
||||||
|
#define SDL_GetGamepadPowerLevel SDL_GetGamepadPowerLevel_REAL
|
||||||
|
|
|
@ -941,3 +941,4 @@ SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),r
|
||||||
/* New API symbols are added at the end */
|
/* New API symbols are added at the end */
|
||||||
SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return)
|
SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadInstanceID,(SDL_Gamepad *a),(a),return)
|
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadInstanceID,(SDL_Gamepad *a),(a),return)
|
||||||
|
SDL_DYNAPI_PROC(SDL_JoystickPowerLevel,SDL_GetGamepadPowerLevel,(SDL_Gamepad *a),(a),return)
|
||||||
|
|
|
@ -2778,6 +2778,16 @@ const char * SDL_GetGamepadSerial(SDL_Gamepad *gamepad)
|
||||||
return SDL_GetJoystickSerial(joystick);
|
return SDL_GetJoystickSerial(joystick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_JoystickPowerLevel SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad)
|
||||||
|
{
|
||||||
|
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
|
||||||
|
|
||||||
|
if (joystick == NULL) {
|
||||||
|
return SDL_JOYSTICK_POWER_UNKNOWN;
|
||||||
|
}
|
||||||
|
return SDL_GetJoystickPowerLevel(joystick);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return if the gamepad in question is currently attached to the system,
|
* Return if the gamepad in question is currently attached to the system,
|
||||||
* \return 0 if not plugged in, 1 if still present.
|
* \return 0 if not plugged in, 1 if still present.
|
||||||
|
|
|
@ -389,7 +389,7 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->battery_level = SDL_GetJoystickPowerLevel(SDL_GetGamepadJoystick(gamepad));
|
ctx->battery_level = SDL_GetGamepadPowerLevel(gamepad);
|
||||||
|
|
||||||
if (SDL_GetNumGamepadTouchpads(gamepad) > 0) {
|
if (SDL_GetNumGamepadTouchpads(gamepad) > 0) {
|
||||||
int num_fingers = SDL_GetNumGamepadTouchpadFingers(gamepad, 0);
|
int num_fingers = SDL_GetNumGamepadTouchpadFingers(gamepad, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue