Hold only the first button, allow other buttons to toggle with dragging as normal.

This commit is contained in:
Henrik Rydgård 2025-02-14 12:40:44 -06:00
parent dbfa865a4a
commit 928854ffd3
3 changed files with 21 additions and 2 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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_;