2014-04-21 14:10:59 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 sapier
|
2018-04-10 22:55:17 +02:00
|
|
|
Copyright (C) 2018 srifqi, Muhammad Rifqi Priyo Susanto
|
|
|
|
<muhammadrifqipriyosusanto@gmail.com>
|
2014-04-21 14:10:59 +02: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
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(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 "irrlichttypes.h"
|
|
|
|
#include "irr_v2d.h"
|
|
|
|
#include "log.h"
|
2018-12-03 19:31:20 +01:00
|
|
|
#include "client/keycode.h"
|
2014-04-21 14:10:59 +02:00
|
|
|
#include "settings.h"
|
|
|
|
#include "gettime.h"
|
|
|
|
#include "util/numeric.h"
|
|
|
|
#include "porting.h"
|
2018-12-03 19:31:20 +01:00
|
|
|
#include "client/guiscalingfilter.h"
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <ISceneCollisionManager.h>
|
|
|
|
|
2015-03-24 13:19:32 +01:00
|
|
|
// Very slow button repeat frequency (in seconds)
|
|
|
|
#define SLOW_BUTTON_REPEAT (1.0f)
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
using namespace irr::core;
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
const char **touchgui_button_imagenames = (const char *[]) {
|
2014-04-21 14:10:59 +02:00
|
|
|
"jump_btn.png",
|
2018-04-18 20:55:42 +02:00
|
|
|
"down.png",
|
2018-07-11 00:33:40 +02:00
|
|
|
"zoom.png",
|
|
|
|
"aux_btn.png"
|
2014-04-21 14:10:59 +02:00
|
|
|
};
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
const char **touchgui_joystick_imagenames = (const char *[]) {
|
|
|
|
"joystick_off.png",
|
|
|
|
"joystick_bg.png",
|
|
|
|
"joystick_center.png"
|
|
|
|
};
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
|
|
|
{
|
|
|
|
std::string key = "";
|
|
|
|
switch (id) {
|
|
|
|
case forward_id:
|
|
|
|
key = "forward";
|
|
|
|
break;
|
|
|
|
case left_id:
|
|
|
|
key = "left";
|
|
|
|
break;
|
|
|
|
case right_id:
|
|
|
|
key = "right";
|
|
|
|
break;
|
|
|
|
case backward_id:
|
|
|
|
key = "backward";
|
|
|
|
break;
|
2014-12-10 04:57:25 +01:00
|
|
|
case inventory_id:
|
|
|
|
key = "inventory";
|
|
|
|
break;
|
|
|
|
case drop_id:
|
|
|
|
key = "drop";
|
|
|
|
break;
|
2014-04-21 14:10:59 +02:00
|
|
|
case jump_id:
|
|
|
|
key = "jump";
|
|
|
|
break;
|
2014-12-10 04:57:25 +01:00
|
|
|
case crunch_id:
|
|
|
|
key = "sneak";
|
|
|
|
break;
|
2018-04-18 20:55:42 +02:00
|
|
|
case zoom_id:
|
|
|
|
key = "zoom";
|
|
|
|
break;
|
2018-07-11 00:33:40 +02:00
|
|
|
case special1_id:
|
|
|
|
key = "special1";
|
|
|
|
break;
|
2014-12-10 04:57:25 +01:00
|
|
|
case fly_id:
|
|
|
|
key = "freemove";
|
|
|
|
break;
|
|
|
|
case noclip_id:
|
|
|
|
key = "noclip";
|
|
|
|
break;
|
|
|
|
case fast_id:
|
|
|
|
key = "fastmove";
|
|
|
|
break;
|
|
|
|
case debug_id:
|
|
|
|
key = "toggle_debug";
|
2014-04-21 14:10:59 +02:00
|
|
|
break;
|
2018-04-18 20:55:42 +02:00
|
|
|
case toggle_chat_id:
|
|
|
|
key = "toggle_chat";
|
|
|
|
break;
|
|
|
|
case minimap_id:
|
|
|
|
key = "minimap";
|
|
|
|
break;
|
2014-04-21 14:10:59 +02:00
|
|
|
case chat_id:
|
|
|
|
key = "chat";
|
|
|
|
break;
|
2014-12-10 04:57:25 +01:00
|
|
|
case camera_id:
|
|
|
|
key = "camera_mode";
|
|
|
|
break;
|
|
|
|
case range_id:
|
|
|
|
key = "rangeselect";
|
2014-04-21 14:10:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(key != "");
|
|
|
|
return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchScreenGUI *g_touchscreengui;
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
static void load_button_texture(button_info *btn, const char *path,
|
|
|
|
rect<s32> button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver)
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
|
|
|
unsigned int tid;
|
2015-12-13 23:00:05 +01:00
|
|
|
video::ITexture *texture = guiScalingImageButton(driver,
|
|
|
|
tsrc->getTexture(path, &tid), button_rect.getWidth(),
|
|
|
|
button_rect.getHeight());
|
2014-04-21 14:10:59 +02:00
|
|
|
if (texture) {
|
|
|
|
btn->guibutton->setUseAlphaChannel(true);
|
2015-03-09 14:32:11 +01: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);
|
|
|
|
btn->guibutton->setPressedImage(texture, txr_rect);
|
|
|
|
btn->guibutton->setScaleImage(false);
|
|
|
|
} else {
|
|
|
|
btn->guibutton->setImage(texture);
|
|
|
|
btn->guibutton->setPressedImage(texture);
|
|
|
|
btn->guibutton->setScaleImage(true);
|
|
|
|
}
|
2014-04-21 14:10:59 +02:00
|
|
|
btn->guibutton->setDrawBorder(false);
|
|
|
|
btn->guibutton->setText(L"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device,
|
2018-04-18 20:55:42 +02:00
|
|
|
IEventReceiver *receiver) :
|
2015-12-13 23:00:05 +01:00
|
|
|
m_driver(device->getVideoDriver()),
|
|
|
|
m_guienv(device->getGUIEnvironment()),
|
2017-06-21 11:51:29 +02:00
|
|
|
m_receiver(receiver)
|
2015-12-13 23:00:05 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
void AutoHideButtonBar::init(ISimpleTextureSource *tsrc,
|
|
|
|
const char *starter_img, int button_id, v2s32 UpperLeft,
|
2015-12-13 23:00:05 +01:00
|
|
|
v2s32 LowerRight, autohide_button_bar_dir dir, float timeout)
|
|
|
|
{
|
|
|
|
m_texturesource = tsrc;
|
|
|
|
|
|
|
|
m_upper_left = UpperLeft;
|
|
|
|
m_lower_right = LowerRight;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// init settings bar
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
irr::core::rect<int> current_button = rect<s32>(UpperLeft.X, UpperLeft.Y,
|
|
|
|
LowerRight.X, LowerRight.Y);
|
|
|
|
|
|
|
|
m_starter.guibutton = m_guienv->addButton(current_button, 0, button_id, L"", 0);
|
|
|
|
m_starter.guibutton->grab();
|
|
|
|
m_starter.repeatcounter = -1;
|
|
|
|
m_starter.keycode = KEY_OEM_8; // use invalid keycode as it's not relevant
|
|
|
|
m_starter.immediate_release = true;
|
|
|
|
m_starter.ids.clear();
|
|
|
|
|
|
|
|
load_button_texture(&m_starter, starter_img, current_button,
|
|
|
|
m_texturesource, m_driver);
|
|
|
|
|
|
|
|
m_dir = dir;
|
|
|
|
m_timeout_value = timeout;
|
|
|
|
|
|
|
|
m_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoHideButtonBar::~AutoHideButtonBar()
|
|
|
|
{
|
2016-12-11 23:17:32 +01:00
|
|
|
if (m_starter.guibutton) {
|
|
|
|
m_starter.guibutton->setVisible(false);
|
|
|
|
m_starter.guibutton->drop();
|
|
|
|
}
|
2015-12-13 23:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
2018-04-18 20:55:42 +02:00
|
|
|
const wchar_t *caption, const char *btn_image)
|
2015-12-13 23:00:05 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_initialized) {
|
|
|
|
errorstream << "AutoHideButtonBar::addButton not yet initialized!"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int button_size = 0;
|
|
|
|
|
|
|
|
if ((m_dir == AHBB_Dir_Top_Bottom) || (m_dir == AHBB_Dir_Bottom_Top)) {
|
|
|
|
button_size = m_lower_right.X - m_upper_left.X;
|
|
|
|
} else {
|
|
|
|
button_size = m_lower_right.Y - m_upper_left.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
irr::core::rect<int> current_button;
|
|
|
|
|
|
|
|
if ((m_dir == AHBB_Dir_Right_Left) || (m_dir == AHBB_Dir_Left_Right)) {
|
|
|
|
|
|
|
|
int x_start = 0;
|
|
|
|
int x_end = 0;
|
|
|
|
|
|
|
|
if (m_dir == AHBB_Dir_Left_Right) {
|
|
|
|
x_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size())
|
|
|
|
+ (button_size * 0.25);
|
|
|
|
x_end = x_start + button_size;
|
|
|
|
} else {
|
|
|
|
x_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size())
|
|
|
|
- (button_size * 0.25);
|
|
|
|
x_start = x_end - button_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_button = rect<s32>(x_start, m_upper_left.Y, x_end,
|
|
|
|
m_lower_right.Y);
|
|
|
|
} else {
|
|
|
|
int y_start = 0;
|
|
|
|
int y_end = 0;
|
|
|
|
|
|
|
|
if (m_dir == AHBB_Dir_Top_Bottom) {
|
|
|
|
y_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size())
|
|
|
|
+ (button_size * 0.25);
|
|
|
|
y_end = y_start + button_size;
|
|
|
|
} else {
|
|
|
|
y_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size())
|
|
|
|
- (button_size * 0.25);
|
|
|
|
y_start = y_end - button_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_button = rect<s32>(m_upper_left.X, y_start, m_lower_right.Y,
|
|
|
|
y_end);
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = new button_info();
|
2015-12-13 23:00:05 +01:00
|
|
|
btn->guibutton = m_guienv->addButton(current_button, 0, button_id, caption, 0);
|
|
|
|
btn->guibutton->grab();
|
|
|
|
btn->guibutton->setVisible(false);
|
|
|
|
btn->guibutton->setEnabled(false);
|
|
|
|
btn->repeatcounter = -1;
|
|
|
|
btn->keycode = id2keycode(button_id);
|
|
|
|
btn->immediate_release = true;
|
|
|
|
btn->ids.clear();
|
|
|
|
|
|
|
|
load_button_texture(btn, btn_image, current_button, m_texturesource,
|
|
|
|
m_driver);
|
|
|
|
|
|
|
|
m_buttons.push_back(btn);
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
void AutoHideButtonBar::addToggleButton(touch_gui_button_id button_id,
|
|
|
|
const wchar_t *caption, const char *btn_image_1,
|
|
|
|
const char *btn_image_2)
|
|
|
|
{
|
|
|
|
addButton(button_id, caption, btn_image_1);
|
|
|
|
button_info *btn = m_buttons.back();
|
|
|
|
btn->togglable = 1;
|
|
|
|
btn->textures.push_back(btn_image_1);
|
|
|
|
btn->textures.push_back(btn_image_2);
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
bool AutoHideButtonBar::isButton(const SEvent &event)
|
|
|
|
{
|
2018-04-18 20:55:42 +02:00
|
|
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
if (rootguielement == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui::IGUIElement *element = rootguielement->getElementFromPoint(
|
|
|
|
core::position2d<s32>(event.TouchInput.X, event.TouchInput.Y));
|
|
|
|
|
|
|
|
if (element == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_active) {
|
2018-04-10 22:55:17 +02:00
|
|
|
// check for all buttons in vector
|
2015-12-13 23:00:05 +01:00
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
if ((*iter)->guibutton == element) {
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
SEvent *translated = new SEvent();
|
2015-12-13 23:00:05 +01:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
|
|
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated->KeyInput.Key = (*iter)->keycode;
|
|
|
|
translated->KeyInput.Control = false;
|
|
|
|
translated->KeyInput.Shift = false;
|
|
|
|
translated->KeyInput.Char = 0;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// add this event
|
2015-12-13 23:00:05 +01:00
|
|
|
translated->KeyInput.PressedDown = true;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// remove this event
|
2015-12-13 23:00:05 +01:00
|
|
|
translated->KeyInput.PressedDown = false;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
|
|
|
|
delete translated;
|
|
|
|
|
|
|
|
(*iter)->ids.push_back(event.TouchInput.ID);
|
|
|
|
|
|
|
|
m_timeout = 0;
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
if ((*iter)->togglable == 1) {
|
|
|
|
(*iter)->togglable = 2;
|
|
|
|
load_button_texture(*iter, (*iter)->textures[1],
|
|
|
|
(*iter)->guibutton->getRelativePosition(),
|
|
|
|
m_texturesource, m_driver);
|
|
|
|
} else if ((*iter)->togglable == 2) {
|
|
|
|
(*iter)->togglable = 1;
|
|
|
|
load_button_texture(*iter, (*iter)->textures[0],
|
|
|
|
(*iter)->guibutton->getRelativePosition(),
|
|
|
|
m_texturesource, m_driver);
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-10 22:55:17 +02:00
|
|
|
// check for starter button only
|
2015-12-13 23:00:05 +01:00
|
|
|
if (element == m_starter.guibutton) {
|
|
|
|
m_starter.ids.push_back(event.TouchInput.ID);
|
|
|
|
m_starter.guibutton->setVisible(false);
|
|
|
|
m_starter.guibutton->setEnabled(false);
|
|
|
|
m_active = true;
|
|
|
|
m_timeout = 0;
|
|
|
|
|
|
|
|
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
(*iter)->guibutton->setVisible(true);
|
|
|
|
(*iter)->guibutton->setEnabled(true);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutoHideButtonBar::isReleaseButton(int eventID)
|
|
|
|
{
|
|
|
|
std::vector<int>::iterator id = std::find(m_starter.ids.begin(),
|
|
|
|
m_starter.ids.end(), eventID);
|
|
|
|
|
|
|
|
if (id != m_starter.ids.end()) {
|
|
|
|
m_starter.ids.erase(id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
std::vector<int>::iterator id = std::find((*iter)->ids.begin(),
|
|
|
|
(*iter)->ids.end(), eventID);
|
|
|
|
|
|
|
|
if (id != (*iter)->ids.end()) {
|
|
|
|
(*iter)->ids.erase(id);
|
|
|
|
// TODO handle settings button release
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoHideButtonBar::step(float dtime)
|
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
m_timeout += dtime;
|
|
|
|
|
|
|
|
if (m_timeout > m_timeout_value) {
|
|
|
|
deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoHideButtonBar::deactivate()
|
|
|
|
{
|
2017-08-20 13:30:50 +02:00
|
|
|
if (m_visible) {
|
2015-12-13 23:00:05 +01:00
|
|
|
m_starter.guibutton->setVisible(true);
|
|
|
|
m_starter.guibutton->setEnabled(true);
|
|
|
|
}
|
|
|
|
m_active = false;
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
(*iter)->guibutton->setVisible(false);
|
|
|
|
(*iter)->guibutton->setEnabled(false);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoHideButtonBar::hide()
|
|
|
|
{
|
|
|
|
m_visible = false;
|
|
|
|
m_starter.guibutton->setVisible(false);
|
|
|
|
m_starter.guibutton->setEnabled(false);
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
(*iter)->guibutton->setVisible(false);
|
|
|
|
(*iter)->guibutton->setEnabled(false);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoHideButtonBar::show()
|
|
|
|
{
|
|
|
|
m_visible = true;
|
|
|
|
|
|
|
|
if (m_active) {
|
2018-04-18 20:55:42 +02:00
|
|
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
while (iter != m_buttons.end()) {
|
|
|
|
(*iter)->guibutton->setVisible(true);
|
|
|
|
(*iter)->guibutton->setEnabled(true);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_starter.guibutton->setVisible(true);
|
|
|
|
m_starter.guibutton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver):
|
2015-12-13 23:00:05 +01:00
|
|
|
m_device(device),
|
|
|
|
m_guienv(device->getGUIEnvironment()),
|
|
|
|
m_receiver(receiver),
|
|
|
|
m_settingsbar(device, receiver),
|
|
|
|
m_rarecontrolsbar(device, receiver)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
|
|
|
|
m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick");
|
2018-07-11 00:33:40 +02:00
|
|
|
m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux");
|
2015-12-13 23:00:05 +01:00
|
|
|
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
2015-03-24 13:19:32 +01:00
|
|
|
std::wstring caption, bool immediate_release, float repeat_delay)
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[id];
|
2014-04-21 14:10:59 +02:00
|
|
|
btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str());
|
|
|
|
btn->guibutton->grab();
|
|
|
|
btn->repeatcounter = -1;
|
2015-03-24 13:19:32 +01:00
|
|
|
btn->repeatdelay = repeat_delay;
|
2014-04-21 14:10:59 +02:00
|
|
|
btn->keycode = id2keycode(id);
|
|
|
|
btn->immediate_release = immediate_release;
|
|
|
|
btn->ids.clear();
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
load_button_texture(btn, touchgui_button_imagenames[id], button_rect,
|
2015-12-13 23:00:05 +01:00
|
|
|
m_texturesource, m_device->getVideoDriver());
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id, rect<s32> button_rect,
|
|
|
|
int texture_id, bool visible)
|
|
|
|
{
|
|
|
|
button_info *btn = new button_info();
|
|
|
|
btn->guibutton = m_guienv->addButton(button_rect, 0, id, L"O");
|
|
|
|
btn->guibutton->setVisible(visible);
|
|
|
|
btn->guibutton->grab();
|
|
|
|
btn->ids.clear();
|
|
|
|
|
|
|
|
load_button_texture(btn, touchgui_joystick_imagenames[texture_id], button_rect,
|
|
|
|
m_texturesource, m_device->getVideoDriver());
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
static int getMaxControlPadSize(float density) {
|
2015-01-07 00:10:46 +01:00
|
|
|
return 200 * density * g_settings->getFloat("hud_scaling");
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
int TouchScreenGUI::getGuiButtonSize()
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
2015-12-13 23:00:05 +01:00
|
|
|
u32 control_pad_size = MYMIN((2 * m_screensize.Y) / 3,
|
|
|
|
getMaxControlPadSize(porting::getDisplayDensity()));
|
|
|
|
|
|
|
|
return control_pad_size / 3;
|
|
|
|
}
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
|
2015-12-13 23:00:05 +01:00
|
|
|
{
|
2018-04-10 22:55:17 +02:00
|
|
|
assert(tsrc);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
u32 button_size = getGuiButtonSize();
|
|
|
|
m_visible = true;
|
|
|
|
m_texturesource = tsrc;
|
|
|
|
|
|
|
|
/* Init joystick display "button"
|
|
|
|
* Joystick is placed on bottom left of screen.
|
|
|
|
*/
|
|
|
|
if (m_fixed_joystick) {
|
|
|
|
m_joystick_btn_off = initJoystickButton(joystick_off_id,
|
|
|
|
rect<s32>(button_size,
|
|
|
|
m_screensize.Y - button_size * 4,
|
|
|
|
button_size * 4,
|
|
|
|
m_screensize.Y - button_size), 0);
|
|
|
|
} else {
|
|
|
|
m_joystick_btn_off = initJoystickButton(joystick_off_id,
|
|
|
|
rect<s32>(button_size,
|
|
|
|
m_screensize.Y - button_size * 3,
|
|
|
|
button_size * 3,
|
|
|
|
m_screensize.Y - button_size), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_joystick_btn_bg = initJoystickButton(joystick_bg_id,
|
|
|
|
rect<s32>(button_size,
|
|
|
|
m_screensize.Y - button_size * 4,
|
|
|
|
button_size * 4,
|
|
|
|
m_screensize.Y - button_size),
|
|
|
|
1, false);
|
|
|
|
|
|
|
|
m_joystick_btn_center = initJoystickButton(joystick_center_id,
|
|
|
|
rect<s32>(0, 0, button_size, button_size), 2, false);
|
|
|
|
|
|
|
|
// init jump button
|
2014-04-21 14:10:59 +02:00
|
|
|
initButton(jump_id,
|
2018-04-18 20:55:42 +02:00
|
|
|
rect<s32>(m_screensize.X - (1.75 * button_size),
|
|
|
|
m_screensize.Y - button_size,
|
|
|
|
m_screensize.X - (0.25 * button_size),
|
2018-06-30 23:33:14 +02:00
|
|
|
m_screensize.Y),
|
2018-04-18 20:55:42 +02:00
|
|
|
L"x", false);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// init crunch button
|
2014-04-21 14:10:59 +02:00
|
|
|
initButton(crunch_id,
|
2018-04-18 20:55:42 +02:00
|
|
|
rect<s32>(m_screensize.X - (3.25 * button_size),
|
|
|
|
m_screensize.Y - button_size,
|
|
|
|
m_screensize.X - (1.75 * button_size),
|
2018-06-30 23:33:14 +02:00
|
|
|
m_screensize.Y),
|
2018-04-18 20:55:42 +02:00
|
|
|
L"H", false);
|
|
|
|
|
|
|
|
// init zoom button
|
|
|
|
initButton(zoom_id,
|
|
|
|
rect<s32>(m_screensize.X - (1.25 * button_size),
|
2018-07-11 00:33:40 +02:00
|
|
|
m_screensize.Y - (4 * button_size),
|
2018-04-18 20:55:42 +02:00
|
|
|
m_screensize.X - (0.25 * button_size),
|
2018-07-11 00:33:40 +02:00
|
|
|
m_screensize.Y - (3 * button_size)),
|
2018-04-18 20:55:42 +02:00
|
|
|
L"z", false);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2018-10-19 05:52:47 +02:00
|
|
|
// init special1/aux button
|
2018-07-11 00:33:40 +02:00
|
|
|
if (!m_joystick_triggers_special1)
|
|
|
|
initButton(special1_id,
|
|
|
|
rect<s32>(m_screensize.X - (1.25 * button_size),
|
|
|
|
m_screensize.Y - (2.5 * button_size),
|
|
|
|
m_screensize.X - (0.25 * button_size),
|
|
|
|
m_screensize.Y - (1.5 * button_size)),
|
|
|
|
L"spc1", false);
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
|
2018-10-19 05:52:47 +02:00
|
|
|
v2s32(m_screensize.X - (1.25 * button_size),
|
|
|
|
m_screensize.Y - ((SETTINGS_BAR_Y_OFFSET + 1.0) * button_size)
|
|
|
|
+ (0.5 * button_size)),
|
|
|
|
v2s32(m_screensize.X - (0.25 * button_size),
|
|
|
|
m_screensize.Y - (SETTINGS_BAR_Y_OFFSET * button_size)
|
|
|
|
+ (0.5 * button_size)),
|
|
|
|
AHBB_Dir_Right_Left, 3.0);
|
2015-12-13 23:00:05 +01:00
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png");
|
|
|
|
m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png");
|
|
|
|
m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png");
|
|
|
|
m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
|
|
|
|
m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
|
|
|
|
m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
|
|
|
|
m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png");
|
|
|
|
|
|
|
|
// Chat is shown by default, so chat_hide_btn.png is shown first.
|
|
|
|
m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat",
|
|
|
|
"chat_hide_btn.png", "chat_show_btn.png");
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
|
2018-10-19 05:52:47 +02:00
|
|
|
rare_controls_starter_id,
|
|
|
|
v2s32(0.25 * button_size,
|
|
|
|
m_screensize.Y - ((RARE_CONTROLS_BAR_Y_OFFSET + 1.0) * button_size)
|
|
|
|
+ (0.5 * button_size)),
|
|
|
|
v2s32(0.75 * button_size,
|
|
|
|
m_screensize.Y - (RARE_CONTROLS_BAR_Y_OFFSET * button_size)
|
|
|
|
+ (0.5 * button_size)),
|
|
|
|
AHBB_Dir_Left_Right, 2.0);
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
m_rarecontrolsbar.addButton(chat_id, L"Chat", "chat_btn.png");
|
|
|
|
m_rarecontrolsbar.addButton(inventory_id, L"inv", "inventory_btn.png");
|
|
|
|
m_rarecontrolsbar.addButton(drop_id, L"drop", "drop_btn.png");
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
|
|
|
{
|
2018-04-18 20:55:42 +02:00
|
|
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (rootguielement != NULL) {
|
|
|
|
gui::IGUIElement *element =
|
2018-04-18 20:55:42 +02:00
|
|
|
rootguielement->getElementFromPoint(core::position2d<s32>(x, y));
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
for (unsigned int i=0; i < after_last_element_id; i++) {
|
|
|
|
if (element == m_buttons[i].guibutton) {
|
|
|
|
return (touch_gui_button_id) i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return after_last_element_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
|
|
|
|
{
|
|
|
|
for (unsigned int i=0; i < after_last_element_id; i++) {
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[i];
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
std::vector<int>::iterator id =
|
2018-04-18 20:55:42 +02:00
|
|
|
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (id != btn->ids.end())
|
|
|
|
return (touch_gui_button_id) i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return after_last_element_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
|
|
|
{
|
|
|
|
// check if hud item is pressed
|
2018-04-18 20:55:42 +02:00
|
|
|
for (std::map<int, rect<s32> >::iterator iter = m_hud_rects.begin();
|
2015-08-25 22:23:05 +02:00
|
|
|
iter != m_hud_rects.end(); ++iter) {
|
2014-04-21 14:10:59 +02:00
|
|
|
if (iter->second.isPointInside(
|
|
|
|
v2s32(event.TouchInput.X,
|
|
|
|
event.TouchInput.Y)
|
|
|
|
)) {
|
|
|
|
if ( iter->first < 8) {
|
2018-04-18 20:55:42 +02:00
|
|
|
SEvent *translated = new SEvent();
|
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02:00
|
|
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchScreenGUI::isReleaseHUDButton(int eventID)
|
|
|
|
{
|
2018-04-18 20:55:42 +02:00
|
|
|
std::map<int, irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (iter != m_hud_ids.end()) {
|
2018-04-18 20:55:42 +02:00
|
|
|
SEvent *translated = new SEvent();
|
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02:00
|
|
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated->KeyInput.Key = iter->second;
|
|
|
|
translated->KeyInput.PressedDown = false;
|
|
|
|
translated->KeyInput.Control = false;
|
|
|
|
translated->KeyInput.Shift = false;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
m_hud_ids.erase(iter);
|
|
|
|
delete translated;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
2014-04-21 14:10:59 +02:00
|
|
|
int eventID, bool action)
|
|
|
|
{
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[button];
|
|
|
|
SEvent *translated = new SEvent();
|
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02: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;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// add this event
|
2014-04-21 14:10:59 +02:00
|
|
|
if (action) {
|
2018-04-18 20:55:42 +02:00
|
|
|
assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == btn->ids.end());
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
btn->ids.push_back(eventID);
|
|
|
|
|
|
|
|
if (btn->ids.size() > 1) return;
|
|
|
|
|
|
|
|
btn->repeatcounter = 0;
|
|
|
|
translated->KeyInput.PressedDown = true;
|
|
|
|
translated->KeyInput.Key = btn->keycode;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
// remove event
|
2014-04-21 14:10:59 +02:00
|
|
|
if ((!action) || (btn->immediate_release)) {
|
|
|
|
|
|
|
|
std::vector<int>::iterator pos =
|
2018-04-18 20:55:42 +02:00
|
|
|
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
2018-04-10 22:55:17 +02:00
|
|
|
// has to be in touch list
|
2014-04-21 14:10:59 +02:00
|
|
|
assert(pos != btn->ids.end());
|
|
|
|
btn->ids.erase(pos);
|
|
|
|
|
|
|
|
if (btn->ids.size() > 0) { return; }
|
|
|
|
|
|
|
|
translated->KeyInput.PressedDown = false;
|
|
|
|
btn->repeatcounter = -1;
|
|
|
|
m_receiver->OnEvent(*translated);
|
|
|
|
}
|
|
|
|
delete translated;
|
|
|
|
}
|
|
|
|
|
2015-12-17 20:43:25 +01:00
|
|
|
|
|
|
|
void TouchScreenGUI::handleReleaseEvent(int evt_id)
|
|
|
|
{
|
|
|
|
touch_gui_button_id button = getButtonID(evt_id);
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle button events
|
2015-12-17 20:43:25 +01:00
|
|
|
if (button != after_last_element_id) {
|
2015-12-13 23:00:05 +01:00
|
|
|
handleButtonEvent(button, evt_id, false);
|
2015-12-17 20:43:25 +01:00
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle hud button events
|
2015-12-17 20:43:25 +01:00
|
|
|
else if (isReleaseHUDButton(evt_id)) {
|
2018-04-10 22:55:17 +02:00
|
|
|
// nothing to do here
|
2015-12-13 23:00:05 +01:00
|
|
|
} else if (m_settingsbar.isReleaseButton(evt_id)) {
|
2018-04-10 22:55:17 +02:00
|
|
|
// nothing to do here
|
2015-12-13 23:00:05 +01:00
|
|
|
} else if (m_rarecontrolsbar.isReleaseButton(evt_id)) {
|
2018-04-10 22:55:17 +02:00
|
|
|
// nothing to do here
|
2015-12-17 20:43:25 +01:00
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle the point used for moving view
|
2015-12-17 20:43:25 +01:00
|
|
|
else if (evt_id == m_move_id) {
|
|
|
|
m_move_id = -1;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// if this pointer issued a mouse event issue symmetric release here
|
2015-12-17 20:43:25 +01:00
|
|
|
if (m_move_sent_as_mouse_event) {
|
2018-04-18 20:55:42 +02:00
|
|
|
SEvent *translated = new SEvent;
|
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2015-12-17 20:43:25 +01: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;
|
|
|
|
}
|
|
|
|
else {
|
2018-04-10 22:55:17 +02:00
|
|
|
// do double tap detection
|
2015-12-17 20:43:25 +01:00
|
|
|
doubleTapDetection();
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle joystick
|
|
|
|
else if (evt_id == m_joystick_id) {
|
|
|
|
m_joystick_id = -1;
|
|
|
|
|
|
|
|
// reset joystick
|
|
|
|
for (unsigned int i = 0; i < 4; i ++)
|
|
|
|
m_joystick_status[i] = false;
|
|
|
|
applyJoystickStatus();
|
|
|
|
|
|
|
|
m_joystick_btn_off->guibutton->setVisible(true);
|
|
|
|
m_joystick_btn_bg->guibutton->setVisible(false);
|
|
|
|
m_joystick_btn_center->guibutton->setVisible(false);
|
|
|
|
}
|
2015-12-17 20:43:25 +01:00
|
|
|
else {
|
|
|
|
infostream
|
|
|
|
<< "TouchScreenGUI::translateEvent released unknown button: "
|
|
|
|
<< evt_id << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::vector<id_status>::iterator iter = m_known_ids.begin();
|
|
|
|
iter != m_known_ids.end(); ++iter) {
|
|
|
|
if (iter->id == evt_id) {
|
|
|
|
m_known_ids.erase(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
void TouchScreenGUI::translateEvent(const SEvent &event)
|
|
|
|
{
|
|
|
|
if (!m_visible) {
|
|
|
|
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.EventType != EET_TOUCH_INPUT_EVENT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
|
|
|
|
|
|
|
/* add to own copy of eventlist ...
|
|
|
|
* android would provide this information but irrlicht guys don't
|
|
|
|
* wanna design a efficient interface
|
|
|
|
*/
|
|
|
|
id_status toadd;
|
|
|
|
toadd.id = event.TouchInput.ID;
|
|
|
|
toadd.X = event.TouchInput.X;
|
|
|
|
toadd.Y = event.TouchInput.Y;
|
|
|
|
m_known_ids.push_back(toadd);
|
|
|
|
|
|
|
|
int eventID = event.TouchInput.ID;
|
|
|
|
|
|
|
|
touch_gui_button_id button =
|
|
|
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle button events
|
2014-04-21 14:10:59 +02:00
|
|
|
if (button != after_last_element_id) {
|
2015-12-13 23:00:05 +01:00
|
|
|
handleButtonEvent(button, eventID, true);
|
|
|
|
m_settingsbar.deactivate();
|
|
|
|
m_rarecontrolsbar.deactivate();
|
|
|
|
} else if (isHUDButton(event)) {
|
|
|
|
m_settingsbar.deactivate();
|
|
|
|
m_rarecontrolsbar.deactivate();
|
2018-04-10 22:55:17 +02:00
|
|
|
// already handled in isHUDButton()
|
2015-12-13 23:00:05 +01:00
|
|
|
} else if (m_settingsbar.isButton(event)) {
|
|
|
|
m_rarecontrolsbar.deactivate();
|
2018-04-10 22:55:17 +02:00
|
|
|
// already handled in isSettingsBarButton()
|
2015-12-13 23:00:05 +01:00
|
|
|
} else if (m_rarecontrolsbar.isButton(event)) {
|
|
|
|
m_settingsbar.deactivate();
|
2018-04-10 22:55:17 +02:00
|
|
|
// already handled in isSettingsBarButton()
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
// handle non button events
|
2014-04-21 14:10:59 +02:00
|
|
|
else {
|
2015-12-13 23:00:05 +01:00
|
|
|
m_settingsbar.deactivate();
|
|
|
|
m_rarecontrolsbar.deactivate();
|
2018-04-10 22:55:17 +02:00
|
|
|
|
|
|
|
u32 button_size = getGuiButtonSize();
|
|
|
|
s32 dxj = event.TouchInput.X - button_size * 5 / 2;
|
|
|
|
s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5 / 2;
|
|
|
|
|
|
|
|
/* Select joystick when left 1/3 of screen dragged or
|
|
|
|
* when joystick tapped (fixed joystick position)
|
|
|
|
*/
|
|
|
|
if ((m_fixed_joystick && dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5) ||
|
|
|
|
(!m_fixed_joystick && event.TouchInput.X < m_screensize.X / 3)) {
|
|
|
|
// If we don't already have a starting point for joystick make this the one.
|
|
|
|
if (m_joystick_id == -1) {
|
|
|
|
m_joystick_id = event.TouchInput.ID;
|
|
|
|
m_joystick_has_really_moved = false;
|
|
|
|
|
|
|
|
m_joystick_btn_off->guibutton->setVisible(false);
|
|
|
|
m_joystick_btn_bg->guibutton->setVisible(true);
|
|
|
|
m_joystick_btn_center->guibutton->setVisible(true);
|
|
|
|
|
|
|
|
// If it's a fixed joystick, don't move the joystick "button".
|
|
|
|
if (!m_fixed_joystick) {
|
|
|
|
m_joystick_btn_bg->guibutton->setRelativePosition(v2s32(
|
|
|
|
event.TouchInput.X - button_size * 3 / 2,
|
|
|
|
event.TouchInput.Y - button_size * 3 / 2));
|
|
|
|
}
|
|
|
|
m_joystick_btn_center->guibutton->setRelativePosition(v2s32(
|
|
|
|
event.TouchInput.X - button_size / 2,
|
|
|
|
event.TouchInput.Y - button_size / 2));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we don't already have a moving point make this the moving one.
|
|
|
|
if (m_move_id == -1) {
|
|
|
|
m_move_id = event.TouchInput.ID;
|
|
|
|
m_move_has_really_moved = false;
|
|
|
|
m_move_downtime = porting::getTimeMs();
|
|
|
|
m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
m_move_sent_as_mouse_event = false;
|
|
|
|
}
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
}
|
|
|
|
else if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
|
|
|
verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
|
2015-12-17 20:43:25 +01:00
|
|
|
handleReleaseEvent(event.TouchInput.ID);
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(event.TouchInput.Event == ETIE_MOVED);
|
|
|
|
int move_idx = event.TouchInput.ID;
|
|
|
|
|
|
|
|
if (m_pointerpos[event.TouchInput.ID] ==
|
|
|
|
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_move_id != -1) {
|
|
|
|
if ((event.TouchInput.ID == m_move_id) &&
|
|
|
|
(!m_move_sent_as_mouse_event)) {
|
|
|
|
|
|
|
|
double distance = sqrt(
|
|
|
|
(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));
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
if ((distance > m_touchscreen_threshold) ||
|
2014-04-21 14:10:59 +02:00
|
|
|
(m_move_has_really_moved)) {
|
|
|
|
m_move_has_really_moved = true;
|
|
|
|
s32 X = event.TouchInput.X;
|
|
|
|
s32 Y = event.TouchInput.Y;
|
|
|
|
|
|
|
|
// update camera_yaw and camera_pitch
|
|
|
|
s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
|
|
|
|
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// adapt to similar behaviour as pc screen
|
|
|
|
double d = g_settings->getFloat("mouse_sensitivity") * 4;
|
2016-12-11 22:57:43 +01:00
|
|
|
double old_yaw = m_camera_yaw_change;
|
2014-04-21 14:10:59 +02:00
|
|
|
double old_pitch = m_camera_pitch;
|
|
|
|
|
2016-12-11 22:57:43 +01:00
|
|
|
m_camera_yaw_change -= dx * d;
|
|
|
|
m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
// update shootline
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(v2s32(X, Y));
|
|
|
|
m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((event.TouchInput.ID == m_move_id) &&
|
|
|
|
(m_move_sent_as_mouse_event)) {
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(
|
2018-04-10 22:55:17 +02:00
|
|
|
v2s32(event.TouchInput.X, event.TouchInput.Y));
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_joystick_id != -1 && event.TouchInput.ID == m_joystick_id) {
|
|
|
|
u32 button_size = getGuiButtonSize();
|
|
|
|
s32 X = event.TouchInput.X;
|
|
|
|
s32 Y = event.TouchInput.Y;
|
|
|
|
|
|
|
|
s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
|
|
|
|
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
|
|
|
if (m_fixed_joystick) {
|
|
|
|
dx = X - button_size * 5 / 2;
|
|
|
|
dy = Y - m_screensize.Y + button_size * 5 / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
double distance_sq = dx * dx + dy * dy;
|
|
|
|
|
|
|
|
s32 dxj = event.TouchInput.X - button_size * 5 / 2;
|
|
|
|
s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5 / 2;
|
|
|
|
bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5);
|
|
|
|
|
|
|
|
if (m_joystick_has_really_moved ||
|
|
|
|
(!m_joystick_has_really_moved && inside_joystick) ||
|
|
|
|
(!m_fixed_joystick &&
|
|
|
|
distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) {
|
|
|
|
m_joystick_has_really_moved = true;
|
|
|
|
double distance = sqrt(distance_sq);
|
|
|
|
|
|
|
|
// angle in degrees
|
|
|
|
double angle = acos(dx / distance) * 180 / M_PI;
|
|
|
|
if (dy < 0)
|
|
|
|
angle *= -1;
|
|
|
|
// rotate to make comparing easier
|
|
|
|
angle = fmod(angle + 180 + 22.5, 360);
|
|
|
|
|
|
|
|
// reset state before applying
|
2018-07-11 00:33:40 +02:00
|
|
|
for (unsigned int i = 0; i < 5; i ++)
|
2018-04-10 22:55:17 +02:00
|
|
|
m_joystick_status[i] = false;
|
|
|
|
|
|
|
|
if (distance <= m_touchscreen_threshold) {
|
|
|
|
// do nothing
|
|
|
|
} else if (angle < 45)
|
|
|
|
m_joystick_status[j_left] = true;
|
|
|
|
else if (angle < 90) {
|
|
|
|
m_joystick_status[j_forward] = true;
|
|
|
|
m_joystick_status[j_left] = true;
|
|
|
|
} else if (angle < 135)
|
|
|
|
m_joystick_status[j_forward] = true;
|
|
|
|
else if (angle < 180) {
|
|
|
|
m_joystick_status[j_forward] = true;
|
|
|
|
m_joystick_status[j_right] = true;
|
|
|
|
} else if (angle < 225)
|
|
|
|
m_joystick_status[j_right] = true;
|
|
|
|
else if (angle < 270) {
|
|
|
|
m_joystick_status[j_backward] = true;
|
|
|
|
m_joystick_status[j_right] = true;
|
|
|
|
} else if (angle < 315)
|
|
|
|
m_joystick_status[j_backward] = true;
|
|
|
|
else if (angle <= 360) {
|
|
|
|
m_joystick_status[j_backward] = true;
|
|
|
|
m_joystick_status[j_left] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distance > button_size) {
|
2018-07-11 00:33:40 +02:00
|
|
|
m_joystick_status[j_special1] = true;
|
|
|
|
// move joystick "button"
|
2018-04-10 22:55:17 +02:00
|
|
|
s32 ndx = (s32) button_size * dx / distance - (s32) button_size / 2;
|
|
|
|
s32 ndy = (s32) button_size * dy / distance - (s32) button_size / 2;
|
|
|
|
if (m_fixed_joystick) {
|
|
|
|
m_joystick_btn_center->guibutton->setRelativePosition(v2s32(
|
|
|
|
button_size * 5 / 2 + ndx,
|
|
|
|
m_screensize.Y - button_size * 5 / 2 + ndy));
|
|
|
|
} else {
|
|
|
|
m_joystick_btn_center->guibutton->setRelativePosition(v2s32(
|
|
|
|
m_pointerpos[event.TouchInput.ID].X + ndx,
|
|
|
|
m_pointerpos[event.TouchInput.ID].Y + ndy));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_joystick_btn_center->guibutton->setRelativePosition(v2s32(
|
|
|
|
X - button_size / 2, Y - button_size / 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_move_id == -1 && m_joystick_id == -1) {
|
2014-04-21 14:10:59 +02:00
|
|
|
handleChangedButton(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
|
|
|
|
|
|
|
if (m_buttons[i].ids.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-13 23:00:05 +01:00
|
|
|
for (std::vector<int>::iterator iter = m_buttons[i].ids.begin();
|
2015-08-25 22:23:05 +02:00
|
|
|
iter != m_buttons[i].ids.end(); ++iter) {
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (event.TouchInput.ID == *iter) {
|
|
|
|
|
|
|
|
int current_button_id =
|
|
|
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
|
|
|
if (current_button_id == i) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// remove old button
|
2018-04-18 20:55:42 +02:00
|
|
|
handleButtonEvent((touch_gui_button_id) i, *iter, false);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (current_button_id == after_last_element_id) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-18 20:55:42 +02:00
|
|
|
handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true);
|
2014-04-21 14:10:59 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
|
|
|
|
|
|
|
if (current_button_id == after_last_element_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[current_button_id];
|
|
|
|
if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID)
|
2015-12-13 23:00:05 +01:00
|
|
|
== btn->ids.end())
|
|
|
|
{
|
|
|
|
handleButtonEvent((touch_gui_button_id) current_button_id,
|
|
|
|
event.TouchInput.ID, true);
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchScreenGUI::doubleTapDetection()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
m_key_events[1].down_time = m_move_downtime;
|
|
|
|
m_key_events[1].x = m_move_downlocation.X;
|
|
|
|
m_key_events[1].y = m_move_downlocation.Y;
|
|
|
|
|
2017-05-26 14:03:36 +02:00
|
|
|
u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
|
2014-04-21 14:10:59 +02:00
|
|
|
if (delta > 400)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
double distance = sqrt(
|
|
|
|
(m_key_events[0].x - m_key_events[1].x) * (m_key_events[0].x - m_key_events[1].x) +
|
|
|
|
(m_key_events[0].y - m_key_events[1].y) * (m_key_events[0].y - m_key_events[1].y));
|
|
|
|
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
if (distance > (20 + m_touchscreen_threshold))
|
2014-04-21 14:10:59 +02:00
|
|
|
return false;
|
|
|
|
|
2018-04-18 20:55:42 +02:00
|
|
|
SEvent *translated = new SEvent();
|
2015-12-13 23:00:05 +01:00
|
|
|
memset(translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02: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));
|
|
|
|
|
|
|
|
translated->MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
void TouchScreenGUI::applyJoystickStatus()
|
|
|
|
{
|
2018-07-11 00:33:40 +02:00
|
|
|
for (unsigned int i = 0; i < 5; i ++) {
|
|
|
|
if (i == 4 && !m_joystick_triggers_special1)
|
|
|
|
continue;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
SEvent translated{};
|
|
|
|
translated.EventType = irr::EET_KEY_INPUT_EVENT;
|
|
|
|
translated.KeyInput.Key = id2keycode(m_joystick_names[i]);
|
|
|
|
translated.KeyInput.PressedDown = false;
|
|
|
|
m_receiver->OnEvent(translated);
|
|
|
|
|
|
|
|
if (m_joystick_status[i]) {
|
|
|
|
translated.KeyInput.PressedDown = true;
|
|
|
|
m_receiver->OnEvent(translated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
TouchScreenGUI::~TouchScreenGUI()
|
|
|
|
{
|
2015-12-13 23:00:05 +01:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[i];
|
2018-04-10 22:55:17 +02:00
|
|
|
if (btn->guibutton) {
|
2014-04-21 14:10:59 +02:00
|
|
|
btn->guibutton->drop();
|
|
|
|
btn->guibutton = NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 22:55:17 +02:00
|
|
|
|
|
|
|
if (m_joystick_btn_off->guibutton) {
|
|
|
|
m_joystick_btn_off->guibutton->drop();
|
|
|
|
m_joystick_btn_off->guibutton = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_joystick_btn_bg->guibutton) {
|
|
|
|
m_joystick_btn_bg->guibutton->drop();
|
|
|
|
m_joystick_btn_bg->guibutton = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_joystick_btn_center->guibutton) {
|
|
|
|
m_joystick_btn_center->guibutton->drop();
|
|
|
|
m_joystick_btn_center->guibutton = NULL;
|
|
|
|
}
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenGUI::step(float dtime)
|
|
|
|
{
|
2018-04-10 22:55:17 +02:00
|
|
|
// simulate keyboard repeats
|
2015-12-13 23:00:05 +01:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[i];
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (btn->ids.size() > 0) {
|
|
|
|
btn->repeatcounter += dtime;
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// in case we're moving around digging does not happen
|
2015-01-06 16:01:49 +01:00
|
|
|
if (m_move_id != -1)
|
|
|
|
m_move_has_really_moved = true;
|
|
|
|
|
2015-03-24 13:19:32 +01:00
|
|
|
if (btn->repeatcounter < btn->repeatdelay) continue;
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
btn->repeatcounter = 0;
|
|
|
|
SEvent translated;
|
2015-12-13 23:00:05 +01:00
|
|
|
memset(&translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
// joystick
|
|
|
|
applyJoystickStatus();
|
|
|
|
|
|
|
|
// if a new placed pointer isn't moved for some time start digging
|
2014-04-21 14:10:59 +02:00
|
|
|
if ((m_move_id != -1) &&
|
|
|
|
(!m_move_has_really_moved) &&
|
|
|
|
(!m_move_sent_as_mouse_event)) {
|
|
|
|
|
2017-05-26 14:03:36 +02:00
|
|
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
if (delta > MIN_DIG_TIME_MS) {
|
|
|
|
m_shootline = m_device
|
|
|
|
->getSceneManager()
|
|
|
|
->getSceneCollisionManager()
|
|
|
|
->getRayFromScreenCoordinates(
|
|
|
|
v2s32(m_move_downlocation.X,m_move_downlocation.Y));
|
|
|
|
|
|
|
|
SEvent translated;
|
2015-12-13 23:00:05 +01:00
|
|
|
memset(&translated, 0, sizeof(SEvent));
|
2014-04-21 14:10:59 +02: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;
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
m_settingsbar.step(dtime);
|
|
|
|
m_rarecontrolsbar.step(dtime);
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenGUI::resetHud()
|
|
|
|
{
|
|
|
|
m_hud_rects.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect)
|
|
|
|
{
|
|
|
|
m_hud_rects[index] = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchScreenGUI::Toggle(bool visible)
|
|
|
|
{
|
|
|
|
m_visible = visible;
|
2015-12-13 23:00:05 +01:00
|
|
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
2018-04-18 20:55:42 +02:00
|
|
|
button_info *btn = &m_buttons[i];
|
2018-04-10 22:55:17 +02:00
|
|
|
if (btn->guibutton) {
|
2014-04-21 14:10:59 +02:00
|
|
|
btn->guibutton->setVisible(visible);
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 20:43:25 +01:00
|
|
|
|
2018-04-10 22:55:17 +02:00
|
|
|
if (m_joystick_btn_off->guibutton) {
|
|
|
|
m_joystick_btn_off->guibutton->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear all active buttons
|
2015-12-17 20:43:25 +01:00
|
|
|
if (!visible) {
|
|
|
|
while (m_known_ids.size() > 0) {
|
|
|
|
handleReleaseEvent(m_known_ids.begin()->id);
|
|
|
|
}
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
m_settingsbar.hide();
|
|
|
|
m_rarecontrolsbar.hide();
|
|
|
|
} else {
|
|
|
|
m_settingsbar.show();
|
|
|
|
m_rarecontrolsbar.show();
|
2015-12-17 20:43:25 +01:00
|
|
|
}
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
void TouchScreenGUI::hide()
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
2015-12-17 20:43:25 +01:00
|
|
|
if (!m_visible)
|
|
|
|
return;
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
Toggle(false);
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
void TouchScreenGUI::show()
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
2015-12-17 20:43:25 +01:00
|
|
|
if (m_visible)
|
|
|
|
return;
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
Toggle(true);
|
|
|
|
}
|