From c17a5b1177405d28ea1edabfee67aaef7023c917 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Sat, 7 Feb 2015 22:40:36 +0100 Subject: [PATCH] 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testrelative.c b/test/testrelative.c index 4425cb8d3..3b6ef810e 100644 --- a/test/testrelative.c +++ b/test/testrelative.c @@ -49,12 +49,20 @@ loop(){ } } 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);