TouchScreenGUI: update and cleanup
This commit is contained in:
parent
46f99ec01c
commit
c3dd4c934a
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2014 sapier
|
Copyright (C) 2014 sapier
|
||||||
Copyright (C) 2014-2019 Maksim Gamarnik [MoNTE48] MoNTE48@mail.ua
|
Copyright (C) 2014-2020 Maksim Gamarnik [MoNTE48] MoNTE48@mail.ua
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
|
|
||||||
const char *touchgui_button_imagenames[][2] = {
|
const char *button_imagenames[][2] = {
|
||||||
{"up_one_btn.png", "up_one_press.png"},
|
{"up_one_btn.png", "up_one_press.png"},
|
||||||
{"up_two_btn.png","up_two_press.png"},
|
{"up_two_btn.png","up_two_press.png"},
|
||||||
{"up_three_btn.png", "up_three_press.png"},
|
{"up_three_btn.png", "up_three_press.png"},
|
||||||
@ -52,24 +52,17 @@ const char *touchgui_button_imagenames[][2] = {
|
|||||||
// {"fast_btn.png"}
|
// {"fast_btn.png"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
||||||
|
{
|
||||||
std::string key = "";
|
std::string key = "";
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case forward_one:
|
case forward_one:
|
||||||
key = "forward";
|
|
||||||
break;
|
|
||||||
case forward_two:
|
case forward_two:
|
||||||
key = "forward";
|
|
||||||
break;
|
|
||||||
case forward_three:
|
case forward_three:
|
||||||
key = "forward";
|
key = "forward";
|
||||||
break;
|
break;
|
||||||
case backward_one:
|
case backward_one:
|
||||||
key = "backward";
|
|
||||||
break;
|
|
||||||
case backward_two:
|
case backward_two:
|
||||||
key = "backward";
|
|
||||||
break;
|
|
||||||
case backward_three:
|
case backward_three:
|
||||||
key = "backward";
|
key = "backward";
|
||||||
break;
|
break;
|
||||||
@ -124,11 +117,12 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
|||||||
TouchScreenGUI *g_touchscreengui;
|
TouchScreenGUI *g_touchscreengui;
|
||||||
|
|
||||||
static void load_button_texture(button_info *btn, touch_gui_button_id id,
|
static void load_button_texture(button_info *btn, touch_gui_button_id id,
|
||||||
rect<s32> button_rect, ISimpleTextureSource *tsrc,
|
const rect<s32> &button_rect, ISimpleTextureSource *tsrc,
|
||||||
video::IVideoDriver *driver) {
|
video::IVideoDriver *driver)
|
||||||
|
{
|
||||||
|
|
||||||
const char *path = touchgui_button_imagenames[id][0];
|
const char *path = button_imagenames[id][0];
|
||||||
const char *path_pressed = (touchgui_button_imagenames[id][1]) ? touchgui_button_imagenames[id][1] : path;
|
const char *path_pressed = button_imagenames[id][1] ? button_imagenames[id][1] : path;
|
||||||
|
|
||||||
unsigned int tid;
|
unsigned int tid;
|
||||||
video::ITexture *texture = guiScalingImageButton(driver,
|
video::ITexture *texture = guiScalingImageButton(driver,
|
||||||
@ -142,7 +136,7 @@ static void load_button_texture(button_info *btn, touch_gui_button_id id,
|
|||||||
tsrc->getTexture(path_pressed, &tid),
|
tsrc->getTexture(path_pressed, &tid),
|
||||||
button_rect.getWidth(),
|
button_rect.getWidth(),
|
||||||
button_rect.getHeight());
|
button_rect.getHeight());
|
||||||
texture_pressed = (texture_pressed) ? texture_pressed : texture;
|
texture_pressed = texture_pressed ? texture_pressed : texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture) {
|
if (texture) {
|
||||||
@ -172,20 +166,21 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver)
|
|||||||
m_receiver(receiver),
|
m_receiver(receiver),
|
||||||
m_move_has_really_moved(false),
|
m_move_has_really_moved(false),
|
||||||
m_move_downtime(0),
|
m_move_downtime(0),
|
||||||
m_move_sent_as_mouse_event(false),
|
m_move_sent_as_mouse_event(false)
|
||||||
// use some downlocation way off screen as init value to avoid invalid behaviour
|
{
|
||||||
m_move_downlocation(v2s32(-10000, -10000)) {
|
for (auto & m_button : m_buttons) {
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
m_button.guibutton = nullptr;
|
||||||
m_buttons[i].guibutton = 0;
|
m_button.repeatcounter = -1;
|
||||||
m_buttons[i].repeatcounter = -1;
|
m_button.repeatdelay = BUTTON_REPEAT_DELAY;
|
||||||
m_buttons[i].repeatdelay = BUTTON_REPEAT_DELAY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
|
||||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
void TouchScreenGUI::initButton(touch_gui_button_id id, const rect<s32> &button_rect,
|
||||||
std::wstring caption, bool immediate_release, float repeat_delay) {
|
const std::wstring &caption, bool immediate_release, float repeat_delay)
|
||||||
|
{
|
||||||
|
|
||||||
button_info *btn = &m_buttons[id];
|
button_info *btn = &m_buttons[id];
|
||||||
btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str());
|
btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str());
|
||||||
@ -200,7 +195,8 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
|||||||
m_texturesource, m_device->getVideoDriver());
|
m_texturesource, m_device->getVideoDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
|
void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
|
||||||
|
{
|
||||||
assert(tsrc != nullptr);
|
assert(tsrc != nullptr);
|
||||||
|
|
||||||
float density = porting::getDisplayDensity() * g_settings->getFloat("hud_scaling");
|
float density = porting::getDisplayDensity() * g_settings->getFloat("hud_scaling");
|
||||||
@ -373,7 +369,8 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
|
|||||||
L"fast", false, SLOW_BUTTON_REPEAT); */
|
L"fast", false, SLOW_BUTTON_REPEAT); */
|
||||||
}
|
}
|
||||||
|
|
||||||
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) {
|
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
||||||
|
{
|
||||||
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
||||||
|
|
||||||
if (rootguielement != nullptr) {
|
if (rootguielement != nullptr) {
|
||||||
@ -390,12 +387,12 @@ touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) {
|
|||||||
return after_last_element_id;
|
return after_last_element_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) {
|
touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID)
|
||||||
|
{
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info *btn = &m_buttons[i];
|
button_info *btn = &m_buttons[i];
|
||||||
|
|
||||||
std::vector<size_t>::iterator id =
|
auto id = std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
||||||
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
|
||||||
|
|
||||||
if (id != btn->ids.end())
|
if (id != btn->ids.end())
|
||||||
return (touch_gui_button_id) i;
|
return (touch_gui_button_id) i;
|
||||||
@ -404,19 +401,16 @@ touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) {
|
|||||||
return after_last_element_id;
|
return after_last_element_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchScreenGUI::isHUDButton(const SEvent &event) {
|
bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
||||||
|
{
|
||||||
// check if hud item is pressed
|
// check if hud item is pressed
|
||||||
for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
|
for (auto & m_hud_rect : m_hud_rects) {
|
||||||
iter != m_hud_rects.end(); ++iter) {
|
if (m_hud_rect.second.isPointInside(v2s32(event.TouchInput.X,
|
||||||
if (iter->second.isPointInside(
|
event.TouchInput.Y))) {
|
||||||
v2s32(event.TouchInput.X,
|
auto *translated = new SEvent();
|
||||||
event.TouchInput.Y)
|
|
||||||
)) {
|
|
||||||
if (iter->first < 9) {
|
|
||||||
SEvent *translated = new SEvent();
|
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
|
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + m_hud_rect.first);
|
||||||
translated->KeyInput.Control = false;
|
translated->KeyInput.Control = false;
|
||||||
translated->KeyInput.Shift = false;
|
translated->KeyInput.Shift = false;
|
||||||
translated->KeyInput.PressedDown = true;
|
translated->KeyInput.PressedDown = true;
|
||||||
@ -426,14 +420,14 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
||||||
size_t eventID, bool action) {
|
size_t eventID, bool action)
|
||||||
|
{
|
||||||
button_info *btn = &m_buttons[button];
|
button_info *btn = &m_buttons[button];
|
||||||
SEvent *translated = new SEvent();
|
auto *translated = new SEvent();
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = btn->keycode;
|
translated->KeyInput.Key = btn->keycode;
|
||||||
@ -456,10 +450,10 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
translated->KeyInput.Key = btn->keycode;
|
translated->KeyInput.Key = btn->keycode;
|
||||||
m_receiver->OnEvent(*translated);
|
m_receiver->OnEvent(*translated);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove event
|
// remove event
|
||||||
if (!action || btn->immediate_release) {
|
if (!action || btn->immediate_release) {
|
||||||
std::vector<size_t>::iterator pos =
|
auto pos = std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
||||||
std::find(btn->ids.begin(),btn->ids.end(), eventID);
|
|
||||||
// has to be in touch list
|
// has to be in touch list
|
||||||
assert(pos != btn->ids.end());
|
assert(pos != btn->ids.end());
|
||||||
btn->ids.erase(pos);
|
btn->ids.erase(pos);
|
||||||
@ -475,7 +469,8 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
delete translated;
|
delete translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
void TouchScreenGUI::handleReleaseEvent(size_t evt_id)
|
||||||
|
{
|
||||||
touch_gui_button_id button = getButtonID(evt_id);
|
touch_gui_button_id button = getButtonID(evt_id);
|
||||||
|
|
||||||
// handle button events
|
// handle button events
|
||||||
@ -488,7 +483,7 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
|||||||
|
|
||||||
// if this pointer issued a mouse event issue symmetric release here
|
// if this pointer issued a mouse event issue symmetric release here
|
||||||
if (m_move_sent_as_mouse_event) {
|
if (m_move_sent_as_mouse_event) {
|
||||||
SEvent *translated = new SEvent;
|
auto *translated = new SEvent;
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_move_downlocation.X;
|
translated->MouseInput.X = m_move_downlocation.X;
|
||||||
@ -500,7 +495,7 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
|||||||
m_receiver->OnEvent(*translated);
|
m_receiver->OnEvent(*translated);
|
||||||
delete translated;
|
delete translated;
|
||||||
} else if (!m_move_has_really_moved) {
|
} else if (!m_move_has_really_moved) {
|
||||||
SEvent *translated = new SEvent;
|
auto *translated = new SEvent;
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_move_downlocation.X;
|
translated->MouseInput.X = m_move_downlocation.X;
|
||||||
@ -520,7 +515,7 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<id_status>::iterator iter = m_known_ids.begin();
|
for (auto iter = m_known_ids.begin();
|
||||||
iter != m_known_ids.end(); ++iter) {
|
iter != m_known_ids.end(); ++iter) {
|
||||||
if (iter->id == evt_id) {
|
if (iter->id == evt_id) {
|
||||||
m_known_ids.erase(iter);
|
m_known_ids.erase(iter);
|
||||||
@ -534,11 +529,12 @@ void TouchScreenGUI::handleReleaseAll()
|
|||||||
m_known_ids.clear();
|
m_known_ids.clear();
|
||||||
if (m_move_id != -1)
|
if (m_move_id != -1)
|
||||||
handleReleaseEvent(m_move_id);
|
handleReleaseEvent(m_move_id);
|
||||||
for (int i = 0; i < after_last_element_id; i++)
|
for (auto & m_button : m_buttons)
|
||||||
m_buttons[i].ids.clear();
|
m_button.ids.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::translateEvent(const SEvent &event) {
|
void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
|
{
|
||||||
if (!m_visible) {
|
if (!m_visible) {
|
||||||
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
||||||
return;
|
return;
|
||||||
@ -548,7 +544,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
||||||
/* add to own copy of eventlist ...
|
/* add to own copy of eventlist...
|
||||||
* android would provide this information but irrlicht guys don't
|
* android would provide this information but irrlicht guys don't
|
||||||
* wanna design a efficient interface */
|
* wanna design a efficient interface */
|
||||||
id_status toadd{};
|
id_status toadd{};
|
||||||
@ -583,7 +579,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) {
|
|||||||
->getRayFromScreenCoordinates(m_move_downlocation);
|
->getRayFromScreenCoordinates(m_move_downlocation);
|
||||||
|
|
||||||
// send a middle click event so the game can handle single touches
|
// send a middle click event so the game can handle single touches
|
||||||
SEvent *translated = new SEvent;
|
auto *translated = new SEvent;
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_move_downlocation.X;
|
translated->MouseInput.X = m_move_downlocation.X;
|
||||||
@ -617,7 +613,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) {
|
|||||||
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) *
|
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) *
|
||||||
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
||||||
|
|
||||||
if (distance > g_settings->getU16("touchscreen_threshold") ||
|
if (distance > m_touchscreen_threshold ||
|
||||||
(m_move_has_really_moved)) {
|
(m_move_has_really_moved)) {
|
||||||
m_move_has_really_moved = true;
|
m_move_has_really_moved = true;
|
||||||
s32 X = event.TouchInput.X;
|
s32 X = event.TouchInput.X;
|
||||||
@ -654,12 +650,13 @@ void TouchScreenGUI::translateEvent(const SEvent &event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::handleChangedButton(const SEvent &event) {
|
void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
||||||
|
{
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
if (m_buttons[i].ids.empty())
|
if (m_buttons[i].ids.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (std::vector<size_t>::iterator iter = m_buttons[i].ids.begin();
|
for (auto iter = m_buttons[i].ids.begin();
|
||||||
iter != m_buttons[i].ids.end(); ++iter) {
|
iter != m_buttons[i].ids.end(); ++iter) {
|
||||||
if (event.TouchInput.ID == *iter) {
|
if (event.TouchInput.ID == *iter) {
|
||||||
int current_button_id =
|
int current_button_id =
|
||||||
@ -693,7 +690,8 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Punch or left click
|
// Punch or left click
|
||||||
bool TouchScreenGUI::quickTapDetection() {
|
bool TouchScreenGUI::quickTapDetection()
|
||||||
|
{
|
||||||
m_key_events[0].down_time = m_key_events[1].down_time;
|
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].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;
|
||||||
@ -703,7 +701,7 @@ bool TouchScreenGUI::quickTapDetection() {
|
|||||||
if (delta < 50)
|
if (delta < 50)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SEvent *translated = new SEvent();
|
auto *translated = new SEvent();
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_key_events[0].x;
|
translated->MouseInput.X = m_key_events[0].x;
|
||||||
@ -731,24 +729,26 @@ bool TouchScreenGUI::quickTapDetection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TouchScreenGUI::~TouchScreenGUI() {
|
TouchScreenGUI::~TouchScreenGUI() {
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (auto & m_button : m_buttons) {
|
||||||
button_info *btn = &m_buttons[i];
|
button_info *btn = &m_button;
|
||||||
if (btn->guibutton != nullptr) {
|
if (btn->guibutton) {
|
||||||
btn->guibutton->drop();
|
btn->guibutton->drop();
|
||||||
btn->guibutton = nullptr;
|
btn->guibutton = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::step(float dtime) {
|
void TouchScreenGUI::step(float dtime)
|
||||||
|
{
|
||||||
// simulate keyboard repeats
|
// simulate keyboard repeats
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (auto & m_button : m_buttons) {
|
||||||
button_info *btn = &m_buttons[i];
|
button_info *btn = &m_button;
|
||||||
|
|
||||||
if (!btn->ids.empty()) {
|
if (!btn->ids.empty()) {
|
||||||
btn->repeatcounter += dtime;
|
btn->repeatcounter += dtime;
|
||||||
|
|
||||||
if (btn->repeatcounter < btn->repeatdelay) continue;
|
if (btn->repeatcounter < btn->repeatdelay)
|
||||||
|
continue;
|
||||||
|
|
||||||
btn->repeatcounter = 0;
|
btn->repeatcounter = 0;
|
||||||
SEvent translated{};
|
SEvent translated{};
|
||||||
@ -769,7 +769,7 @@ void TouchScreenGUI::step(float dtime) {
|
|||||||
(!m_move_sent_as_mouse_event)) {
|
(!m_move_sent_as_mouse_event)) {
|
||||||
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
||||||
|
|
||||||
if (delta > (MIN_DIG_TIME * 1000.F)) {
|
if (delta > MIN_DIG_TIME) {
|
||||||
m_shootline = m_device
|
m_shootline = m_device
|
||||||
->getSceneManager()
|
->getSceneManager()
|
||||||
->getSceneCollisionManager()
|
->getSceneCollisionManager()
|
||||||
@ -792,38 +792,41 @@ void TouchScreenGUI::step(float dtime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::resetHud() {
|
void TouchScreenGUI::resetHud()
|
||||||
|
{
|
||||||
m_hud_rects.clear();
|
m_hud_rects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect) {
|
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect)
|
||||||
|
{
|
||||||
m_hud_rects[index] = rect;
|
m_hud_rects[index] = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::Toggle(bool visible) {
|
void TouchScreenGUI::Toggle(bool visible)
|
||||||
|
{
|
||||||
m_visible = visible;
|
m_visible = visible;
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (auto & m_button : m_buttons) {
|
||||||
button_info *btn = &m_buttons[i];
|
if (m_button.guibutton)
|
||||||
if (btn->guibutton != nullptr)
|
m_button.guibutton->setVisible(visible);
|
||||||
btn->guibutton->setVisible(visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear all active buttons
|
// clear all active buttons
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
while (!m_known_ids.empty()) {
|
while (!m_known_ids.empty())
|
||||||
handleReleaseEvent(m_known_ids.begin()->id);
|
handleReleaseEvent(m_known_ids.begin()->id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::hide() {
|
void TouchScreenGUI::hide()
|
||||||
|
{
|
||||||
if (!m_visible)
|
if (!m_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Toggle(false);
|
Toggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::show() {
|
void TouchScreenGUI::show()
|
||||||
|
{
|
||||||
if (m_visible)
|
if (m_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2014 sapier
|
Copyright (C) 2014 sapier
|
||||||
Copyright (C) 2014-2019 Maksim Gamarnik [MoNTE48] MoNTE48@mail.ua
|
Copyright (C) 2014-2020 Maksim Gamarnik [MoNTE48] MoNTE48@mail.ua
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -17,8 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TOUCHSCREENGUI_HEADER
|
#pragma once
|
||||||
#define TOUCHSCREENGUI_HEADER
|
|
||||||
|
|
||||||
#include <IEventReceiver.h>
|
#include <IEventReceiver.h>
|
||||||
#include <IGUIButton.h>
|
#include <IGUIButton.h>
|
||||||
@ -34,7 +33,8 @@ using namespace irr;
|
|||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
using namespace irr::gui;
|
using namespace irr::gui;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
forward_one,
|
forward_one,
|
||||||
forward_two,
|
forward_two,
|
||||||
forward_three,
|
forward_three,
|
||||||
@ -58,11 +58,12 @@ typedef enum {
|
|||||||
after_last_element_id
|
after_last_element_id
|
||||||
} touch_gui_button_id;
|
} touch_gui_button_id;
|
||||||
|
|
||||||
#define SLOW_BUTTON_REPEAT 1.0f
|
#define MIN_DIG_TIME 500
|
||||||
#define MIN_DIG_TIME 0.5f
|
|
||||||
#define BUTTON_REPEAT_DELAY 0.2f
|
#define BUTTON_REPEAT_DELAY 0.2f
|
||||||
|
#define SLOW_BUTTON_REPEAT 1.0f
|
||||||
|
|
||||||
struct button_info {
|
struct button_info
|
||||||
|
{
|
||||||
float repeatcounter;
|
float repeatcounter;
|
||||||
float repeatdelay;
|
float repeatdelay;
|
||||||
irr::EKEY_CODE keycode;
|
irr::EKEY_CODE keycode;
|
||||||
@ -71,7 +72,8 @@ struct button_info {
|
|||||||
bool immediate_release;
|
bool immediate_release;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TouchScreenGUI {
|
class TouchScreenGUI
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
|
TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
|
||||||
|
|
||||||
@ -81,7 +83,8 @@ public:
|
|||||||
|
|
||||||
void init(ISimpleTextureSource *tsrc);
|
void init(ISimpleTextureSource *tsrc);
|
||||||
|
|
||||||
double getYawChange() {
|
double getYawChange()
|
||||||
|
{
|
||||||
double res = m_camera_yaw_change;
|
double res = m_camera_yaw_change;
|
||||||
m_camera_yaw_change = 0;
|
m_camera_yaw_change = 0;
|
||||||
return res;
|
return res;
|
||||||
@ -117,6 +120,7 @@ private:
|
|||||||
IEventReceiver *m_receiver;
|
IEventReceiver *m_receiver;
|
||||||
ISimpleTextureSource *m_texturesource;
|
ISimpleTextureSource *m_texturesource;
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
|
double m_touchscreen_threshold;
|
||||||
std::map<int, rect<s32> > m_hud_rects;
|
std::map<int, rect<s32> > m_hud_rects;
|
||||||
std::map<size_t, irr::EKEY_CODE> m_hud_ids;
|
std::map<size_t, irr::EKEY_CODE> m_hud_ids;
|
||||||
bool m_visible; // is the gui visible
|
bool m_visible; // is the gui visible
|
||||||
@ -151,11 +155,12 @@ private:
|
|||||||
void handleChangedButton(const SEvent &event);
|
void handleChangedButton(const SEvent &event);
|
||||||
|
|
||||||
// initialize a button
|
// initialize a button
|
||||||
void initButton(touch_gui_button_id id, rect<s32> button_rect,
|
void initButton(touch_gui_button_id id, const rect<s32> &button_rect,
|
||||||
std::wstring caption, bool immediate_release,
|
const std::wstring &caption, bool immediate_release,
|
||||||
float repeat_delay = BUTTON_REPEAT_DELAY);
|
float repeat_delay = BUTTON_REPEAT_DELAY);
|
||||||
|
|
||||||
struct id_status {
|
struct id_status
|
||||||
|
{
|
||||||
size_t id;
|
size_t id;
|
||||||
int X;
|
int X;
|
||||||
int Y;
|
int Y;
|
||||||
@ -177,7 +182,8 @@ private:
|
|||||||
void handleReleaseEvent(size_t evt_id);
|
void handleReleaseEvent(size_t evt_id);
|
||||||
|
|
||||||
// long-click detection variables
|
// long-click detection variables
|
||||||
struct key_event {
|
struct key_event
|
||||||
|
{
|
||||||
u64 down_time;
|
u64 down_time;
|
||||||
s32 x;
|
s32 x;
|
||||||
s32 y;
|
s32 y;
|
||||||
@ -191,4 +197,3 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern TouchScreenGUI *g_touchscreengui;
|
extern TouchScreenGUI *g_touchscreengui;
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user