Luanti 5.11.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 "irr_ptr.h"
9#include "rect.h"
10#include <iostream>
11#include <unordered_map>
12
14namespace irr::gui
15{
16 class IGUIStaticText;
17}
18namespace irr::video
19{
20 class ITexture;
21}
22
54
55extern const char *button_names[];
56extern const char *button_titles[];
57extern const char *button_image_names[];
58
59struct ButtonMeta {
60 // Position, specified as a percentage of the screensize in the range [0,1].
61 // The editor currently writes the values 0, 0.5 and 1.
63 // Offset, multiplied by the global button size before it is applied.
64 // Together, position and offset define the position of the button's center.
66
67 // Returns the button's effective center position in pixels.
68 v2s32 getPos(v2u32 screensize, s32 button_size) const;
69 // Sets the button's effective center position in pixels.
70 void setPos(v2s32 pos, v2u32 screensize, s32 button_size);
71};
72
76 static s32 getButtonSize(v2u32 screensize);
78
79 static video::ITexture *getTexture(touch_gui_button_id btn, ISimpleTextureSource *tsrc);
80 static void clearTextureCache();
81
82 std::unordered_map<touch_gui_button_id, ButtonMeta> layout;
83
84 core::recti getRect(touch_gui_button_id btn,
85 v2u32 screensize, s32 button_size, ISimpleTextureSource *tsrc);
86
87 std::vector<touch_gui_button_id> getMissingButtons();
88
89 void serializeJson(std::ostream &os) const;
90 void deserializeJson(std::istream &is);
91
92 static const ButtonLayout predefined;
93
94private:
95 static std::unordered_map<touch_gui_button_id, irr_ptr<video::ITexture>> texture_cache;
96};
97
98void layout_button_grid(v2u32 screensize, ISimpleTextureSource *tsrc,
99 const std::vector<touch_gui_button_id> &buttons,
100 // pos refers to the center of the button.
101 const std::function<void(touch_gui_button_id btn, v2s32 pos, core::recti rect)> &callback);
102
103void make_button_grid_title(gui::IGUIStaticText *text,
104 touch_gui_button_id btn,v2s32 pos, core::recti rect);
Definition texturesource.h:25
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:14
Definition clientmap.h:35
Definition touchscreenlayout.h:73
static ButtonLayout loadFromSettings()
Definition touchscreenlayout.cpp:165
static void clearTextureCache()
Definition touchscreenlayout.cpp:205
void deserializeJson(std::istream &is)
Definition touchscreenlayout.cpp:260
std::unordered_map< touch_gui_button_id, ButtonMeta > layout
Definition touchscreenlayout.h:82
void serializeJson(std::ostream &os) const
Definition touchscreenlayout.cpp:233
static s32 getButtonSize(v2u32 screensize)
Definition touchscreenlayout.cpp:135
static video::ITexture * getTexture(touch_gui_button_id btn, ISimpleTextureSource *tsrc)
Definition touchscreenlayout.cpp:189
core::recti getRect(touch_gui_button_id btn, v2u32 screensize, s32 button_size, ISimpleTextureSource *tsrc)
Definition touchscreenlayout.cpp:210
static bool isButtonAllowed(touch_gui_button_id id)
Definition touchscreenlayout.cpp:124
static std::unordered_map< touch_gui_button_id, irr_ptr< video::ITexture > > texture_cache
Definition touchscreenlayout.h:95
static bool isButtonRequired(touch_gui_button_id id)
Definition touchscreenlayout.cpp:130
std::vector< touch_gui_button_id > getMissingButtons()
Definition touchscreenlayout.cpp:222
static const ButtonLayout predefined
Definition touchscreenlayout.h:142
Definition touchscreenlayout.h:59
v2f position
Definition touchscreenlayout.h:62
void setPos(v2s32 pos, v2u32 screensize, s32 button_size)
Definition touchscreenlayout.cpp:102
v2s32 getPos(v2u32 screensize, s32 button_size) const
Definition touchscreenlayout.cpp:96
v2f offset
Definition touchscreenlayout.h:65
const char * button_titles[]
Definition touchscreenlayout.cpp:43
const char * button_image_names[]
Definition touchscreenlayout.cpp:69
const char * button_names[]
Definition touchscreenlayout.cpp:16
touch_gui_button_id
Definition touchscreenlayout.h:24
@ joystick_center_id
Definition touchscreenlayout.h:50
@ fast_id
Definition touchscreenlayout.h:39
@ chat_id
Definition touchscreenlayout.h:32
@ inventory_id
Definition touchscreenlayout.h:33
@ debug_id
Definition touchscreenlayout.h:41
@ range_id
Definition touchscreenlayout.h:43
@ zoom_id
Definition touchscreenlayout.h:27
@ exit_id
Definition touchscreenlayout.h:35
@ aux1_id
Definition touchscreenlayout.h:28
@ fly_id
Definition touchscreenlayout.h:38
@ minimap_id
Definition touchscreenlayout.h:44
@ camera_id
Definition touchscreenlayout.h:42
@ touch_gui_button_id_END
Definition touchscreenlayout.h:52
@ drop_id
Definition touchscreenlayout.h:34
@ jump_id
Definition touchscreenlayout.h:25
@ joystick_off_id
Definition touchscreenlayout.h:48
@ toggle_chat_id
Definition touchscreenlayout.h:45
@ joystick_bg_id
Definition touchscreenlayout.h:49
@ sneak_id
Definition touchscreenlayout.h:26
@ noclip_id
Definition touchscreenlayout.h:40
@ overflow_id
Definition touchscreenlayout.h:29
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:297
void make_button_grid_title(gui::IGUIStaticText *text, touch_gui_button_id btn, v2s32 pos, core::recti rect)
Definition touchscreenlayout.cpp:335