Merge pull request #3058 from fufesou/fix/cursor_zoom
cursor position and size update
This commit is contained in:
commit
a2c3c8ef91
@ -399,42 +399,51 @@ 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) {
|
mouseRegion({child}) => Obx(() {
|
||||||
// debug win10
|
double getCursorScale() {
|
||||||
final isViewAdaptive = c.viewStyle.style == kRemoteViewStyleAdaptive;
|
var c = Provider.of<CanvasModel>(context);
|
||||||
if (zoomCursor.value && isViewAdaptive) {
|
var cursorScale = 1.0;
|
||||||
cursorScale = s * c.devicePixelRatio;
|
if (Platform.isWindows) {
|
||||||
}
|
// debug win10
|
||||||
} else {
|
final isViewAdaptive =
|
||||||
final isViewOriginal = c.viewStyle.style == kRemoteViewStyleOriginal;
|
c.viewStyle.style == kRemoteViewStyleAdaptive;
|
||||||
if (zoomCursor.value || isViewOriginal) {
|
if (zoomCursor.value && isViewAdaptive) {
|
||||||
cursorScale = s;
|
cursorScale = s * c.devicePixelRatio;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
final isViewOriginal =
|
||||||
|
c.viewStyle.style == kRemoteViewStyleOriginal;
|
||||||
|
if (zoomCursor.value || isViewOriginal) {
|
||||||
|
cursorScale = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cursorScale;
|
||||||
|
}
|
||||||
|
|
||||||
mouseRegion({child}) => Obx(() => MouseRegion(
|
return MouseRegion(
|
||||||
cursor: cursorOverImage.isTrue
|
cursor: cursorOverImage.isTrue
|
||||||
? c.cursorEmbedded
|
? c.cursorEmbedded
|
||||||
? SystemMouseCursors.none
|
? SystemMouseCursors.none
|
||||||
: keyboardEnabled.isTrue
|
: keyboardEnabled.isTrue
|
||||||
? (() {
|
? (() {
|
||||||
if (remoteCursorMoved.isTrue) {
|
if (remoteCursorMoved.isTrue) {
|
||||||
_lastRemoteCursorMoved = true;
|
_lastRemoteCursorMoved = true;
|
||||||
return SystemMouseCursors.none;
|
return SystemMouseCursors.none;
|
||||||
} else {
|
} else {
|
||||||
if (_lastRemoteCursorMoved) {
|
if (_lastRemoteCursorMoved) {
|
||||||
_lastRemoteCursorMoved = false;
|
_lastRemoteCursorMoved = false;
|
||||||
_firstEnterImage.value = true;
|
_firstEnterImage.value = true;
|
||||||
}
|
}
|
||||||
return _buildCustomCursor(context, cursorScale);
|
return _buildCustomCursor(
|
||||||
}
|
context, getCursorScale());
|
||||||
}())
|
}
|
||||||
: _buildDisabledCursor(context, cursorScale)
|
}())
|
||||||
: MouseCursor.defer,
|
: _buildDisabledCursor(context, getCursorScale())
|
||||||
onHover: (evt) {},
|
: MouseCursor.defer,
|
||||||
child: child));
|
onHover: (evt) {},
|
||||||
|
child: child);
|
||||||
|
});
|
||||||
|
|
||||||
if (c.imageOverflow.isTrue && c.scrollStyle == ScrollStyle.scrollbar) {
|
if (c.imageOverflow.isTrue && c.scrollStyle == ScrollStyle.scrollbar) {
|
||||||
final imageWidth = c.getDisplayWidth() * s;
|
final imageWidth = c.getDisplayWidth() * s;
|
||||||
|
@ -790,6 +790,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||||||
_PopupMenuRoute({
|
_PopupMenuRoute({
|
||||||
required this.position,
|
required this.position,
|
||||||
required this.items,
|
required this.items,
|
||||||
|
this.menuWrapper,
|
||||||
this.initialValue,
|
this.initialValue,
|
||||||
this.elevation,
|
this.elevation,
|
||||||
required this.barrierLabel,
|
required this.barrierLabel,
|
||||||
@ -802,6 +803,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||||||
|
|
||||||
final RelativeRect position;
|
final RelativeRect position;
|
||||||
final List<PopupMenuEntry<T>> items;
|
final List<PopupMenuEntry<T>> items;
|
||||||
|
final MenuWrapper? menuWrapper;
|
||||||
final List<Size?> itemSizes;
|
final List<Size?> itemSizes;
|
||||||
final T? initialValue;
|
final T? initialValue;
|
||||||
final double? elevation;
|
final double? elevation;
|
||||||
@ -844,11 +846,14 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Widget menu = _PopupMenu<T>(
|
Widget menu = _PopupMenu<T>(
|
||||||
route: this,
|
route: this,
|
||||||
semanticLabel: semanticLabel,
|
semanticLabel: semanticLabel,
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
);
|
);
|
||||||
|
if (this.menuWrapper != null) {
|
||||||
|
menu = this.menuWrapper!(menu);
|
||||||
|
}
|
||||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
return MediaQuery.removePadding(
|
return MediaQuery.removePadding(
|
||||||
context: context,
|
context: context,
|
||||||
@ -1035,6 +1040,7 @@ Future<T?> showMenu<T>({
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required RelativeRect position,
|
required RelativeRect position,
|
||||||
required List<PopupMenuEntry<T>> items,
|
required List<PopupMenuEntry<T>> items,
|
||||||
|
MenuWrapper? menuWrapper,
|
||||||
T? initialValue,
|
T? initialValue,
|
||||||
double? elevation,
|
double? elevation,
|
||||||
String? semanticLabel,
|
String? semanticLabel,
|
||||||
@ -1062,6 +1068,7 @@ Future<T?> showMenu<T>({
|
|||||||
return navigator.push(_PopupMenuRoute<T>(
|
return navigator.push(_PopupMenuRoute<T>(
|
||||||
position: position,
|
position: position,
|
||||||
items: items,
|
items: items,
|
||||||
|
menuWrapper: menuWrapper,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
elevation: elevation,
|
elevation: elevation,
|
||||||
semanticLabel: semanticLabel,
|
semanticLabel: semanticLabel,
|
||||||
@ -1094,6 +1101,8 @@ typedef PopupMenuCanceled = void Function();
|
|||||||
typedef PopupMenuItemBuilder<T> = List<PopupMenuEntry<T>> Function(
|
typedef PopupMenuItemBuilder<T> = List<PopupMenuEntry<T>> Function(
|
||||||
BuildContext context);
|
BuildContext context);
|
||||||
|
|
||||||
|
typedef MenuWrapper = Widget Function(Widget child);
|
||||||
|
|
||||||
/// Displays a menu when pressed and calls [onSelected] when the menu is dismissed
|
/// Displays a menu when pressed and calls [onSelected] when the menu is dismissed
|
||||||
/// because an item was selected. The value passed to [onSelected] is the value of
|
/// because an item was selected. The value passed to [onSelected] is the value of
|
||||||
/// the selected menu item.
|
/// the selected menu item.
|
||||||
@ -1124,6 +1133,7 @@ class PopupMenuButton<T> extends StatefulWidget {
|
|||||||
const PopupMenuButton({
|
const PopupMenuButton({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.itemBuilder,
|
required this.itemBuilder,
|
||||||
|
this.menuWrapper,
|
||||||
this.initialValue,
|
this.initialValue,
|
||||||
this.onHover,
|
this.onHover,
|
||||||
this.onSelected,
|
this.onSelected,
|
||||||
@ -1151,6 +1161,9 @@ class PopupMenuButton<T> extends StatefulWidget {
|
|||||||
/// Called when the button is pressed to create the items to show in the menu.
|
/// Called when the button is pressed to create the items to show in the menu.
|
||||||
final PopupMenuItemBuilder<T> itemBuilder;
|
final PopupMenuItemBuilder<T> itemBuilder;
|
||||||
|
|
||||||
|
/// Menu wrapper.
|
||||||
|
final MenuWrapper? menuWrapper;
|
||||||
|
|
||||||
/// The value of the menu item, if any, that should be highlighted when the menu opens.
|
/// The value of the menu item, if any, that should be highlighted when the menu opens.
|
||||||
final T? initialValue;
|
final T? initialValue;
|
||||||
|
|
||||||
@ -1333,6 +1346,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
|||||||
context: context,
|
context: context,
|
||||||
elevation: widget.elevation ?? popupMenuTheme.elevation,
|
elevation: widget.elevation ?? popupMenuTheme.elevation,
|
||||||
items: items,
|
items: items,
|
||||||
|
menuWrapper: widget.menuWrapper,
|
||||||
initialValue: widget.initialValue,
|
initialValue: widget.initialValue,
|
||||||
position: position,
|
position: position,
|
||||||
shape: widget.shape ?? popupMenuTheme.shape,
|
shape: widget.shape ?? popupMenuTheme.shape,
|
||||||
|
@ -221,6 +221,16 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildPointerTrackWidget(Widget child) {
|
||||||
|
return Listener(
|
||||||
|
onPointerHover: (PointerHoverEvent e) =>
|
||||||
|
widget.ffi.inputModel.lastMousePos = e.position,
|
||||||
|
child: MouseRegion(
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildMenubar(BuildContext context) {
|
Widget _buildMenubar(BuildContext context) {
|
||||||
final List<Widget> menubarItems = [];
|
final List<Widget> menubarItems = [];
|
||||||
if (!isWebDesktop) {
|
if (!isWebDesktop) {
|
||||||
@ -379,13 +389,10 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
mod_menu.PopupMenuItem<String>(
|
mod_menu.PopupMenuItem<String>(
|
||||||
height: _MenubarTheme.height,
|
height: _MenubarTheme.height,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
child: Listener(
|
child: _buildPointerTrackWidget(
|
||||||
onPointerHover: (PointerHoverEvent e) =>
|
Row(
|
||||||
widget.ffi.inputModel.lastMousePos = e.position,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
child: MouseRegion(
|
children: rowChildren,
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: rowChildren),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -435,6 +442,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
),
|
),
|
||||||
tooltip: translate('Display Settings'),
|
tooltip: translate('Display Settings'),
|
||||||
position: mod_menu.PopupMenuPosition.under,
|
position: mod_menu.PopupMenuPosition.under,
|
||||||
|
menuWrapper: _buildPointerTrackWidget,
|
||||||
itemBuilder: (BuildContext context) =>
|
itemBuilder: (BuildContext context) =>
|
||||||
_getDisplayMenu(snapshot.data!, remoteCount)
|
_getDisplayMenu(snapshot.data!, remoteCount)
|
||||||
.map((entry) => entry.build(
|
.map((entry) => entry.build(
|
||||||
|
@ -310,7 +310,6 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _signOrZero(num x) {
|
int _signOrZero(num x) {
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -362,7 +361,6 @@ class InputModel {
|
|||||||
trackpadScrollDistance = Offset.zero;
|
trackpadScrollDistance = Offset.zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void onPointDownImage(PointerDownEvent e) {
|
void onPointDownImage(PointerDownEvent e) {
|
||||||
debugPrint("onPointDownImage");
|
debugPrint("onPointDownImage");
|
||||||
if (e.kind != ui.PointerDeviceKind.mouse) {
|
if (e.kind != ui.PointerDeviceKind.mouse) {
|
||||||
|
@ -244,7 +244,6 @@ class FfiModel with ChangeNotifier {
|
|||||||
parent.target?.canvasModel.updateViewStyle();
|
parent.target?.canvasModel.updateViewStyle();
|
||||||
}
|
}
|
||||||
parent.target?.recordingModel.onSwitchDisplay();
|
parent.target?.recordingModel.onSwitchDisplay();
|
||||||
parent.target?.inputModel.refreshMousePos();
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,6 +620,7 @@ class CanvasModel with ChangeNotifier {
|
|||||||
_y = (size.height - displayHeight * _scale) / 2;
|
_y = (size.height - displayHeight * _scale) / 2;
|
||||||
_imageOverflow.value = _x < 0 || y < 0;
|
_imageOverflow.value = _x < 0 || y < 0;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
parent.target?.inputModel.refreshMousePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateScrollStyle() async {
|
updateScrollStyle() async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user