1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Add double_tap attribute to InputEventScreenTouch

This provides parity with the `InputEventMouseButton` allowing for proper conversion between the two events.
This commit is contained in:
Fredia Huya-Kouadio
2022-10-18 20:03:31 -07:00
parent 2342f174a4
commit be4b07c3e4
12 changed files with 54 additions and 43 deletions

View File

@@ -100,7 +100,7 @@ public class GodotLib {
/**
* Forward touch events.
*/
public static native void dispatchTouchEvent(int event, int pointer, int pointerCount, float[] positions);
public static native void dispatchTouchEvent(int event, int pointer, int pointerCount, float[] positions, boolean doubleTap);
/**
* Dispatch mouse events

View File

@@ -53,17 +53,14 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
*/
var panningAndScalingEnabled = false
private var doubleTapInProgress = false
private var nextDownIsDoubleTap = false
private var dragInProgress = false
private var scaleInProgress = false
private var contextClickInProgress = false
override fun onDown(event: MotionEvent): Boolean {
// Don't send / register a down event while we're in the middle of a double-tap
if (!doubleTapInProgress) {
// Send the down event
GodotInputHandler.handleMotionEvent(event)
}
GodotInputHandler.handleMotionEvent(event.source, MotionEvent.ACTION_DOWN, event.buttonState, event.x, event.y, nextDownIsDoubleTap)
nextDownIsDoubleTap = false
return true
}
@@ -145,24 +142,14 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
override fun onDoubleTapEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_UP) {
doubleTapInProgress = false
nextDownIsDoubleTap = false
GodotInputHandler.handleMotionEvent(event)
}
return true
}
override fun onDoubleTap(event: MotionEvent): Boolean {
doubleTapInProgress = true
val x = event.x
val y = event.y
val buttonMask =
if (GodotInputHandler.isMouseEvent(event)) {
event.buttonState
} else {
MotionEvent.BUTTON_PRIMARY
}
GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_DOWN, buttonMask, x, y, true)
GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_UP, 0, x, y, false)
nextDownIsDoubleTap = true
return true
}

View File

@@ -426,15 +426,19 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
}
static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y) {
return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, 0, 0);
return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, false);
}
static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY) {
static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, boolean doubleTap) {
return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, 0, 0, doubleTap);
}
static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, boolean doubleTap) {
if (isMouseEvent(eventSource)) {
return handleMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, false);
return handleMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, doubleTap);
}
return handleTouchEvent(eventAction, x, y);
return handleTouchEvent(eventAction, x, y, doubleTap);
}
static boolean handleMouseEvent(final MotionEvent event) {
@@ -452,10 +456,6 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
return handleMouseEvent(eventAction, buttonsMask, x, y, 0, 0, false);
}
static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, boolean doubleClick) {
return handleMouseEvent(eventAction, buttonsMask, x, y, 0, 0, doubleClick);
}
static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, boolean doubleClick) {
switch (eventAction) {
case MotionEvent.ACTION_CANCEL:
@@ -492,14 +492,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
final int action = event.getActionMasked();
final int actionPointerId = event.getPointerId(event.getActionIndex());
return handleTouchEvent(action, actionPointerId, pointerCount, positions);
return handleTouchEvent(action, actionPointerId, pointerCount, positions, false);
}
static boolean handleTouchEvent(int eventAction, float x, float y) {
return handleTouchEvent(eventAction, 0, 1, new float[] { 0, x, y });
static boolean handleTouchEvent(int eventAction, float x, float y, boolean doubleTap) {
return handleTouchEvent(eventAction, 0, 1, new float[] { 0, x, y }, doubleTap);
}
static boolean handleTouchEvent(int eventAction, int actionPointerId, int pointerCount, float[] positions) {
static boolean handleTouchEvent(int eventAction, int actionPointerId, int pointerCount, float[] positions, boolean doubleTap) {
switch (eventAction) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_CANCEL:
@@ -507,7 +507,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN: {
GodotLib.dispatchTouchEvent(eventAction, actionPointerId, pointerCount, positions);
GodotLib.dispatchTouchEvent(eventAction, actionPointerId, pointerCount, positions, doubleTap);
return true;
}
}