ANDROID: Support physical mouse wheel up-down

Tested and works with physical mouse but does not work with Android Studio emulated device
This commit is contained in:
antoniou79 2023-04-02 00:49:00 +03:00
parent 09ae3a1132
commit ea2585db02
4 changed files with 102 additions and 42 deletions

View file

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

View file

@ -190,46 +190,61 @@ public class MouseHelper implements View.OnHoverListener {
0,
0, 0, 0);
int buttonState = e.getButtonState();
//Log.d(ScummVM.LOG_TAG, "onMouseEvent buttonState = " + buttonState);
boolean lmbDown = (buttonState & MotionEvent.BUTTON_PRIMARY) == MotionEvent.BUTTON_PRIMARY;
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;
}
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 (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;
}
_lmbPressed = true;
//Log.d(ScummVM.LOG_TAG, "onMouseEvent Wheel Up/Down = " + eventJEWheelUpDown);
_scummvm.pushEvent(eventJEWheelUpDown,
(int) e.getX(),
(int) e.getY(),
0,
0, 0, 0);
} 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);
int buttonState = e.getButtonState();
//Log.d(ScummVM.LOG_TAG, "onMouseEvent buttonState = " + buttonState);
boolean lmbDown = (buttonState & MotionEvent.BUTTON_PRIMARY) == MotionEvent.BUTTON_PRIMARY;
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 = false;
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 = 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);
}
_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);
}
_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;
}

View file

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

View file

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