瀏覽代碼

calibrate positions

melon.yin 2 年之前
父節點
當前提交
8f389006bc

+ 4 - 0
lib/interfaces/process/workspace/application.dart

@@ -45,6 +45,10 @@ abstract class IApplication {
   /// 活动测量项
   IMeasureItem? get activeItem;
 
+  /// 显示尺寸
+  Size get displaySize;
+  set displaySize(Size value);
+
   /// 当前模式变化事件
   late FEventHandler<IMode> currentModeChanged;
 

+ 7 - 0
lib/interfaces/process/workspace/point_info.dart

@@ -35,4 +35,11 @@ class PointInfo extends DPoint {
   factory PointInfo.fromOffset(Offset offset, PointInfoType pointType) {
     return PointInfo(offset.dx, offset.dy, pointType);
   }
+
+  /// 转换为Area内逻辑点
+  DPoint toAreaLogicPoint() {
+    if (hostVisualArea == null) return this;
+    // TODO: 转换为Area内逻辑点
+    return DPoint(x, y);
+  }
 }

+ 7 - 0
lib/process/items/item_feature.dart

@@ -44,4 +44,11 @@ abstract class MeasureItemFeature implements IMeasureItemFeature {
       _isActive = value;
     }
   }
+
+  @protected
+  DPoint convert2ViewPoint(Size size, DPoint logicPoint) {
+    final x = size.width * logicPoint.x;
+    final y = size.height * logicPoint.y;
+    return DPoint(x, y);
+  }
 }

+ 4 - 3
lib/process/primitives/straightline.dart

@@ -55,7 +55,8 @@ class StraightLine extends MeasureItem<StraightLineFeature> {
   void handleMouseDownWhileWaiting(PointInfo args) {
     // TODO: 判断是否当前area
     // 转换为Area逻辑位置
-    feature = StraightLineFeature(this, args, args);
+    final point = args.toAreaLogicPoint();
+    feature = StraightLineFeature(this, point, point);
     if (args.hostVisualArea != null) {
       feature!.hostVisualArea = args.hostVisualArea;
     }
@@ -89,10 +90,10 @@ class StraightLineFeature extends MeasureItemFeature {
 
     const double vertexSize = 10;
 
-    final startOffset = startPoint.toOffset();
+    final startOffset = convert2ViewPoint(size, startPoint).toOffset();
     canvas.drawVertex(startOffset, vertexSize);
 
-    final endOffset = endPoint.toOffset();
+    final endOffset = convert2ViewPoint(size, endPoint).toOffset();
     canvas.drawDashLine(startOffset, endOffset, 1, 10, paintPan);
     canvas.drawVertex(endOffset, vertexSize, active: isActive);
   }

+ 12 - 3
lib/process/workspace/application.dart

@@ -22,6 +22,7 @@ class Application implements IApplication {
   List<IVisual>? _visuals;
   IMeasureItem? _activeItem;
   bool _canMeasure = false;
+  Size _displaySize = Size.zero;
 
   Application(VidUsProbe probe) {
     _probe = probe;
@@ -61,6 +62,15 @@ class Application implements IApplication {
   @override
   List<IVisual> get visuals => _visuals!;
 
+  @override
+  Size get displaySize => _displaySize;
+  @override
+  set displaySize(Size value) {
+    if (value != _displaySize) {
+      _displaySize = value;
+    }
+  }
+
   @override
   List<IMode> get avaliableModes {
     final modes = <IMode>[];
@@ -101,9 +111,8 @@ class Application implements IApplication {
     if (frameData == null) {
       throw NullThrownError();
     }
-    const scaleRatio = 1.0;
-    final width = frameData!.width * scaleRatio;
-    final height = frameData!.height * scaleRatio;
+    final width = displaySize.width;
+    final height = displaySize.height;
     final x = offset.dx / width;
     final y = offset.dy / height;
     final percentOffset = Offset(x, y);

+ 11 - 0
lib/view/canvas/active_canvas.dart

@@ -47,6 +47,17 @@ class _ActiveCanvasPanelState extends State<MeasureActiveCanvasPanel> {
   @override
   Widget build(BuildContext context) {
     if (feature == null) return const SizedBox();
+    return LayoutBuilder(builder: (context, constraints) {
+      return SizedBox(
+        width: constraints.maxWidth,
+        height: constraints.maxHeight,
+        child: RepaintBoundary(
+          child: CustomPaint(
+            painter: _PanelPainter(feature!),
+          ),
+        ),
+      );
+    });
     return RepaintBoundary(
       child: CustomPaint(
         painter: _PanelPainter(feature!),

+ 2 - 0
lib/view/main/desktop.dart

@@ -118,6 +118,8 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
     final offset = layoutOffset!;
     final renderSize = layoutSize!;
 
+    Get.find<IApplication>().displaySize = renderSize;
+
     layoutLayer(_LayerLayoutIds.player, offset, renderSize);
 
     /// 其他层按播放器尺寸位置层叠布局