From e794057d9f3d0e0f9947c23984712e71afcfc168 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 15 Mar 2023 10:19:55 -0700 Subject: [PATCH] Move the popup windows to follow the mouse --- test/testpopup.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/testpopup.c b/test/testpopup.c index 4e5f80e6b..8be2c2b05 100644 --- a/test/testpopup.c +++ b/test/testpopup.c @@ -152,6 +152,17 @@ static void loop() SDL_zero(tooltip); } tooltip_timer = SDL_GetTicks() + TOOLTIP_DELAY; + + if (num_menus > 0) { + int parent_x = 0, parent_y = 0; + int x = event.motion.x; + int y = event.motion.y; + + SDL_GetWindowPosition(menus[0].parent, &parent_x, &parent_y); + x -= parent_x; + y -= parent_y; + SDL_SetWindowPosition(menus[0].win, x, y); + } } else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) { /* Left click closes the popup menus */ if (event.button.button == SDL_BUTTON_LEFT) { @@ -245,4 +256,4 @@ int main(int argc, char *argv[]) quit(0); /* keep the compiler happy ... */ return 0; -} \ No newline at end of file +}