adjust canvas offset when scale
This commit is contained in:
parent
2606a44f77
commit
b04f90ef67
@ -1,4 +1,5 @@
|
|||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
|
import 'package:flutter/gestures.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:math';
|
||||||
@ -210,11 +211,20 @@ class CanvasModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateScale(double v) {
|
void updateScale(double v) {
|
||||||
|
final offset = FFI.cursorModel.offset;
|
||||||
|
var r = FFI.cursorModel.getVisibleRect();
|
||||||
|
final px0 = (offset.dx - r.left) * _scale;
|
||||||
|
final py0 = (offset.dy - r.top) * _scale;
|
||||||
_scale *= v;
|
_scale *= v;
|
||||||
final maxs = FFI.imageModel.maxScale;
|
final maxs = FFI.imageModel.maxScale;
|
||||||
final mins = FFI.imageModel.minScale;
|
final mins = FFI.imageModel.minScale;
|
||||||
if (_scale > maxs) _scale = maxs;
|
if (_scale > maxs) _scale = maxs;
|
||||||
if (_scale < mins) _scale = mins;
|
if (_scale < mins) _scale = mins;
|
||||||
|
r = FFI.cursorModel.getVisibleRect();
|
||||||
|
final px1 = (offset.dx - r.left) * _scale;
|
||||||
|
final py1 = (offset.dy - r.top) * _scale;
|
||||||
|
_x -= px1 - px0;
|
||||||
|
_y -= py1 - py0;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,10 +248,11 @@ class CursorModel with ChangeNotifier {
|
|||||||
ui.Image get image => _image;
|
ui.Image get image => _image;
|
||||||
double get x => _x - _displayOriginX;
|
double get x => _x - _displayOriginX;
|
||||||
double get y => _y - _displayOriginY;
|
double get y => _y - _displayOriginY;
|
||||||
|
Offset get offset => Offset(_x, _y);
|
||||||
double get hotx => _hotx;
|
double get hotx => _hotx;
|
||||||
double get hoty => _hoty;
|
double get hoty => _hoty;
|
||||||
|
|
||||||
// physical display coordinate
|
// remote physical display coordinate
|
||||||
Rect getVisibleRect() {
|
Rect getVisibleRect() {
|
||||||
final size = MediaQueryData.fromWindow(ui.window).size;
|
final size = MediaQueryData.fromWindow(ui.window).size;
|
||||||
final xoffset = FFI.canvasModel.x;
|
final xoffset = FFI.canvasModel.x;
|
||||||
@ -255,8 +266,10 @@ class CursorModel with ChangeNotifier {
|
|||||||
double adjustForKeyboard() {
|
double adjustForKeyboard() {
|
||||||
var keyboardHeight = MediaQueryData.fromWindow(ui.window).viewInsets.bottom;
|
var keyboardHeight = MediaQueryData.fromWindow(ui.window).viewInsets.bottom;
|
||||||
if (keyboardHeight < 100) return 0;
|
if (keyboardHeight < 100) return 0;
|
||||||
var h = _y - getVisibleRect().top;
|
final s = FFI.canvasModel.scale;
|
||||||
return h > 200 ? h - 200 : 0;
|
final thresh = 120;
|
||||||
|
var h = (_y - getVisibleRect().top) * s; // local physical display height
|
||||||
|
return h > thresh ? h - thresh : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePan(double dx, double dy) {
|
void updatePan(double dx, double dy) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user