[Scummvm-git-logs] scummvm master -> 106f9caa89002ccf62fe86bb87d39fff4d00b827

lephilousophe noreply at scummvm.org
Sun Feb 9 13:00:52 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
106f9caa89 ANDROID: Improve emulated gamepad buttons handling


Commit: 106f9caa89002ccf62fe86bb87d39fff4d00b827
    https://github.com/scummvm/scummvm/commit/106f9caa89002ccf62fe86bb87d39fff4d00b827
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2025-02-09T14:00:19+01:00

Commit Message:
ANDROID: Improve emulated gamepad buttons handling

When triggering buttons on the virtual gamepad, the down and up events
are sent on release. That's a leftover from the previous virtual gamepad
which didn't allow to select the buttons easily.
On the new virtual gamepad, the button choice is better so we can
trigger a button down as soon as the finger is on it.
This fixes a bug in some AGS games which missed the button press because
the release was sent too soon.
Fixes Trac#15444.

Changed paths:
    backends/platform/android/touchcontrols.cpp


diff --git a/backends/platform/android/touchcontrols.cpp b/backends/platform/android/touchcontrols.cpp
index 73aa8965e40..1287d5793be 100644
--- a/backends/platform/android/touchcontrols.cpp
+++ b/backends/platform/android/touchcontrols.cpp
@@ -553,10 +553,26 @@ bool TouchControls::FunctionRight::isInside(int x, int y) {
 }
 
 void TouchControls::FunctionRight::touch(int dX, int dY, Action action) {
-	if (action == JACTION_CANCEL) {
+	static const Common::JoystickButton buttons[] = {
+		Common::JOYSTICK_BUTTON_Y, Common::JOYSTICK_BUTTON_B,
+		Common::JOYSTICK_BUTTON_A, Common::JOYSTICK_BUTTON_X
+	};
+	static const Common::JoystickButton modifiers[] = {
+		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID,
+		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID
+	};
+	if (action == JACTION_CANCEL ||
+		action == JACTION_UP) {
+		if (button) {
+			buttonUp(buttons[button - 1]);
+			buttonUp(modifiers[button - 1]);
+		}
+		resetState();
 		return;
 	}
 
+	uint32 newButton = 0;
+
 	// norm 2 squared (to avoid square root)
 	unsigned int sqNorm = (unsigned int)(dX * dX) + (unsigned int)(dY * dY);
 
@@ -573,36 +589,35 @@ void TouchControls::FunctionRight::touch(int dX, int dY, Action action) {
 		if (adY <= adX) {
 			// X or B
 			if (dX < 0) {
-				button = 4;
+				newButton = 4;
 			} else {
-				button = 2;
+				newButton = 2;
 			}
 		} else {
 			// Y or A
 			if (dY < 0) {
-				button = 1;
+				newButton = 1;
 			} else {
-				button = 3;
+				newButton = 3;
 			}
 
 		}
 	} else {
-		button = 0;
+		newButton = 0;
 	}
 
-	static const Common::JoystickButton buttons[] = {
-		Common::JOYSTICK_BUTTON_Y, Common::JOYSTICK_BUTTON_B,
-		Common::JOYSTICK_BUTTON_A, Common::JOYSTICK_BUTTON_X
-	};
-	static const Common::JoystickButton modifiers[] = {
-		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID,
-		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID
-	};
-	if (action == JACTION_UP && button) {
-		buttonDown(modifiers[button - 1]);
-		buttonPress(buttons[button - 1]);
-		buttonUp(modifiers[button - 1]);
-		button = 0;
+	if (button != newButton) {
+		// Release the previously pressed button, if any
+		if (button) {
+			buttonUp(buttons[button - 1]);
+			buttonUp(modifiers[button - 1]);
+		}
+		button = newButton;
+		// Press the new button
+		if (button) {
+			buttonDown(modifiers[button - 1]);
+			buttonDown(buttons[button - 1]);
+		}
 	}
 }
 
@@ -658,10 +673,26 @@ bool TouchControls::FunctionCenter::isInside(int x, int y) {
 }
 
 void TouchControls::FunctionCenter::touch(int dX, int dY, Action action) {
-	if (action == JACTION_CANCEL) {
+	static const Common::JoystickButton buttons[] = {
+		Common::JOYSTICK_BUTTON_GUIDE, Common::JOYSTICK_BUTTON_RIGHT_STICK,
+		Common::JOYSTICK_BUTTON_START, Common::JOYSTICK_BUTTON_LEFT_STICK
+	};
+	static const Common::JoystickButton modifiers[] = {
+		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID,
+		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID
+	};
+	if (action == JACTION_CANCEL ||
+		action == JACTION_UP) {
+		if (button) {
+			buttonUp(buttons[button - 1]);
+			buttonUp(modifiers[button - 1]);
+		}
+		resetState();
 		return;
 	}
 
+	uint32 newButton = 0;
+
 	// norm 2 squared (to avoid square root)
 	unsigned int sqNorm = (unsigned int)(dX * dX) + (unsigned int)(dY * dY);
 
@@ -678,36 +709,35 @@ void TouchControls::FunctionCenter::touch(int dX, int dY, Action action) {
 		if (adY <= adX) {
 			// X or B
 			if (dX < 0) {
-				button = 4;
+				newButton = 4;
 			} else {
-				button = 2;
+				newButton = 2;
 			}
 		} else {
 			// Y or A
 			if (dY < 0) {
-				button = 1;
+				newButton = 1;
 			} else {
-				button = 3;
+				newButton = 3;
 			}
 
 		}
 	} else {
-		button = 0;
+		newButton = 0;
 	}
 
-	static const Common::JoystickButton buttons[] = {
-		Common::JOYSTICK_BUTTON_GUIDE, Common::JOYSTICK_BUTTON_RIGHT_STICK,
-		Common::JOYSTICK_BUTTON_START, Common::JOYSTICK_BUTTON_LEFT_STICK
-	};
-	static const Common::JoystickButton modifiers[] = {
-		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID,
-		Common::JOYSTICK_BUTTON_INVALID, Common::JOYSTICK_BUTTON_INVALID
-	};
-	if (action == JACTION_UP && button) {
-		buttonDown(modifiers[button - 1]);
-		buttonPress(buttons[button - 1]);
-		buttonUp(modifiers[button - 1]);
-		button = 0;
+	if (button != newButton) {
+		// Release the previously pressed button, if any
+		if (button) {
+			buttonUp(buttons[button - 1]);
+			buttonUp(modifiers[button - 1]);
+		}
+		button = newButton;
+		// Press the new button
+		if (button) {
+			buttonDown(modifiers[button - 1]);
+			buttonDown(buttons[button - 1]);
+		}
 	}
 }
 




More information about the Scummvm-git-logs mailing list