Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InputEventScreenDrag on Android #84331

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading