mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Formspec: Pass the second-touch event as is (#13872)
The second-touch event is passed to the GUIFormSpecMenu::OnEvent() function as a touch event. There are two types of event for inventory formspec: (1) mouse event and (2) touch event. The touch event is just a modifier of the mouse event. Co-authored-by: Gregor Parzefall <82708541+grorp@users.noreply.github.com>
This commit is contained in:
parent
771da80bbb
commit
53886dcdb5
3 changed files with 97 additions and 62 deletions
|
@ -278,12 +278,9 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
|
|||
irr_ptr<GUIModalMenu> holder;
|
||||
holder.grab(this); // keep this alive until return (it might be dropped downstream [?])
|
||||
|
||||
switch ((int)event.TouchInput.touchedCount) {
|
||||
case 1: {
|
||||
if (event.TouchInput.ID == 0) {
|
||||
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);
|
||||
|
@ -298,26 +295,19 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
|
|||
if (event.TouchInput.Event == ETIE_LEFT_UP)
|
||||
leave();
|
||||
return ret;
|
||||
}
|
||||
case 2: {
|
||||
if (event.TouchInput.Event != ETIE_PRESSED_DOWN)
|
||||
} else if (event.TouchInput.ID == 1) {
|
||||
if (event.TouchInput.Event != ETIE_LEFT_UP)
|
||||
return true; // ignore
|
||||
auto focused = Environment->getFocus();
|
||||
if (!focused)
|
||||
return true;
|
||||
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);
|
||||
// The second-touch event is propagated as is (not converted).
|
||||
m_second_touch = true;
|
||||
focused->OnEvent(event);
|
||||
m_second_touch = false;
|
||||
return true;
|
||||
}
|
||||
default: // ignored
|
||||
} else {
|
||||
// Any other touch after the second touch is ignored.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue