zoom cursor with dpi
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
d511d1e27a
commit
f9e3a3f074
@ -399,6 +399,20 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
final m = Provider.of<ImageModel>(context);
|
final m = Provider.of<ImageModel>(context);
|
||||||
var c = Provider.of<CanvasModel>(context);
|
var c = Provider.of<CanvasModel>(context);
|
||||||
final s = c.scale;
|
final s = c.scale;
|
||||||
|
var cursorScale = 1.0;
|
||||||
|
|
||||||
|
if (Platform.isWindows) {
|
||||||
|
// debug win10
|
||||||
|
final isViewAdaptive = c.viewStyle.style == kRemoteViewStyleAdaptive;
|
||||||
|
if (zoomCursor.value && isViewAdaptive) {
|
||||||
|
cursorScale = s * c.devicePixelRatio;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final isViewOriginal = c.viewStyle.style == kRemoteViewStyleOriginal;
|
||||||
|
if (zoomCursor.value || isViewOriginal) {
|
||||||
|
cursorScale = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mouseRegion({child}) => Obx(() => MouseRegion(
|
mouseRegion({child}) => Obx(() => MouseRegion(
|
||||||
cursor: cursorOverImage.isTrue
|
cursor: cursorOverImage.isTrue
|
||||||
@ -414,10 +428,10 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
_lastRemoteCursorMoved = false;
|
_lastRemoteCursorMoved = false;
|
||||||
_firstEnterImage.value = true;
|
_firstEnterImage.value = true;
|
||||||
}
|
}
|
||||||
return _buildCustomCursor(context, s);
|
return _buildCustomCursor(context, cursorScale);
|
||||||
}
|
}
|
||||||
}())
|
}())
|
||||||
: _buildDisabledCursor(context, s)
|
: _buildDisabledCursor(context, cursorScale)
|
||||||
: MouseCursor.defer,
|
: MouseCursor.defer,
|
||||||
onHover: (evt) {},
|
onHover: (evt) {},
|
||||||
child: child));
|
child: child));
|
||||||
@ -466,19 +480,7 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
if (cache == null) {
|
if (cache == null) {
|
||||||
return MouseCursor.defer;
|
return MouseCursor.defer;
|
||||||
} else {
|
} else {
|
||||||
bool shouldScale = false;
|
final key = cache.updateGetKey(scale);
|
||||||
if (Platform.isWindows) {
|
|
||||||
final isViewAdaptive =
|
|
||||||
Provider.of<CanvasModel>(context, listen: false).viewStyle.style ==
|
|
||||||
kRemoteViewStyleAdaptive;
|
|
||||||
shouldScale = zoomCursor.value && isViewAdaptive;
|
|
||||||
} else {
|
|
||||||
final isViewOriginal =
|
|
||||||
Provider.of<CanvasModel>(context, listen: false).viewStyle.style ==
|
|
||||||
kRemoteViewStyleOriginal;
|
|
||||||
shouldScale = zoomCursor.value || isViewOriginal;
|
|
||||||
}
|
|
||||||
final key = cache.updateGetKey(scale, shouldScale);
|
|
||||||
if (!cursor.cachedKeys.contains(key)) {
|
if (!cursor.cachedKeys.contains(key)) {
|
||||||
debugPrint("Register custom cursor with key $key");
|
debugPrint("Register custom cursor with key $key");
|
||||||
// [Safety]
|
// [Safety]
|
||||||
|
@ -540,6 +540,7 @@ class CanvasModel with ChangeNotifier {
|
|||||||
double _y = 0;
|
double _y = 0;
|
||||||
// image scale
|
// image scale
|
||||||
double _scale = 1.0;
|
double _scale = 1.0;
|
||||||
|
double _devicePixelRatio = 1.0;
|
||||||
Size _size = Size.zero;
|
Size _size = Size.zero;
|
||||||
// the tabbar over the image
|
// the tabbar over the image
|
||||||
// double tabBarHeight = 0.0;
|
// double tabBarHeight = 0.0;
|
||||||
@ -563,6 +564,7 @@ class CanvasModel with ChangeNotifier {
|
|||||||
double get x => _x;
|
double get x => _x;
|
||||||
double get y => _y;
|
double get y => _y;
|
||||||
double get scale => _scale;
|
double get scale => _scale;
|
||||||
|
double get devicePixelRatio => _devicePixelRatio;
|
||||||
Size get size => _size;
|
Size get size => _size;
|
||||||
ScrollStyle get scrollStyle => _scrollStyle;
|
ScrollStyle get scrollStyle => _scrollStyle;
|
||||||
ViewStyle get viewStyle => _lastViewStyle;
|
ViewStyle get viewStyle => _lastViewStyle;
|
||||||
@ -611,8 +613,9 @@ class CanvasModel with ChangeNotifier {
|
|||||||
_lastViewStyle = viewStyle;
|
_lastViewStyle = viewStyle;
|
||||||
_scale = viewStyle.scale;
|
_scale = viewStyle.scale;
|
||||||
|
|
||||||
|
_devicePixelRatio = ui.window.devicePixelRatio;
|
||||||
if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
|
if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
|
||||||
_scale = 1.0 / ui.window.devicePixelRatio;
|
_scale = 1.0 / _devicePixelRatio;
|
||||||
}
|
}
|
||||||
_x = (size.width - displayWidth * _scale) / 2;
|
_x = (size.width - displayWidth * _scale) / 2;
|
||||||
_y = (size.height - displayHeight * _scale) / 2;
|
_y = (size.height - displayHeight * _scale) / 2;
|
||||||
@ -772,11 +775,9 @@ class CursorData {
|
|||||||
|
|
||||||
int _doubleToInt(double v) => (v * 10e6).round().toInt();
|
int _doubleToInt(double v) => (v * 10e6).round().toInt();
|
||||||
|
|
||||||
double _checkUpdateScale(double scale, bool shouldScale) {
|
double _checkUpdateScale(double scale) {
|
||||||
double oldScale = this.scale;
|
double oldScale = this.scale;
|
||||||
if (!shouldScale) {
|
if (scale != 1.0) {
|
||||||
scale = 1.0;
|
|
||||||
} else {
|
|
||||||
// Update data if scale changed.
|
// Update data if scale changed.
|
||||||
final tgtWidth = (width * scale).toInt();
|
final tgtWidth = (width * scale).toInt();
|
||||||
final tgtHeight = (width * scale).toInt();
|
final tgtHeight = (width * scale).toInt();
|
||||||
@ -817,8 +818,8 @@ class CursorData {
|
|||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
String updateGetKey(double scale, bool shouldScale) {
|
String updateGetKey(double scale) {
|
||||||
scale = _checkUpdateScale(scale, shouldScale);
|
scale = _checkUpdateScale(scale);
|
||||||
return '${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
return '${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user