Skip to content

Commit ba4fec5

Browse files
committed
android tilt and pressure
1 parent 01c78d8 commit ba4fec5

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

platform/android/android_input_handler.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void AndroidInputHandler::_release_mouse_event_info(bool p_source_mouse_relative
254254
mouse_event_info.valid = false;
255255
}
256256

257-
void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_android_buttons_mask, Point2 p_event_pos, Vector2 p_delta, bool p_double_click, bool p_source_mouse_relative) {
257+
void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_android_buttons_mask, Point2 p_event_pos, Vector2 p_delta, float p_pressure, Vector2 p_tilt, bool p_double_click, bool p_source_mouse_relative) {
258258
int event_buttons_mask = _android_button_mask_to_godot_button_mask(p_event_android_buttons_mask);
259259
switch (p_event_action) {
260260
case AMOTION_EVENT_ACTION_HOVER_MOVE: // hover move
@@ -267,6 +267,8 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an
267267
ev->set_position(p_event_pos);
268268
ev->set_global_position(p_event_pos);
269269
ev->set_relative(p_event_pos - hover_prev_pos);
270+
ev->set_pressure(p_pressure);
271+
ev->set_tilt(p_tilt);
270272
input->parse_input_event(ev);
271273
hover_prev_pos = p_event_pos;
272274
} break;
@@ -311,6 +313,8 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an
311313
hover_prev_pos = p_event_pos;
312314
}
313315
ev->set_button_mask(event_buttons_mask);
316+
ev->set_pressure(p_pressure);
317+
ev->set_tilt(p_tilt);
314318
input->parse_input_event(ev);
315319
} break;
316320

platform/android/java/lib/src/org/godotengine/godot/GodotLib.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ public class GodotLib {
101101
* Forward touch events.
102102
*/
103103
public static native void dispatchTouchEvent(int event, int pointer, int pointerCount, float[] positions, boolean doubleTap);
104-
105104
/**
106105
* Dispatch mouse events
107106
*/
108-
public static native void dispatchMouseEvent(int event, int buttonMask, float x, float y, float deltaX, float deltaY, boolean doubleClick, boolean sourceMouseRelative);
107+
public static native void dispatchMouseEvent(int event, int buttonMask, float x, float y, float deltaX, float deltaY, float pressure, float tiltX, float tiltY, boolean doubleClick, boolean sourceMouseRelative);
109108

110109
public static native void magnify(float x, float y, float factor);
111110

platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java

+22-16
Original file line numberDiff line numberDiff line change
@@ -485,27 +485,28 @@ static boolean handleMouseEvent(final MotionEvent event) {
485485
final float y = event.getY();
486486
final int buttonsMask = event.getButtonState();
487487

488-
float verticalFactor = 0;
489-
float horizontalFactor = 0;
490-
491-
// If event came from RotaryEncoder (Bezel or Crown rotate event on Wear OS smart watches),
492-
// convert it to mouse wheel event.
493-
if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) {
494-
if (rotaryInputAxis == ROTARY_INPUT_HORIZONTAL_AXIS) {
495-
horizontalFactor = -event.getAxisValue(MotionEvent.AXIS_SCROLL);
496-
} else {
497-
// If rotaryInputAxis is not ROTARY_INPUT_HORIZONTAL_AXIS then use default ROTARY_INPUT_VERTICAL_AXIS axis.
498-
verticalFactor = -event.getAxisValue(MotionEvent.AXIS_SCROLL);
499-
}
500-
} else {
501-
verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
502-
horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
488+
float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
489+
float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
490+
float pressure = event.getPressure();
491+
float tiltX = event.getAxisValue(MotionEvent.AXIS_TILT_X);
492+
float tiltY = event.getAxisValue(MotionEvent.AXIS_TILT_Y);
493+
494+
// Check if the event has tilt data
495+
if (Float.isNaN(tiltX) || Float.isNaN(tiltY)) {
496+
tiltX = 0; // Default value if tilt data is not available
497+
tiltY = 0; // Default value if tilt data is not available
503498
}
499+
500+
// Check if the event has pressure data
501+
if (Float.isNaN(pressure)) {
502+
pressure = 1; // Default value if pressure data is not available
503+
}
504+
504505
boolean sourceMouseRelative = false;
505506
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
506507
sourceMouseRelative = event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE);
507508
}
508-
return handleMouseEvent(eventAction, buttonsMask, x, y, horizontalFactor, verticalFactor, false, sourceMouseRelative);
509+
return handleMouseEvent(eventAction, buttonsMask, x, y, horizontalFactor, verticalFactor, pressure, tiltX, tiltY, false, sourceMouseRelative);
509510
}
510511

511512
static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y) {
@@ -551,6 +552,11 @@ static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float
551552
return false;
552553
}
553554

555+
static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, float pressure, float tiltX, float tiltY, boolean doubleClick, boolean sourceMouseRelative) {
556+
GodotLib.dispatchMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, pressure, tiltX, tiltY, doubleClick, sourceMouseRelative);
557+
return true;
558+
}
559+
554560
static boolean handleTouchEvent(final MotionEvent event) {
555561
final int pointerCount = event.getPointerCount();
556562
if (pointerCount == 0) {

0 commit comments

Comments
 (0)