Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
TouchScreen Control: fix some bugs, cleanup
  • Loading branch information
MoNTE48 authored and SmallJoker committed Jun 9, 2020
1 parent 756dc89 commit 0d8e5bf
Showing 1 changed file with 19 additions and 40 deletions.
59 changes: 19 additions & 40 deletions src/gui/modalMenu.cpp
Expand Up @@ -28,8 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "touchscreengui.h"
#endif

// clang-format off
GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id,
GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
IMenuManager *menumgr) :
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
core::rect<s32>(0, 0, 100, 100)),
Expand Down Expand Up @@ -153,8 +152,8 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
if (((gui::IGUIEditBox *)hovered)->isPasswordBox())
type = 3;

porting::showInputDialog(gettext("ok"), "",
wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type);
porting::showInputDialog(gettext("OK"), "",
wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type);
return retval;
}
}
Expand All @@ -167,18 +166,17 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)

if (!root) {
errorstream << "GUIModalMenu::preprocessEvent"
<< " unable to get root element" << std::endl;
<< " unable to get root element" << std::endl;
return false;
}
gui::IGUIElement *hovered = root->getElementFromPoint(
core::position2d<s32>(event.TouchInput.X, event.TouchInput.Y));
gui::IGUIElement *hovered =
root->getElementFromPoint(core::position2d<s32>(
event.TouchInput.X, event.TouchInput.Y));

translated.MouseInput.X = event.TouchInput.X;
translated.MouseInput.Y = event.TouchInput.Y;
translated.MouseInput.Control = false;

bool dont_send_event = false;

if (event.TouchInput.touchedCount == 1) {
switch (event.TouchInput.Event) {
case ETIE_PRESSED_DOWN:
Expand All @@ -205,11 +203,7 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
m_down_pos = v2s32(0, 0);
break;
default:
dont_send_event = true;
// this is not supposed to happen
errorstream << "GUIModalMenu::preprocessEvent"
<< " unexpected usecase Event="
<< event.TouchInput.Event << std::endl;
break;
}
} else if ((event.TouchInput.touchedCount == 2) &&
(event.TouchInput.Event == ETIE_PRESSED_DOWN)) {
Expand All @@ -219,50 +213,37 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
translated.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
translated.MouseInput.X = m_pointer.X;
translated.MouseInput.Y = m_pointer.Y;
if (hovered) {
if (hovered)
hovered->OnEvent(translated);
}

translated.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
translated.MouseInput.ButtonStates = EMBSM_LEFT;

if (hovered) {
if (hovered)
hovered->OnEvent(translated);
}
dont_send_event = true;
}
// ignore unhandled 2 touch events ... accidental moving for example
else if (event.TouchInput.touchedCount == 2) {
dont_send_event = true;
}
else if (event.TouchInput.touchedCount > 2) {
errorstream << "GUIModalMenu::preprocessEvent"
<< " to many multitouch events "
<< event.TouchInput.touchedCount << " ignoring them"
<< std::endl;
}

if (dont_send_event) {
return true;
} else {
// ignore unhandled 2 touch events (accidental moving for example)
return true;
}

// check if translated event needs to be preprocessed again
if (preprocessEvent(translated)) {
if (preprocessEvent(translated))
return true;
}

if (hovered) {
grab();
bool retval = hovered->OnEvent(translated);

if (event.TouchInput.Event == ETIE_LEFT_UP) {
if (event.TouchInput.Event == ETIE_LEFT_UP)
// reset pointer
m_pointer = v2s32(0, 0);
}

drop();
return retval;
}
}
// clang-format on
#endif
return false;
}
Expand All @@ -271,14 +252,12 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
bool GUIModalMenu::hasAndroidUIInput()
{
// no dialog shown
if (m_jni_field_name.empty()) {
if (m_jni_field_name.empty())
return false;
}

// still waiting
if (porting::getInputDialogState() == -1) {
if (porting::getInputDialogState() == -1)
return true;
}

// no value abort dialog processing
if (porting::getInputDialogState() != 0) {
Expand Down

0 comments on commit 0d8e5bf

Please sign in to comment.