Cleanup sfSymbolName support and add them to the dynamic API functions

This commit is contained in:
Sam Lantinga 2021-11-07 11:16:48 -08:00
parent 149e5c656a
commit e14358265e
4 changed files with 58 additions and 116 deletions

View File

@ -936,7 +936,11 @@ extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecon
* *
* \param gamecontroller the controller to query * \param gamecontroller the controller to query
* \param button a button on the game controller * \param button a button on the game controller
* \returns the sfSymbolsName or NULL if the name can't be found
* *
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_GameControllerGetAppleSFSymbolsNameForAxis
*/ */
extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button); extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
@ -945,12 +949,15 @@ extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForBu
* *
* \param gamecontroller the controller to query * \param gamecontroller the controller to query
* \param button an axis on the game controller * \param button an axis on the game controller
* \returns the sfSymbolsName or NULL if the name can't be found
* *
* \since This function is available since SDL 2.0.18.
*
* \sa SDL_GameControllerGetAppleSFSymbolsNameForButton
*/ */
extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis); extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -825,3 +825,5 @@
#define SDL_GetWindowICCProfile SDL_GetWindowICCProfile_REAL #define SDL_GetWindowICCProfile SDL_GetWindowICCProfile_REAL
#define SDL_GetTicks64 SDL_GetTicks64_REAL #define SDL_GetTicks64 SDL_GetTicks64_REAL
#define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_REAL #define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_REAL
#define SDL_GameControllerGetAppleSFSymbolsNameForButton SDL_GameControllerGetAppleSFSymbolsNameForButton_REAL
#define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis_REAL

View File

@ -894,3 +894,5 @@ SDL_DYNAPI_PROC(Uint64,SDL_GetTicks64,(void),(),return)
#ifdef __LINUX__ #ifdef __LINUX__
SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return)
#endif #endif
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return)

View File

