From 73fc2b03a3b398243c5131fc5c7624b610d73e2d Mon Sep 17 00:00:00 2001 From: Susko3 Date: Wed, 22 Jan 2025 04:54:57 +0000 Subject: [PATCH] Copy pen handling code from `SDLSurface` to `SDLControllerManager` --- .../main/java/org/libsdl/app/SDLControllerManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index dc6fb9d12a..e1c892e71b 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -705,9 +705,14 @@ class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener { x = event.getX(i); y = event.getY(i); float p = event.getPressure(i); + if (p > 1.0f) { + // may be larger than 1.0f on some devices + // see the documentation of getPressure(i) + p = 1.0f; + } - // BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4 - int buttons = event.getButtonState() >> 4; + // BUTTON_STYLUS_PRIMARY is 2^5, so shift by 4, and apply SDL_PEN_INPUT_DOWN/SDL_PEN_INPUT_ERASER_TIP + int buttons = (event.getButtonState() >> 4) | (1 << (toolType == MotionEvent.TOOL_TYPE_STYLUS ? 0 : 30)); SDLActivity.onNativePen(event.getPointerId(i), buttons, action, x, y, p); consumed = true;