From 3979ea8ed015c9408ae443e2ea4399c05e002048 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 2 May 2024 10:16:36 -0400 Subject: [PATCH] tests: Add a pointer warp test to testmouse Press 'c' to center the pointer in the window using relative coordinates via SDL_WarpMouseInWindow(). Press alt+'c' to center the pointer in the window using global coordinates via SDL_WarpMouseGlobal(). --- test/testmouse.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/testmouse.c b/test/testmouse.c index d59542319..2e087c05c 100644 --- a/test/testmouse.c +++ b/test/testmouse.c @@ -211,6 +211,20 @@ static void loop(void *arg) break; case SDL_EVENT_KEY_DOWN: + if (event.key.keysym.sym == SDLK_c) { + int x, y, w, h; + SDL_GetWindowPosition(window, &x, &y); + SDL_GetWindowSize(window, &w, &h); + w /= 2; + h /= 2; + + if (event.key.keysym.mod & SDL_KMOD_ALT) { + SDL_WarpMouseGlobal((float)(x + w), (float)(y + h)); + } else { + SDL_WarpMouseInWindow(window, (float)w, (float)h); + } + } + SDL_FALLTHROUGH; case SDL_EVENT_KEY_UP: switch (event.key.keysym.sym) { case SDLK_LSHIFT: