mouse_gesture_area_for_roi.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:fis_measure/interfaces/date_types/rect_region.dart';
  2. import 'package:fis_measure/view/gesture/cross_position_indicator.dart';
  3. import 'package:fis_measure/view/gesture/mouse_gesture.dart';
  4. import 'package:fis_measure/values/colors.dart';
  5. import 'package:fis_measure/view/cursor.dart';
  6. import 'package:flutter/material.dart';
  7. // 鼠标指示器(无需测量,无需控制器)
  8. class MouseGestureAreaForRoi extends StatefulWidget {
  9. const MouseGestureAreaForRoi({super.key, this.onMouseDown, this.onMouseMove});
  10. final ValueChanged<Offset>? onMouseDown;
  11. final ValueChanged<Offset>? onMouseMove;
  12. @override
  13. State<MouseGestureAreaForRoi> createState() => _MouseGestureAreaForRoiState();
  14. }
  15. class _MouseGestureAreaForRoiState extends State<MouseGestureAreaForRoi> {
  16. Offset? cursorPosition;
  17. CursorDisplayType displayType = CursorDisplayType.none;
  18. RectRegion tissueTMPixelRegion = RectRegion();
  19. @override
  20. Widget build(BuildContext context) {
  21. return GestureDetector(
  22. onTapDown: (details) {
  23. widget.onMouseDown?.call(details.localPosition);
  24. },
  25. onPanUpdate: (details) {
  26. setState(() {
  27. cursorPosition = details.localPosition;
  28. });
  29. widget.onMouseMove?.call(details.localPosition);
  30. },
  31. child: MouseRegion(
  32. cursor: SystemMouseCursors.none,
  33. onHover: (event) {
  34. setState(() {
  35. cursorPosition = event.localPosition;
  36. });
  37. widget.onMouseMove?.call(event.localPosition);
  38. // _handleAreaChange(event.localPosition);
  39. },
  40. onEnter: (e) {
  41. setState(() {
  42. displayType = CursorDisplayType.normal;
  43. });
  44. },
  45. onExit: (e) {
  46. setState(() {
  47. displayType = CursorDisplayType.none;
  48. });
  49. },
  50. child: Stack(
  51. children: [
  52. _buildCursor(),
  53. // if (isShowRightClickTip && displayType != CursorDisplayType.none)
  54. // _buildTip(),
  55. ],
  56. ),
  57. ),
  58. );
  59. }
  60. Widget _buildCursor() {
  61. switch (displayType) {
  62. case CursorDisplayType.none:
  63. return Container();
  64. case CursorDisplayType.normal:
  65. return _buildPositionedCursor(cursorPosition);
  66. case CursorDisplayType.cross:
  67. return CrossIndicator(
  68. areaRegion: Rect.fromLTRB(
  69. tissueTMPixelRegion.left,
  70. tissueTMPixelRegion.top,
  71. tissueTMPixelRegion.right,
  72. tissueTMPixelRegion.bottom),
  73. );
  74. }
  75. }
  76. Widget _buildPositionedCursor(Offset? cursorPosition) {
  77. if (cursorPosition == null) return Container();
  78. /// FIXME 更多参数需要通过刷新来传入
  79. final cursorSize = 12;
  80. final cursorScaleRatio = 2.0;
  81. final offset = cursorScaleRatio * cursorSize / 2;
  82. final dx = cursorPosition.dx - offset;
  83. final dy = cursorPosition.dy - offset;
  84. return Positioned(
  85. left: dx,
  86. top: dy,
  87. child: MeasureCursor(
  88. type: MeasureCursorType.cursor01,
  89. size: cursorSize * cursorScaleRatio,
  90. color: MeasureColors.Primary,
  91. ),
  92. );
  93. }
  94. }