From e6fe7273a5add54025e37e2c0ffacc8ee281c7af Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 16 Mar 2023 11:02:58 -0700
Subject: [PATCH] Toggle menu visibility with the space bar
---
test/testpopup.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/test/testpopup.c b/test/testpopup.c
index 3ee4587d1c1d..0a41d6618b97 100644
--- a/test/testpopup.c
+++ b/test/testpopup.c
@@ -143,8 +143,6 @@ static void loop()
/* Check for events */
while (SDL_PollEvent(&event)) {
- SDLTest_CommonEvent(state, &event, &done);
-
if (event.type == SDL_EVENT_MOUSE_MOTION) {
/* Hide the tooltip and restart the timer if the mouse is moved */
if (tooltip.win) {
@@ -170,7 +168,21 @@ static void loop()
++num_menus;
}
}
+ } else if (event.type == SDL_EVENT_KEY_DOWN) {
+ if (event.key.keysym.sym == SDLK_SPACE) {
+ for (i = 0; i < num_menus; ++i) {
+ if (SDL_GetWindowFlags(menus[i].win) & SDL_WINDOW_HIDDEN) {
+ SDL_ShowWindow(menus[i].win);
+ } else {
+ SDL_HideWindow(menus[i].win);
+ }
+ }
+ // Don't process this event in SDLTest_CommonEvent()
+ continue;
+ }
}
+
+ SDLTest_CommonEvent(state, &event, &done);
}
/* Show the tooltip if the delay period has elapsed */