Fixed bug 2866 - testrelative.c: patch to make the orange box wrap around
authorPhilipp Wiesemann
Sat, 07 Feb 2015 22:40:36 +0100
changeset 9333de02c2d8a06f
parent 9332 e29fec41a2c6
child 9334 5eb5ab33286e
Fixed bug 2866 - testrelative.c: patch to make the orange box wrap around

Eric Wasylishen

Here's a patch to make the 'testrelative' demo program more useful: it just makes the orange rectangle wrap around. Previously, the orange cursor would just disappear off screen if you move the mouse a lot in one direction, so it was hard to tell if relative mouse mode was still working.
test/testrelative.c
     1.1 --- a/test/testrelative.c	Tue Feb 03 21:22:25 2015 +0100
     1.2 +++ b/test/testrelative.c	Sat Feb 07 22:40:36 2015 +0100
     1.3 @@ -49,12 +49,20 @@
     1.4          }
     1.5      }
     1.6      for (i = 0; i < state->num_windows; ++i) {
     1.7 +        SDL_Rect viewport;
     1.8          SDL_Renderer *renderer = state->renderers[i];
     1.9          if (state->windows[i] == NULL)
    1.10              continue;
    1.11          SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.12          SDL_RenderClear(renderer);
    1.13  
    1.14 +        /* Wrap the cursor rectangle at the screen edges to keep it visible */
    1.15 +        SDL_RenderGetViewport(renderer, &viewport);
    1.16 +        if (rect.x < viewport.x) rect.x += viewport.w;
    1.17 +        if (rect.y < viewport.y) rect.y += viewport.h;
    1.18 +        if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
    1.19 +        if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
    1.20 +
    1.21          DrawRects(renderer, &rect);
    1.22  
    1.23          SDL_RenderPresent(renderer);