flutter_desktop: remote window cursor debug
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
af2e555e41
commit
fd8c83497d
@ -41,6 +41,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
String _value = '';
|
||||
double _scale = 1;
|
||||
double _mouseScrollIntegral = 0; // mouse scroll speed controller
|
||||
var _cursorOverImage = false.obs;
|
||||
|
||||
var _more = true;
|
||||
var _fn = false;
|
||||
@ -291,62 +292,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
}
|
||||
|
||||
Widget getRawPointerAndKeyBody(Widget child) {
|
||||
return Listener(
|
||||
onPointerHover: (e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (!_isPhysicalMouse) {
|
||||
setState(() {
|
||||
_isPhysicalMouse = true;
|
||||
});
|
||||
}
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousemove'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
},
|
||||
onPointerDown: (e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) {
|
||||
if (_isPhysicalMouse) {
|
||||
setState(() {
|
||||
_isPhysicalMouse = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousedown'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
},
|
||||
onPointerUp: (e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mouseup'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
},
|
||||
onPointerMove: (e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousemove'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
},
|
||||
onPointerSignal: (e) {
|
||||
if (e is PointerScrollEvent) {
|
||||
var dx = e.scrollDelta.dx;
|
||||
var dy = e.scrollDelta.dy;
|
||||
if (dx > 0)
|
||||
dx = -1;
|
||||
else if (dx < 0) dx = 1;
|
||||
if (dy > 0)
|
||||
dy = -1;
|
||||
else if (dy < 0) dy = 1;
|
||||
bind.sessionSendMouse(
|
||||
id: widget.id,
|
||||
msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
|
||||
}
|
||||
},
|
||||
child: Consumer<FfiModel>(
|
||||
return Consumer<FfiModel>(
|
||||
builder: (context, FfiModel, _child) => MouseRegion(
|
||||
cursor: FfiModel.permissions['keyboard'] != false
|
||||
? SystemMouseCursors.none
|
||||
@ -394,11 +340,13 @@ class _RemotePageState extends State<RemotePage>
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
},
|
||||
child: child)))));
|
||||
child: child))));
|
||||
}
|
||||
|
||||
Widget? getBottomAppBar() {
|
||||
return BottomAppBar(
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.basic,
|
||||
child: BottomAppBar(
|
||||
elevation: 10,
|
||||
color: MyTheme.accent,
|
||||
child: Row(
|
||||
@ -498,6 +446,81 @@ class _RemotePageState extends State<RemotePage>
|
||||
/// DoubleFiner -> right click
|
||||
/// HoldDrag -> left drag
|
||||
|
||||
void _onPointHoverImage(PointerHoverEvent e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (!_isPhysicalMouse) {
|
||||
setState(() {
|
||||
_isPhysicalMouse = true;
|
||||
});
|
||||
}
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousemove'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPointDownImage(PointerDownEvent e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) {
|
||||
if (_isPhysicalMouse) {
|
||||
setState(() {
|
||||
_isPhysicalMouse = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousedown'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPointUpImage(PointerUpEvent e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mouseup'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPointMoveImage(PointerMoveEvent e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (_isPhysicalMouse) {
|
||||
_ffi.handleMouse(getEvent(e, 'mousemove'),
|
||||
tabBarHeight: super.widget.tabBarHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPointerSignalImage(PointerSignalEvent e) {
|
||||
if (e is PointerScrollEvent) {
|
||||
var dx = e.scrollDelta.dx;
|
||||
var dy = e.scrollDelta.dy;
|
||||
if (dx > 0)
|
||||
dx = -1;
|
||||
else if (dx < 0) dx = 1;
|
||||
if (dy > 0)
|
||||
dy = -1;
|
||||
else if (dy < 0) dy = 1;
|
||||
bind.sessionSendMouse(
|
||||
id: widget.id, msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildImageListener(Widget child) {
|
||||
return Listener(
|
||||
onPointerHover: _onPointHoverImage,
|
||||
onPointerDown: _onPointDownImage,
|
||||
onPointerUp: _onPointUpImage,
|
||||
onPointerMove: _onPointMoveImage,
|
||||
onPointerSignal: _onPointerSignalImage,
|
||||
child: MouseRegion(
|
||||
onEnter: (evt) {
|
||||
_cursorOverImage.value = true;
|
||||
},
|
||||
onExit: (evt) {
|
||||
_cursorOverImage.value = false;
|
||||
},
|
||||
child: child));
|
||||
}
|
||||
|
||||
Widget getBodyForDesktop(BuildContext context, bool keyboard) {
|
||||
var paints = <Widget>[
|
||||
MouseRegion(onEnter: (evt) {
|
||||
@ -824,10 +847,17 @@ class _RemotePageState extends State<RemotePage>
|
||||
|
||||
class ImagePaint extends StatelessWidget {
|
||||
final String id;
|
||||
final Rx<bool> cursorOverImage;
|
||||
final Widget Function(Widget)? listenerBuilder;
|
||||
final ScrollController _horizontal = ScrollController();
|
||||
final ScrollController _vertical = ScrollController();
|
||||
|
||||
ImagePaint({Key? key, required this.id}) : super(key: key);
|
||||
ImagePaint(
|
||||
{Key? key,
|
||||
required this.id,
|
||||
required this.cursorOverImage,
|
||||
this.listenerBuilder = null})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -835,6 +865,12 @@ class ImagePaint extends StatelessWidget {
|
||||
var c = Provider.of<CanvasModel>(context);
|
||||
final s = c.scale;
|
||||
if (c.scrollStyle == ScrollStyle.scrollbar) {
|
||||
final imageWidget = SizedBox(
|
||||
width: c.getDisplayWidth() * s,
|
||||
height: c.getDisplayHeight() * s,
|
||||
child: CustomPaint(
|
||||
painter: new ImagePainter(image: m.image, x: 0, y: 0, scale: s),
|
||||
));
|
||||
return Center(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (_notification) {
|
||||
@ -849,7 +885,26 @@ class ImagePaint extends StatelessWidget {
|
||||
c.setScrollPercent(percentX, percentY);
|
||||
return false;
|
||||
},
|
||||
child: Scrollbar(
|
||||
child: Obx(() => MouseRegion(
|
||||
cursor: cursorOverImage.value
|
||||
? SystemMouseCursors.none
|
||||
: SystemMouseCursors.basic,
|
||||
child: _buildCrossScrollbar(_buildListener(imageWidget)))),
|
||||
));
|
||||
} else {
|
||||
final imageWidget = SizedBox(
|
||||
width: c.size.width,
|
||||
height: c.size.height,
|
||||
child: CustomPaint(
|
||||
painter: new ImagePainter(
|
||||
image: m.image, x: c.x / s, y: c.y / s, scale: s),
|
||||
));
|
||||
return _buildListener(imageWidget);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildCrossScrollbar(Widget child) {
|
||||
return Scrollbar(
|
||||
controller: _vertical,
|
||||
thumbVisibility: true,
|
||||
trackVisibility: true,
|
||||
@ -863,47 +918,18 @@ class ImagePaint extends StatelessWidget {
|
||||
child: SingleChildScrollView(
|
||||
controller: _horizontal,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: buildListener(SizedBox(
|
||||
width: c.getDisplayWidth() * s,
|
||||
height: c.getDisplayHeight() * s,
|
||||
child: CustomPaint(
|
||||
painter: new ImagePainter(
|
||||
image: m.image, x: 0, y: 0, scale: s),
|
||||
)))),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
)),
|
||||
));
|
||||
} else {
|
||||
return buildListener(CustomPaint(
|
||||
painter:
|
||||
new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildListener(Widget child) {
|
||||
return Listener(
|
||||
onPointerHover: (e) {
|
||||
debugPrint(
|
||||
'REMOVE ME ======================== 4444 onPointerHover ${e.position}');
|
||||
},
|
||||
onPointerDown: (e) {
|
||||
debugPrint(
|
||||
'REMOVE ME ======================== 4444 onPointerDown ${e.position}');
|
||||
},
|
||||
onPointerUp: (e) {
|
||||
debugPrint(
|
||||
'REMOVE ME ======================== 4444 onPointerUp ${e.position}');
|
||||
},
|
||||
onPointerMove: (e) {
|
||||
debugPrint(
|
||||
'REMOVE ME ======================== 4444 onPointerMove ${e.position}');
|
||||
},
|
||||
onPointerSignal: (e) {
|
||||
debugPrint(
|
||||
'REMOVE ME ======================== 3333 onPointerSignal ${e.position}');
|
||||
},
|
||||
child: child);
|
||||
Widget _buildListener(Widget child) {
|
||||
if (listenerBuilder != null) {
|
||||
return listenerBuilder!(child);
|
||||
} else {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user