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
This commit is contained in:
Dragon-Baroque 2024-05-21 22:19:16 +02:00 committed by Sam Lantinga
parent 888a45977d
commit 05fb91c7b4
2 changed files with 20 additions and 2 deletions

View File

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

View File

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