mirror of https://github.com/libsdl-org/SDL
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:
parent
3a6d9c59f4
commit
3979ea8ed0
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue