Skip to content

Commit

Permalink
Fix dig & place not being released when switching touch -> mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed May 15, 2024
1 parent 9aa738f commit 57cf513
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/client/inputhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ bool MyEventReceiver::OnEvent(const SEvent &event)

if (g_touchscreengui_tsrc && g_last_pointer_type == PointerType::Mouse &&
g_touchscreengui) {
g_touchscreengui->hide();
delete g_touchscreengui;
TouchScreenGUI *gui = g_touchscreengui;
g_touchscreengui = nullptr;
delete gui;
} else if (g_touchscreengui_tsrc && g_last_pointer_type == PointerType::Touch &&
!g_touchscreengui) {
g_touchscreengui = new TouchScreenGUI(RenderingEngine::get_raw_device(),
Expand Down
26 changes: 23 additions & 3 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsr
}
}

TouchScreenGUI::~TouchScreenGUI()
{
releaseAll();
}

void TouchScreenGUI::addButton(touch_gui_button_id id, const std::string &image, const recti &rect)
{
IGUIImage *btn_gui_button = m_guienv->addImage(rect, nullptr, id);
Expand Down Expand Up @@ -796,6 +801,23 @@ void TouchScreenGUI::applyJoystickStatus()
}
}

void TouchScreenGUI::releaseAll()
{
while (!m_pointer_pos.empty())
handleReleaseEvent(m_pointer_pos.begin()->first);

// Release those manually too since the change initiated by
// handleReleaseEvent will only be applied later by applyContextControls.
if (m_dig_pressed) {
emitMouseEvent(EMIE_LMOUSE_LEFT_UP);
m_dig_pressed = false;
}
if (m_place_pressed) {
emitMouseEvent(EMIE_RMOUSE_LEFT_UP);
m_place_pressed = false;
}
}

void TouchScreenGUI::step(float dtime)
{
// simulate keyboard repeats
Expand Down Expand Up @@ -853,10 +875,8 @@ void TouchScreenGUI::setVisible(bool visible)
if (m_joystick_btn_off)
m_joystick_btn_off->setVisible(visible);

// clear all active buttons
if (!visible) {
while (!m_pointer_pos.empty())
handleReleaseEvent(m_pointer_pos.begin()->first);
releaseAll();
for (AutoHideButtonBar &bar : m_buttonbars) {
bar.deactivate();
bar.hide();
Expand Down
6 changes: 6 additions & 0 deletions src/gui/touchscreengui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "itemdef.h"
#include "client/game.h"
#include "util/basic_macros.h"

using namespace irr;
using namespace irr::core;
Expand Down Expand Up @@ -187,6 +188,8 @@ class TouchScreenGUI
{
public:
TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsrc);
~TouchScreenGUI();
DISABLE_CLASS_COPY(TouchScreenGUI);

void translateEvent(const SEvent &event);
void applyContextControls(const TouchInteractionMode &mode);
Expand Down Expand Up @@ -295,6 +298,9 @@ class TouchScreenGUI
// apply joystick status
void applyJoystickStatus();

// release all buttons etc.
void releaseAll();

// map to store the IDs and original positions of currently pressed pointers
std::unordered_map<size_t, v2s32> m_pointer_downpos;
// map to store the IDs and positions of currently pressed pointers
Expand Down

0 comments on commit 57cf513

Please sign in to comment.