diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 350887c59..0c5afe81e 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -803,6 +803,82 @@ static void SDLTest_PrintWindowFlags(char *text, size_t maxlen, Uint32 flags) } } +static void SDLTest_PrintModStateFlag(char *text, size_t maxlen, SDL_Keymod flag) +{ + switch (flag) { + case KMOD_LSHIFT: + SDL_snprintfcat(text, maxlen, "LSHIFT"); + break; + case KMOD_RSHIFT: + SDL_snprintfcat(text, maxlen, "RSHIFT"); + break; + case KMOD_LCTRL: + SDL_snprintfcat(text, maxlen, "LCTRL"); + break; + case KMOD_RCTRL: + SDL_snprintfcat(text, maxlen, "RCTRL"); + break; + case KMOD_LALT: + SDL_snprintfcat(text, maxlen, "LALT"); + break; + case KMOD_RALT: + SDL_snprintfcat(text, maxlen, "RALT"); + break; + case KMOD_LGUI: + SDL_snprintfcat(text, maxlen, "LGUI"); + break; + case KMOD_RGUI: + SDL_snprintfcat(text, maxlen, "RGUI"); + break; + case KMOD_NUM: + SDL_snprintfcat(text, maxlen, "NUM"); + break; + case KMOD_CAPS: + SDL_snprintfcat(text, maxlen, "CAPS"); + break; + case KMOD_MODE: + SDL_snprintfcat(text, maxlen, "MODE"); + break; + case KMOD_SCROLL: + SDL_snprintfcat(text, maxlen, "SCROLL"); + break; + default: + SDL_snprintfcat(text, maxlen, "0x%8.8x", (unsigned int) flag); + break; + } +} + +static void SDLTest_PrintModState(char *text, size_t maxlen, SDL_Keymod keymod) +{ + const SDL_Keymod kmod_flags[] = { + KMOD_LSHIFT, + KMOD_RSHIFT, + KMOD_LCTRL, + KMOD_RCTRL, + KMOD_LALT, + KMOD_RALT, + KMOD_LGUI, + KMOD_RGUI, + KMOD_NUM, + KMOD_CAPS, + KMOD_MODE, + KMOD_SCROLL + }; + + int i; + int count = 0; + for (i = 0; i < SDL_arraysize(kmod_flags); ++i) { + const SDL_Keymod flag = kmod_flags[i]; + if ((keymod & flag) == flag) { + if (count > 0) { + SDL_snprintfcat(text, maxlen, " | "); + } + SDLTest_PrintModStateFlag(text, maxlen, flag); + ++count; + } + } +} + static void SDLTest_PrintButtonMask(char *text, size_t maxlen, Uint32 flags) { int i; @@ -2401,6 +2477,20 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in SDLTest_DrawString(renderer, 0, textY, text); textY += lineHeight; + /* Keyboard */ + + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDLTest_DrawString(renderer, 0, textY, "-- Keyboard --"); + textY += lineHeight; + + SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); + + flags = SDL_GetMouseState(&x, &y); + (void)SDL_snprintf(text, sizeof(text), "SDL_GetModState: "); + SDLTest_PrintModState(text, sizeof(text), SDL_GetModState()); + SDLTest_DrawString(renderer, 0, textY, text); + textY += lineHeight; + if (usedHeight) { *usedHeight = textY; }