]> git.lizzy.rs Git - minetest.git/blob - src/touchscreengui.h
Translated using Weblate (Czech)
[minetest.git] / src / touchscreengui.h
1 /*
2 Copyright (C) 2014 sapier
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #ifndef TOUCHSCREENGUI_HEADER
20 #define TOUCHSCREENGUI_HEADER
21
22 #include <IGUIEnvironment.h>
23 #include <IGUIButton.h>
24 #include <IEventReceiver.h>
25
26 #include <vector>
27 #include <map>
28
29 #include "game.h"
30 #include "client/tile.h"
31
32 using namespace irr;
33 using namespace irr::core;
34 using namespace irr::gui;
35
36 typedef enum {
37         forward_id = 0,
38         backward_id,
39         left_id,
40         right_id,
41         inventory_id,
42         drop_id,
43         jump_id,
44         crunch_id,
45         fly_id,
46         noclip_id,
47         fast_id,
48         debug_id,
49         chat_id,
50         camera_id,
51         range_id,
52         after_last_element_id
53 } touch_gui_button_id;
54
55 #define MIN_DIG_TIME_MS 500
56 #define MAX_TOUCH_COUNT 64
57 #define BUTTON_REPEAT_DELAY 0.2f
58
59 extern const char** touchgui_button_imagenames;
60
61 class TouchScreenGUI
62 {
63 public:
64         TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver);
65         ~TouchScreenGUI();
66
67         void translateEvent(const SEvent &event);
68
69         void init(ISimpleTextureSource* tsrc,float density);
70
71         double getYaw() { return m_camera_yaw; }
72         double getPitch() { return m_camera_pitch; }
73         line3d<f32> getShootline() { return m_shootline; }
74
75         void step(float dtime);
76         void resetHud();
77         void registerHudItem(int index, const rect<s32> &rect);
78         void Toggle(bool visible);
79
80         void Hide();
81         void Show();
82
83 private:
84         IrrlichtDevice*         m_device;
85         IGUIEnvironment*        m_guienv;
86         IEventReceiver*         m_receiver;
87         ISimpleTextureSource*   m_texturesource;
88         v2u32                   m_screensize;
89         std::map<int,rect<s32> > m_hud_rects;
90         std::map<int,irr::EKEY_CODE> m_hud_ids;
91         bool                    m_visible; // is the gui visible
92
93         /* value in degree */
94         double                  m_camera_yaw;
95         double                  m_camera_pitch;
96
97         line3d<f32>             m_shootline;
98
99         rect<s32>               m_control_pad_rect;
100
101         int                     m_move_id;
102         bool                    m_move_has_really_moved;
103         s32                     m_move_downtime;
104         bool                    m_move_sent_as_mouse_event;
105         v2s32                   m_move_downlocation;
106
107         struct button_info {
108                 float            repeatcounter;
109                 float            repeatdelay;
110                 irr::EKEY_CODE   keycode;
111                 std::vector<int> ids;
112                 IGUIButton*      guibutton;
113                 bool             immediate_release;
114         };
115
116         button_info m_buttons[after_last_element_id];
117
118         /* gui button detection */
119         touch_gui_button_id getButtonID(s32 x, s32 y);
120
121         /* gui button by eventID */
122         touch_gui_button_id getButtonID(int eventID);
123
124         /* check if a button has changed */
125         void handleChangedButton(const SEvent &event);
126
127         /* initialize a button */
128         void initButton(touch_gui_button_id id, rect<s32> button_rect,
129                         std::wstring caption, bool immediate_release,
130                         float repeat_delay = BUTTON_REPEAT_DELAY);
131
132         /* load texture */
133         void loadButtonTexture(button_info* btn, const char* path, rect<s32> button_rect);
134
135         struct id_status{
136                 int id;
137                 int X;
138                 int Y;
139         };
140
141         /* vector to store known ids and their initial touch positions*/
142         std::vector<id_status> m_known_ids;
143
144         /* handle a button event */
145         void ButtonEvent(touch_gui_button_id bID, int eventID, bool action);
146
147         /* handle pressed hud buttons */
148         bool isHUDButton(const SEvent &event);
149
150         /* handle released hud buttons */
151         bool isReleaseHUDButton(int eventID);
152
153         /* handle double taps */
154         bool doubleTapDetection();
155
156         /* doubleclick detection variables */
157         struct key_event {
158                 unsigned int down_time;
159                 s32 x;
160                 s32 y;
161         };
162
163         /* array for saving last known position of a pointer */
164         v2s32 m_pointerpos[MAX_TOUCH_COUNT];
165
166         /* array for doubletap detection */
167         key_event m_key_events[2];
168 };
169 extern TouchScreenGUI *g_touchscreengui;
170 #endif