Skip to content

Commit

Permalink
Revert "Formspec: Pass the second-touch event as is (#13872)"
Browse files Browse the repository at this point in the history
This reverts commit 53886dc.
  • Loading branch information
okias committed Dec 16, 2023
1 parent df72a33 commit 4f285d2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 91 deletions.
122 changes: 42 additions & 80 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4207,16 +4207,14 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}

/* Mouse event other than movement, or crossing the border of inventory
field while holding left, right, or middle mouse button
or touch event (for touch screen devices)
field while holding left, right, or middle mouse button
*/
if ((event.EventType == EET_MOUSE_INPUT_EVENT &&
(event.MouseInput.Event != EMIE_MOUSE_MOVED ||
((event.MouseInput.isLeftPressed() ||
event.MouseInput.isRightPressed() ||
event.MouseInput.isMiddlePressed()) &&
getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) ||
event.EventType == EET_TOUCH_INPUT_EVENT) {
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
(event.MouseInput.Event != EMIE_MOUSE_MOVED ||
((event.MouseInput.isLeftPressed() ||
event.MouseInput.isRightPressed() ||
event.MouseInput.isMiddlePressed()) &&
getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) {

// Get selected item and hovered/clicked item (s)

Expand Down Expand Up @@ -4285,46 +4283,35 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)

ButtonEventType button = BET_OTHER;
ButtonEventType updown = BET_OTHER;
bool mouse_shift = false;
if (event.EventType == EET_MOUSE_INPUT_EVENT) {
mouse_shift = event.MouseInput.Shift;
switch (event.MouseInput.Event) {
case EMIE_LMOUSE_PRESSED_DOWN:
button = BET_LEFT; updown = BET_DOWN;
break;
case EMIE_RMOUSE_PRESSED_DOWN:
button = BET_RIGHT; updown = BET_DOWN;
break;
case EMIE_MMOUSE_PRESSED_DOWN:
button = BET_MIDDLE; updown = BET_DOWN;
break;
case EMIE_MOUSE_WHEEL:
button = (event.MouseInput.Wheel > 0) ?
BET_WHEEL_UP : BET_WHEEL_DOWN;
updown = BET_DOWN;
break;
case EMIE_LMOUSE_LEFT_UP:
button = BET_LEFT; updown = BET_UP;
break;
case EMIE_RMOUSE_LEFT_UP:
button = BET_RIGHT; updown = BET_UP;
break;
case EMIE_MMOUSE_LEFT_UP:
button = BET_MIDDLE; updown = BET_UP;
break;
case EMIE_MOUSE_MOVED:
updown = BET_MOVE;
break;
default:
break;
}
}

// The second touch (see GUIModalMenu::preprocessEvent() function)
ButtonEventType touch = BET_OTHER;
if (event.EventType == EET_TOUCH_INPUT_EVENT) {
if (event.TouchInput.Event == ETIE_LEFT_UP)
touch = BET_RIGHT;
switch (event.MouseInput.Event) {
case EMIE_LMOUSE_PRESSED_DOWN:
button = BET_LEFT; updown = BET_DOWN;
break;
case EMIE_RMOUSE_PRESSED_DOWN:
button = BET_RIGHT; updown = BET_DOWN;
break;
case EMIE_MMOUSE_PRESSED_DOWN:
button = BET_MIDDLE; updown = BET_DOWN;
break;
case EMIE_MOUSE_WHEEL:
button = (event.MouseInput.Wheel > 0) ?
BET_WHEEL_UP : BET_WHEEL_DOWN;
updown = BET_DOWN;
break;
case EMIE_LMOUSE_LEFT_UP:
button = BET_LEFT; updown = BET_UP;
break;
case EMIE_RMOUSE_LEFT_UP:
button = BET_RIGHT; updown = BET_UP;
break;
case EMIE_MMOUSE_LEFT_UP:
button = BET_MIDDLE; updown = BET_UP;
break;
case EMIE_MOUSE_MOVED:
updown = BET_MOVE;
break;
default:
break;
}

// Set this number to a positive value to generate a move action
Expand Down Expand Up @@ -4352,7 +4339,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)

if (m_held_mouse_button != BET_OTHER)
break;

if (button == BET_LEFT || button == BET_RIGHT || button == BET_MIDDLE)
m_held_mouse_button = button;

Expand All @@ -4372,13 +4358,13 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
// Craft preview has been clicked: craft
if (button == BET_MIDDLE)
craft_amount = 10;
else if (mouse_shift && button == BET_LEFT)
else if (event.MouseInput.Shift && button == BET_LEFT)
craft_amount = list_s->getItem(s.i).getStackMax(m_client->idef());
else
craft_amount = 1;

// Holding shift moves the crafted item to the inventory
m_shift_move_after_craft = mouse_shift;
m_shift_move_after_craft = event.MouseInput.Shift;

} else if (!m_selected_item && button != BET_WHEEL_UP && !empty) {
// Non-empty stack has been clicked: select or shift-move it
Expand All @@ -4392,7 +4378,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
else if (button == BET_LEFT)
count = s_count;

if (mouse_shift) {
if (event.MouseInput.Shift) {
// Shift pressed: move item, right click moves 1
shift_move_amount = button == BET_RIGHT ? 1 : count;
} else {
Expand All @@ -4413,7 +4399,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
else if (button == BET_LEFT)
move_amount = m_selected_amount;

if (mouse_shift && !identical && matching) {
if (event.MouseInput.Shift && !identical && matching) {
// Shift-move all items the same as the selected item to the next list
move_amount = 0;

Expand Down Expand Up @@ -4551,7 +4537,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (!s.isValid() || s.listname == "craftpreview")
break;

if (!m_selected_item && mouse_shift) {
if (!m_selected_item && event.MouseInput.Shift) {
// Shift-move items while dragging
if (m_held_mouse_button == BET_RIGHT)
shift_move_amount = 1;
Expand Down Expand Up @@ -4601,8 +4587,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
case BET_OTHER: {
// Some other mouse event has occured
// Currently only left-double-click should trigger this
if (!s.isValid() || event.EventType != EET_MOUSE_INPUT_EVENT ||
event.MouseInput.Event != EMIE_LMOUSE_DOUBLE_CLICK)
if (!s.isValid() || event.MouseInput.Event != EMIE_LMOUSE_DOUBLE_CLICK)
break;

// Only do the pickup all thing when putting down an item.
Expand Down Expand Up @@ -4670,26 +4655,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
break;
}

if (g_settings->getBool("enable_touch") && touch == BET_RIGHT && m_selected_item && !m_left_dragging) {
if (!s.isValid()) {
// Not a valid slot
if (!getAbsoluteClippingRect().isPointInside(m_pointer))
// Is outside the menu
drop_amount = 1;
} else {
// Over a valid slot
move_amount = 1;
if (identical) {
// Change the selected amount instead of moving
if (move_amount >= m_selected_amount)
m_selected_amount = 0;
else
m_selected_amount -= move_amount;
move_amount = 0;
}
}
}

// Update left-dragged slots
if (m_left_dragging && m_left_drag_stacks.size() > 1) {
// The split amount will always at least one, because the number
Expand Down Expand Up @@ -5057,9 +5022,6 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}
}

if (g_settings->getBool("enable_touch") && m_second_touch)
return true; // Stop propagating the event

return Parent ? Parent->OnEvent(event) : false;
}

Expand Down
28 changes: 19 additions & 9 deletions src/gui/modalMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,12 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
irr_ptr<GUIModalMenu> holder;
holder.grab(this); // keep this alive until return (it might be dropped downstream [?])

if (event.TouchInput.ID == 0) {
switch ((int)event.TouchInput.touchedCount) {
case 1: {
if (event.TouchInput.Event == ETIE_PRESSED_DOWN || event.TouchInput.Event == ETIE_MOVED)
m_pointer = v2s32(event.TouchInput.X, event.TouchInput.Y);
if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
m_down_pos = m_pointer;
gui::IGUIElement *hovered = Environment->getRootGUIElement()->getElementFromPoint(core::position2d<s32>(m_pointer));
if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
Environment->setFocus(hovered);
Expand All @@ -281,19 +284,26 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
if (event.TouchInput.Event == ETIE_LEFT_UP)
leave();
return ret;
} else if (event.TouchInput.ID == 1) {
if (event.TouchInput.Event != ETIE_LEFT_UP)
}
case 2: {
if (event.TouchInput.Event != ETIE_PRESSED_DOWN)
return true; // ignore
auto focused = Environment->getFocus();
if (!focused)
return true;
// The second-touch event is propagated as is (not converted).
m_second_touch = true;
focused->OnEvent(event);
m_second_touch = false;
SEvent rclick_event{};
rclick_event.EventType = EET_MOUSE_INPUT_EVENT;
rclick_event.MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
rclick_event.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
rclick_event.MouseInput.X = m_pointer.X;
rclick_event.MouseInput.Y = m_pointer.Y;
focused->OnEvent(rclick_event);
rclick_event.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
rclick_event.MouseInput.ButtonStates = EMBSM_LEFT;
focused->OnEvent(rclick_event);
return true;
} else {
// Any other touch after the second touch is ignored.
}
default: // ignored
return true;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/gui/modalMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class GUIModalMenu : public gui::IGUIElement
#ifdef __ANDROID__
std::string m_jni_field_name;
#endif
// This is set to true if the menu is currently processing a second-touch event.
bool m_second_touch = false;
v2s32 m_down_pos;
bool m_touchscreen_visible = true;

private:
Expand Down

0 comments on commit 4f285d2

Please sign in to comment.