2014-04-21 05:10:59 -07:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 sapier
|
2019-04-01 12:33:19 -07:00
|
|
|
Copyright (C) 2014-2019 Maksim Gamarnik [MoNTE48] MoNTE48@mail.ua
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
2015-08-13 15:26:28 -07:00
|
|
|
the Free Software Foundation; either version 3.0 of the License, or
|
2014-04-21 05:10:59 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "touchscreengui.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "keycode.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "porting.h"
|
2015-03-09 06:32:11 -07:00
|
|
|
#include "guiscalingfilter.h"
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace irr::core;
|
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
const char *touchgui_button_imagenames[][2] = {
|
|
|
|
{"up_one_btn.png", "up_one_press.png"},
|
|
|
|
{"up_two_btn.png","up_two_press.png"},
|
|
|
|
{"up_three_btn.png", "up_three_press.png"},
|
|
|
|
{"down_one_btn.png", "down_one_press.png"},
|
|
|
|
{"down_two_btn.png", "down_two_press.png"},
|
|
|
|
{"down_three_btn.png", "down_three_press.png"},
|
|
|
|
{"left_btn.png", "left_press.png"},
|
|
|
|
{"right_btn.png", "right_press.png"},
|
|
|
|
{"empty_btn.png"},
|
|
|
|
{"inventory_btn.png"},
|
|
|
|
{"drop_btn.png"},
|
|
|
|
{"jump_btn.png"},
|
|
|
|
{"down_btn.png"},
|
|
|
|
{"escape_btn.png"},
|
|
|
|
{"minimap_btn.png"},
|
|
|
|
{"rangeview_btn.png"},
|
2020-01-17 13:59:51 -08:00
|
|
|
{"camera_btn.png"},
|
2019-09-11 09:28:44 -07:00
|
|
|
{"chat_btn.png"}
|
2020-01-17 13:59:51 -08:00
|
|
|
// {"noclip_btn.png"},
|
|
|
|
// {"fast_btn.png"}
|
2014-04-21 05:10:59 -07:00
|
|
|
};
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
2019-08-23 07:15:11 -07:00
|
|
|
std::string key = "";
|
2014-04-21 05:10:59 -07:00
|
|
|
switch (id) {
|
2016-02-06 17:11:12 -08:00
|
|
|
case forward_one:
|
|
|
|
key = "forward";
|
|
|
|
break;
|
|
|
|
case forward_two:
|
|
|
|
key = "forward";
|
|
|
|
break;
|
|
|
|
case forward_three:
|
2014-04-21 05:10:59 -07:00
|
|
|
key = "forward";
|
|
|
|
break;
|
2016-02-06 17:11:12 -08:00
|
|
|
case backward_one:
|
|
|
|
key = "backward";
|
|
|
|
break;
|
|
|
|
case backward_two:
|
|
|
|
key = "backward";
|
|
|
|
break;
|
|
|
|
case backward_three:
|
|
|
|
key = "backward";
|
|
|
|
break;
|
2014-04-21 05:10:59 -07:00
|
|
|
case left_id:
|
|
|
|
key = "left";
|
|
|
|
break;
|
|
|
|
case right_id:
|
|
|
|
key = "right";
|
|
|
|
break;
|
2019-09-11 09:28:44 -07:00
|
|
|
case empty_id:
|
|
|
|
key = "forward";
|
|
|
|
break;
|
2014-12-09 19:57:25 -08:00
|
|
|
case inventory_id:
|
|
|
|
key = "inventory";
|
|
|
|
break;
|
|
|
|
case drop_id:
|
|
|
|
key = "drop";
|
|
|
|
break;
|
2014-04-21 05:10:59 -07:00
|
|
|
case jump_id:
|
|
|
|
key = "jump";
|
|
|
|
break;
|
2014-12-09 19:57:25 -08:00
|
|
|
case crunch_id:
|
|
|
|
key = "sneak";
|
|
|
|
break;
|
2019-08-06 17:38:08 -07:00
|
|
|
case escape_id:
|
|
|
|
return irr::KEY_ESCAPE;
|
2016-04-08 10:43:15 -07:00
|
|
|
case minimap_id:
|
|
|
|
key = "minimap";
|
|
|
|
break;
|
2019-08-06 17:38:08 -07:00
|
|
|
case range_id:
|
|
|
|
key = "rangeselect";
|
|
|
|
break;
|
2020-01-17 13:59:51 -08:00
|
|
|
case camera_id:
|
|
|
|
key = "camera_mode";
|
|
|
|
break;
|
2014-04-21 05:10:59 -07:00
|
|
|
case chat_id:
|
|
|
|
key = "chat";
|
|
|
|
break;
|
2019-09-11 09:28:44 -07:00
|
|
|
/* case noclip_id:
|
2020-01-17 13:59:51 -08:00
|
|
|
key = "noclip";
|
|
|
|
break;
|
|
|
|
case fast_id:
|
|
|
|
key = "fast";
|
2019-09-11 09:28:44 -07:00
|
|
|
break; */
|
2019-08-06 17:38:08 -07:00
|
|
|
case after_last_element_id:
|
|
|
|
break;
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
2019-08-06 17:38:08 -07:00
|
|
|
assert(!key.empty());
|
2016-01-31 11:15:20 -08:00
|
|
|
return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TouchScreenGUI *g_touchscreengui;
|
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
static void load_button_texture(button_info *btn, touch_gui_button_id id,
|
2019-08-23 07:15:11 -07:00
|
|
|
rect<s32> button_rect, ISimpleTextureSource *tsrc,
|
2019-08-06 17:38:08 -07:00
|
|
|
video::IVideoDriver *driver) {
|
2019-09-11 09:28:44 -07:00
|
|
|
|
|
|
|
const char *path = touchgui_button_imagenames[id][0];
|
|
|
|
const char *path_pressed = (touchgui_button_imagenames[id][1]) ? touchgui_button_imagenames[id][1] : path;
|
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
unsigned int tid;
|
2019-06-19 15:09:23 -07:00
|
|
|
video::ITexture *texture = guiScalingImageButton(driver,
|
2019-08-06 17:38:08 -07:00
|
|
|
tsrc->getTexture(path, &tid),
|
|
|
|
button_rect.getWidth(),
|
|
|
|
button_rect.getHeight());
|
2019-09-11 09:28:44 -07:00
|
|
|
|
|
|
|
video::ITexture *texture_pressed = texture;
|
|
|
|
if (strcmp(path, path_pressed) != 0) {
|
|
|
|
texture_pressed = guiScalingImageButton(driver,
|
|
|
|
tsrc->getTexture(path_pressed, &tid),
|
|
|
|
button_rect.getWidth(),
|
|
|
|
button_rect.getHeight());
|
|
|
|
texture_pressed = (texture_pressed) ? texture_pressed : texture;
|
|
|
|
}
|
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
if (texture) {
|
|
|
|
btn->guibutton->setUseAlphaChannel(true);
|
2015-03-09 06:32:11 -07:00
|
|
|
if (g_settings->getBool("gui_scaling_filter")) {
|
|
|
|
rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), button_rect.getHeight());
|
|
|
|
btn->guibutton->setImage(texture, txr_rect);
|
2019-09-11 09:28:44 -07:00
|
|
|
btn->guibutton->setPressedImage(texture_pressed, txr_rect);
|
2015-03-09 06:32:11 -07:00
|
|
|
btn->guibutton->setScaleImage(false);
|
|
|
|
} else {
|
|
|
|
btn->guibutton->setImage(texture);
|
2019-09-11 09:28:44 -07:00
|
|
|
btn->guibutton->setPressedImage(texture_pressed);
|
2015-03-09 06:32:11 -07:00
|
|
|
btn->guibutton->setScaleImage(true);
|
|
|
|
}
|
2014-04-21 05:10:59 -07:00
|
|
|
btn->guibutton->setDrawBorder(false);
|
|
|
|
btn->guibutton->setText(L"");
|
2019-08-06 17:38:08 -07:00
|
|
|
}
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) :
|
2019-06-19 15:09:23 -07:00
|
|
|
m_device(device),
|
|
|
|
m_guienv(device->getGUIEnvironment()),
|
|
|
|
m_camera_yaw_change(0.0),
|
|
|
|
m_camera_pitch(0.0),
|
|
|
|
m_visible(false),
|
|
|
|
m_move_id(-1),
|
|
|
|
m_receiver(receiver),
|
|
|
|
m_move_has_really_moved(false),
|
|
|
|
m_move_downtime(0),
|
|
|
|
m_move_sent_as_mouse_event(false),
|
2019-08-06 17:38:08 -07:00
|
|
|
// use some downlocation way off screen as init value to avoid invalid behaviour
|
|
|
|
m_move_downlocation(v2s32(-10000, -10000)) {
|
2019-08-23 07:15:11 -07:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
|
|
|
m_buttons[i].guibutton = 0;
|
|
|
|
m_buttons[i].repeatcounter = -1;
|
|
|
|
m_buttons[i].repeatdelay = BUTTON_REPEAT_DELAY;
|
2019-06-19 15:09:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
|
|
|
}
|
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
2019-08-06 17:38:08 -07:00
|
|
|
std::wstring caption, bool immediate_release, float repeat_delay) {
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
button_info *btn = &m_buttons[id];
|
|
|
|
btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str());
|
2014-04-21 05:10:59 -07:00
|
|
|
btn->guibutton->grab();
|
|
|
|
btn->repeatcounter = -1;
|
2015-03-24 05:19:32 -07:00
|
|
|
btn->repeatdelay = repeat_delay;
|
2014-04-21 05:10:59 -07:00
|
|
|
btn->keycode = id2keycode(id);
|
|
|
|
btn->immediate_release = immediate_release;
|
|
|
|
btn->ids.clear();
|
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
load_button_texture(btn, id, button_rect,
|
2019-08-06 17:38:08 -07:00
|
|
|
m_texturesource, m_device->getVideoDriver());
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
|
|
|
|
assert(tsrc != nullptr);
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
float density = porting::getDisplayDensity() * g_settings->getFloat("hud_scaling");
|
|
|
|
s32 button_size = static_cast<s32>(density * 60);
|
|
|
|
s32 ctlpad_size = static_cast<s32>(density * 85);
|
|
|
|
m_visible = true;
|
|
|
|
m_texturesource = tsrc;
|
|
|
|
m_control_pad_rect = rect<s32>(0, (m_screensize.Y - ctlpad_size * 3),
|
|
|
|
(ctlpad_size * 3), m_screensize.Y);
|
2015-05-02 03:43:02 -07:00
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
/*
|
|
|
|
draw control pad
|
2015-04-16 22:27:39 -07:00
|
|
|
0 3 6
|
|
|
|
1 4 7
|
|
|
|
2 5 8
|
2014-04-21 05:10:59 -07:00
|
|
|
*/
|
2018-08-22 16:43:33 -07:00
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
int number = 0;
|
2016-01-31 11:15:20 -08:00
|
|
|
for (int y = 0; y < 3; ++y)
|
|
|
|
for (int x = 0; x < 3; ++x, ++number) {
|
2015-05-02 00:31:36 -07:00
|
|
|
v2s32 tl;
|
2020-01-17 13:59:51 -08:00
|
|
|
tl.X = ctlpad_size * y;
|
|
|
|
tl.Y = m_screensize.Y - ctlpad_size * (3 - x);
|
2015-05-02 03:28:09 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32> button_rect(tl.X, tl.Y, tl.X + ctlpad_size, tl.Y + ctlpad_size);
|
2014-04-21 05:10:59 -07:00
|
|
|
touch_gui_button_id id = after_last_element_id;
|
|
|
|
std::wstring caption;
|
|
|
|
switch (number) {
|
2019-08-06 17:38:08 -07:00
|
|
|
case 0:
|
|
|
|
id = forward_one;
|
|
|
|
caption = L"^";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
id = forward_two;
|
|
|
|
caption = L"^";
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
id = forward_three;
|
|
|
|
caption = L"^";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
id = left_id;
|
|
|
|
caption = L"<";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
id = empty_id;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
id = backward_one;
|
|
|
|
caption = L"v";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
id = backward_two;
|
|
|
|
caption = L"v";
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
id = backward_three;
|
|
|
|
caption = L"v";
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
id = right_id;
|
|
|
|
caption = L">";
|
|
|
|
break;
|
2019-11-02 13:06:13 -07:00
|
|
|
default:
|
|
|
|
break;
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
2020-01-17 13:59:51 -08:00
|
|
|
if (id != after_last_element_id)
|
2014-04-21 05:10:59 -07:00
|
|
|
initButton(id, button_rect, caption, false);
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
// init inventory button
|
2014-04-21 05:10:59 -07:00
|
|
|
initButton(inventory_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X - button_size * 1.5,
|
|
|
|
m_screensize.Y - button_size * 1.5,
|
2019-08-06 17:38:08 -07:00
|
|
|
m_screensize.X,
|
|
|
|
m_screensize.Y),
|
2016-05-02 18:21:56 -07:00
|
|
|
L"inv", false, SLOW_BUTTON_REPEAT);
|
2015-05-02 03:28:09 -07:00
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
// init crunch button
|
2014-04-21 05:10:59 -07:00
|
|
|
initButton(crunch_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X - button_size * 3,
|
|
|
|
m_screensize.Y - button_size / 1.5,
|
|
|
|
m_screensize.X - button_size * 1.5,
|
2019-08-06 17:38:08 -07:00
|
|
|
m_screensize.Y),
|
2016-02-12 13:06:12 -08:00
|
|
|
L"H", false, SLOW_BUTTON_REPEAT);
|
2016-05-02 18:21:56 -07:00
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
// init jump button
|
2016-04-08 10:43:15 -07:00
|
|
|
initButton(jump_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X - button_size * 3,
|
|
|
|
m_screensize.Y - button_size * 3,
|
|
|
|
m_screensize.X - button_size * 1.5,
|
|
|
|
m_screensize.Y - button_size * 1.5),
|
2019-04-01 12:33:19 -07:00
|
|
|
L"x", false, SLOW_BUTTON_REPEAT);
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
// init drop button
|
|
|
|
initButton(drop_id,
|
|
|
|
rect<s32>(m_screensize.X - button_size,
|
|
|
|
m_screensize.Y / 2 - button_size,
|
|
|
|
m_screensize.X,
|
|
|
|
m_screensize.Y / 2),
|
|
|
|
L"drop", false, SLOW_BUTTON_REPEAT);
|
|
|
|
|
|
|
|
//dirty implementation of positions for iOS
|
|
|
|
double button_075 = 1;
|
|
|
|
double button_05 = 1;
|
|
|
|
double button_05b = 0;
|
2016-11-05 15:14:16 -07:00
|
|
|
#ifdef __IOS__
|
2020-01-17 13:59:51 -08:00
|
|
|
button_075 = 0.75;
|
|
|
|
button_05 = 2;
|
|
|
|
button_05b = button_size / 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// init pause button [1]
|
2016-11-05 15:14:16 -07:00
|
|
|
initButton(escape_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X / 2 - button_size * 2 * button_075,
|
2019-11-02 13:06:13 -07:00
|
|
|
0,
|
2020-01-17 13:59:51 -08:00
|
|
|
m_screensize.X / 2 - button_size / button_05,
|
|
|
|
button_size),
|
2016-11-05 15:14:16 -07:00
|
|
|
L"Exit", false, SLOW_BUTTON_REPEAT);
|
2018-08-22 16:43:33 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
// init minimap button [2]
|
|
|
|
#ifndef __IOS__
|
|
|
|
// iOS have memory leak with enabled minimap
|
2016-11-23 10:21:32 -08:00
|
|
|
initButton(minimap_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X / 2 - button_size,
|
2019-11-02 13:06:13 -07:00
|
|
|
0,
|
2020-01-17 13:59:51 -08:00
|
|
|
m_screensize.X / 2,
|
|
|
|
button_size),
|
2019-08-06 17:38:08 -07:00
|
|
|
L"minimap", false, SLOW_BUTTON_REPEAT);
|
|
|
|
#endif
|
2020-01-17 13:59:51 -08:00
|
|
|
|
|
|
|
// init rangeselect button [3]
|
2019-08-06 17:38:08 -07:00
|
|
|
initButton(range_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X / 2 - button_05b,
|
|
|
|
0,
|
|
|
|
m_screensize.X / 2 + button_size / button_05,
|
|
|
|
button_size),
|
2019-08-06 17:38:08 -07:00
|
|
|
L"far", false, SLOW_BUTTON_REPEAT);
|
2018-08-22 16:43:33 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
// init camera button [4]
|
|
|
|
initButton(camera_id,
|
|
|
|
rect<s32>(m_screensize.X / 2 + button_size / button_05,
|
|
|
|
0,
|
|
|
|
m_screensize.X / 2 + button_size * 2 * button_075,
|
|
|
|
button_size),
|
|
|
|
L"cam", false, SLOW_BUTTON_REPEAT);
|
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
// init chat button
|
2016-04-08 10:43:15 -07:00
|
|
|
initButton(chat_id,
|
2020-01-17 13:59:51 -08:00
|
|
|
rect<s32>(m_screensize.X - button_size * 1.25,
|
2019-11-02 13:06:13 -07:00
|
|
|
0,
|
2020-01-17 13:59:51 -08:00
|
|
|
m_screensize.X,
|
|
|
|
button_size),
|
|
|
|
L"far", false, SLOW_BUTTON_REPEAT);
|
2016-11-05 15:14:16 -07:00
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
// init noclip button
|
|
|
|
/* initButton(noclip_id,
|
2019-11-02 13:06:13 -07:00
|
|
|
rect<s32>(m_screensize.X - button_size * 0.75,
|
|
|
|
m_screensize.Y - button_size * 4.75,
|
|
|
|
m_screensize.X,
|
|
|
|
m_screensize.Y - button_size * 4),
|
2019-09-11 09:28:44 -07:00
|
|
|
L"clip", false, SLOW_BUTTON_REPEAT);
|
|
|
|
// init fast button
|
|
|
|
initButton(fast_id,
|
2019-11-02 13:06:13 -07:00
|
|
|
rect<s32>(m_screensize.X - button_size * 0.75,
|
|
|
|
m_screensize.Y - button_size * 4,
|
|
|
|
m_screensize.X,
|
|
|
|
m_screensize.Y - button_size * 3.25),
|
2020-01-17 13:59:51 -08:00
|
|
|
L"fast", false, SLOW_BUTTON_REPEAT); */
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) {
|
|
|
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (rootguielement != nullptr) {
|
2014-04-21 05:10:59 -07:00
|
|
|
gui::IGUIElement *element =
|
2019-08-06 17:38:08 -07:00
|
|
|
rootguielement->getElementFromPoint(core::position2d<s32>(x, y));
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
if (element) {
|
2016-02-01 08:11:26 -08:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2020-01-17 13:59:51 -08:00
|
|
|
if (element == m_buttons[i].guibutton)
|
2014-04-21 05:10:59 -07:00
|
|
|
return (touch_gui_button_id) i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return after_last_element_id;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) {
|
2016-02-01 08:11:26 -08:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2019-08-06 17:38:08 -07:00
|
|
|
button_info *btn = &m_buttons[i];
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-23 07:15:11 -07:00
|
|
|
std::vector<size_t>::iterator id =
|
2019-08-06 17:38:08 -07:00
|
|
|
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
if (id != btn->ids.end())
|
|
|
|
return (touch_gui_button_id) i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return after_last_element_id;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
bool TouchScreenGUI::isHUDButton(const SEvent &event) {
|
2014-04-21 05:10:59 -07:00
|
|
|
// check if hud item is pressed
|
2019-08-23 07:15:11 -07:00
|
|
|
for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
|
|
|
|
iter != m_hud_rects.end(); ++iter) {
|
|
|
|
if (iter->second.isPointInside(
|
2014-04-21 05:10:59 -07:00
|
|
|
v2s32(event.TouchInput.X,
|
2019-08-06 17:38:08 -07:00
|
|
|
event.TouchInput.Y)
|
|
|
|
)) {
|
2019-08-23 07:15:11 -07:00
|
|
|
if (iter->first < 9) {
|
2019-11-02 13:06:13 -07:00
|
|
|
SEvent *translated = new SEvent();
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
2019-08-23 07:15:11 -07:00
|
|
|
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->KeyInput.Control = false;
|
|
|
|
translated->KeyInput.Shift = false;
|
|
|
|
translated->KeyInput.PressedDown = true;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
m_hud_ids[event.TouchInput.ID] = translated->KeyInput.Key;
|
|
|
|
delete translated;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:11:26 -08:00
|
|
|
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
2019-08-06 17:38:08 -07:00
|
|
|
size_t eventID, bool action) {
|
|
|
|
button_info *btn = &m_buttons[button];
|
2019-11-02 13:06:13 -07:00
|
|
|
SEvent *translated = new SEvent();
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated->KeyInput.Key = btn->keycode;
|
|
|
|
translated->KeyInput.Control = false;
|
|
|
|
translated->KeyInput.Shift = false;
|
|
|
|
translated->KeyInput.Char = 0;
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// add this event
|
2014-04-21 05:10:59 -07:00
|
|
|
if (action) {
|
2019-08-06 17:38:08 -07:00
|
|
|
assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == btn->ids.end());
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
btn->ids.push_back(eventID);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (btn->ids.size() > 1)
|
|
|
|
return;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
btn->repeatcounter = 0;
|
2019-09-11 09:28:44 -07:00
|
|
|
m_buttons[button].guibutton->setPressed(true);
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->KeyInput.PressedDown = true;
|
|
|
|
translated->KeyInput.Key = btn->keycode;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
}
|
2019-08-06 17:38:08 -07:00
|
|
|
// remove event
|
2020-01-17 13:59:51 -08:00
|
|
|
if (!action || btn->immediate_release) {
|
2019-08-23 07:15:11 -07:00
|
|
|
std::vector<size_t>::iterator pos =
|
|
|
|
std::find(btn->ids.begin(),btn->ids.end(), eventID);
|
2019-08-06 17:38:08 -07:00
|
|
|
// has to be in touch list
|
2014-04-21 05:10:59 -07:00
|
|
|
assert(pos != btn->ids.end());
|
|
|
|
btn->ids.erase(pos);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (!btn->ids.empty())
|
|
|
|
return;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
m_buttons[button].guibutton->setPressed(false);
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->KeyInput.PressedDown = false;
|
|
|
|
btn->repeatcounter = -1;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
}
|
|
|
|
delete translated;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
2015-12-27 12:55:32 -08:00
|
|
|
touch_gui_button_id button = getButtonID(evt_id);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// handle button events
|
2020-01-17 13:59:51 -08:00
|
|
|
if (button != after_last_element_id)
|
2016-02-01 08:11:26 -08:00
|
|
|
handleButtonEvent(button, evt_id, false);
|
2020-01-17 13:59:51 -08:00
|
|
|
|
2019-08-23 07:15:11 -07:00
|
|
|
// handle the point used for moving view
|
2020-01-17 13:59:51 -08:00
|
|
|
if (evt_id == m_move_id) {
|
2015-12-27 12:55:32 -08:00
|
|
|
m_move_id = -1;
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// if this pointer issued a mouse event issue symmetric release here
|
2015-12-27 12:55:32 -08:00
|
|
|
if (m_move_sent_as_mouse_event) {
|
2019-11-02 13:06:13 -07:00
|
|
|
SEvent *translated = new SEvent;
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2015-12-27 12:55:32 -08:00
|
|
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
|
|
|
translated->MouseInput.X = m_move_downlocation.X;
|
|
|
|
translated->MouseInput.Y = m_move_downlocation.Y;
|
|
|
|
translated->MouseInput.Shift = false;
|
|
|
|
translated->MouseInput.Control = false;
|
|
|
|
translated->MouseInput.ButtonStates = 0;
|
|
|
|
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
delete translated;
|
2019-08-06 17:38:08 -07:00
|
|
|
} else if (!m_move_has_really_moved) {
|
2019-11-02 13:06:13 -07:00
|
|
|
SEvent *translated = new SEvent;
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2015-12-27 12:55:32 -08:00
|
|
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
|
|
|
translated->MouseInput.X = m_move_downlocation.X;
|
|
|
|
translated->MouseInput.Y = m_move_downlocation.Y;
|
|
|
|
translated->MouseInput.Shift = false;
|
|
|
|
translated->MouseInput.Control = false;
|
|
|
|
translated->MouseInput.ButtonStates = 0;
|
|
|
|
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
delete translated;
|
2019-08-06 17:38:08 -07:00
|
|
|
quickTapDetection();
|
2015-12-27 12:55:32 -08:00
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(
|
2019-08-06 17:38:08 -07:00
|
|
|
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
2015-12-27 12:55:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 07:15:11 -07:00
|
|
|
for (std::vector<id_status>::iterator iter = m_known_ids.begin();
|
2016-01-31 11:15:20 -08:00
|
|
|
iter != m_known_ids.end(); ++iter) {
|
2015-12-27 12:55:32 -08:00
|
|
|
if (iter->id == evt_id) {
|
|
|
|
m_known_ids.erase(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 13:23:16 -08:00
|
|
|
void TouchScreenGUI::handleReleaseAll()
|
|
|
|
{
|
|
|
|
m_known_ids.clear();
|
2020-01-17 13:59:51 -08:00
|
|
|
if (m_move_id != -1)
|
2016-12-19 13:23:16 -08:00
|
|
|
handleReleaseEvent(m_move_id);
|
2020-01-17 13:59:51 -08:00
|
|
|
for (int i = 0; i < after_last_element_id; i++)
|
2016-12-19 13:23:16 -08:00
|
|
|
m_buttons[i].ids.clear();
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::translateEvent(const SEvent &event) {
|
2014-04-21 05:10:59 -07:00
|
|
|
if (!m_visible) {
|
|
|
|
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (event.EventType != EET_TOUCH_INPUT_EVENT)
|
2014-04-21 05:10:59 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
|
|
|
/* add to own copy of eventlist ...
|
|
|
|
* android would provide this information but irrlicht guys don't
|
2019-08-06 17:38:08 -07:00
|
|
|
* wanna design a efficient interface */
|
|
|
|
id_status toadd{};
|
2014-04-21 05:10:59 -07:00
|
|
|
toadd.id = event.TouchInput.ID;
|
|
|
|
toadd.X = event.TouchInput.X;
|
|
|
|
toadd.Y = event.TouchInput.Y;
|
|
|
|
m_known_ids.push_back(toadd);
|
|
|
|
|
2016-11-05 15:14:07 -07:00
|
|
|
size_t eventID = event.TouchInput.ID;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
touch_gui_button_id button =
|
|
|
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// handle button events
|
2014-04-21 05:10:59 -07:00
|
|
|
if (button != after_last_element_id) {
|
2016-02-01 08:11:26 -08:00
|
|
|
handleButtonEvent(button, eventID, true);
|
2020-01-17 13:59:51 -08:00
|
|
|
// ignore events inside the control pad and HUD if not already handled
|
|
|
|
} else if (!(m_control_pad_rect.isPointInside(v2s32(toadd.X, toadd.Y)) || isHUDButton(event))) {
|
2019-08-06 17:38:08 -07:00
|
|
|
// handle non button events
|
|
|
|
// if we don't already have a moving point make this the moving one
|
2014-04-21 05:10:59 -07:00
|
|
|
if (m_move_id == -1) {
|
|
|
|
m_move_id = event.TouchInput.ID;
|
|
|
|
m_move_has_really_moved = false;
|
2016-03-06 11:31:16 -08:00
|
|
|
m_move_downtime = porting::getTimeMs();
|
2014-04-21 05:10:59 -07:00
|
|
|
m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
m_move_sent_as_mouse_event = false;
|
2016-12-20 14:49:28 -08:00
|
|
|
|
|
|
|
// update shootline (in case the game handles the event we send below)
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(m_move_downlocation);
|
|
|
|
|
|
|
|
// send a middle click event so the game can handle single touches
|
2019-08-23 07:15:11 -07:00
|
|
|
SEvent *translated = new SEvent;
|
2016-12-20 14:49:28 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
|
|
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
|
|
|
translated->MouseInput.X = m_move_downlocation.X;
|
|
|
|
translated->MouseInput.Y = m_move_downlocation.Y;
|
|
|
|
translated->MouseInput.ButtonStates = EMBSM_MIDDLE; // << important!
|
|
|
|
translated->MouseInput.Event = EMIE_MMOUSE_LEFT_UP;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
delete translated;
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
2019-08-06 17:38:08 -07:00
|
|
|
} else if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
2014-04-21 05:10:59 -07:00
|
|
|
verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
|
2015-12-27 12:55:32 -08:00
|
|
|
handleReleaseEvent(event.TouchInput.ID);
|
2019-08-06 17:38:08 -07:00
|
|
|
} else {
|
2014-04-21 05:10:59 -07:00
|
|
|
assert(event.TouchInput.Event == ETIE_MOVED);
|
|
|
|
|
2019-06-19 15:09:23 -07:00
|
|
|
if (m_pointerpos[event.TouchInput.ID] ==
|
2019-08-06 17:38:08 -07:00
|
|
|
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
2014-04-21 05:10:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_move_id != -1) {
|
|
|
|
if ((event.TouchInput.ID == m_move_id) &&
|
2016-10-16 14:40:44 -07:00
|
|
|
(!m_move_sent_as_mouse_event || !g_settings->getBool("touchtarget"))) {
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
double distance = sqrt(
|
2019-06-19 15:09:23 -07:00
|
|
|
(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) *
|
|
|
|
(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) +
|
|
|
|
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) *
|
|
|
|
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2020-01-17 13:59:51 -08:00
|
|
|
if (distance > g_settings->getU16("touchscreen_threshold") ||
|
2019-08-06 17:38:08 -07:00
|
|
|
(m_move_has_really_moved)) {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_move_has_really_moved = true;
|
|
|
|
s32 X = event.TouchInput.X;
|
|
|
|
s32 Y = event.TouchInput.Y;
|
|
|
|
|
|
|
|
// update camera_yaw and camera_pitch
|
2019-08-23 07:15:11 -07:00
|
|
|
s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
|
|
|
|
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// adapt to similar behaviour as pc screen
|
2019-11-02 13:06:13 -07:00
|
|
|
double d = g_settings->getFloat("mouse_sensitivity");
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2016-12-11 13:57:43 -08:00
|
|
|
m_camera_yaw_change -= dx * d;
|
|
|
|
m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
// update shootline
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(v2s32(X, Y));
|
2019-06-19 15:09:23 -07:00
|
|
|
m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
2019-08-06 17:38:08 -07:00
|
|
|
} else if ((event.TouchInput.ID == m_move_id) &&
|
2014-04-21 05:10:59 -07:00
|
|
|
(m_move_sent_as_mouse_event)) {
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(
|
2019-08-06 17:38:08 -07:00
|
|
|
v2s32(event.TouchInput.X, event.TouchInput.Y));
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
2016-05-02 18:21:56 -07:00
|
|
|
} else {
|
2014-04-21 05:10:59 -07:00
|
|
|
handleChangedButton(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::handleChangedButton(const SEvent &event) {
|
2014-04-21 05:10:59 -07:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2019-08-06 17:38:08 -07:00
|
|
|
if (m_buttons[i].ids.empty())
|
2014-04-21 05:10:59 -07:00
|
|
|
continue;
|
2019-08-06 17:38:08 -07:00
|
|
|
|
2019-08-23 07:15:11 -07:00
|
|
|
for (std::vector<size_t>::iterator iter = m_buttons[i].ids.begin();
|
2019-08-06 17:38:08 -07:00
|
|
|
iter != m_buttons[i].ids.end(); ++iter) {
|
2014-04-21 05:10:59 -07:00
|
|
|
if (event.TouchInput.ID == *iter) {
|
|
|
|
int current_button_id =
|
|
|
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (current_button_id == i)
|
2014-04-21 05:10:59 -07:00
|
|
|
continue;
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// remove old button
|
|
|
|
handleButtonEvent((touch_gui_button_id) i, *iter, false);
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (current_button_id == after_last_element_id)
|
2014-04-21 05:10:59 -07:00
|
|
|
return;
|
2019-08-06 17:38:08 -07:00
|
|
|
|
|
|
|
handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true);
|
2014-04-21 05:10:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (current_button_id == after_last_element_id)
|
2014-04-21 05:10:59 -07:00
|
|
|
return;
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
button_info *btn = &m_buttons[current_button_id];
|
|
|
|
if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID)
|
2020-01-17 13:59:51 -08:00
|
|
|
== btn->ids.end())
|
2016-02-01 08:11:26 -08:00
|
|
|
handleButtonEvent((touch_gui_button_id) current_button_id,
|
2019-08-06 17:38:08 -07:00
|
|
|
event.TouchInput.ID, true);
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// Punch or left click
|
|
|
|
bool TouchScreenGUI::quickTapDetection() {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_key_events[0].down_time = m_key_events[1].down_time;
|
|
|
|
m_key_events[0].x = m_key_events[1].x;
|
|
|
|
m_key_events[0].y = m_key_events[1].y;
|
2019-08-06 17:38:08 -07:00
|
|
|
|
|
|
|
// ignore the occasional touch
|
|
|
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
|
|
|
if (delta < 50)
|
2014-04-21 05:10:59 -07:00
|
|
|
return false;
|
|
|
|
|
2019-11-02 13:06:13 -07:00
|
|
|
SEvent *translated = new SEvent();
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 05:10:59 -07:00
|
|
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
|
|
|
translated->MouseInput.X = m_key_events[0].x;
|
|
|
|
translated->MouseInput.Y = m_key_events[0].y;
|
|
|
|
translated->MouseInput.Shift = false;
|
|
|
|
translated->MouseInput.Control = false;
|
|
|
|
translated->MouseInput.ButtonStates = EMBSM_RIGHT;
|
|
|
|
|
|
|
|
// update shootline
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(v2s32(m_key_events[0].x, m_key_events[0].y));
|
|
|
|
|
2019-09-11 09:28:44 -07:00
|
|
|
translated->MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
|
2014-04-21 05:10:59 -07:00
|
|
|
verbosestream << "TouchScreenGUI::translateEvent right click press" << std::endl;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
|
|
|
|
translated->MouseInput.ButtonStates = 0;
|
|
|
|
translated->MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
|
|
|
|
verbosestream << "TouchScreenGUI::translateEvent right click release" << std::endl;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
delete translated;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
TouchScreenGUI::~TouchScreenGUI() {
|
2019-08-23 07:15:11 -07:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
|
|
|
button_info *btn = &m_buttons[i];
|
2019-08-06 17:38:08 -07:00
|
|
|
if (btn->guibutton != nullptr) {
|
2014-04-21 05:10:59 -07:00
|
|
|
btn->guibutton->drop();
|
2019-08-06 17:38:08 -07:00
|
|
|
btn->guibutton = nullptr;
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::step(float dtime) {
|
|
|
|
// simulate keyboard repeats
|
2019-08-23 07:15:11 -07:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
|
|
|
button_info *btn = &m_buttons[i];
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (!btn->ids.empty()) {
|
2016-01-31 11:15:20 -08:00
|
|
|
btn->repeatcounter += dtime;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2015-03-24 05:19:32 -07:00
|
|
|
if (btn->repeatcounter < btn->repeatdelay) continue;
|
2014-04-21 05:10:59 -07:00
|
|
|
|
|
|
|
btn->repeatcounter = 0;
|
2019-08-06 17:38:08 -07:00
|
|
|
SEvent translated{};
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(&translated, 0, sizeof(SEvent));
|
2014-04-21 05:10:59 -07:00
|
|
|
translated.EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated.KeyInput.Key = btn->keycode;
|
|
|
|
translated.KeyInput.PressedDown = false;
|
|
|
|
m_receiver->OnEvent(translated);
|
|
|
|
|
|
|
|
translated.KeyInput.PressedDown = true;
|
|
|
|
m_receiver->OnEvent(translated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// if a new placed pointer isn't moved for some time start digging
|
2014-04-21 05:10:59 -07:00
|
|
|
if ((m_move_id != -1) &&
|
|
|
|
(!m_move_has_really_moved) &&
|
|
|
|
(!m_move_sent_as_mouse_event)) {
|
2017-05-26 05:03:36 -07:00
|
|
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
if (delta > (MIN_DIG_TIME * 1000.F)) {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(
|
2019-08-06 17:38:08 -07:00
|
|
|
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
2014-04-21 05:10:59 -07:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
SEvent translated{};
|
2016-02-01 08:11:26 -08:00
|
|
|
memset(&translated, 0, sizeof(SEvent));
|
2014-04-21 05:10:59 -07:00
|
|
|
translated.EventType = EET_MOUSE_INPUT_EVENT;
|
|
|
|
translated.MouseInput.X = m_move_downlocation.X;
|
|
|
|
translated.MouseInput.Y = m_move_downlocation.Y;
|
|
|
|
translated.MouseInput.Shift = false;
|
|
|
|
translated.MouseInput.Control = false;
|
|
|
|
translated.MouseInput.ButtonStates = EMBSM_LEFT;
|
|
|
|
translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
|
|
|
|
verbosestream << "TouchScreenGUI::step left click press" << std::endl;
|
|
|
|
m_receiver->OnEvent(translated);
|
|
|
|
m_move_sent_as_mouse_event = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::resetHud() {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_hud_rects.clear();
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect) {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_hud_rects[index] = rect;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::Toggle(bool visible) {
|
2014-04-21 05:10:59 -07:00
|
|
|
m_visible = visible;
|
2019-08-23 07:15:11 -07:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
|
|
|
button_info *btn = &m_buttons[i];
|
2020-01-17 13:59:51 -08:00
|
|
|
if (btn->guibutton != nullptr)
|
2014-04-21 05:10:59 -07:00
|
|
|
btn->guibutton->setVisible(visible);
|
|
|
|
}
|
2015-12-27 12:55:32 -08:00
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
// clear all active buttons
|
2015-12-27 12:55:32 -08:00
|
|
|
if (!visible) {
|
2019-08-06 17:38:08 -07:00
|
|
|
while (!m_known_ids.empty()) {
|
2015-12-27 12:55:32 -08:00
|
|
|
handleReleaseEvent(m_known_ids.begin()->id);
|
|
|
|
}
|
|
|
|
}
|
2014-04-21 05:10:59 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::hide() {
|
2015-12-27 12:55:32 -08:00
|
|
|
if (!m_visible)
|
|
|
|
return;
|
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
Toggle(false);
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:38:08 -07:00
|
|
|
void TouchScreenGUI::show() {
|
2015-12-27 12:55:32 -08:00
|
|
|
if (m_visible)
|
|
|
|
return;
|
|
|
|
|
2014-04-21 05:10:59 -07:00
|
|
|
Toggle(true);
|
2016-02-23 18:27:46 -08:00
|
|
|
}
|