2 Copyright (C) 2014 sapier
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.
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.
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.
21 #include <IEventReceiver.h>
22 #include <IGUIButton.h>
23 #include <IGUIEnvironment.h>
28 #include "client/tile.h"
32 using namespace irr::core;
33 using namespace irr::gui;
42 after_last_element_id,
44 rare_controls_starter_id,
54 } touch_gui_button_id;
61 } autohide_button_bar_dir;
63 #define MIN_DIG_TIME_MS 500
64 #define MAX_TOUCH_COUNT 64
65 #define BUTTON_REPEAT_DELAY 0.2f
67 #define SETTINGS_BAR_Y_OFFSET 6.5
68 #define RARE_CONTROLS_BAR_Y_OFFSET 4
70 extern const char **touchgui_button_imagenames;
76 irr::EKEY_CODE keycode;
78 IGUIButton *guibutton = nullptr;
79 bool immediate_release;
82 class AutoHideButtonBar
85 AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver);
87 void init(ISimpleTextureSource *tsrc, const char *starter_img, int button_id,
88 v2s32 UpperLeft, v2s32 LowerRight, autohide_button_bar_dir dir,
93 /* add button to be shown */
94 void addButton(touch_gui_button_id id, const wchar_t *caption,
95 const char *btn_image);
97 /* detect settings bar button events */
98 bool isButton(const SEvent &event);
100 /* handle released hud buttons */
101 bool isReleaseButton(int eventID);
104 void step(float dtime);
106 /* deactivate button bar */
109 /* hide the whole buttonbar */
112 /* unhide the buttonbar */
116 ISimpleTextureSource *m_texturesource = nullptr;
117 irr::video::IVideoDriver *m_driver;
118 IGUIEnvironment *m_guienv;
119 IEventReceiver *m_receiver;
120 button_info m_starter;
121 std::vector<button_info *> m_buttons;
126 /* show settings bar */
127 bool m_active = false;
129 bool m_visible = true;
131 /* settings bar timeout */
132 float m_timeout = 0.0f;
133 float m_timeout_value = 3.0f;
134 bool m_initialized = false;
135 autohide_button_bar_dir m_dir = AHBB_Dir_Right_Left;
141 TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
144 void translateEvent(const SEvent &event);
146 void init(ISimpleTextureSource *tsrc);
148 double getYawChange()
150 double res = m_camera_yaw_change;
151 m_camera_yaw_change = 0;
155 double getPitch() { return m_camera_pitch; }
157 line3d<f32> getShootline() { return m_shootline; }
159 void step(float dtime);
161 void registerHudItem(int index, const rect<s32> &rect);
162 void Toggle(bool visible);
168 IrrlichtDevice *m_device;
169 IGUIEnvironment *m_guienv;
170 IEventReceiver *m_receiver;
171 ISimpleTextureSource *m_texturesource;
173 std::map<int, rect<s32>> m_hud_rects;
174 std::map<int, irr::EKEY_CODE> m_hud_ids;
175 bool m_visible; // is the gui visible
177 /* value in degree */
178 double m_camera_yaw_change = 0.0;
179 double m_camera_pitch = 0.0;
181 line3d<f32> m_shootline;
184 bool m_move_has_really_moved = false;
185 s64 m_move_downtime = 0;
186 bool m_move_sent_as_mouse_event = false;
187 v2s32 m_move_downlocation = v2s32(-10000, -10000);
189 button_info m_buttons[after_last_element_id];
191 /* gui button detection */
192 touch_gui_button_id getButtonID(s32 x, s32 y);
194 /* gui button by eventID */
195 touch_gui_button_id getButtonID(int eventID);
197 /* check if a button has changed */
198 void handleChangedButton(const SEvent &event);
200 /* initialize a button */
201 void initButton(touch_gui_button_id id, rect<s32> button_rect,
202 std::wstring caption, bool immediate_release,
203 float repeat_delay = BUTTON_REPEAT_DELAY);
212 /* vector to store known ids and their initial touch positions*/
213 std::vector<id_status> m_known_ids;
215 /* handle a button event */
216 void handleButtonEvent(touch_gui_button_id bID, int eventID, bool action);
218 /* handle pressed hud buttons */
219 bool isHUDButton(const SEvent &event);
221 /* handle released hud buttons */
222 bool isReleaseHUDButton(int eventID);
224 /* handle double taps */
225 bool doubleTapDetection();
227 /* handle release event */
228 void handleReleaseEvent(int evt_id);
230 /* get size of regular gui control button */
231 int getGuiButtonSize();
233 /* doubleclick detection variables */
236 unsigned int down_time;
241 /* array for saving last known position of a pointer */
242 v2s32 m_pointerpos[MAX_TOUCH_COUNT];
244 /* array for doubletap detection */
245 key_event m_key_events[2];
248 AutoHideButtonBar m_settingsbar;
250 /* rare controls bar */
251 AutoHideButtonBar m_rarecontrolsbar;
253 extern TouchScreenGUI *g_touchscreengui;