From 8daac0ba49c4ab077d0daff271158b06a6f64028 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Wed, 16 Aug 2023 14:05:41 +0300 Subject: [PATCH] TouchScreenGUI: minor fixes --- src/gui/modalMenu.cpp | 4 ++-- src/gui/touchscreengui.cpp | 12 ++++++++---- src/gui/touchscreengui.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp index 955e73e26..37f3c762d 100644 --- a/src/gui/modalMenu.cpp +++ b/src/gui/modalMenu.cpp @@ -168,12 +168,12 @@ void GUIModalMenu::quitMenu() Environment->forceUpdateHoveredElement(); #endif - this->drop(); - #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui && g_touchscreengui->isActive() && m_touchscreen_visible) g_touchscreengui->show(); #endif + + this->drop(); } void GUIModalMenu::removeChildren() diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 1c465520b..a09e41c5f 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -598,7 +598,6 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) { assert(tsrc); - m_visible = true; m_texturesource = tsrc; /* Init joystick display "button" @@ -1095,10 +1094,10 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) for (auto iter = m_buttons[i].ids.begin(); iter != m_buttons[i].ids.end(); ++iter) { if (event.TouchInput.ID == *iter) { - s32 current_button_id = + touch_gui_button_id current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y); - if (current_button_id == i) + if (current_button_id == (touch_gui_button_id) i) continue; // remove old button @@ -1113,7 +1112,8 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) } } - s32 current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y); + touch_gui_button_id current_button_id = getButtonID(event.TouchInput.X, + event.TouchInput.Y); if (current_button_id == after_last_element_id) return; @@ -1289,6 +1289,10 @@ void TouchScreenGUI::registerHudItem(s32 index, const rect &rect) void TouchScreenGUI::Toggle(bool visible) { m_visible = visible; + + if (!m_buttons_initialized) + return; + for (auto &button : m_buttons) { if (button.guibutton) button.guibutton->setVisible(visible); diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 74fa6db89..745af290d 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -225,7 +225,7 @@ private: double m_touch_sensitivity; std::map> m_hud_rects; std::map m_hud_ids; - bool m_visible; // is the gui visible + bool m_visible = true; // is the gui visible bool m_buttons_initialized = false; // value in degree