Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse wheel scrolling support for Android to the UI #18473

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Common/UI/ScrollView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool ScrollView::Key(const KeyInput &input) {
if (input.flags & KEY_DOWN) {
if ((input.keyCode == NKCODE_EXT_MOUSEWHEEL_UP || input.keyCode == NKCODE_EXT_MOUSEWHEEL_DOWN) &&
(input.flags & KEY_HASWHEELDELTA)) {
scrollSpeed = (float)(short)(input.flags >> 16) * 1.25f; // Fudge factor
scrollSpeed = (float)(short)(input.flags >> 16) * 1.25f; // Fudge factor. TODO: Should be moved to the backends.
}

switch (input.keyCode) {
Expand Down
20 changes: 19 additions & 1 deletion android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,25 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent(
JNIEnv *env, jclass, jint stick, jfloat x, jfloat y) {
if (!renderer_inited)
return false;
// TODO: Support mousewheel for android
// TODO: Mousewheel should probably be an axis instead.
int wheelDelta = y * 30.0f;
if (wheelDelta > 500) wheelDelta = 500;
if (wheelDelta < -500) wheelDelta = -500;

KeyInput key;
key.deviceId = DEVICE_ID_MOUSE;
if (wheelDelta < 0) {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
wheelDelta = -wheelDelta;
} else {
key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
}
// There's no separate keyup event for mousewheel events,
// so we release it with a slight delay.
key.flags = KEY_DOWN | KEY_HASWHEELDELTA | (wheelDelta << 16);
NativeKey(key);
key.flags = KEY_UP;
NativeKey(key);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {
// process the mouse hover movement...
return true;
case MotionEvent.ACTION_SCROLL:
NativeApp.mouseWheelEvent(event.getX(), event.getY());
NativeApp.mouseWheelEvent(event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
return true;
}
}
Expand Down