Browse Source

fix some annotion bugs

melon.yin 2 years ago
parent
commit
2e4e3b828f

+ 2 - 14
lib/measure_page_test.dart

@@ -188,20 +188,7 @@ class _MeasureRightBoardState extends State<MeasureRightBoard> {
   Widget build(BuildContext context) {
     return Container(
       padding: const EdgeInsets.all(8).copyWith(left: 0),
-      child: Column(
-        children: [
-          const Expanded(
-            child: MeasureMainView(),
-          ),
-          const Divider(),
-          SizedBox(
-            height: 80,
-            child: VidPlayerControlBoard(
-              playerController as VidPlayerController,
-            ),
-          ),
-        ],
-      ),
+      child: const MeasureMainView(),
     );
   }
 }
@@ -334,6 +321,7 @@ class _MeasureLeftAnnotationState extends State<_MeasureLeftAnnotation> {
             final name = C_SUPPORTED_TEXTS[index];
             const style = TextStyle(color: Colors.white, fontSize: 16);
             const dragStyle = TextStyle(color: Colors.amber, fontSize: 18);
+            // TODO: melon - set drag cursor after version updated up then 3.0
             return Draggable<String>(
               data: name,
               dragAnchorStrategy: (data, context, offset) {

+ 3 - 5
lib/process/annotations/arrow_annotation.dart

@@ -71,11 +71,9 @@ class ArrowAnnotationItemFeature extends AnnotationItemFeature {
 
   @override
   void paint(Canvas canvas, Size size) {
-    double arrowLen = C_ARROW_LENGTH;
-    final frame = Get.find<IApplication>().frameData;
-    if (frame != null) {
-      arrowLen = arrowLen * size.width / frame.width;
-    }
+    double arrowLen =
+        C_ARROW_LENGTH * Get.find<IApplication>().displayScaleRatio;
+
     final startOffset = startPoint.scale2Size(size).toOffset();
     final Offset endOffset;
     if (points.length < 2 || startPoint == endPoint) {

+ 20 - 11
lib/process/annotations/input_annotation.dart

@@ -25,17 +25,7 @@ class InputAnnotation extends AnnotationItem<InputAnnotationItemFeature> {
     if (state == AnnotationStates.running) {
       if (args.pointType != PointInfoType.mouseDown) return false;
 
-      if (text != null && text!.isNotEmpty) {
-        if (feature != null) {
-          feature!.text = text;
-          doFeatureFinish(true);
-        } else {
-          doFeatureFinish(false);
-        }
-      } else {
-        doFeatureFinish(false);
-      }
-      text = null;
+      _finishOnce();
       feature = InputAnnotationItemFeature(this, args);
       state = AnnotationStates.running;
     }
@@ -47,6 +37,25 @@ class InputAnnotation extends AnnotationItem<InputAnnotationItemFeature> {
     // TODO: implement onExecuteTouch
     throw UnimplementedError();
   }
+
+  void _finishOnce() {
+    if (text != null && text!.isNotEmpty) {
+      if (feature != null) {
+        feature!.text = text;
+        doFeatureFinish(true);
+      } else {
+        doFeatureFinish(false);
+      }
+    } else {
+      doFeatureFinish(false);
+    }
+    text = null;
+  }
+
+  @override
+  void finishLast() {
+    _finishOnce();
+  }
 }
 
 class InputAnnotationItemFeature extends AnnotationItemFeature {

+ 1 - 5
lib/process/annotations/label_annotation.dart

@@ -15,7 +15,7 @@ import 'annotation.dart';
 
 /// 文本标签注释
 class LabelAnnotation extends AnnotationItem<LabelAnnotationItemFeature> {
-  LabelAnnotation() : super(AnnotationType.input);
+  LabelAnnotation() : super(AnnotationType.label);
 
   @override
   bool onExecuteMouse(PointInfo args) {
@@ -60,10 +60,6 @@ class LabelAnnotationItemFeature extends AnnotationItemFeature {
   void paint(Canvas canvas, Size size) {
     if (text == null) return;
     double fontSize = 14 * Get.find<IApplication>().displayScaleRatio;
-    // final frame = Get.find<IApplication>().frameData;
-    // if (frame != null) {
-    //   fontSize *= size.width / frame.width;
-    // }
     final style = TextStyle(
       fontSize: fontSize,
       color: isActive ? MeasureColors.ActiveCaliper : MeasureColors.Primary,

+ 1 - 1
lib/process/workspace/application.dart

@@ -122,7 +122,7 @@ class Application implements IApplication {
   @override
   double get displayScaleRatio {
     if (frameData != null) {
-      displaySize.width / frameData!.width;
+      return displaySize.width / frameData!.width;
     }
     return 1.0;
   }

+ 30 - 3
lib/view/gesture/annotation/annotation_gesture.dart

@@ -1,4 +1,5 @@
 import 'package:fis_measure/interfaces/enums/annotation.dart';
+import 'package:fis_measure/interfaces/process/annotations/annotation.dart';
 import 'package:fis_measure/interfaces/process/workspace/application.dart';
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
@@ -21,6 +22,33 @@ class _AnnotationGestureLayerState extends State<AnnotationGestureLayer> {
 
   final mouseState = Get.put<IMouseState>(MouseState());
 
+  IAnnotationItem? currentItem;
+
+  @override
+  void initState() {
+    currentItem = application.activeAnnotationItem;
+    application.activeAnnotationItemChanged.addListener(_onItemChanged);
+    super.initState();
+  }
+
+  @override
+  void dispose() {
+    application.activeAnnotationItemChanged.removeListener(_onItemChanged);
+    super.dispose();
+  }
+
+  void _onItemChanged(Object sender, IAnnotationItem? item) {
+    if (!mounted) return;
+
+    if (item?.type != currentItem?.type) {
+      setState(() {
+        currentItem = item;
+      });
+    } else {
+      currentItem = item;
+    }
+  }
+
   @override
   Widget build(BuildContext context) {
     return _buildItemPanel();
@@ -53,11 +81,10 @@ class _AnnotationGestureLayerState extends State<AnnotationGestureLayer> {
   }
 
   Widget _buildItemPanel() {
-    final item = application.activeAnnotationItem;
-    if (item == null) {
+    if (currentItem == null) {
       return const SizedBox();
     }
-    final type = item.type;
+    final type = currentItem!.type;
     switch (type) {
       case AnnotationType.label:
         return const AnnotationLabelDragTargetPanel();

+ 1 - 1
lib/view/gesture/annotation/arrow_gesture_panel.dart

@@ -16,7 +16,7 @@ class AnnotationArrowGesturePanel extends StatefulWidget {
 class _PanelState extends State<AnnotationArrowGesturePanel> {
   late final application = Get.find<IApplication>();
 
-  final mouseState = Get.put<IMouseState>(MouseState());
+  final mouseState = Get.find<IMouseState>();
 
   @override
   Widget build(BuildContext context) {

+ 1 - 1
lib/view/gesture/annotation/input_position_panel.dart

@@ -18,7 +18,7 @@ class AnnotationInputPositionPanel extends StatefulWidget {
 
 class _PanelState extends State<AnnotationInputPositionPanel> {
   late final application = Get.find<IApplication>();
-  final mouseState = Get.put<IMouseState>(MouseState()..cursorSize = 10);
+  final mouseState = Get.find<IMouseState>();
 
   Offset? position;
 

+ 21 - 5
lib/view/gesture/annotation/label_drag_target_pannel.dart

@@ -1,3 +1,4 @@
+import 'package:fis_measure/interfaces/enums/annotation.dart';
 import 'package:fis_measure/interfaces/process/workspace/application.dart';
 import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
 import 'package:flutter/material.dart';
@@ -15,6 +16,7 @@ class AnnotationLabelDragTargetPanel extends StatefulWidget {
 
 class _PanelState extends State<AnnotationLabelDragTargetPanel> {
   late final application = Get.find<IApplication>();
+  final mouseState = Get.find<IMouseState>();
 
   @override
   void initState() {
@@ -28,11 +30,24 @@ class _PanelState extends State<AnnotationLabelDragTargetPanel> {
       // color: Colors.green,
       child: DragTarget<String>(
         builder: (context, candidateData, rejectedData) {
-          return Container(
-            child: Stack(
-              children: const [
-                PositionedCursor(),
-              ],
+          return GestureDetector(
+            onPanDown: (details) {
+              application.createPointInfo(
+                details.localPosition,
+                PointInfoType.mouseDown,
+              );
+              application.switchAnnotation(AnnotationType.input);
+            },
+            child: MouseRegion(
+              cursor: SystemMouseCursors.none,
+              onHover: (event) {
+                mouseState.mousePosition = event.localPosition;
+              },
+              child: Stack(
+                children: const [
+                  PositionedCursor(),
+                ],
+              ),
             ),
           );
         },
@@ -52,6 +67,7 @@ class _PanelState extends State<AnnotationLabelDragTargetPanel> {
     PointInfoType type,
   ) {
     final localOffset = _findLocalPosition(context, offset);
+    mouseState.mousePosition = localOffset;
     application.createPointInfo(localOffset, type);
   }