[Scummvm-git-logs] scummvm master -> d813908b54754a9f6c17d94e3465817ecdd81242
antoniou79
noreply at scummvm.org
Sat Apr 1 21:50:09 UTC 2023
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:
d813908b54 ANDROID: Support physical mouse wheel up-down
Commit: d813908b54754a9f6c17d94e3465817ecdd81242
https://github.com/scummvm/scummvm/commit/d813908b54754a9f6c17d94e3465817ecdd81242
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2023-04-02T00:50:00+03:00
Commit Message:
ANDROID: Support physical mouse wheel up-down
Tested and works with physical mouse but does not work with Android Studio emulated device
Changed paths:
backends/platform/android/events.cpp
backends/platform/android/org/scummvm/scummvm/MouseHelper.java
backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index bed36bbc2b8..d53cf3194ac 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -76,7 +76,9 @@ enum {
JE_BMB_UP = 19,
JE_FMB_DOWN = 20,
JE_FMB_UP = 21,
- JE_TV_REMOTE = 22,
+ JE_MOUSE_WHEEL_UP = 22,
+ JE_MOUSE_WHEEL_DOWN = 23,
+ JE_TV_REMOTE = 24,
JE_QUIT = 0x1000,
JE_MENU = 0x1001
};
@@ -1151,6 +1153,26 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
return;
+ case JE_MOUSE_WHEEL_UP:
+ e.type = Common::EVENT_WHEELUP;
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
+// e.mouse = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+
+ pushEvent(e);
+
+ return;
+
+ case JE_MOUSE_WHEEL_DOWN:
+ e.type = Common::EVENT_WHEELDOWN;
+ e.mouse.x = arg1;
+ e.mouse.y = arg2;
+// e.mouse = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+
+ pushEvent(e);
+
+ return;
+
case JE_GAMEPAD:
switch (arg1) {
case AKEY_EVENT_ACTION_DOWN:
diff --git a/backends/platform/android/org/scummvm/scummvm/MouseHelper.java b/backends/platform/android/org/scummvm/scummvm/MouseHelper.java
index 5647cac8a5e..9c241a2ae50 100644
--- a/backends/platform/android/org/scummvm/scummvm/MouseHelper.java
+++ b/backends/platform/android/org/scummvm/scummvm/MouseHelper.java
@@ -190,46 +190,61 @@ public class MouseHelper implements View.OnHoverListener {
0,
0, 0, 0);
- int buttonState = e.getButtonState();
+ if (e.getActionMasked() == MotionEvent.ACTION_SCROLL) {
+ // The call is coming from ScummVMEventsModern, from a GenericMotionEvent (scroll wheel movement)
+ // TODO Do we want the JE_MOUSE_MOVE event too in this case?
+ int eventJEWheelUpDown = ScummVMEventsBase.JE_MOUSE_WHEEL_UP;
+ if (e.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f) {
+ eventJEWheelUpDown = ScummVMEventsBase.JE_MOUSE_WHEEL_DOWN;
+ }
+ //Log.d(ScummVM.LOG_TAG, "onMouseEvent Wheel Up/Down = " + eventJEWheelUpDown);
+ _scummvm.pushEvent(eventJEWheelUpDown,
+ (int) e.getX(),
+ (int) e.getY(),
+ 0,
+ 0, 0, 0);
+ } else {
- //Log.d(ScummVM.LOG_TAG, "onMouseEvent buttonState = " + buttonState);
+ int buttonState = e.getButtonState();
- boolean lmbDown = (buttonState & MotionEvent.BUTTON_PRIMARY) == MotionEvent.BUTTON_PRIMARY;
+ //Log.d(ScummVM.LOG_TAG, "onMouseEvent buttonState = " + buttonState);
- if (!hover && e.getAction() != MotionEvent.ACTION_UP && buttonState == 0) {
- // On some device types, ButtonState is 0 even when tapping on the touch-pad or using the stylus on the screen etc.
- lmbDown = true;
- }
+ boolean lmbDown = (buttonState & MotionEvent.BUTTON_PRIMARY) == MotionEvent.BUTTON_PRIMARY;
- if (lmbDown) {
- if (!_lmbPressed) {
- // left mouse button was pressed just now
- _scummvm.pushEvent(ScummVMEventsBase.JE_LMB_DOWN, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0, 0);
+ if (!hover && e.getActionMasked() != MotionEvent.ACTION_UP && buttonState == 0) {
+ // On some device types, ButtonState is 0 even when tapping on the touch-pad or using the stylus on the screen etc.
+ lmbDown = true;
}
- _lmbPressed = true;
- } else {
- if (_lmbPressed) {
- // left mouse button was released just now
- _scummvm.pushEvent(ScummVMEventsBase.JE_LMB_UP, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0, 0);
- }
+ if (lmbDown) {
+ if (!_lmbPressed) {
+ // left mouse button was pressed just now
+ _scummvm.pushEvent(ScummVMEventsBase.JE_LMB_DOWN, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0, 0);
+ }
- _lmbPressed = false;
- }
+ _lmbPressed = true;
+ } else {
+ if (_lmbPressed) {
+ // left mouse button was released just now
+ _scummvm.pushEvent(ScummVMEventsBase.JE_LMB_UP, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0, 0);
+ }
- _rmbPressed = handleButton(e, _rmbPressed, MotionEvent.BUTTON_SECONDARY, ScummVMEventsBase.JE_RMB_DOWN, ScummVMEventsBase.JE_RMB_UP);
- _mmbPressed = handleButton(e, _mmbPressed, MotionEvent.BUTTON_TERTIARY, ScummVMEventsBase.JE_MMB_DOWN, ScummVMEventsBase.JE_MMB_UP);
- _bmbPressed = handleButton(e, _bmbPressed, MotionEvent.BUTTON_BACK, ScummVMEventsBase.JE_BMB_DOWN, ScummVMEventsBase.JE_BMB_UP);
- _fmbPressed = handleButton(e, _fmbPressed, MotionEvent.BUTTON_FORWARD, ScummVMEventsBase.JE_FMB_DOWN, ScummVMEventsBase.JE_FMB_UP);
- // Lint warning for BUTTON_STYLUS... "
- // Field requires API level 23 (current min is 16): android.view.MotionEvent#BUTTON_STYLUS_PRIMARY"
- // Field requires API level 23 (current min is 16): android.view.MotionEvent#BUTTON_STYLUS_SECONDARY"
- // We suppress it:
- //
- // https://stackoverflow.com/a/48588149
- _srmbPressed = handleButton(e, _srmbPressed, MotionEvent.BUTTON_STYLUS_PRIMARY, ScummVMEventsBase.JE_RMB_DOWN, ScummVMEventsBase.JE_RMB_UP);
- _smmbPressed = handleButton(e, _smmbPressed, MotionEvent.BUTTON_STYLUS_SECONDARY, ScummVMEventsBase.JE_MMB_DOWN, ScummVMEventsBase.JE_MMB_UP);
+ _lmbPressed = false;
+ }
+ _rmbPressed = handleButton(e, _rmbPressed, MotionEvent.BUTTON_SECONDARY, ScummVMEventsBase.JE_RMB_DOWN, ScummVMEventsBase.JE_RMB_UP);
+ _mmbPressed = handleButton(e, _mmbPressed, MotionEvent.BUTTON_TERTIARY, ScummVMEventsBase.JE_MMB_DOWN, ScummVMEventsBase.JE_MMB_UP);
+ _bmbPressed = handleButton(e, _bmbPressed, MotionEvent.BUTTON_BACK, ScummVMEventsBase.JE_BMB_DOWN, ScummVMEventsBase.JE_BMB_UP);
+ _fmbPressed = handleButton(e, _fmbPressed, MotionEvent.BUTTON_FORWARD, ScummVMEventsBase.JE_FMB_DOWN, ScummVMEventsBase.JE_FMB_UP);
+ // Lint warning for BUTTON_STYLUS... "
+ // Field requires API level 23 (current min is 16): android.view.MotionEvent#BUTTON_STYLUS_PRIMARY"
+ // Field requires API level 23 (current min is 16): android.view.MotionEvent#BUTTON_STYLUS_SECONDARY"
+ // We suppress it:
+ //
+ // https://stackoverflow.com/a/48588149
+ _srmbPressed = handleButton(e, _srmbPressed, MotionEvent.BUTTON_STYLUS_PRIMARY, ScummVMEventsBase.JE_RMB_DOWN, ScummVMEventsBase.JE_RMB_UP);
+ _smmbPressed = handleButton(e, _smmbPressed, MotionEvent.BUTTON_STYLUS_SECONDARY, ScummVMEventsBase.JE_MMB_DOWN, ScummVMEventsBase.JE_MMB_UP);
+ }
return true;
}
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
index 746264016c1..c95af692571 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
@@ -48,7 +48,9 @@ public class ScummVMEventsBase implements
public static final int JE_BMB_UP = 19;
public static final int JE_FMB_DOWN = 20;
public static final int JE_FMB_UP = 21;
- public static final int JE_TV_REMOTE = 22;
+ public static final int JE_MOUSE_WHEEL_UP = 22;
+ public static final int JE_MOUSE_WHEEL_DOWN = 23;
+ public static final int JE_TV_REMOTE = 24;
public static final int JE_QUIT = 0x1000;
public static final int JE_MENU = 0x1001;
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
index b614c6aef3a..969e71238f3 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
@@ -4,7 +4,7 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
-import android.util.Log;
+//import android.util.Log;
import android.view.MotionEvent;
import android.view.InputDevice;
@@ -183,15 +183,14 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
// Check that the event came from a joystick
if (((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK
|| (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0)) {
- int action = event.getActionMasked();
- if (action == MotionEvent.ACTION_MOVE) {
-
+ switch(event.getActionMasked()) {
+ case MotionEvent.ACTION_MOVE:
// Process all historical movement samples in the batch
final int historySize = event.getHistorySize();
// Process the movements starting from the
// earliest historical position in the batch
- for (int i = 0; i < historySize; i++) {
+ for (int i = 0; i < historySize; ++i) {
// Process the event at historical position i
//Log.d(ScummVM.LOG_TAG, "JOYSTICK - onGenericMotionEvent(m) hist: ");
processJoystickInput(event, i);
@@ -201,6 +200,28 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
//Log.d(ScummVM.LOG_TAG, "JOYSTICK - onGenericMotionEvent(m): " );
processJoystickInput(event, -1);
return true;
+
+ default:
+ break;
+ }
+ } else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
+ // TODO Check if we need to handle other cases of InputDevice SOURCE_CLASS_POINTER for GenericMotionEvent, that are not ACTION_SCROLL
+ //Log.d(ScummVM.LOG_TAG, "MOUSE PHYSICAL POINTER - onGenericMotionEvent(m) ");
+ //
+ // Check that the event might be a mouse scroll wheel
+ // Code inspired from https://stackoverflow.com/a/33086042
+ switch (event.getActionMasked()) {
+ case MotionEvent.ACTION_SCROLL:
+ //Log.d(ScummVM.LOG_TAG, "MOUSE PHYSICAL POINTER - ACTION SCROLL");
+ // This action is not a touch event so it is delivered to
+ // View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).
+ if (_mouseHelper != null) {
+ return _mouseHelper.onMouseEvent(event, false);
+ }
+ break;
+
+ default:
+ break;
}
}
// this basically returns false since the super just returns false
More information about the Scummvm-git-logs
mailing list