]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/modalMenu.h
Replace all uses of core::list with std::list (#12313)
[dragonfireclient.git] / src / gui / modalMenu.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "irr_ptr.h"
24 #include "util/string.h"
25
26 class GUIModalMenu;
27
28 class IMenuManager
29 {
30 public:
31         // A GUIModalMenu calls these when this class is passed as a parameter
32         virtual void createdMenu(gui::IGUIElement *menu) = 0;
33         virtual void deletingMenu(gui::IGUIElement *menu) = 0;
34 };
35
36 // Remember to drop() the menu after creating, so that it can
37 // remove itself when it wants to.
38
39 class GUIModalMenu : public gui::IGUIElement
40 {
41 public:
42         GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
43                 IMenuManager *menumgr, bool remap_dbl_click = true);
44         virtual ~GUIModalMenu();
45
46         void allowFocusRemoval(bool allow);
47         bool canTakeFocus(gui::IGUIElement *e);
48         void draw();
49         void quitMenu();
50
51         virtual void regenerateGui(v2u32 screensize) = 0;
52         virtual void drawMenu() = 0;
53         virtual bool preprocessEvent(const SEvent &event);
54         virtual bool OnEvent(const SEvent &event) { return false; };
55         virtual bool pausesGame() { return false; } // Used for pause menu
56 #ifdef __ANDROID__
57         virtual bool getAndroidUIInput() { return false; }
58         bool hasAndroidUIInput();
59 #endif
60
61 protected:
62         virtual std::wstring getLabelByID(s32 id) = 0;
63         virtual std::string getNameByID(s32 id) = 0;
64
65         /**
66          * check if event is part of a double click
67          * @param event event to evaluate
68          * @return true/false if a doubleclick was detected
69          */
70         bool DoubleClickDetection(const SEvent &event);
71
72         v2s32 m_pointer;
73         v2s32 m_old_pointer;  // Mouse position after previous mouse event
74         v2u32 m_screensize_old;
75         float m_gui_scale;
76 #ifdef __ANDROID__
77         std::string m_jni_field_name;
78 #endif
79 #ifdef HAVE_TOUCHSCREENGUI
80         v2s32 m_down_pos;
81         bool m_touchscreen_visible = true;
82 #endif
83
84 private:
85         struct clickpos
86         {
87                 v2s32 pos;
88                 s64 time;
89         };
90         clickpos m_doubleclickdetect[2];
91
92         IMenuManager *m_menumgr;
93         /* If true, remap a double-click (or double-tap) action to ESC. This is so
94          * that, for example, Android users can double-tap to close a formspec.
95         *
96          * This value can (currently) only be set by the class constructor
97          * and the default value for the setting is true.
98          */
99         bool m_remap_dbl_click;
100         // This might be necessary to expose to the implementation if it
101         // wants to launch other menus
102         bool m_allow_focus_removal = false;
103
104 #ifdef HAVE_TOUCHSCREENGUI
105         irr_ptr<gui::IGUIElement> m_hovered;
106
107         bool simulateMouseEvent(gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event);
108         void enter(gui::IGUIElement *element);
109         void leave();
110 #endif
111 };