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