Small set of fixes to the input logic

This commit is contained in:
Fredia Huya-Kouadio 2022-10-20 12:00:34 -07:00
parent b61fda9d2a
commit 5f4a3e57de
4 changed files with 32 additions and 38 deletions

View File

@ -127,7 +127,9 @@ public class GodotEditText extends EditText {
edit.setText("");
edit.append(text);
if (msg.arg2 != -1) {
edit.setSelection(msg.arg1, msg.arg2);
int selectionStart = Math.min(msg.arg1, edit.length());
int selectionEnd = Math.min(msg.arg2, edit.length());
edit.setSelection(selectionStart, selectionEnd);
edit.mInputWrapper.setSelection(true);
} else {
edit.mInputWrapper.setSelection(false);

View File

@ -77,7 +77,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
}
private fun contextClickRouter(event: MotionEvent) {
if (scaleInProgress) {
if (scaleInProgress || nextDownIsDoubleTap) {
return
}
@ -134,40 +134,24 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
}
private fun onActionUp(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_CANCEL && pointerCaptureInProgress) {
// Don't dispatch the ACTION_CANCEL while a capture is in progress
return true
}
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
} else {
false
}
when {
pointerCaptureInProgress -> {
return if (event.actionMasked == MotionEvent.ACTION_CANCEL) {
// Don't dispatch the ACTION_CANCEL while a capture is in progress
true
} else {
GodotInputHandler.handleMouseEvent(
MotionEvent.ACTION_UP,
event.buttonState,
event.x,
event.y,
0f,
0f,
false,
sourceMouseRelative
)
pointerCaptureInProgress = false
true
}
}
dragInProgress -> {
GodotInputHandler.handleMotionEvent(event)
dragInProgress = false
return true
}
contextClickInProgress -> {
if (pointerCaptureInProgress || dragInProgress || contextClickInProgress) {
if (contextClickInProgress || GodotInputHandler.isMouseEvent(event)) {
// This may be an ACTION_BUTTON_RELEASE event which we don't handle,
// so we convert it to an ACTION_UP event.
GodotInputHandler.handleMouseEvent(
event.actionMasked,
0,
MotionEvent.ACTION_UP,
event.buttonState,
event.x,
event.y,
0f,
@ -175,11 +159,16 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
false,
sourceMouseRelative
)
contextClickInProgress = false
return true
} else {
GodotInputHandler.handleTouchEvent(event)
}
else -> return false
pointerCaptureInProgress = false
dragInProgress = false
contextClickInProgress = false
return true
}
return false
}
private fun onActionMove(event: MotionEvent): Boolean {
@ -242,7 +231,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
val x = terminusEvent.x
val y = terminusEvent.y
if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled) {
if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled && !pointerCaptureInProgress) {
GodotLib.pan(x, y, distanceX / 5f, distanceY / 5f)
} else {
GodotInputHandler.handleMotionEvent(terminusEvent)
@ -251,7 +240,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
}
override fun onScale(detector: ScaleGestureDetector?): Boolean {
if (detector == null || !panningAndScalingEnabled) {
if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {
return false
}
GodotLib.magnify(
@ -263,7 +252,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
}
override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean {
if (detector == null || !panningAndScalingEnabled) {
if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {
return false
}
scaleInProgress = true

View File

@ -245,7 +245,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
}
return true;
}
} else if (isMouseEvent(event)) {
} else {
return handleMouseEvent(event);
}
@ -473,6 +473,9 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
}
static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, boolean doubleClick, boolean sourceMouseRelative) {
// We don't handle ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE events as they typically
// follow ACTION_DOWN and ACTION_UP events. As such, handling them would result in duplicate
// stream of events to the engine.
switch (eventAction) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:

View File

@ -68,7 +68,7 @@ void GodotJavaViewWrapper::request_pointer_capture() {
}
void GodotJavaViewWrapper::release_pointer_capture() {
if (_request_pointer_capture != nullptr) {
if (_release_pointer_capture != nullptr) {
JNIEnv *env = get_jni_env();
ERR_FAIL_NULL(env);