Skip to content

Commit 54379cd

Browse files
authored
Merge pull request #19983 from hrydgard/touch-gliding
Touch: Implement "Touch gliding" (keep all dragged/touched buttons pressed until touch release)
2 parents 4f2ceca + 928854f commit 54379cd

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

Common/Input/InputState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ enum {
145145
TOUCH_TOOL_STYLUS = 2 << 10,
146146
TOUCH_TOOL_MOUSE = 3 << 10,
147147
TOUCH_TOOL_ERASER = 4 << 10,
148+
149+
TOUCH_MAX_POINTERS = 10,
148150
};
149151

150152
// Used for asynchronous touch input.

Core/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ static const ConfigSetting generalSettings[] = {
284284
ConfigSetting("SwipeSmoothing", &g_Config.fSwipeSmoothing, 0.3f, CfgFlag::PER_GAME),
285285
ConfigSetting("DoubleTapGesture", &g_Config.iDoubleTapGesture, 0, CfgFlag::PER_GAME),
286286
ConfigSetting("GestureControlEnabled", &g_Config.bGestureControlEnabled, false, CfgFlag::PER_GAME),
287+
ConfigSetting("TouchGliding", &g_Config.bTouchGliding, false, CfgFlag::PER_GAME),
287288

288289
// "default" means let emulator decide, "" means disable.
289290
ConfigSetting("ReportingHost", &g_Config.sReportHost, "default", CfgFlag::DEFAULT),

Core/Config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ struct Config {
361361

362362
// Disable diagonals
363363
bool bDisableDpadDiagonals;
364+
364365
bool bGamepadOnlyFocused;
366+
365367
// Control Style
366368
int iTouchButtonStyle;
367369
int iTouchButtonOpacity;
@@ -377,6 +379,9 @@ struct Config {
377379
// Sticky D-pad (can't glide off it)
378380
bool bStickyTouchDPad;
379381

382+
// Touch gliding (see #14490)
383+
bool bTouchGliding;
384+
380385
//space between PSP buttons
381386
//the PSP button's center (triangle, circle, square, cross)
382387
ConfigTouchPos touchActionButtonCenter;

UI/EmuScreen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,9 @@ bool EmuScreen::key(const KeyInput &key) {
10801080
void EmuScreen::touch(const TouchInput &touch) {
10811081
if (g_Config.bShowImDebugger && imguiInited_) {
10821082
ImGui_ImplPlatform_TouchEvent(touch);
1083+
if (!ImGui::GetIO().WantCaptureMouse) {
1084+
UIScreen::touch(touch);
1085+
}
10831086
} else {
10841087
UIScreen::touch(touch);
10851088
}

UI/GameSettingsScreen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ void GameSettingsScreen::CreateControlsSettings(UI::ViewGroup *controlsSettings)
801801
autoHide->SetFormat(di->T("%d seconds"));
802802
autoHide->SetZeroLabel(co->T("Off"));
803803

804+
controlsSettings->Add(new CheckBox(&g_Config.bTouchGliding, co->T("Touch gliding")));
805+
804806
// Hide stick background, useful when increasing the size
805807
CheckBox *hideStickBackground = controlsSettings->Add(new CheckBox(&g_Config.bHideStickBackground, co->T("Hide touch analog stick background circle")));
806808
hideStickBackground->SetEnabledPtr(&g_Config.bShowTouchControls);

UI/GamepadEmu.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static uint32_t analogPointerMask = 0;
4242
static float g_gamepadOpacity;
4343
static double g_lastTouch;
4444

45+
MultiTouchButton *primaryButton[TOUCH_MAX_POINTERS]{};
46+
4547
void GamepadUpdateOpacity(float force) {
4648
if (force >= 0.0f) {
4749
g_gamepadOpacity = force;
@@ -100,23 +102,36 @@ void MultiTouchButton::GetContentDimensions(const UIContext &dc, float &w, float
100102
}
101103
}
102104

105+
bool MultiTouchButton::CanGlide() const {
106+
return g_Config.bTouchGliding;
107+
}
108+
103109
bool MultiTouchButton::Touch(const TouchInput &input) {
110+
_dbg_assert_(input.id >= 0 && input.id < TOUCH_MAX_POINTERS);
111+
104112
bool retval = GamepadView::Touch(input);
105113
if ((input.flags & TOUCH_DOWN) && bounds_.Contains(input.x, input.y)) {
106114
pointerDownMask_ |= 1 << input.id;
107115
usedPointerMask |= 1 << input.id;
116+
if (CanGlide() && !primaryButton[input.id])
117+
primaryButton[input.id] = this;
108118
}
109119
if (input.flags & TOUCH_MOVE) {
110120
if (!(input.flags & TOUCH_MOUSE) || input.buttons) {
111-
if (bounds_.Contains(input.x, input.y) && !(analogPointerMask & (1 << input.id)))
121+
if (bounds_.Contains(input.x, input.y) && !(analogPointerMask & (1 << input.id))) {
122+
if (CanGlide() && !primaryButton[input.id]) {
123+
primaryButton[input.id] = this;
124+
}
112125
pointerDownMask_ |= 1 << input.id;
113-
else
126+
} else if (primaryButton[input.id] != this) {
114127
pointerDownMask_ &= ~(1 << input.id);
128+
}
115129
}
116130
}
117131
if (input.flags & TOUCH_UP) {
118132
pointerDownMask_ &= ~(1 << input.id);
119133
usedPointerMask &= ~(1 << input.id);
134+
primaryButton[input.id] = nullptr;
120135
}
121136
if (input.flags & TOUCH_RELEASE_ALL) {
122137
pointerDownMask_ = 0;

UI/GamepadEmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class MultiTouchButton : public GamepadView {
5454
MultiTouchButton *SetAngle(float angle) { angle_ = angle; bgAngle_ = angle; return this; }
5555
MultiTouchButton *SetAngle(float angle, float bgAngle) { angle_ = angle; bgAngle_ = bgAngle; return this; }
5656

57+
bool CanGlide() const;
58+
5759
protected:
5860
uint32_t pointerDownMask_ = 0;
5961
float scale_;

0 commit comments

Comments
 (0)