Fixed bug 3646 - SDL_test_common.c: Add key bindings for testing SDL_SetWindowPosition
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Aug 2017 10:42:26 -0700
changeset 112214753f2320927
parent 11220 54ea94875b88
child 11222 083133ba8f9b
Fixed bug 3646 - SDL_test_common.c: Add key bindings for testing SDL_SetWindowPosition

Eric Wasylishen

Alt-Up/Down/Left/Right switches between displays using SDL_WINDOWPOS_CENTERED_DISPLAY

Shift-Up/Down/Left/Right shifts the window by 100px
src/test/SDL_test_common.c
     1.1 --- a/src/test/SDL_test_common.c	Fri Aug 11 10:32:47 2017 -0700
     1.2 +++ b/src/test/SDL_test_common.c	Fri Aug 11 10:42:26 2017 -0700
     1.3 @@ -1380,6 +1380,49 @@
     1.4                  }
     1.5              }
     1.6              break;
     1.7 +        case SDLK_UP:
     1.8 +        case SDLK_DOWN:
     1.9 +        case SDLK_LEFT:
    1.10 +        case SDLK_RIGHT:
    1.11 +            if (withAlt) {
    1.12 +                /* Alt-Up/Down/Left/Right switches between displays */
    1.13 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.14 +                if (window) {
    1.15 +                    int currentIndex = SDL_GetWindowDisplayIndex(window);
    1.16 +                    int numDisplays = SDL_GetNumVideoDisplays();
    1.17 +
    1.18 +                    if (currentIndex >= 0 && numDisplays >= 1) {
    1.19 +                        int dest;
    1.20 +                        if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) {
    1.21 +                            dest = (currentIndex + numDisplays - 1) % numDisplays;
    1.22 +                        } else {
    1.23 +                            dest = (currentIndex + numDisplays + 1) % numDisplays;
    1.24 +                        }
    1.25 +                        SDL_Log("Centering on display %d\n", dest);
    1.26 +                        SDL_SetWindowPosition(window,
    1.27 +                            SDL_WINDOWPOS_CENTERED_DISPLAY(dest),
    1.28 +                            SDL_WINDOWPOS_CENTERED_DISPLAY(dest));
    1.29 +                    }
    1.30 +                }
    1.31 +            }
    1.32 +            if (withShift) {
    1.33 +                /* Shift-Up/Down/Left/Right shift the window by 100px */
    1.34 +                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
    1.35 +                if (window) {
    1.36 +                    const int delta = 100;
    1.37 +                    int x, y;
    1.38 +                    SDL_GetWindowPosition(window, &x, &y);
    1.39 +                    
    1.40 +                    if (event->key.keysym.sym == SDLK_UP)    y -= delta;
    1.41 +                    if (event->key.keysym.sym == SDLK_DOWN)  y += delta;
    1.42 +                    if (event->key.keysym.sym == SDLK_LEFT)  x -= delta;
    1.43 +                    if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
    1.44 +
    1.45 +                    SDL_Log("Setting position to (%d, %d)\n", x, y);
    1.46 +                    SDL_SetWindowPosition(window, x, y);
    1.47 +                }
    1.48 +            }
    1.49 +            break;
    1.50          case SDLK_o:
    1.51              if (withControl) {
    1.52                  /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */