]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Formspecs: volume and key settings windows can now be closed by doubleclicking/tappin...
authorZughy <63455151+Zughy@users.noreply.github.com>
Tue, 14 Jul 2020 20:37:28 +0000 (22:37 +0200)
committerGitHub <noreply@github.com>
Tue, 14 Jul 2020 20:37:28 +0000 (22:37 +0200)
Co-authored-by: Xx_Crazyminer_xX <carlo.digioia@hotmail.it>
Co-authored-by: Marco <4279489-marco_a@users.noreply.gitlab.com>
src/gui/guiConfirmRegistration.cpp
src/gui/guiEngine.h
src/gui/guiFormSpecMenu.cpp
src/gui/guiFormSpecMenu.h
src/gui/guiKeyChangeMenu.cpp
src/gui/guiMainMenu.h
src/gui/guiPasswordChange.cpp
src/gui/guiVolumeChange.cpp
src/gui/modalMenu.cpp
src/gui/modalMenu.h

index 58ac427406d210cebb86e17176caeceaddacda5b..55c111df83462cd70aa1453fcf8b94c1a6bb56f1 100644 (file)
@@ -222,7 +222,7 @@ bool GUIConfirmRegistration::OnEvent(const SEvent &event)
 
        if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
                if (!canTakeFocus(event.GUIEvent.Element)) {
-                       dstream << "GUIConfirmRegistration: Not allowing focus change."
+                       infostream << "GUIConfirmRegistration: Not allowing focus change."
                                << std::endl;
                        // Returning true disables focus change
                        return true;
index e55531bbca638c9c2f2f5b9331b0b3a8b817c9fb..f9ad0fb0a90c8e8fe70a9ebbf38de3d076c37df7 100644 (file)
@@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 /* Includes                                                                   */
 /******************************************************************************/
 #include "irrlichttypes.h"
-#include "modalMenu.h"
 #include "guiFormSpecMenu.h"
 #include "client/sound.h"
 #include "client/tile.h"
index db89d2c43bfa7efe2cb404cd91de2bf614117a4c..601c5c18ee4018f5d14523d1c17a9b81b0776fdc 100644 (file)
@@ -95,29 +95,21 @@ inline u32 clamp_u8(s32 value)
 GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
                gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
                Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
-               const std::string &formspecPrepend,
-               bool remap_dbl_click):
-       GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr),
+               const std::string &formspecPrepend, bool remap_dbl_click):
+       GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click),
        m_invmgr(client),
        m_tsrc(tsrc),
        m_client(client),
        m_formspec_prepend(formspecPrepend),
        m_form_src(fsrc),
        m_text_dst(tdst),
-       m_joystick(joystick),
-       m_remap_dbl_click(remap_dbl_click)
+       m_joystick(joystick)
 {
        current_keys_pending.key_down = false;
        current_keys_pending.key_up = false;
        current_keys_pending.key_enter = false;
        current_keys_pending.key_escape = false;
 
-       m_doubleclickdetect[0].time = 0;
-       m_doubleclickdetect[1].time = 0;
-
-       m_doubleclickdetect[0].pos = v2s32(0, 0);
-       m_doubleclickdetect[1].pos = v2s32(0, 0);
-
        m_tooltip_show_delay = (u32)g_settings->getS32("tooltip_show_delay");
        m_tooltip_append_itemname = g_settings->getBool("tooltip_append_itemname");
 }
@@ -3851,17 +3843,6 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
        }
 }
 
-static bool isChild(gui::IGUIElement *tocheck, gui::IGUIElement *parent)
-{
-       while (tocheck) {
-               if (tocheck == parent) {
-                       return true;
-               }
-               tocheck = tocheck->getParent();
-       }
-       return false;
-}
-
 bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
 {
        // The IGUITabControl renders visually using the skin's selected
@@ -3922,22 +3903,6 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
                }
        }
 
-       if (event.EventType == EET_MOUSE_INPUT_EVENT) {
-               s32 x = event.MouseInput.X;
-               s32 y = event.MouseInput.Y;
-               gui::IGUIElement *hovered =
-                       Environment->getRootGUIElement()->getElementFromPoint(
-                               core::position2d<s32>(x, y));
-               if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
-                       m_old_tooltip_id = -1;
-               }
-               if (!isChild(hovered, this)) {
-                       if (DoubleClickDetection(event)) {
-                               return true;
-                       }
-               }
-       }
-
        if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
                /* TODO add a check like:
                if (event.JoystickEvent != joystick_we_listen_for)
@@ -3960,64 +3925,6 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
        return GUIModalMenu::preprocessEvent(event);
 }
 
-/******************************************************************************/
-bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event)
-{
-       /* The following code is for capturing double-clicks of the mouse button
-        * and translating the double-click into an EET_KEY_INPUT_EVENT event
-        * -- which closes the form -- under some circumstances.
-        *
-        * There have been many github issues reporting this as a bug even though it
-        * was an intended feature.  For this reason, remapping the double-click as
-        * an ESC must be explicitly set when creating this class via the
-        * /p remap_dbl_click parameter of the constructor.
-        */
-
-       if (!m_remap_dbl_click)
-               return false;
-
-       if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
-               m_doubleclickdetect[0].pos  = m_doubleclickdetect[1].pos;
-               m_doubleclickdetect[0].time = m_doubleclickdetect[1].time;
-
-               m_doubleclickdetect[1].pos  = m_pointer;
-               m_doubleclickdetect[1].time = porting::getTimeMs();
-       }
-       else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
-               u64 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs());
-               if (delta > 400) {
-                       return false;
-               }
-
-               double squaredistance =
-                               m_doubleclickdetect[0].pos
-                               .getDistanceFromSQ(m_doubleclickdetect[1].pos);
-
-               if (squaredistance > (30*30)) {
-                       return false;
-               }
-
-               SEvent* translated = new SEvent();
-               assert(translated != 0);
-               //translate doubleclick to escape
-               memset(translated, 0, sizeof(SEvent));
-               translated->EventType = irr::EET_KEY_INPUT_EVENT;
-               translated->KeyInput.Key         = KEY_ESCAPE;
-               translated->KeyInput.Control     = false;
-               translated->KeyInput.Shift       = false;
-               translated->KeyInput.PressedDown = true;
-               translated->KeyInput.Char        = 0;
-               OnEvent(*translated);
-
-               // no need to send the key up event as we're already deleted
-               // and no one else did notice this event
-               delete translated;
-               return true;
-       }
-
-       return false;
-}
-
 void GUIFormSpecMenu::tryClose()
 {
        if (m_allowclose) {
index 5a6b467aad7abba8d9884d68d04c8378c4923849..613acaa043fb926656ae2555bbb19afa35e29485 100644 (file)
@@ -457,30 +457,8 @@ class GUIFormSpecMenu : public GUIModalMenu
         */
        void legacySortElements(core::list<IGUIElement *>::Iterator from);
 
-       /**
-        * check if event is part of a double click
-        * @param event event to evaluate
-        * @return true/false if a doubleclick was detected
-        */
-       bool DoubleClickDetection(const SEvent event);
-
-       struct clickpos
-       {
-               v2s32 pos;
-               s64 time;
-       };
-       clickpos m_doubleclickdetect[2];
-
        int m_btn_height;
        gui::IGUIFont *m_font = nullptr;
-
-       /* If true, remap a double-click (or double-tap) action to ESC. This is so
-        * that, for example, Android users can double-tap to close a formspec.
-       *
-        * This value can (currently) only be set by the class constructor
-        * and the default value for the setting is true.
-        */
-       bool m_remap_dbl_click;
 };
 
 class FormspecFormSource: public IFormSource
index da0e25c239b986afcaccd5e0e954cf9697d2da52..eb641d95230584b27b000a59a93a17c70987139c 100644 (file)
@@ -360,7 +360,7 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event)
                {
                        if (!canTakeFocus(event.GUIEvent.Element))
                        {
-                               dstream << "GUIMainMenu: Not allowing focus change."
+                               infostream << "GUIKeyChangeMenu: Not allowing focus change."
                                << std::endl;
                                // Returning true disables focus change
                                return true;
index 43a3b1a33e851cc20fd63430dddf42340d71ab94..1dca8bf2d295863c3c8993f15afc08b6894611ce 100644 (file)
@@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #pragma once
 
 #include "irrlichttypes_extrabloated.h"
-#include "modalMenu.h"
 #include <string>
 #include <list>
 
index 965a2d6f75a418a7fada73511830076d1595c7f7..5311c6fefb1d182bb72c9c5c952adc8082927156 100644 (file)
@@ -236,7 +236,7 @@ bool GUIPasswordChange::OnEvent(const SEvent &event)
                if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST &&
                                isVisible()) {
                        if (!canTakeFocus(event.GUIEvent.Element)) {
-                               dstream << "GUIPasswordChange: Not allowing focus change."
+                               infostream << "GUIPasswordChange: Not allowing focus change."
                                        << std::endl;
                                // Returning true disables focus change
                                return true;
index 07b11248ca2c5c636e7424a61b4011863c38d239..f17cfa9867e0952c7d4918a8d2a99f536956862b 100644 (file)
@@ -171,7 +171,7 @@ bool GUIVolumeChange::OnEvent(const SEvent& event)
                if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
                                && isVisible()) {
                        if (!canTakeFocus(event.GUIEvent.Element)) {
-                               dstream << "GUIMainMenu: Not allowing focus change."
+                               infostream << "GUIVolumeChange: Not allowing focus change."
                                << std::endl;
                                // Returning true disables focus change
                                return true;
index a6fe7ebaf4fc9866723fa6885bb16b3df445645a..9b1e6dd9c7c84a109d2bc639e0cb47634214d9d3 100644 (file)
@@ -28,14 +28,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "touchscreengui.h"
 #endif
 
-GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
-               IMenuManager *menumgr) :
+// clang-format off
+GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
+       s32 id, IMenuManager *menumgr, bool remap_dbl_click) :
                IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
                                core::rect<s32>(0, 0, 100, 100)),
 #ifdef __ANDROID__
                m_jni_field_name(""),
 #endif
-               m_menumgr(menumgr)
+               m_menumgr(menumgr),
+               m_remap_dbl_click(remap_dbl_click)
 {
        m_gui_scale = g_settings->getFloat("gui_scaling");
 #ifdef __ANDROID__
@@ -45,6 +47,12 @@ GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent,
        setVisible(true);
        Environment->setFocus(this);
        m_menumgr->createdMenu(this);
+
+       m_doubleclickdetect[0].time = 0;
+       m_doubleclickdetect[1].time = 0;
+
+       m_doubleclickdetect[0].pos = v2s32(0, 0);
+       m_doubleclickdetect[1].pos = v2s32(0, 0);
 }
 // clang-format on
 
@@ -112,6 +120,69 @@ void GUIModalMenu::removeChildren()
        }
 }
 
