Small set of fixes to the input logic
This commit is contained in:
parent
b61fda9d2a
commit
5f4a3e57de
|
@ -127,7 +127,9 @@ public class GodotEditText extends EditText {
|
||||||
edit.setText("");
|
edit.setText("");
|
||||||
edit.append(text);
|
edit.append(text);
|
||||||
if (msg.arg2 != -1) {
|
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);
|
edit.mInputWrapper.setSelection(true);
|
||||||
} else {
|
} else {
|
||||||
edit.mInputWrapper.setSelection(false);
|
edit.mInputWrapper.setSelection(false);
|
||||||
|
|
|
@ -77,7 +77,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun contextClickRouter(event: MotionEvent) {
|
private fun contextClickRouter(event: MotionEvent) {
|
||||||
if (scaleInProgress) {
|
if (scaleInProgress || nextDownIsDoubleTap) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,40 +134,24 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onActionUp(event: MotionEvent): Boolean {
|
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) {
|
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
|
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
when {
|
|
||||||
pointerCaptureInProgress -> {
|
if (pointerCaptureInProgress || dragInProgress || contextClickInProgress) {
|
||||||
return if (event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
if (contextClickInProgress || GodotInputHandler.isMouseEvent(event)) {
|
||||||
// Don't dispatch the ACTION_CANCEL while a capture is in progress
|
// This may be an ACTION_BUTTON_RELEASE event which we don't handle,
|
||||||
true
|
// so we convert it to an ACTION_UP event.
|
||||||
} 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 -> {
|
|
||||||
GodotInputHandler.handleMouseEvent(
|
GodotInputHandler.handleMouseEvent(
|
||||||
event.actionMasked,
|
MotionEvent.ACTION_UP,
|
||||||
0,
|
event.buttonState,
|
||||||
event.x,
|
event.x,
|
||||||
event.y,
|
event.y,
|
||||||
0f,
|
0f,
|
||||||
|
@ -175,11 +159,16 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
false,
|
false,
|
||||||
sourceMouseRelative
|
sourceMouseRelative
|
||||||
)
|
)
|
||||||
contextClickInProgress = false
|
} else {
|
||||||
return true
|
GodotInputHandler.handleTouchEvent(event)
|
||||||
}
|
}
|
||||||
else -> return false
|
pointerCaptureInProgress = false
|
||||||
|
dragInProgress = false
|
||||||
|
contextClickInProgress = false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onActionMove(event: MotionEvent): Boolean {
|
private fun onActionMove(event: MotionEvent): Boolean {
|
||||||
|
@ -242,7 +231,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
|
|
||||||
val x = terminusEvent.x
|
val x = terminusEvent.x
|
||||||
val y = terminusEvent.y
|
val y = terminusEvent.y
|
||||||
if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled) {
|
if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled && !pointerCaptureInProgress) {
|
||||||
GodotLib.pan(x, y, distanceX / 5f, distanceY / 5f)
|
GodotLib.pan(x, y, distanceX / 5f, distanceY / 5f)
|
||||||
} else {
|
} else {
|
||||||
GodotInputHandler.handleMotionEvent(terminusEvent)
|
GodotInputHandler.handleMotionEvent(terminusEvent)
|
||||||
|
@ -251,7 +240,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScale(detector: ScaleGestureDetector?): Boolean {
|
override fun onScale(detector: ScaleGestureDetector?): Boolean {
|
||||||
if (detector == null || !panningAndScalingEnabled) {
|
if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
GodotLib.magnify(
|
GodotLib.magnify(
|
||||||
|
@ -263,7 +252,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean {
|
override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean {
|
||||||
if (detector == null || !panningAndScalingEnabled) {
|
if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
scaleInProgress = true
|
scaleInProgress = true
|
||||||
|
|
|
@ -245,7 +245,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (isMouseEvent(event)) {
|
} else {
|
||||||
return handleMouseEvent(event);
|
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) {
|
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) {
|
switch (eventAction) {
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
|
|
|
@ -68,7 +68,7 @@ void GodotJavaViewWrapper::request_pointer_capture() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GodotJavaViewWrapper::release_pointer_capture() {
|
void GodotJavaViewWrapper::release_pointer_capture() {
|
||||||
if (_request_pointer_capture != nullptr) {
|
if (_release_pointer_capture != nullptr) {
|
||||||
JNIEnv *env = get_jni_env();
|
JNIEnv *env = get_jni_env();
|
||||||
ERR_FAIL_NULL(env);
|
ERR_FAIL_NULL(env);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue