Luanti 5.18.0-dev
Loading...
Searching...
No Matches
touchscreenlayout.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2024 grorp, Gregor Parzefall <grorp@posteo.de>
4
5#pragma once
6
7#include <iostream>
8#include <unordered_map>
9#include <vector>
10#include "irr_ptr.h"
12#include "rect.h"
13#include "util/enum_string.h"
14
16namespace gui
17{
18 class IGUIStaticText;
19}
20namespace video
21{
22 class ITexture;
23}
24
31extern const struct EnumString es_TouchInteractionStyle[];
32
67
68extern const char *button_names[];
69extern const char *button_titles[];
70extern const char *button_image_names[];
71
72struct ButtonMeta {
73 // Position, specified as a percentage of the screensize in the range [0,1].
74 // The editor currently writes the values 0, 0.5 and 1.
76 // Offset, multiplied by the global button size before it is applied.
77 // Together, position and offset define the position of the button's center.
79
80 // Returns the button's effective center position in pixels.
81 v2s32 getPos(v2u32 screensize, s32 button_size) const;
82 // Sets the button's effective center position in pixels.
83 void setPos(v2s32 pos, v2u32 screensize, s32 button_size);
84};
85
87 using ButtonMap = std::unordered_map<touch_gui_button_id, ButtonMeta>;
88
89 static bool isButtonValid(touch_gui_button_id id);
92 static s32 getButtonSize(v2u32 screensize);
93
94 // Returns the default layout.
95 // Note: Indirectly depends on settings.
97 // Reads the layout from the "touch_layout" setting. Falls back to loadDefault
98 // if the setting is absent or invalid.
99 // Note: Indirectly depends on additional settings.
101
102 static video::ITexture *getTexture(touch_gui_button_id btn, ISimpleTextureSource *tsrc);
103 static void clearTextureCache();
104
106
107 // Contains disallowed buttons that have been loaded.
108 // These are only preserved to be saved again later.
109 // This exists to prevent data loss: If you edit the layout while some button
110 // is temporarily disallowed, this prevents that button's custom position
111 // from being lost. See isButtonAllowed.
112 // This may result in overlapping buttons when the buttons are allowed again
113 // (could be fixed by resolving collisions in postProcessLoaded).
115
116 core::recti getRect(touch_gui_button_id btn,
117 v2u32 screensize, s32 button_size, ISimpleTextureSource *tsrc);
118
119 std::vector<touch_gui_button_id> getMissingButtons();
120
121 void serializeJson(std::ostream &os) const;
122
123private:
124 static const ButtonMap default_data;
125 static ButtonMap deserializeJson(std::istream &is);
126 static ButtonLayout postProcessLoaded(const ButtonMap &map);
127
128 static std::unordered_map<touch_gui_button_id, irr_ptr<video::ITexture>> texture_cache;
129};
130
131void layout_button_grid(v2u32 screensize, ISimpleTextureSource *tsrc,
132 const std::vector<touch_gui_button_id> &buttons,
133 // pos refers to the center of the button.
134 const std::function<void(touch_gui_button_id btn, v2s32 pos, core::recti rect)> &callback);
135
136void make_button_grid_title(gui::IGUIStaticText *text,
137 touch_gui_button_id btn,v2s32 pos, core::recti rect);
Definition texturesource.h:34
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
Definition fontengine.h:15
Definition clientmap.h:36
Definition touchscreenlayout.h:86
static bool isButtonValid(touch_gui_button_id id)
Definition touchscreenlayout.cpp:142
static ButtonLayout loadFromSettings()
Definition touchscreenlayout.cpp:220
static void clearTextureCache()
Definition touchscreenlayout.cpp:254
void serializeJson(std::ostream &os) const
Definition touchscreenlayout.cpp:282
static ButtonLayout postProcessLoaded(const ButtonMap &map)
Definition touchscreenlayout.cpp:202
static s32 getButtonSize(v2u32 screensize)
Definition touchscreenlayout.cpp:164
static video::ITexture * getTexture(touch_gui_button_id btn, ISimpleTextureSource *tsrc)
Definition touchscreenlayout.cpp:238
static ButtonMap deserializeJson(std::istream &is)
Definition touchscreenlayout.cpp:312
std::unordered_map< touch_gui_button_id, ButtonMeta > ButtonMap
Definition touchscreenlayout.h:87
static const ButtonMap default_data
Definition touchscreenlayout.h:171
core::recti getRect(touch_gui_button_id btn, v2u32 screensize, s32 button_size, ISimpleTextureSource *tsrc)
Definition touchscreenlayout.cpp:259
static bool isButtonAllowed(touch_gui_button_id id)
Definition touchscreenlayout.cpp:150
ButtonMap layout
Definition touchscreenlayout.h:105
static std::unordered_map< touch_gui_button_id, irr_ptr< video::ITexture > > texture_cache
Definition touchscreenlayout.h:128
static ButtonLayout loadDefault()
Definition touchscreenlayout.cpp:215
static bool isButtonRequired(touch_gui_button_id id)
Definition touchscreenlayout.cpp:159
ButtonMap preserved_disallowed
Definition touchscreenlayout.h:114
std::vector< touch_gui_button_id > getMissingButtons()
Definition touchscreenlayout.cpp:271
Definition touchscreenlayout.h:72
v2f position
Definition touchscreenlayout.h:75
void setPos(v2s32 pos, v2u32 screensize, s32 button_size)
Definition touchscreenlayout.cpp:120
v2s32 getPos(v2u32 screensize, s32 button_size) const
Definition touchscreenlayout.cpp:114
v2f offset
Definition touchscreenlayout.h:78
Definition enum_string.h:11
const char * button_titles[]
Definition touchscreenlayout.cpp:55
const char * button_image_names[]
Definition touchscreenlayout.cpp:84
const char * button_names[]
Definition touchscreenlayout.cpp:25
const struct EnumString es_TouchInteractionStyle[]
Definition touchscreenlayout.cpp:17
TouchInteractionStyle
Definition touchscreenlayout.h:26
@ TAP
Definition touchscreenlayout.h:27
@ TAP_CROSSHAIR
Definition touchscreenlayout.h:28
@ BUTTONS_CROSSHAIR
Definition touchscreenlayout.h:29
touch_gui_button_id
Definition touchscreenlayout.h:34
@ joystick_center_id
Definition touchscreenlayout.h:63
@ fast_id
Definition touchscreenlayout.h:52
@ chat_id
Definition touchscreenlayout.h:45
@ place_id
Definition touchscreenlayout.h:36
@ inventory_id
Definition touchscreenlayout.h:46
@ debug_id
Definition touchscreenlayout.h:54
@ range_id
Definition touchscreenlayout.h:56
@ zoom_id
Definition touchscreenlayout.h:40
@ exit_id
Definition touchscreenlayout.h:48
@ aux1_id
Definition touchscreenlayout.h:41
@ fly_id
Definition touchscreenlayout.h:51
@ minimap_id
Definition touchscreenlayout.h:57
@ camera_id
Definition touchscreenlayout.h:55
@ touch_gui_button_id_END
Definition touchscreenlayout.h:65
@ drop_id
Definition touchscreenlayout.h:47
@ jump_id
Definition touchscreenlayout.h:38
@ joystick_off_id
Definition touchscreenlayout.h:61
@ toggle_chat_id
Definition touchscreenlayout.h:58
@ joystick_bg_id
Definition touchscreenlayout.h:62
@ dig_id
Definition touchscreenlayout.h:35
@ sneak_id
Definition touchscreenlayout.h:39
@ noclip_id
Definition touchscreenlayout.h:53
@ overflow_id
Definition touchscreenlayout.h:42
void layout_button_grid(v2u32 screensize, ISimpleTextureSource *tsrc, const std::vector< touch_gui_button_id > &buttons, const std::function< void(touch_gui_button_id btn, v2s32 pos, core::recti rect)> &callback)
Definition touchscreenlayout.cpp:367
void make_button_grid_title(gui::IGUIStaticText *text, touch_gui_button_id btn, v2s32 pos, core::recti rect)
Definition touchscreenlayout.cpp:405