+// clang-format off
+bool GUIModalMenu::DoubleClickDetection(const SEvent &event)
+{
+       /* The following code is for capturing double-clicks of the mouse button
+        * and translating the double-click into an EET_KEY_INPUT_EVENT event
+        * -- which closes the form -- under some circumstances.
+        *
+        * There have been many github issues reporting this as a bug even though it
+        * was an intended feature.  For this reason, remapping the double-click as
+        * an ESC must be explicitly set when creating this class via the
+        * /p remap_dbl_click parameter of the constructor.
+        */
+
+       if (!m_remap_dbl_click)
+               return false;
+
+       if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
+               m_doubleclickdetect[0].pos = m_doubleclickdetect[1].pos;
+               m_doubleclickdetect[0].time = m_doubleclickdetect[1].time;
+
+               m_doubleclickdetect[1].pos = m_pointer;
+               m_doubleclickdetect[1].time = porting::getTimeMs();
+       } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
+               u64 delta = porting::getDeltaMs(
+                       m_doubleclickdetect[0].time, porting::getTimeMs());
+               if (delta > 400)
+                       return false;
+
+               double squaredistance = m_doubleclickdetect[0].pos.
+                       getDistanceFromSQ(m_doubleclickdetect[1].pos);
+
+               if (squaredistance > (30 * 30)) {
+                       return false;
+               }
+
+               SEvent translated{};
+               // translate doubleclick to escape
+               translated.EventType            = EET_KEY_INPUT_EVENT;
+               translated.KeyInput.Key         = KEY_ESCAPE;
+               translated.KeyInput.Control     = false;
+               translated.KeyInput.Shift       = false;
+               translated.KeyInput.PressedDown = true;
+               translated.KeyInput.Char        = 0;
+               OnEvent(translated);
+
+               return true;
+       }
+
+       return false;
+}
+// clang-format on
+
+static bool isChild(gui::IGUIElement *tocheck, gui::IGUIElement *parent)
+{
+       while (tocheck) {
+               if (tocheck == parent) {
+                       return true;
+               }
+               tocheck = tocheck->getParent();
+       }
+       return false;
+}
+
 bool GUIModalMenu::preprocessEvent(const SEvent &event)
 {
 #ifdef __ANDROID__
@@ -245,6 +316,19 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
                }
        }
 #endif