@ -652,7 +652,7 @@ IOS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
} }
static SDL_JoystickGUID static SDL_JoystickGUID
IOS_JoystickGetDeviceGUID( int device_index ) IOS_JoystickGetDeviceGUID(int device_index)
{ {
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
SDL_JoystickGUID guid; SDL_JoystickGUID guid;
@ -1576,8 +1576,7 @@ GetDirectionalPadForController(GCController *controller)
return nil; return nil;
} }
#endif #endif /* SDL_JOYSTICK_MFI && ENABLE_PHYSICAL_INPUT_PROFILE */
static char elementName[256]; static char elementName[256];
@ -1585,153 +1584,106 @@ const char *
SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button) SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
{ {
elementName[0] = '\0'; elementName[0] = '\0';
if (!gamecontroller) {
return elementName;
}
if (SDL_GameControllerGetJoystick(gamecontroller)->driver != &SDL_IOS_JoystickDriver) {
return elementName;
}
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE) #if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) { if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller; if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements; if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
switch (button) NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;
{ switch (button)
case SDL_CONTROLLER_BUTTON_INVALID: { {
break; case SDL_CONTROLLER_BUTTON_A:
}
case SDL_CONTROLLER_BUTTON_A: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonA], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonA], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_B:
case SDL_CONTROLLER_BUTTON_B: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonB], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonB], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_X:
case SDL_CONTROLLER_BUTTON_X: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonX], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonX], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_Y:
case SDL_CONTROLLER_BUTTON_Y: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonY], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonY], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_BACK:
case SDL_CONTROLLER_BUTTON_BACK: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonOptions], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonOptions], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_GUIDE:
case SDL_CONTROLLER_BUTTON_GUIDE: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonHome], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonHome], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_START:
case SDL_CONTROLLER_BUTTON_START: {
GetAppleSFSymbolsNameForElement(elements[GCInputButtonMenu], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputButtonMenu], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_LEFTSTICK:
case SDL_CONTROLLER_BUTTON_LEFTSTICK: {
GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstickButton], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstickButton], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
case SDL_CONTROLLER_BUTTON_RIGHTSTICK: {
GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstickButton], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstickButton], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: {
GetAppleSFSymbolsNameForElement(elements[GCInputLeftShoulder], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputLeftShoulder], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: {
GetAppleSFSymbolsNameForElement(elements[GCInputRightShoulder], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputRightShoulder], elementName);
break; break;
}
case SDL_CONTROLLER_BUTTON_DPAD_UP: { case SDL_CONTROLLER_BUTTON_DPAD_UP: {
GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller); GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller);
if (dpad) { if (dpad) {
GetAppleSFSymbolsNameForElement(dpad.up, elementName); GetAppleSFSymbolsNameForElement(dpad.up, elementName);
if (SDL_strlen(elementName) == 0) { if (SDL_strlen(elementName) == 0) {
SDL_strlcpy( elementName, "dpad.up.fill", 255 ); SDL_strlcpy(elementName, "dpad.up.fill", sizeof(elementName));
} }
} }
break; break;
} }
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: { case SDL_CONTROLLER_BUTTON_DPAD_DOWN: {
GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller); GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller);
if (dpad) { if (dpad) {
GetAppleSFSymbolsNameForElement(dpad.down, elementName); GetAppleSFSymbolsNameForElement(dpad.down, elementName);
if (SDL_strlen(elementName) == 0) { if (SDL_strlen(elementName) == 0) {
SDL_strlcpy( elementName, "dpad.down.fill", 255 ); SDL_strlcpy(elementName, "dpad.down.fill", sizeof(elementName));
} }
} }
break; break;
} }
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: { case SDL_CONTROLLER_BUTTON_DPAD_LEFT: {
GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller); GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller);
if (dpad) { if (dpad) {
GetAppleSFSymbolsNameForElement(dpad.left, elementName); GetAppleSFSymbolsNameForElement(dpad.left, elementName);
if (SDL_strlen(elementName) == 0) { if (SDL_strlen(elementName) == 0) {
SDL_strlcpy( elementName, "dpad.left.fill", 255 ); SDL_strlcpy(elementName, "dpad.left.fill", sizeof(elementName));
} }
} }
break; break;
} }
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: { case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: {
GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller); GCControllerDirectionPad * dpad = GetDirectionalPadForController(controller);
if (dpad) { if (dpad) {
GetAppleSFSymbolsNameForElement(dpad.right, elementName); GetAppleSFSymbolsNameForElement(dpad.right, elementName);
if (SDL_strlen(elementName) == 0) { if (SDL_strlen(elementName) == 0) {
SDL_strlcpy( elementName, "dpad.right.fill", 255 ); SDL_strlcpy(elementName, "dpad.right.fill", sizeof(elementName));
} }
} }
break; break;
} }
case SDL_CONTROLLER_BUTTON_MISC1:
case SDL_CONTROLLER_BUTTON_MISC1: {
GetAppleSFSymbolsNameForElement(elements[GCInputDualShockTouchpadButton], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputDualShockTouchpadButton], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_PADDLE1:
case SDL_CONTROLLER_BUTTON_PADDLE1: {
GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleOne], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleOne], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_PADDLE2:
case SDL_CONTROLLER_BUTTON_PADDLE2: {
GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleTwo], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleTwo], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_PADDLE3:
case SDL_CONTROLLER_BUTTON_PADDLE3: {
GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleThree], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleThree], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_PADDLE4:
case SDL_CONTROLLER_BUTTON_PADDLE4: {
GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleFour], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputXboxPaddleFour], elementName);
break; break;
} case SDL_CONTROLLER_BUTTON_TOUCHPAD:
case SDL_CONTROLLER_BUTTON_TOUCHPAD: {
GetAppleSFSymbolsNameForElement(elements[GCInputDualShockTouchpadButton], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputDualShockTouchpadButton], elementName);
break; break;
} default:
case SDL_CONTROLLER_BUTTON_MAX: {
break; break;
} }
} }
@ -1746,61 +1698,40 @@ const char *
SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis) SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
{ {
elementName[0] = '\0'; elementName[0] = '\0';
if (!gamecontroller) {
return elementName;
}
if (SDL_GameControllerGetJoystick(gamecontroller)->driver != &SDL_IOS_JoystickDriver) {
return elementName;
}
#if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE) #if defined(SDL_JOYSTICK_MFI) && defined(ENABLE_PHYSICAL_INPUT_PROFILE)
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) { if (gamecontroller && SDL_GameControllerGetJoystick(gamecontroller)->driver == &SDL_IOS_JoystickDriver) {
GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller; if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, *)) {
if ([controller respondsToSelector:@selector(physicalInputProfile)]) { GCController *controller = SDL_GameControllerGetJoystick(gamecontroller)->hwdata->controller;
NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements; if ([controller respondsToSelector:@selector(physicalInputProfile)]) {
switch (axis) NSDictionary<NSString *,GCControllerElement *> *elements = controller.physicalInputProfile.elements;
{ switch (axis)
{
case SDL_CONTROLLER_AXIS_INVALID: case SDL_CONTROLLER_AXIS_LEFTX:
break;
case SDL_CONTROLLER_AXIS_LEFTX:{
GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstick], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstick], elementName);
break; break;
} case SDL_CONTROLLER_AXIS_LEFTY:
case SDL_CONTROLLER_AXIS_LEFTY: {
GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstick], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputLeftThumbstick], elementName);
break; break;
} case SDL_CONTROLLER_AXIS_RIGHTX:
case SDL_CONTROLLER_AXIS_RIGHTX: {
GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstick], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstick], elementName);
break; break;
} case SDL_CONTROLLER_AXIS_RIGHTY:
case SDL_CONTROLLER_AXIS_RIGHTY: {
GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstick], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputRightThumbstick], elementName);
break; break;
} case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: {
GetAppleSFSymbolsNameForElement(elements[GCInputLeftTrigger], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputLeftTrigger], elementName);
break; break;
} case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: {
GetAppleSFSymbolsNameForElement(elements[GCInputRightTrigger], elementName); GetAppleSFSymbolsNameForElement(elements[GCInputRightTrigger], elementName);
break; break;
} default:
case SDL_CONTROLLER_AXIS_MAX: {
break; break;
} }
} }
} }
} }
#endif #endif
return elementName; return *elementName ? elementName : NULL;
} }