Luanti 5.18.0-dev
Loading...
Searching...
No Matches
modalMenu.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "IGUIElement.h"
9#include "irr_ptr.h"
10
11#ifdef __ANDROID__
12 #include <porting_android.h>
13#endif
14
17 u64 time; // ms
18
19 static PointerAction fromEvent(const SEvent &event);
20 bool isRelated(PointerAction other);
21};
22
23class GUIModalMenu;
24
26{
27public:
28 // A GUIModalMenu calls these when this class is passed as a parameter
29 virtual void createdMenu(gui::IGUIElement *menu) = 0;
30 virtual void deletingMenu(gui::IGUIElement *menu) = 0;
31 virtual void inhibitKeyEvent(EKEY_CODE key) = 0;
32};
33
34// Remember to drop() the menu after creating, so that it can
35// remove itself when it wants to.
36
37class GUIModalMenu : public gui::IGUIElement
38{
39public:
40 GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
41 IMenuManager *menumgr, bool remap_dbl_click = true);
42 virtual ~GUIModalMenu();
43
44 void allowFocusRemoval(bool allow);
45 bool canTakeFocus(gui::IGUIElement *e);
46 void draw();
47 void quitMenu();
48
49 virtual void regenerateGui(v2u32 screensize) = 0;
50 virtual void drawMenu() = 0;
51 virtual bool preprocessEvent(const SEvent &event);
52 virtual bool OnEvent(const SEvent &event) { return false; };
53 virtual bool pausesGame() { return false; } // Used for pause menu
54#ifdef __ANDROID__
55 virtual void getAndroidUIInput() {};
56 porting::AndroidDialogState getAndroidUIInputState();
57#endif
58
59protected:
60 virtual std::wstring getLabelByID(s32 id) = 0;
61 virtual std::string getNameByID(s32 id) = 0;
62
63 // Stores the last known pointer position.
64 // If the last input event was a mouse event, it's the cursor position.
65 // If the last input event was a touch event, it's the finger position.
67 v2s32 m_old_pointer; // Mouse position after previous mouse event
68
71#ifdef __ANDROID__
72 std::string m_jni_field_name;
73#endif
74
75 struct ScalingInfo {
76 f32 scale;
77 core::rect<s32> rect;
78 };
79 ScalingInfo getScalingInfo(v2u32 screensize, v2u32 base_size);
80
81 // This is set to true if the menu is currently processing a second-touch event.
82 bool m_second_touch = false;
83
84 virtual bool remapClickOutside(const SEvent &event);
85
86private:
88 bool m_is_window_focused = false;
89 /* If true, remap a click outside the formspec to ESC. This is so that, for
90 * example, touchscreen users can close formspecs.
91 * The default for this setting is true. Currently, it's set to false for
92 * the mainmenu to prevent Minetest from closing unexpectedly.
93 */
96
97 // This might be necessary to expose to the implementation if it
98 // wants to launch other menus
100
101 // Stuff related to touchscreen input
102
103 irr_ptr<gui::IGUIElement> m_touch_hovered;
104
105 // Converts touches into clicks.
106 bool simulateMouseEvent(ETOUCH_INPUT_EVENT touch_event, bool second_try=false);
107 void enter(gui::IGUIElement *element);
108 void leave();
109
110 // Used to detect double-taps and convert them into double-click events.
112};
Definition modalMenu.h:38
ScalingInfo getScalingInfo(v2u32 screensize, v2u32 base_size)
Definition modalMenu.cpp:376
virtual void drawMenu()=0
bool m_is_window_focused
Definition modalMenu.h:88
virtual std::string getNameByID(s32 id)=0
bool m_remap_click_outside
Definition modalMenu.h:94
float m_gui_scale
Definition modalMenu.h:70
virtual bool preprocessEvent(const SEvent &event)
Definition modalMenu.cpp:233
virtual bool OnEvent(const SEvent &event)
Definition modalMenu.h:52
void allowFocusRemoval(bool allow)
Definition modalMenu.cpp:56
PointerAction m_last_touch
Definition modalMenu.h:111
virtual bool pausesGame()
Definition modalMenu.h:53
irr_ptr< gui::IGUIElement > m_touch_hovered
Definition modalMenu.h:103
void leave()
Definition modalMenu.cpp:221
void draw()
Definition modalMenu.cpp:66
v2s32 m_pointer
Definition modalMenu.h:66
bool m_second_touch
Definition modalMenu.h:82
virtual void regenerateGui(v2u32 screensize)=0
virtual bool remapClickOutside(const SEvent &event)
Definition modalMenu.cpp:109
void quitMenu()
Definition modalMenu.cpp:91
bool simulateMouseEvent(ETOUCH_INPUT_EVENT touch_event, bool second_try=false)
Definition modalMenu.cpp:153
bool canTakeFocus(gui::IGUIElement *e)
Definition modalMenu.cpp:61
IMenuManager * m_menumgr
Definition modalMenu.h:87
bool m_allow_focus_removal
Definition modalMenu.h:99
PointerAction m_last_click_outside
Definition modalMenu.h:95
virtual std::wstring getLabelByID(s32 id)=0
GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, bool remap_dbl_click=true)
Definition modalMenu.cpp:34
virtual ~GUIModalMenu()
Definition modalMenu.cpp:51
v2u32 m_screensize_old
Definition modalMenu.h:69
v2s32 m_old_pointer
Definition modalMenu.h:67
void enter(gui::IGUIElement *element)
Definition modalMenu.cpp:207
Definition modalMenu.h:26
virtual void deletingMenu(gui::IGUIElement *menu)=0
virtual void inhibitKeyEvent(EKEY_CODE key)=0
virtual void createdMenu(gui::IGUIElement *menu)=0
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
AndroidDialogState
Definition porting_android.h:65
Definition modalMenu.h:75
core::rect< s32 > rect
Definition modalMenu.h:77
f32 scale
Definition modalMenu.h:76
Definition modalMenu.h:15
static PointerAction fromEvent(const SEvent &event)
Definition modalMenu.cpp:15
v2s32 pos
Definition modalMenu.h:16
u64 time
Definition modalMenu.h:17
bool isRelated(PointerAction other)
Definition modalMenu.cpp:26