+
+       if (event.EventType == EET_MOUSE_INPUT_EVENT) {
+               s32 x = event.MouseInput.X;
+               s32 y = event.MouseInput.Y;
+               gui::IGUIElement *hovered =
+                               Environment->getRootGUIElement()->getElementFromPoint(
+                                               core::position2d<s32>(x, y));
+               if (!isChild(hovered, this)) {
+                       if (DoubleClickDetection(event)) {
+                               return true;
+                       }
+               }
+       }
        return false;
 }
 
index 5bd70bb84749175f8306febfb1569a5605231262..1cb687f82782255aac539dc462e76cd418a556ca 100644 (file)
@@ -39,7 +39,7 @@ class GUIModalMenu : public gui::IGUIElement
 {
 public:
        GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
-               IMenuManager *menumgr);
+               IMenuManager *menumgr, bool remap_dbl_click = true);
        virtual ~GUIModalMenu();
 
        void allowFocusRemoval(bool allow);
@@ -50,8 +50,8 @@ class GUIModalMenu : public gui::IGUIElement
 
        virtual void regenerateGui(v2u32 screensize) = 0;
        virtual void drawMenu() = 0;
-       virtual bool preprocessEvent(const SEventevent);
-       virtual bool OnEvent(const SEventevent) { return false; };
+       virtual bool preprocessEvent(const SEvent &event);
+       virtual bool OnEvent(const SEvent &event) { return false; };
        virtual bool pausesGame() { return false; } // Used for pause menu
 #ifdef __ANDROID__
        virtual bool getAndroidUIInput() { return false; }
@@ -62,6 +62,13 @@ class GUIModalMenu : public gui::IGUIElement
        virtual std::wstring getLabelByID(s32 id) = 0;
        virtual std::string getNameByID(s32 id) = 0;
 
+       /**
+        * check if event is part of a double click
+        * @param event event to evaluate
+        * @return true/false if a doubleclick was detected
+        */
+       bool DoubleClickDetection(const SEvent &event);
+
        v2s32 m_pointer;
        v2s32 m_old_pointer;  // Mouse position after previous mouse event
        v2u32 m_screensize_old;
@@ -73,8 +80,23 @@ class GUIModalMenu : public gui::IGUIElement
 #ifdef HAVE_TOUCHSCREENGUI
        bool m_touchscreen_visible = true;
 #endif
+
 private:
+       struct clickpos
+       {
+               v2s32 pos;
+               s64 time;
+       };
+       clickpos m_doubleclickdetect[2];
+
        IMenuManager *m_menumgr;
+       /* If true, remap a double-click (or double-tap) action to ESC. This is so
+        * that, for example, Android users can double-tap to close a formspec.
+       *
+        * This value can (currently) only be set by the class constructor
+        * and the default value for the setting is true.
+        */
+       bool m_remap_dbl_click;
        // This might be necessary to expose to the implementation if it
        // wants to launch other menus
        bool m_allow_focus_removal = false;