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().
pull/9685/head
Frank Praznik 2024-05-02 10:16:36 -04:00
parent 3a6d9c59f4
commit 3979ea8ed0
1 changed files with 14 additions and 0 deletions

View File

@ -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: