Browse Source

TESTWM : Option and Keyboard action to ShowCursor and HideCursor

In include/SDL3/SDL_test_common.h
   Add flag hide_cursor
In src/test/SDL_test_common.c
   Handle option --hide-cursor to SDL_HideCursor
   Handle Ctrl-h toggle to SDL_HideCursor and SDL_ShowCursor
Dragon-Baroque 11 tháng trước cách đây
mục cha
commit
05fb91c7b4
2 tập tin đã thay đổi với 20 bổ sung2 xóa
  1. 1 0
      include/SDL3/SDL_test_common.h
  2. 19 2
      src/test/SDL_test_common.c

+ 1 - 0
include/SDL3/SDL_test_common.h

@@ -127,6 +127,7 @@ typedef struct
 
     /* Mouse info */
     SDL_Rect confine;
+    SDL_bool hide_cursor;
 
 } SDLTest_CommonState;
 

+ 19 - 2
src/test/SDL_test_common.c

@@ -590,6 +590,10 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
             state->window_flags |= SDL_WINDOW_UTILITY;
             return 1;
         }
+        if (SDL_strcasecmp(argv[index], "--hide-cursor") == 0) {
+            state->hide_cursor = SDL_TRUE;
+            return 1;
+        }
     }
 
     if (state->flags & SDL_INIT_AUDIO) {
@@ -1400,6 +1404,9 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
 
             SDL_ShowWindow(state->windows[i]);
         }
+        if (state->hide_cursor) {
+            SDL_HideCursor();
+        }
     }
 
     if (state->flags & SDL_INIT_AUDIO) {
@@ -2181,6 +2188,16 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
                 }
             }
             break;
+        case SDLK_h:
+            if (withControl) {
+                /* Ctrl-H changes cursor visibility. */
+                if (SDL_CursorVisible()) {
+                    SDL_HideCursor();
+                } else {
+                    SDL_ShowCursor();
+                }
+            }
+            break;
         case SDLK_c:
             if (withAlt) {
                 /* Alt-C copy awesome text to the primary selection! */
@@ -2318,7 +2335,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
                 if (window) {
                     SDL_WindowFlags flags = SDL_GetWindowFlags(window);
                     if (!(flags & SDL_WINDOW_FULLSCREEN) ||
-						!SDL_GetWindowFullscreenMode(window)) {
+                        !SDL_GetWindowFullscreenMode(window)) {
                         SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode);
                         SDL_SetWindowFullscreen(window, SDL_TRUE);
                     } else {
@@ -2331,7 +2348,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
                 if (window) {
                     SDL_WindowFlags flags = SDL_GetWindowFlags(window);
                     if (!(flags & SDL_WINDOW_FULLSCREEN) ||
-						SDL_GetWindowFullscreenMode(window)) {
+                        SDL_GetWindowFullscreenMode(window)) {
                         SDL_SetWindowFullscreenMode(window, NULL);
                         SDL_SetWindowFullscreen(window, SDL_TRUE);
                     } else {