initialize send mouse and max/min scale

This commit is contained in:
open-trade 2020-11-24 12:11:55 +08:00
parent 982df980bd
commit b776f1339a
2 changed files with 43 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'dart:ffi'; import 'dart:ffi';
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
@ -89,6 +90,10 @@ class FfiModel with ChangeNotifier {
if (rgba != null) { if (rgba != null) {
if (_waitForImage) { if (_waitForImage) {
_waitForImage = false; _waitForImage = false;
final size = MediaQueryData.fromWindow(ui.window).size;
final xscale = size.width / _display.width.toDouble();
final yscale = size.height / _display.height.toDouble();
FFI.canvasModel.scale = max(xscale, yscale);
dismissLoading(); dismissLoading();
} }
_decoding = true; _decoding = true;
@ -153,6 +158,22 @@ class ImageModel with ChangeNotifier {
_image = image; _image = image;
if (image != null) notifyListeners(); if (image != null) notifyListeners();
} }
double get maxScale {
if (_image == null) return 1.0;
final size = MediaQueryData.fromWindow(ui.window).size;
final xscale = size.width / _image.width;
final yscale = size.height / _image.height;
return max(1.0, max(xscale, yscale));
}
double get minScale {
if (_image == null) return 1.0;
final size = MediaQueryData.fromWindow(ui.window).size;
final xscale = size.width / _image.width;
final yscale = size.height / _image.height;
return min(xscale, yscale);
}
} }
class CanvasModel with ChangeNotifier { class CanvasModel with ChangeNotifier {
@ -170,6 +191,11 @@ class CanvasModel with ChangeNotifier {
double get y => _y; double get y => _y;
double get scale => _scale; double get scale => _scale;
set scale(v) {
_scale = v;
notifyListeners();
}
void startPan() { void startPan() {
_xPan = 0; _xPan = 0;
_yPan = 0; _yPan = 0;
@ -200,7 +226,10 @@ class CanvasModel with ChangeNotifier {
void updateScale(double v) { void updateScale(double v) {
_scale *= v; _scale *= v;
if (_scale > 1) _scale = 1; final maxs = FFI.imageModel.maxScale;
final mins = FFI.imageModel.minScale;
if (_scale > maxs) _scale = maxs;
if (_scale < mins) _scale = mins;
notifyListeners(); notifyListeners();
} }
@ -302,6 +331,16 @@ class FFI {
return getByName('remote_id'); return getByName('remote_id');
} }
static void tap() {
FFI.sendMouse('down', 'left');
FFI.sendMouse('up', 'left');
}
static void sendMouse(String type, String buttons) {
FFI.setByName(
'send_mouse', json.encode({'type': type, 'buttons': buttons}));
}
static List<Peer> peers() { static List<Peer> peers() {
try { try {
List<dynamic> peers = json.decode(getByName('peers')); List<dynamic> peers = json.decode(getByName('peers'));

View File

@ -80,7 +80,8 @@ class _RemotePageState extends State<RemotePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('${MediaQueryData.fromWindow(ui.window).size}'); final size = MediaQueryData.fromWindow(ui.window).size;
print('$size');
print('${MediaQuery.of(context).size}'); print('${MediaQuery.of(context).size}');
EasyLoading.instance.loadingStyle = EasyLoadingStyle.light; EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
return WillPopScope( return WillPopScope(
@ -170,7 +171,7 @@ class _RemotePageState extends State<RemotePage> {
}(); }();
}, },
onTap: () { onTap: () {
print('tap'); FFI.tap();
}, },
onScaleStart: (details) { onScaleStart: (details) {
_scale = 1; _scale = 1;