TouchScreenGUI: Don't release pointers when toggling grid menu

This commit is contained in:
Gregor Parzefall 2024-08-19 16:06:26 +02:00 committed by grorp
parent 2e567b7d40
commit 88397c2908

View File

@ -477,16 +477,13 @@ void TouchControls::handleReleaseEvent(size_t pointer_id)
m_pointer_downpos.erase(pointer_id); m_pointer_downpos.erase(pointer_id);
m_pointer_pos.erase(pointer_id); m_pointer_pos.erase(pointer_id);
if (m_overflow_open) {
buttons_handleRelease(m_overflow_buttons, pointer_id, m_device->getVideoDriver(),
m_receiver, m_texturesource);
return;
}
// handle buttons // handle buttons
if (buttons_handleRelease(m_buttons, pointer_id, m_device->getVideoDriver(), if (buttons_handleRelease(m_buttons, pointer_id, m_device->getVideoDriver(),
m_receiver, m_texturesource)) m_receiver, m_texturesource))
return; return;
if (buttons_handleRelease(m_overflow_buttons, pointer_id, m_device->getVideoDriver(),
m_receiver, m_texturesource))
return;
if (m_has_move_id && pointer_id == m_move_id) { if (m_has_move_id && pointer_id == m_move_id) {
// handle the point used for moving view // handle the point used for moving view
@ -513,9 +510,7 @@ void TouchControls::handleReleaseEvent(size_t pointer_id)
m_joystick_status_aux1 = false; m_joystick_status_aux1 = false;
applyJoystickStatus(); applyJoystickStatus();
m_joystick_btn_off->setVisible(true); updateVisibility();
m_joystick_btn_bg->setVisible(false);
m_joystick_btn_center->setVisible(false);
} else { } else {
infostream << "TouchControls::translateEvent released unknown button: " infostream << "TouchControls::translateEvent released unknown button: "
<< pointer_id << std::endl; << pointer_id << std::endl;
@ -572,9 +567,6 @@ void TouchControls::translateEvent(const SEvent &event)
toggleOverflowMenu(); toggleOverflowMenu();
// refresh since visibility of buttons has changed // refresh since visibility of buttons has changed
element = m_guienv->getRootGUIElement()->getElementFromPoint(touch_pos); element = m_guienv->getRootGUIElement()->getElementFromPoint(touch_pos);
// restore after releaseAll in toggleOverflowMenu
m_pointer_downpos[pointer_id] = touch_pos;
m_pointer_pos[pointer_id] = touch_pos;
// continue processing, but avoid accidentally placing a node // continue processing, but avoid accidentally placing a node
// when closing the overflow menu // when closing the overflow menu
prevent_short_tap = true; prevent_short_tap = true;
@ -600,9 +592,7 @@ void TouchControls::translateEvent(const SEvent &event)
m_joystick_id = pointer_id; m_joystick_id = pointer_id;
m_joystick_has_really_moved = false; m_joystick_has_really_moved = false;
m_joystick_btn_off->setVisible(false); updateVisibility();
m_joystick_btn_bg->setVisible(true);
m_joystick_btn_center->setVisible(true);
// If it's a fixed joystick, don't move the joystick "button". // If it's a fixed joystick, don't move the joystick "button".
if (!m_fixed_joystick) if (!m_fixed_joystick)
@ -633,9 +623,6 @@ void TouchControls::translateEvent(const SEvent &event)
} else { } else {
assert(event.TouchInput.Event == ETIE_MOVED); assert(event.TouchInput.Event == ETIE_MOVED);
if (m_overflow_open)
return;
if (!(m_has_joystick_id && m_fixed_joystick) && if (!(m_has_joystick_id && m_fixed_joystick) &&
m_pointer_pos[event.TouchInput.ID] == touch_pos) m_pointer_pos[event.TouchInput.ID] == touch_pos)
return; return;
@ -721,13 +708,9 @@ void TouchControls::applyJoystickStatus()
void TouchControls::step(float dtime) void TouchControls::step(float dtime)
{ {
if (m_overflow_open) {
buttons_step(m_overflow_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource);
return;
}
// simulate keyboard repeats // simulate keyboard repeats
buttons_step(m_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource); buttons_step(m_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource);
buttons_step(m_overflow_buttons, dtime, m_device->getVideoDriver(), m_receiver, m_texturesource);
// joystick // joystick
applyJoystickStatus(); applyJoystickStatus();
@ -774,7 +757,6 @@ void TouchControls::setVisible(bool visible)
return; return;
m_visible = visible; m_visible = visible;
// order matters
if (!visible) { if (!visible) {
releaseAll(); releaseAll();
m_overflow_open = false; m_overflow_open = false;
@ -784,7 +766,8 @@ void TouchControls::setVisible(bool visible)
void TouchControls::toggleOverflowMenu() void TouchControls::toggleOverflowMenu()
{ {
releaseAll(); // must be done first // no releaseAll here so that you can e.g. continue holding the joystick
// while the overflow menu is open
m_overflow_open = !m_overflow_open; m_overflow_open = !m_overflow_open;
updateVisibility(); updateVisibility();
} }
@ -795,7 +778,10 @@ void TouchControls::updateVisibility()
for (auto &button : m_buttons) for (auto &button : m_buttons)
button.gui_button->setVisible(regular_visible); button.gui_button->setVisible(regular_visible);
m_overflow_btn->setVisible(regular_visible); m_overflow_btn->setVisible(regular_visible);
m_joystick_btn_off->setVisible(regular_visible);
m_joystick_btn_off->setVisible(regular_visible && !m_has_joystick_id);
m_joystick_btn_bg->setVisible(regular_visible && m_has_joystick_id);
m_joystick_btn_center->setVisible(regular_visible && m_has_joystick_id);
bool overflow_visible = m_visible && m_overflow_open; bool overflow_visible = m_visible && m_overflow_open;
m_overflow_bg->setVisible(overflow_visible); m_overflow_bg->setVisible(overflow_visible);