fix: android, pan, canvas, remove toInt() (#10103)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-29 22:39:07 +08:00 committed by GitHub
parent b91b49229a
commit b32ff87c6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 27 deletions

View File

@ -1080,7 +1080,7 @@ class InputModel {
onExit: true, onExit: true,
); );
static int tryGetNearestRange(int v, int min, int max, int n) { static double tryGetNearestRange(double v, double min, double max, double n) {
if (v < min && v >= min - n) { if (v < min && v >= min - n) {
v = min; v = min;
} }
@ -1138,8 +1138,8 @@ class InputModel {
return; return;
} }
evtValue = { evtValue = {
'x': pos.x, 'x': pos.x.toInt(),
'y': pos.y, 'y': pos.y.toInt(),
}; };
} }
@ -1221,8 +1221,8 @@ class InputModel {
evt['x'] = '0'; evt['x'] = '0';
evt['y'] = '0'; evt['y'] = '0';
} else { } else {
evt['x'] = '${pos.x}'; evt['x'] = '${pos.x.toInt()}';
evt['y'] = '${pos.y}'; evt['y'] = '${pos.y.toInt()}';
} }
Map<int, String> mapButtons = { Map<int, String> mapButtons = {
@ -1362,31 +1362,27 @@ class InputModel {
y = pos.dy; y = pos.dy;
} }
var evtX = 0;
var evtY = 0;
try {
evtX = x.round();
evtY = y.round();
} catch (e) {
debugPrintStack(label: 'canvas.scale value ${canvas.scale}, $e');
return null;
}
return InputModel.getPointInRemoteRect( return InputModel.getPointInRemoteRect(
true, peerPlatform, kind, evtType, evtX, evtY, rect, true, peerPlatform, kind, evtType, x, y, rect,
buttons: buttons); buttons: buttons);
} }
static Point? getPointInRemoteRect(bool isLocalDesktop, String? peerPlatform, static Point<double>? getPointInRemoteRect(
String kind, String evtType, int evtX, int evtY, Rect rect, bool isLocalDesktop,
String? peerPlatform,
String kind,
String evtType,
double evtX,
double evtY,
Rect rect,
{int buttons = kPrimaryMouseButton}) { {int buttons = kPrimaryMouseButton}) {
int minX = rect.left.toInt(); double minX = rect.left;
// https://github.com/rustdesk/rustdesk/issues/6678 // https://github.com/rustdesk/rustdesk/issues/6678
// For Windows, [0,maxX], [0,maxY] should be set to enable window snapping. // For Windows, [0,maxX], [0,maxY] should be set to enable window snapping.
int maxX = (rect.left + rect.width).toInt() - double maxX = (rect.left + rect.width) -
(peerPlatform == kPeerPlatformWindows ? 0 : 1); (peerPlatform == kPeerPlatformWindows ? 0 : 1);
int minY = rect.top.toInt(); double minY = rect.top;
int maxY = (rect.top + rect.height).toInt() - double maxY = (rect.top + rect.height) -
(peerPlatform == kPeerPlatformWindows ? 0 : 1); (peerPlatform == kPeerPlatformWindows ? 0 : 1);
evtX = InputModel.tryGetNearestRange(evtX, minX, maxX, 5); evtX = InputModel.tryGetNearestRange(evtX, minX, maxX, 5);
evtY = InputModel.tryGetNearestRange(evtY, minY, maxY, 5); evtY = InputModel.tryGetNearestRange(evtY, minY, maxY, 5);

View File

@ -2184,7 +2184,7 @@ class CursorModel with ChangeNotifier {
if (dx == 0 && dy == 0) return; if (dx == 0 && dy == 0) return;
Point? newPos; Point<double>? newPos;
final rect = parent.target?.ffiModel.rect; final rect = parent.target?.ffiModel.rect;
if (rect == null) { if (rect == null) {
// unreachable // unreachable
@ -2195,8 +2195,8 @@ class CursorModel with ChangeNotifier {
parent.target?.ffiModel.pi.platform, parent.target?.ffiModel.pi.platform,
kPointerEventKindMouse, kPointerEventKindMouse,
kMouseEventTypeDefault, kMouseEventTypeDefault,
(_x + dx).toInt(), _x + dx,
(_y + dy).toInt(), _y + dy,
rect, rect,
buttons: kPrimaryButton); buttons: kPrimaryButton);
if (newPos == null) { if (newPos == null) {
@ -2204,8 +2204,8 @@ class CursorModel with ChangeNotifier {
} }
dx = newPos.x - _x; dx = newPos.x - _x;
dy = newPos.y - _y; dy = newPos.y - _y;
_x = newPos.x.toDouble(); _x = newPos.x;
_y = newPos.y.toDouble(); _y = newPos.y;
if (tryMoveCanvasX && dx != 0) { if (tryMoveCanvasX && dx != 0) {
parent.target?.canvasModel.panX(-dx * scale); parent.target?.canvasModel.panX(-dx * scale);
} }