new pan works

This commit is contained in:
open-trade 2020-11-24 23:36:46 +08:00
parent 514341180d
commit 4b07075355

View File

@ -51,7 +51,7 @@ class FfiModel with ChangeNotifier {
print('$_permissions'); print('$_permissions');
} }
bool keyboard() => _permissions['keyboard'] == true; bool keyboard() => _permissions['keyboard'] != false;
void clear() { void clear() {
_pi = PeerInfo(); _pi = PeerInfo();
@ -287,21 +287,21 @@ class CursorModel with ChangeNotifier {
var tryMoveCanvasY = false; var tryMoveCanvasY = false;
if (dy > 0) { if (dy > 0) {
final mayCanvasCanMove = final mayCanvasCanMove =
_displayOriginY + FFI.imageModel.image.width - r.right; _displayOriginY + FFI.imageModel.image.height - r.bottom;
tryMoveCanvasY = _y + dy > cy && mayCanvasCanMove > 0; tryMoveCanvasY = _y + dy > cy && mayCanvasCanMove > 0;
if (tryMoveCanvasY) { if (tryMoveCanvasY) {
dy = min(dy, mayCanvasCanMove); dy = min(dy, mayCanvasCanMove);
} else { } else {
final mayCursorCanMove = r.right - _y; final mayCursorCanMove = r.bottom - _y;
dy = min(dy, mayCursorCanMove); dy = min(dy, mayCursorCanMove);
} }
} else if (dy < 0) { } else if (dy < 0) {
final mayCanvasCanMove = _displayOriginY - r.left; final mayCanvasCanMove = _displayOriginY - r.top;
tryMoveCanvasY = _y + dy < cy && mayCanvasCanMove < 0; tryMoveCanvasY = _y + dy < cy && mayCanvasCanMove < 0;
if (tryMoveCanvasY) { if (tryMoveCanvasY) {
dy = max(dy, mayCanvasCanMove); dy = max(dy, mayCanvasCanMove);
} else { } else {
final mayCursorCanMove = r.left - _y; final mayCursorCanMove = r.top - _y;
dy = max(dy, mayCursorCanMove); dy = max(dy, mayCursorCanMove);
} }
} }
@ -310,10 +310,10 @@ class CursorModel with ChangeNotifier {
_x += dx; _x += dx;
_y += dy; _y += dy;
if (tryMoveCanvasX && dx != 0) { if (tryMoveCanvasX && dx != 0) {
FFI.canvasModel.panX(dx); FFI.canvasModel.panX(-dx);
} }
if (tryMoveCanvasY && dy != 0) { if (tryMoveCanvasY && dy != 0) {
FFI.canvasModel.panY(dy); FFI.canvasModel.panY(-dy);
} }
_xPan += dx; _xPan += dx;
@ -321,7 +321,7 @@ class CursorModel with ChangeNotifier {
var px = (_xPan > 0 ? _xPan.floor() : _xPan.ceil()).toDouble(); var px = (_xPan > 0 ? _xPan.floor() : _xPan.ceil()).toDouble();
var py = (_yPan > 0 ? _yPan.floor() : _yPan.ceil()).toDouble(); var py = (_yPan > 0 ? _yPan.floor() : _yPan.ceil()).toDouble();
if (px != 0 || py != 0) { if (px != 0 || py != 0) {
FFI.cursorModel.update(-px, -py); FFI.cursorModel.update(px, py);
_xPan -= px; _xPan -= px;
_yPan -= py; _yPan -= py;
} }
@ -366,15 +366,16 @@ class CursorModel with ChangeNotifier {
void updateDisplayOrigin(double x, double y) { void updateDisplayOrigin(double x, double y) {
_displayOriginX = x; _displayOriginX = x;
_displayOriginY = y; _displayOriginY = y;
_x = x;
_y = y;
FFI.moveMouse(x, y);
notifyListeners(); notifyListeners();
} }
void update(double dx, double dy) { void update(double dx, double dy) {
_x += dx; _x += dx;
_y += dy; _y += dy;
var x = _x.toInt(); FFI.moveMouse(_x, _y);
var y = _y.toInt();
FFI.setByName('send_mouse', json.encode({'x': '$x', 'y': '$y'}));
} }
void clear() { void clear() {
@ -409,10 +410,18 @@ class FFI {
} }
static void sendMouse(String type, String buttons) { static void sendMouse(String type, String buttons) {
if (!FFI.ffiModel.keyboard()) return;
FFI.setByName( FFI.setByName(
'send_mouse', json.encode({'type': type, 'buttons': buttons})); 'send_mouse', json.encode({'type': type, 'buttons': buttons}));
} }
static void moveMouse(double x, double y) {
if (!FFI.ffiModel.keyboard()) return;
var x2 = x.toInt();
var y2 = y.toInt();
FFI.setByName('send_mouse', json.encode({'x': '$x2', 'y': '$y2'}));
}
static List<Peer> peers() { static List<Peer> peers() {
try { try {
List<dynamic> peers = json.decode(getByName('peers')); List<dynamic> peers = json.decode(getByName('peers'));