feat: implemented remote control on desktop

This commit is contained in:
SoLongAndThanksForAllThePizza 2022-06-27 16:50:02 +08:00
parent 53f373c36f
commit 0ce2c88c50
2 changed files with 58 additions and 37 deletions

View File

@ -425,18 +425,35 @@ class CanvasModel with ChangeNotifier {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720);
final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280);
if (s == 'shrink') { // Closure to perform shrink operation.
final shrinkOp = () {
final s = s1 < s2 ? s1 : s2; final s = s1 < s2 ? s1 : s2;
if (s < 1) { if (s < 1) {
_scale = s; _scale = s;
} }
} else if (s == 'stretch') { };
// Closure to perform stretch operation.
final stretchOp = () {
final s = s1 > s2 ? s1 : s2; final s = s1 > s2 ? s1 : s2;
if (s > 1) { if (s > 1) {
_scale = s; _scale = s;
} }
};
// Closure to perform default operation(set the scale to 1.0).
final defaultOp = () {
_scale = 1.0;
};
if (s == 'shrink') {
shrinkOp();
} else if (s == 'stretch') {
stretchOp();
} else { } else {
_scale = 1; // On desktop, shrink is the default behavior.
if (isDesktop) {
shrinkOp();
} else {
defaultOp();
}
} }
_x = (size.width - getDisplayWidth() * _scale) / 2; _x = (size.width - getDisplayWidth() * _scale) / 2;
_y = (size.height - getDisplayHeight() * _scale) / 2; _y = (size.height - getDisplayHeight() * _scale) / 2;
@ -459,6 +476,8 @@ class CanvasModel with ChangeNotifier {
} }
void moveDesktopMouse(double x, double y) { void moveDesktopMouse(double x, double y) {
// On mobile platforms, move the canvas with the cursor.
if (!isDesktop) {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
final dw = getDisplayWidth() * _scale; final dw = getDisplayWidth() * _scale;
final dh = getDisplayHeight() * _scale; final dh = getDisplayHeight() * _scale;
@ -475,6 +494,7 @@ class CanvasModel with ChangeNotifier {
if (dxOffset != 0 || dyOffset != 0) { if (dxOffset != 0 || dyOffset != 0) {
notifyListeners(); notifyListeners();
} }
}
parent.target?.cursorModel.moveLocal(x, y); parent.target?.cursorModel.moveLocal(x, y);
} }
@ -714,6 +734,7 @@ class CursorModel with ChangeNotifier {
} }
} }
/// Update the cursor position.
void updateCursorPosition(Map<String, dynamic> evt) { void updateCursorPosition(Map<String, dynamic> evt) {
_x = double.parse(evt['x']); _x = double.parse(evt['x']);
_y = double.parse(evt['y']); _y = double.parse(evt['y']);