Fix tap location for styluses without hover support

This commit is contained in:
Cameron Gutman 2020-04-22 22:00:25 -07:00
parent 3b0f485b41
commit 0c72910eb7

View File

@ -1176,6 +1176,23 @@ public class Game extends Activity implements SurfaceHolder.Callback,
return true; return true;
} }
// Always update the position before sending any button events. If we're
// dealing with a stylus without hover support, our position might be
// significantly different than before.
if (inputCaptureProvider.eventHasRelativeMouseAxes(event)) {
// Send the deltas straight from the motion event
short deltaX = (short)inputCaptureProvider.getRelativeAxisX(event);
short deltaY = (short)inputCaptureProvider.getRelativeAxisY(event);
if (deltaX != 0 || deltaY != 0) {
conn.sendMouseMove(deltaX, deltaY);
}
}
else if (view != null) {
// Otherwise send absolute position
updateMousePosition(view, event);
}
if (event.getActionMasked() == MotionEvent.ACTION_SCROLL) { if (event.getActionMasked() == MotionEvent.ACTION_SCROLL) {
// Send the vertical scroll packet // Send the vertical scroll packet
byte vScrollClicks = (byte) event.getAxisValue(MotionEvent.AXIS_VSCROLL); byte vScrollClicks = (byte) event.getAxisValue(MotionEvent.AXIS_VSCROLL);
@ -1271,17 +1288,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
} }
} }
// Get relative axis values if we can
if (inputCaptureProvider.eventHasRelativeMouseAxes(event)) {
// Send the deltas straight from the motion event
conn.sendMouseMove((short) inputCaptureProvider.getRelativeAxisX(event),
(short) inputCaptureProvider.getRelativeAxisY(event));
}
else if (view != null) {
// Otherwise send absolute position
updateMousePosition(view, event);
}
lastButtonState = event.getButtonState(); lastButtonState = event.getButtonState();
} }
// This case is for fingers // This case is for fingers