]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/modalMenu.h
Fix "Could not create ITexture, texture needs to have a non-empty name" warning
[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         void removeChildren();
51
52         virtual void regenerateGui(v2u32 screensize) = 0;
53         virtual void drawMenu() = 0;
54         virtual bool preprocessEvent(const SEvent &event);
55         virtual bool OnEvent(const SEvent &event) { return false; };
56         virtual bool pausesGame() { return false; } // Used for pause menu
57 #ifdef __ANDROID__
58         virtual bool getAndroidUIInput() { return false; }
59         bool hasAndroidUIInput();
60 #endif
61
62 protected:
63         virtual std::wstring getLabelByID(s32 id) = 0;
64         virtual std::string getNameByID(s32 id) = 0;
65
66         /**
67          * check if event is part of a double click
68          * @param event event to evaluate
69          * @return true/false if a doubleclick was detected
70          */
71         bool DoubleClickDetection(const SEvent &event);
72
73         v2s32 m_pointer;
74         v2s32 m_old_pointer;  // Mouse position after previous mouse event
75         v2u32 m_screensize_old;
76         float m_gui_scale;
77 #ifdef __ANDROID__
78         v2s32 m_down_pos;
79         std::string m_jni_field_name;
80 #endif
81 #ifdef HAVE_TOUCHSCREENGUI
82         bool m_touchscreen_visible = true;
83 #endif
84
85 private:
86         struct clickpos
87         {
88                 v2s32 pos;
89                 s64 time;
90         };
91         clickpos m_doubleclickdetect[2];
92
93         IMenuManager *m_menumgr;
94         /* If true, remap a double-click (or double-tap) action to ESC. This is so
95          * that, for example, Android users can double-tap to close a formspec.
96         *
97          * This value can (currently) only be set by the class constructor
98          * and the default value for the setting is true.
99          */
100         bool m_remap_dbl_click;
101         // This might be necessary to expose to the implementation if it
102         // wants to launch other menus
103         bool m_allow_focus_removal = false;
104
105 #ifdef __ANDROID__
106         irr_ptr<gui::IGUIElement> m_hovered;
107
108         bool simulateMouseEvent(gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event);
109         void enter(gui::IGUIElement *element);
110         void leave();
111 #endif
112 };