Putting the simple back into Simple DirectMedia Layer

This commit is contained in:
Sam Lantinga 2024-08-05 20:58:41 -07:00
parent 0d3db8390d
commit a1998d106d
7 changed files with 26 additions and 35 deletions

View File

@ -286,9 +286,6 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
* If the key doesn't have a name, this function returns an empty string ("").
*
* \param key the desired SDL_Keycode to query.
* \param uppercase SDL_TRUE if the name should be the letter printed on the
* key on the keyboard, which is usually uppercase, or
* SDL_FALSE to return the name of the key unchanged.
* \returns a UTF-8 encoded string of the key name.
*
* \since This function is available since SDL 3.0.0.
@ -297,16 +294,12 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetScancodeFromKey
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key);
/**
* Get a key code from a human-readable name.
*
* \param name the human-readable key name.
* \param uppercase SDL_TRUE if the name is the letter printed on the key on
* the keyboard, which is usually uppercase, and this
* function should return the unshifted version of the key,
* or SDL_FALSE to return the key unchanged.
* \returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call
* SDL_GetError() for more information.
*
@ -316,7 +309,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key, SDL_boo
* \sa SDL_GetKeyName
* \sa SDL_GetScancodeFromName
*/
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name, SDL_bool uppercase);
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
/**
* Start accepting Unicode text input events in a window.

View File

@ -365,9 +365,9 @@ SDL_DYNAPI_PROC(SDL_JoystickType,SDL_GetJoystickTypeForID,(SDL_JoystickID a),(a)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendor,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendorForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a, SDL_bool b),(a, b),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b, SDL_bool c),(a,b,c),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return)
SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)

View File

@ -981,8 +981,9 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
return SDL_SCANCODE_UNKNOWN;
}
const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
const char *SDL_GetKeyName(SDL_Keycode key)
{
const SDL_bool uppercase = SDL_TRUE;
char name[8];
char *end;
@ -1027,8 +1028,9 @@ const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
}
}
SDL_Keycode SDL_GetKeyFromName(const char *name, SDL_bool uppercase)
SDL_Keycode SDL_GetKeyFromName(const char *name)
{
const SDL_bool uppercase = SDL_TRUE;
SDL_Keycode key;
/* Check input */

View File

@ -1717,7 +1717,7 @@ void SDLTest_PrintEvent(const SDL_Event *event)
event->key.windowID,
event->key.scancode,
SDL_GetScancodeName(event->key.scancode),
event->key.key, SDL_GetKeyName(event->key.key, SDL_TRUE),
event->key.key, SDL_GetKeyName(event->key.key),
modstr);
break;
}

View File

@ -202,7 +202,7 @@ static void PrintKey(SDL_KeyboardEvent *event)
event->raw,
event->scancode,
event->scancode == SDL_SCANCODE_UNKNOWN ? "UNKNOWN" : SDL_GetScancodeName(event->scancode),
event->key, SDL_GetKeyName(event->key, SDL_TRUE));
event->key, SDL_GetKeyName(event->key));
} else {
print_string(&spot, &left,
"Unknown Key (raw 0x%.2x, scancode %d = %s) %s ",

View File

@ -59,41 +59,37 @@ static int keyboard_getKeyFromName(void *arg)
SDL_Keycode result;
/* Case where Key is known, 1 character input */
result = SDL_GetKeyFromName("A", SDL_TRUE);
result = SDL_GetKeyFromName("A");
SDLTest_AssertPass("Call to SDL_GetKeyFromName('A', SDL_TRUE)");
SDLTest_AssertCheck(result == SDLK_A, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_A, result);
result = SDL_GetKeyFromName("A", SDL_FALSE);
SDLTest_AssertPass("Call to SDL_GetKeyFromName('A', SDL_FALSE)");
SDLTest_AssertCheck(result == 'A', "Verify result from call, expected: %d, got: %" SDL_PRIu32, 'A', result);
/* Case where Key is known, 2 character input */
result = SDL_GetKeyFromName("F1", SDL_TRUE);
result = SDL_GetKeyFromName("F1");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_F1, result);
/* Case where Key is known, 3 character input */
result = SDL_GetKeyFromName("End", SDL_TRUE);
result = SDL_GetKeyFromName("End");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_END, result);
/* Case where Key is known, 4 character input */
result = SDL_GetKeyFromName("Find", SDL_TRUE);
result = SDL_GetKeyFromName("Find");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_FIND, result);
/* Case where Key is known, multiple character input */
result = SDL_GetKeyFromName("MediaStop", SDL_TRUE);
result = SDL_GetKeyFromName("MediaStop");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
SDLTest_AssertCheck(result == SDLK_MEDIA_STOP, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_MEDIA_STOP, result);
/* Case where Key is unknown */
result = SDL_GetKeyFromName("NotThere", SDL_TRUE);
result = SDL_GetKeyFromName("NotThere");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
/* Case where input is NULL/invalid */
result = SDL_GetKeyFromName(NULL, SDL_TRUE);
result = SDL_GetKeyFromName(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
@ -168,42 +164,42 @@ static int keyboard_getKeyName(void *arg)
/* Case where key has a 1 character name */
expected = "3";
result = SDL_GetKeyName(SDLK_3, SDL_TRUE);
result = SDL_GetKeyName(SDLK_3);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 2 character name */
expected = "F1";
result = SDL_GetKeyName(SDLK_F1, SDL_TRUE);
result = SDL_GetKeyName(SDLK_F1);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 3 character name */
expected = "Cut";
result = SDL_GetKeyName(SDLK_CUT, SDL_TRUE);
result = SDL_GetKeyName(SDLK_CUT);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 4 character name */
expected = "Down";
result = SDL_GetKeyName(SDLK_DOWN, SDL_TRUE);
result = SDL_GetKeyName(SDLK_DOWN);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name */
expected = "MediaPlay";
result = SDL_GetKeyName(SDLK_MEDIA_PLAY, SDL_TRUE);
result = SDL_GetKeyName(SDLK_MEDIA_PLAY);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name with space */
expected = "Keypad MemStore";
result = SDL_GetKeyName(SDLK_KP_MEMSTORE, SDL_TRUE);
result = SDL_GetKeyName(SDLK_KP_MEMSTORE);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
@ -250,7 +246,7 @@ static int keyboard_getKeyNameNegative(void *arg)
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
result = SDL_GetKeyName(keycode, SDL_TRUE);
result = SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIu32 "/unknown)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
@ -261,7 +257,7 @@ static int keyboard_getKeyNameNegative(void *arg)
/* Negative keycode */
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
result = SDL_GetKeyName(keycode, SDL_TRUE);
result = SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIu32 "/negative)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);

View File

@ -1209,7 +1209,7 @@ int main(int argc, char *argv[])
event.key.scancode,
SDL_GetScancodeName(event.key.scancode),
SDL_static_cast(Uint32, event.key.key),
SDL_GetKeyName(event.key.key, SDL_TRUE));
SDL_GetKeyName(event.key.key));
break;
}
case SDL_EVENT_TEXT_INPUT: {