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