Fixed bug 2866 - testrelative.c: patch to make the orange box wrap around
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 07 Feb 2015 22:40:36 +0100
changeset 9333 de02c2d8a06f
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
--- a/test/testrelative.c	Tue Feb 03 21:22:25 2015 +0100
+++ b/test/testrelative.c	Sat Feb 07 22:40:36 2015 +0100
@@ -49,12 +49,20 @@
         }
     }
     for (i = 0; i < state->num_windows; ++i) {
+        SDL_Rect viewport;
         SDL_Renderer *renderer = state->renderers[i];
         if (state->windows[i] == NULL)
             continue;
         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
         SDL_RenderClear(renderer);
 
+        /* Wrap the cursor rectangle at the screen edges to keep it visible */
+        SDL_RenderGetViewport(renderer, &viewport);
+        if (rect.x < viewport.x) rect.x += viewport.w;
+        if (rect.y < viewport.y) rect.y += viewport.h;
+        if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
+        if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
+
         DrawRects(renderer, &rect);
 
         SDL_RenderPresent(renderer);