Skip to content

Commit

Permalink
Fix InputEventScreenDrag on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex2782 committed May 20, 2024
1 parent 40b4130 commit ab9e377
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
private var contextClickInProgress = false
private var pointerCaptureInProgress = false

private var lastDragX: Float = 0.0f
private var lastDragY: Float = 0.0f

override fun onDown(event: MotionEvent): Boolean {
GodotInputHandler.handleMotionEvent(event.source, MotionEvent.ACTION_DOWN, event.buttonState, event.x, event.y, nextDownIsDoubleTap)
nextDownIsDoubleTap = false
Expand Down Expand Up @@ -165,6 +168,8 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
pointerCaptureInProgress = false
dragInProgress = false
contextClickInProgress = false
lastDragX = 0.0f
lastDragY = 0.0f
return true
}

Expand All @@ -189,6 +194,17 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
sourceMouseRelative
)
return true
} else if (!scaleInProgress) {
// The 'onScroll' event is triggered with a long delay.
// Force the 'InputEventScreenDrag' event earlier here.
// We don't toggle 'dragInProgress' here so that the scaling logic can override the drag operation if needed.
// Once the 'onScroll' event kicks-in, 'dragInProgress' will be properly set.
if (lastDragX != event.getX(0) || lastDragY != event.getY(0)) {
lastDragX = event.getX(0)
lastDragY = event.getY(0)
GodotInputHandler.handleMotionEvent(event)
return true
}
}
return false
}
Expand Down Expand Up @@ -216,7 +232,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
distanceY: Float
): Boolean {
if (scaleInProgress) {
if (dragInProgress) {
if (dragInProgress || lastDragX != 0.0f || lastDragY != 0.0f) {
if (originEvent != null) {
// Cancel the drag
GodotInputHandler.handleMotionEvent(
Expand All @@ -228,15 +244,19 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
)
}
dragInProgress = false
lastDragX = 0.0f
lastDragY = 0.0f
}
}

val x = terminusEvent.x
val y = terminusEvent.y
if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled && !pointerCaptureInProgress && !dragInProgress) {
GodotLib.pan(x, y, distanceX / 5f, distanceY / 5f)
} else if (!scaleInProgress){
} else if (!scaleInProgress) {
dragInProgress = true
lastDragX = terminusEvent.getX(0)
lastDragY = terminusEvent.getY(0)
GodotInputHandler.handleMotionEvent(terminusEvent)
}
return true
Expand Down

0 comments on commit ab9e377

Please sign in to comment.