فهرست منبع

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().
Frank Praznik 11 ماه پیش
والد
کامیت
3979ea8ed0
1فایلهای تغییر یافته به همراه14 افزوده شده و 0 حذف شده
  1. 14 0
      test/testmouse.c

+ 14 - 0
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: