Minetest  5.4.0
modalMenu.h
Go to the documentation of this file.
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 
23 #include "irr_ptr.h"
24 #include "util/string.h"
25 
26 class GUIModalMenu;
27 
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 
71  bool DoubleClickDetection(const SEvent &event);
72 
74  v2s32 m_old_pointer; // Mouse position after previous mouse event
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  {
89  s64 time;
90  };
92 
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  */
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 };
Definition: modalMenu.h:40
virtual void drawMenu()=0
clickpos m_doubleclickdetect[2]
Definition: modalMenu.h:91
virtual std::string getNameByID(s32 id)=0
bool DoubleClickDetection(const SEvent &event)
check if event is part of a double click
Definition: modalMenu.cpp:124
float m_gui_scale
Definition: modalMenu.h:76
virtual bool preprocessEvent(const SEvent &event)
Definition: modalMenu.cpp:244
virtual bool OnEvent(const SEvent &event)
Definition: modalMenu.h:55
void allowFocusRemoval(bool allow)
Definition: modalMenu.cpp:64
virtual bool pausesGame()
Definition: modalMenu.h:56
void draw()
Definition: modalMenu.cpp:74
v2s32 m_pointer
Definition: modalMenu.h:73
bool m_remap_dbl_click
Definition: modalMenu.h:100
virtual void regenerateGui(v2u32 screensize)=0
void quitMenu()
Definition: modalMenu.cpp:97
bool canTakeFocus(gui::IGUIElement *e)
Definition: modalMenu.cpp:69
IMenuManager * m_menumgr
Definition: modalMenu.h:93
bool m_allow_focus_removal
Definition: modalMenu.h:103
virtual std::wstring getLabelByID(s32 id)=0
void removeChildren()
Definition: modalMenu.cpp:110
GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, bool remap_dbl_click=true)
Definition: modalMenu.cpp:32
virtual ~GUIModalMenu()
Definition: modalMenu.cpp:59
v2u32 m_screensize_old
Definition: modalMenu.h:75
v2s32 m_old_pointer
Definition: modalMenu.h:74
Definition: modalMenu.h:29
virtual void deletingMenu(gui::IGUIElement *menu)=0
virtual void createdMenu(gui::IGUIElement *menu)=0
Shared pointer for IrrLicht objects.
Definition: irr_ptr.h:43
core::vector2d< s32 > v2s32
Definition: irr_v2d.h:28
core::vector2d< u32 > v2u32
Definition: irr_v2d.h:29
Definition: modalMenu.h:87
v2s32 pos
Definition: modalMenu.h:88
s64 time
Definition: modalMenu.h:89