mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 14:53:47 +08:00
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().
This commit is contained in:
@@ -211,6 +211,20 @@ static void loop(void *arg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_EVENT_KEY_DOWN:
|
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:
|
case SDL_EVENT_KEY_UP:
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
case SDLK_LSHIFT:
|
case SDLK_LSHIFT:
|
||||||
|
|||||||
Reference in New Issue
Block a user