Fix prev commit "Touchscreengui. Some improvements"
This commit is contained in:
parent
36d6527af1
commit
862ed96826
@ -7,7 +7,7 @@ buildscript {
|
|||||||
maven { url 'https://maven.fabric.io/public' }
|
maven { url 'https://maven.fabric.io/public' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.0-rc03'
|
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||||
classpath 'com.google.gms:google-services:4.3.0'
|
classpath 'com.google.gms:google-services:4.3.0'
|
||||||
classpath 'io.fabric.tools:gradle:1.29.0'
|
classpath 'io.fabric.tools:gradle:1.29.0'
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
@ -59,7 +59,7 @@ const char **touchgui_button_imagenames = (const char *[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
||||||
std::string key = key;
|
std::string key = "";
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case forward_one:
|
case forward_one:
|
||||||
key = "forward";
|
key = "forward";
|
||||||
@ -133,7 +133,7 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
|||||||
TouchScreenGUI *g_touchscreengui;
|
TouchScreenGUI *g_touchscreengui;
|
||||||
|
|
||||||
static void load_button_texture(button_info *btn, const char *path,
|
static void load_button_texture(button_info *btn, const char *path,
|
||||||
const rect<s32> &button_rect, ISimpleTextureSource *tsrc,
|
rect<s32> button_rect, ISimpleTextureSource *tsrc,
|
||||||
video::IVideoDriver *driver) {
|
video::IVideoDriver *driver) {
|
||||||
unsigned int tid;
|
unsigned int tid;
|
||||||
video::ITexture *texture = guiScalingImageButton(driver,
|
video::ITexture *texture = guiScalingImageButton(driver,
|
||||||
@ -170,10 +170,10 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver)
|
|||||||
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
|
// use some downlocation way off screen as init value to avoid invalid behaviour
|
||||||
m_move_downlocation(v2s32(-10000, -10000)) {
|
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_screensize = m_device->getVideoDriver()->getScreenSize();
|
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||||
@ -376,7 +376,7 @@ 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];
|
||||||
|
|
||||||
auto id =
|
std::vector<size_t>::iterator 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())
|
||||||
@ -388,16 +388,17 @@ touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) {
|
|||||||
|
|
||||||
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 (auto &m_hud_rect : m_hud_rects) {
|
for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
|
||||||
if (m_hud_rect.second.isPointInside(
|
iter != m_hud_rects.end(); ++iter) {
|
||||||
|
if (iter->second.isPointInside(
|
||||||
v2s32(event.TouchInput.X,
|
v2s32(event.TouchInput.X,
|
||||||
event.TouchInput.Y)
|
event.TouchInput.Y)
|
||||||
)) {
|
)) {
|
||||||
if (m_hud_rect.first < 9) {
|
if (iter->first < 9) {
|
||||||
auto *translated = new SEvent();
|
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 + m_hud_rect.first);
|
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->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;
|
||||||
@ -411,29 +412,10 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchScreenGUI::isReleaseHUDButton(size_t eventID) {
|
|
||||||
auto iter = m_hud_ids.find(eventID);
|
|
||||||
|
|
||||||
if (iter != m_hud_ids.end()) {
|
|
||||||
auto *translated = new SEvent();
|
|
||||||
memset(translated, 0, sizeof(SEvent));
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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];
|
||||||
auto *translated = new SEvent();
|
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 = btn->keycode;
|
translated->KeyInput.Key = btn->keycode;
|
||||||
@ -458,7 +440,8 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
// remove event
|
// remove event
|
||||||
if ((!action) || (btn->immediate_release)) {
|
if ((!action) || (btn->immediate_release)) {
|
||||||
|
|
||||||
auto pos = std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
std::vector<size_t>::iterator pos =
|
||||||
|
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);
|
||||||
@ -481,17 +464,13 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
|||||||
if (button != after_last_element_id) {
|
if (button != after_last_element_id) {
|
||||||
handleButtonEvent(button, evt_id, false);
|
handleButtonEvent(button, evt_id, false);
|
||||||
}
|
}
|
||||||
// handle hud button events
|
// handle the point used for moving view
|
||||||
else if (isReleaseHUDButton(evt_id)) {
|
|
||||||
// nothing to do here
|
|
||||||
}
|
|
||||||
// handle the point used for moving view
|
|
||||||
else if (evt_id == m_move_id) {
|
else if (evt_id == m_move_id) {
|
||||||
m_move_id = -1;
|
m_move_id = -1;
|
||||||
|
|
||||||
// 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) {
|
||||||
auto *translated = new SEvent;
|
SEvent* 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;
|
||||||
@ -503,7 +482,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) {
|
||||||
auto *translated = new SEvent;
|
SEvent* 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;
|
||||||
@ -521,13 +500,9 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
|
|||||||
->getRayFromScreenCoordinates(
|
->getRayFromScreenCoordinates(
|
||||||
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
infostream
|
|
||||||
<< "TouchScreenGUI::translateEvent released unknown button: "
|
|
||||||
<< evt_id << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto iter = m_known_ids.begin();
|
for (std::vector<id_status>::iterator 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);
|
||||||
@ -594,7 +569,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
|
||||||
auto *translated = new SEvent;
|
SEvent *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;
|
||||||
@ -636,8 +611,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) {
|
|||||||
s32 Y = event.TouchInput.Y;
|
s32 Y = event.TouchInput.Y;
|
||||||
|
|
||||||
// update camera_yaw and camera_pitch
|
// update camera_yaw and camera_pitch
|
||||||
auto dx = X - m_pointerpos[event.TouchInput.ID].X;
|
s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
|
||||||
auto dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
||||||
|
|
||||||
// adapt to similar behaviour as pc screen
|
// adapt to similar behaviour as pc screen
|
||||||
double d = g_settings->getFloat("mouse_sensitivity");
|
double d = g_settings->getFloat("mouse_sensitivity");
|
||||||
@ -674,7 +649,7 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event) {
|
|||||||
if (m_buttons[i].ids.empty())
|
if (m_buttons[i].ids.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (auto iter = m_buttons[i].ids.begin();
|
for (std::vector<size_t>::iterator 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) {
|
||||||
@ -737,7 +712,7 @@ bool TouchScreenGUI::quickTapDetection() {
|
|||||||
if (distance > (20 + g_settings->getU16("touchscreen_threshold")))
|
if (distance > (20 + g_settings->getU16("touchscreen_threshold")))
|
||||||
return false;*/
|
return false;*/
|
||||||
|
|
||||||
auto *translated = new SEvent();
|
SEvent* 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;
|
||||||
@ -765,8 +740,8 @@ bool TouchScreenGUI::quickTapDetection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TouchScreenGUI::~TouchScreenGUI() {
|
TouchScreenGUI::~TouchScreenGUI() {
|
||||||
for (auto &m_button : m_buttons) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info *btn = &m_button;
|
button_info *btn = &m_buttons[i];
|
||||||
if (btn->guibutton != nullptr) {
|
if (btn->guibutton != nullptr) {
|
||||||
btn->guibutton->drop();
|
btn->guibutton->drop();
|
||||||
btn->guibutton = nullptr;
|
btn->guibutton = nullptr;
|
||||||
@ -776,8 +751,8 @@ TouchScreenGUI::~TouchScreenGUI() {
|
|||||||
|
|
||||||
void TouchScreenGUI::step(float dtime) {
|
void TouchScreenGUI::step(float dtime) {
|
||||||
// simulate keyboard repeats
|
// simulate keyboard repeats
|
||||||
for (auto &m_button : m_buttons) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info *btn = &m_button;
|
button_info *btn = &m_buttons[i];
|
||||||
|
|
||||||
if (!btn->ids.empty()) {
|
if (!btn->ids.empty()) {
|
||||||
btn->repeatcounter += dtime;
|
btn->repeatcounter += dtime;
|
||||||
@ -837,8 +812,8 @@ void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect) {
|
|||||||
|
|
||||||
void TouchScreenGUI::Toggle(bool visible) {
|
void TouchScreenGUI::Toggle(bool visible) {
|
||||||
m_visible = visible;
|
m_visible = visible;
|
||||||
for (auto &m_button : m_buttons) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info *btn = &m_button;
|
button_info *btn = &m_buttons[i];
|
||||||
if (btn->guibutton != nullptr) {
|
if (btn->guibutton != nullptr) {
|
||||||
btn->guibutton->setVisible(visible);
|
btn->guibutton->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
@ -175,9 +175,6 @@ private:
|
|||||||
// handle pressed hud buttons
|
// handle pressed hud buttons
|
||||||
bool isHUDButton(const SEvent &event);
|
bool isHUDButton(const SEvent &event);
|
||||||
|
|
||||||
// handle released hud buttons
|
|
||||||
bool isReleaseHUDButton(size_t eventID);
|
|
||||||
|
|
||||||
// handle quick touch
|
// handle quick touch
|
||||||
bool quickTapDetection();
|
bool quickTapDetection();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user