From a0fe7f40489a172252c266d7dac405f4b18416d8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 6 Dec 2019 00:06:41 +0100 Subject: [PATCH] - more mouse fixes. Most of the menu is now mouse controllable again. The exceptions are the text screens which do not react to the mouse and the confirmation screen which treats a mouse click as a cancel event. --- source/build/src/sdlayer.cpp | 2 ++ source/common/menu/menu.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 8dcf02b66..7bb988b39 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -1712,6 +1712,8 @@ int32_t handleevents_sdlcommon(SDL_Event *ev) event_t evt; evt.type = EV_GUI_Event; evt.subtype = uint8_t((ev->button.state == SDL_PRESSED) ? EV_GUI_LButtonDown : EV_GUI_LButtonUp); + evt.data1 = ev->motion.x; + evt.data2 = ev->motion.y; SDL_Keymod kmod = SDL_GetModState(); evt.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) | diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index ee1191f0e..7163ccf0d 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -63,6 +63,7 @@ extern bool rotatesprite_2doverride; bool help_disabled, credits_disabled; int g_currentMenu; // accessible by CON scripts - contains the current menu's script ID if defined or INT_MAX if none given. int DrawBackground; +TArray toDelete; // // Todo: Move these elsewhere @@ -227,7 +228,7 @@ void DMenu::Close () else { Destroy(); - delete this; + toDelete.Push(this); if (DMenu::CurrentMenu == NULL) { M_ClearMenus(); @@ -620,7 +621,7 @@ bool M_SetMenu(FName menu, int param, FName caller) // //============================================================================= -bool M_Responder (event_t *ev) +bool M_DoResponder (event_t *ev) { int ch = 0; bool keyup = false; @@ -803,6 +804,15 @@ bool M_Responder (event_t *ev) return false; } +bool M_Responder(event_t* ev) +{ + // delayed deletion, so that self-deleting menus don't crash if they are getting accesses after being closed. + auto res = M_DoResponder(ev); + for (auto p : toDelete) delete p; + toDelete.Clear(); + return res; +} + //============================================================================= // //