Tests: Refactor key modifier checking.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Wed, 15 Jan 2014 10:40:14 -0800
changeset 81089733fba62719
parent 8107 faed2556c828
child 8109 19f0074531cf
Tests: Refactor key modifier checking.
src/test/SDL_test_common.c
     1.1 --- a/src/test/SDL_test_common.c	Wed Jan 15 12:29:17 2014 -0300
     1.2 +++ b/src/test/SDL_test_common.c	Wed Jan 15 10:40:14 2014 -0800
     1.3 @@ -1293,7 +1293,11 @@
     1.4              break;
     1.5          }
     1.6          break;
     1.7 -    case SDL_KEYDOWN:
     1.8 +    case SDL_KEYDOWN: {
     1.9 +        SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
    1.10 +        SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
    1.11 +        SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
    1.12 +
    1.13          switch (event->key.keysym.sym) {
    1.14              /* Add hotkeys here */
    1.15          case SDLK_PRINTSCREEN: {
    1.16 @@ -1308,7 +1312,7 @@
    1.17              }
    1.18              break;
    1.19          case SDLK_EQUALS:
    1.20 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.21 +            if (withControl) {
    1.22                  /* Ctrl-+ double the size of the window */
    1.23                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.24                  if (window) {
    1.25 @@ -1319,7 +1323,7 @@
    1.26              }
    1.27              break;
    1.28          case SDLK_MINUS:
    1.29 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.30 +            if (withControl) {
    1.31                  /* Ctrl-- half the size of the window */
    1.32                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.33                  if (window) {
    1.34 @@ -1330,12 +1334,12 @@
    1.35              }
    1.36              break;
    1.37          case SDLK_c:
    1.38 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.39 +            if (withControl) {
    1.40                  /* Ctrl-C copy awesome text! */
    1.41                  SDL_SetClipboardText("SDL rocks!\nYou know it!");
    1.42                  printf("Copied text to clipboard\n");
    1.43              }
    1.44 -            if (event->key.keysym.mod & KMOD_ALT) {
    1.45 +            if (withAlt) {
    1.46                  /* Alt-C toggle a render clip rectangle */
    1.47                  for (i = 0; i < state->num_windows; ++i) {
    1.48                      int w, h;
    1.49 @@ -1357,7 +1361,7 @@
    1.50              }
    1.51              break;
    1.52          case SDLK_v:
    1.53 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.54 +            if (withControl) {
    1.55                  /* Ctrl-V paste awesome text! */
    1.56                  char *text = SDL_GetClipboardText();
    1.57                  if (*text) {
    1.58 @@ -1369,7 +1373,7 @@
    1.59              }
    1.60              break;
    1.61          case SDLK_g:
    1.62 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.63 +            if (withControl) {
    1.64                  /* Ctrl-G toggle grab */
    1.65                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.66                  if (window) {
    1.67 @@ -1378,7 +1382,7 @@
    1.68              }
    1.69              break;
    1.70          case SDLK_m:
    1.71 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.72 +            if (withControl) {
    1.73                  /* Ctrl-M maximize */
    1.74                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.75                  if (window) {
    1.76 @@ -1392,13 +1396,13 @@
    1.77              }
    1.78              break;
    1.79          case SDLK_r:
    1.80 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.81 +            if (withControl) {
    1.82                  /* Ctrl-R toggle mouse relative mode */
    1.83                  SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE);
    1.84              }
    1.85              break;
    1.86          case SDLK_z:
    1.87 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.88 +            if (withControl) {
    1.89                  /* Ctrl-Z minimize */
    1.90                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.91                  if (window) {
    1.92 @@ -1407,7 +1411,7 @@
    1.93              }
    1.94              break;
    1.95          case SDLK_RETURN:
    1.96 -            if (event->key.keysym.mod & KMOD_CTRL) {
    1.97 +            if (withControl) {
    1.98                  /* Ctrl-Enter toggle fullscreen */
    1.99                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
   1.100                  if (window) {
   1.101 @@ -1418,7 +1422,7 @@
   1.102                          SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
   1.103                      }
   1.104                  }
   1.105 -            } else if (event->key.keysym.mod & KMOD_ALT) {
   1.106 +            } else if (withAlt) {
   1.107                  /* Alt-Enter toggle fullscreen desktop */
   1.108                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
   1.109                  if (window) {
   1.110 @@ -1432,7 +1436,7 @@
   1.111              }
   1.112              break;
   1.113          case SDLK_b:
   1.114 -            if (event->key.keysym.mod & KMOD_CTRL) {
   1.115 +            if (withControl) {
   1.116                  /* Ctrl-B toggle window border */
   1.117                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
   1.118                  if (window) {
   1.119 @@ -1443,18 +1447,18 @@
   1.120              }
   1.121              break;
   1.122          case SDLK_0:
   1.123 -            if (event->key.keysym.mod & KMOD_CTRL) {
   1.124 +            if (withControl) {
   1.125                  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
   1.126                  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
   1.127              }
   1.128              break;
   1.129          case SDLK_1:
   1.130 -            if (event->key.keysym.mod & KMOD_CTRL) {
   1.131 +            if (withControl) {
   1.132                  FullscreenTo(0, event->key.windowID);
   1.133              }
   1.134              break;
   1.135          case SDLK_2:
   1.136 -            if (event->key.keysym.mod & KMOD_CTRL) {
   1.137 +            if (withControl) {
   1.138                  FullscreenTo(1, event->key.windowID);
   1.139              }
   1.140              break;
   1.141 @@ -1474,6 +1478,7 @@
   1.142              break;
   1.143          }
   1.144          break;
   1.145 +    }
   1.146      case SDL_QUIT:
   1.147          *done = 1;
   1.148          break;