annotation_gesture.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import 'package:fis_measure/interfaces/enums/annotation.dart';
  2. import 'package:fis_measure/interfaces/process/annotations/annotation.dart';
  3. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  4. import 'package:fis_measure/view/gesture/mouse_gesture.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:get/get.dart';
  7. import '../positioned_cursor.dart';
  8. import 'arrow_gesture_panel.dart';
  9. import 'input_position_panel.dart';
  10. import 'label_drag_target_pannel.dart';
  11. /// 注释手势层
  12. class AnnotationGestureLayer extends StatefulWidget {
  13. const AnnotationGestureLayer({Key? key}) : super(key: key);
  14. @override
  15. State<AnnotationGestureLayer> createState() => _AnnotationGestureLayerState();
  16. }
  17. class _AnnotationGestureLayerState extends State<AnnotationGestureLayer> {
  18. late final application = Get.find<IApplication>();
  19. final mouseState = Get.find<IMouseState>();
  20. IAnnotationItem? currentItem;
  21. @override
  22. void initState() {
  23. currentItem = application.activeAnnotationItem;
  24. application.activeAnnotationItemChanged.addListener(_onItemChanged);
  25. super.initState();
  26. }
  27. @override
  28. void dispose() {
  29. application.activeAnnotationItemChanged.removeListener(_onItemChanged);
  30. super.dispose();
  31. }
  32. void _onItemChanged(Object sender, IAnnotationItem? item) {
  33. if (!mounted) return;
  34. if (item?.type != currentItem?.type) {
  35. setState(() {
  36. currentItem = item;
  37. });
  38. } else {
  39. currentItem = item;
  40. }
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return _buildItemPanel();
  45. // TODO: melon - optimize with handlers
  46. // return Stack(
  47. // children: [
  48. // _buildItemPanel(),
  49. // _buildTopGesture(),
  50. // ],
  51. // );
  52. }
  53. Widget _buildTopGesture() {
  54. return GestureDetector(
  55. onPanUpdate: (details) {
  56. mouseState.mousePosition = details.localPosition;
  57. },
  58. child: MouseRegion(
  59. cursor: SystemMouseCursors.none,
  60. onHover: (details) {
  61. mouseState.mousePosition = details.localPosition;
  62. },
  63. child: Stack(
  64. children: const [
  65. PositionedCursor(),
  66. ],
  67. ),
  68. ),
  69. );
  70. }
  71. Widget _buildItemPanel() {
  72. if (currentItem == null) {
  73. return const SizedBox();
  74. }
  75. final type = currentItem!.type;
  76. switch (type) {
  77. case AnnotationType.label:
  78. return const AnnotationLabelDragTargetPanel();
  79. case AnnotationType.input:
  80. return const AnnotationInputPositionPanel();
  81. case AnnotationType.arrow:
  82. return const AnnotationArrowGesturePanel();
  83. }
  84. }
  85. }