From 928854ffd399c5fba218d2c6e44bee4bbca1440f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 14 Feb 2025 12:40:44 -0600 Subject: [PATCH] Hold only the first button, allow other buttons to toggle with dragging as normal. --- Common/Input/InputState.h | 2 ++ UI/GamepadEmu.cpp | 19 +++++++++++++++++-- UI/GamepadEmu.h | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index 2edb14210e..6aa30cb23e 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -145,6 +145,8 @@ enum { TOUCH_TOOL_STYLUS = 2 << 10, TOUCH_TOOL_MOUSE = 3 << 10, TOUCH_TOOL_ERASER = 4 << 10, + + TOUCH_MAX_POINTERS = 10, }; // Used for asynchronous touch input. diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 90633be5d4..134169aca6 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -42,6 +42,8 @@ static uint32_t analogPointerMask = 0; static float g_gamepadOpacity; static double g_lastTouch; +MultiTouchButton *primaryButton[TOUCH_MAX_POINTERS]{}; + void GamepadUpdateOpacity(float force) { if (force >= 0.0f) { g_gamepadOpacity = force; @@ -100,23 +102,36 @@ void MultiTouchButton::GetContentDimensions(const UIContext &dc, float &w, float } } +bool MultiTouchButton::CanGlide() const { + return g_Config.bTouchGliding; +} + bool MultiTouchButton::Touch(const TouchInput &input) { + _dbg_assert_(input.id >= 0 && input.id < TOUCH_MAX_POINTERS); + bool retval = GamepadView::Touch(input); if ((input.flags & TOUCH_DOWN) && bounds_.Contains(input.x, input.y)) { pointerDownMask_ |= 1 << input.id; usedPointerMask |= 1 << input.id; + if (CanGlide() && !primaryButton[input.id]) + primaryButton[input.id] = this; } if (input.flags & TOUCH_MOVE) { if (!(input.flags & TOUCH_MOUSE) || input.buttons) { - if (bounds_.Contains(input.x, input.y) && !(analogPointerMask & (1 << input.id))) + if (bounds_.Contains(input.x, input.y) && !(analogPointerMask & (1 << input.id))) { + if (CanGlide() && !primaryButton[input.id]) { + primaryButton[input.id] = this; + } pointerDownMask_ |= 1 << input.id; - else if (!g_Config.bTouchGliding) + } else if (primaryButton[input.id] != this) { pointerDownMask_ &= ~(1 << input.id); + } } } if (input.flags & TOUCH_UP) { pointerDownMask_ &= ~(1 << input.id); usedPointerMask &= ~(1 << input.id); + primaryButton[input.id] = nullptr; } if (input.flags & TOUCH_RELEASE_ALL) { pointerDownMask_ = 0; diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index b4ad53c81c..a23a678674 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -54,6 +54,8 @@ public: MultiTouchButton *SetAngle(float angle) { angle_ = angle; bgAngle_ = angle; return this; } MultiTouchButton *SetAngle(float angle, float bgAngle) { angle_ = angle; bgAngle_ = bgAngle; return this; } + bool CanGlide() const; + protected: uint32_t pointerDownMask_ = 0; float scale_;