Skip to content

Commit

Permalink
android q tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
HEAVYPOLY committed Aug 29, 2024
1 parent 16a84f0 commit 3120b2c
Showing 1 changed file with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,39 +488,21 @@ static boolean handleMouseEvent(final MotionEvent event) {
float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
float pressure = event.getPressure();
float tiltX = 0f;
float tiltY = 0f;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
tiltX = event.getAxisValue(MotionEvent.AXIS_TILT_X);
tiltY = event.getAxisValue(MotionEvent.AXIS_TILT_Y);
}

boolean sourceMouseRelative = false;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
sourceMouseRelative = event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE);
}

GodotLib.dispatchMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, pressure, tiltX, tiltY, doubleClick, sourceMouseRelative);

// Check if the event has tilt data
if (Float.isNaN(tiltX) || Float.isNaN(tiltY)) {
tiltX = 0f; // Default value if tilt data is not available
tiltY = 0f; // Default value if tilt data is not available
}
float tiltX = 0;
float tiltY = 0;

// Check if the event has pressure data
if (Float.isNaN(pressure)) {
pressure = 1f; // Default value if pressure data is not available
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
tiltX = event.getAxisValue(MotionEvent.AXIS_TILT_X);
tiltY = event.getAxisValue(MotionEvent.AXIS_TILT_Y);
}

boolean sourceMouseRelative = false;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
sourceMouseRelative = event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
sourceMouseRelative = event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE);
}
return handleMouseEvent(eventAction, buttonsMask, x, y, horizontalFactor, verticalFactor, pressure, tiltX, tiltY, false, sourceMouseRelative);
}

static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y) {
return handleMouseEvent(eventAction, buttonsMask, x, y, 0, 0, false, false);
}
Expand Down

0 comments on commit 3120b2c

Please sign in to comment.