Browse Source

Line tool overlay - removed preview line and fixed single click

flabbet 8 months ago
parent
commit
7f60c89d0b

+ 2 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/LineExecutor.cs

@@ -10,6 +10,7 @@ using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using Drawie.Numerics;
 using PixiEditor.Helpers;
+using PixiEditor.Models.Controllers.InputDevice;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
@@ -56,6 +57,7 @@ internal abstract class LineExecutor<T> : SimpleShapeToolExecutor where T : ILin
                 toolbar.StrokeColor = colorsVM.PrimaryColor.ToColor();
             }
 
+            document.LineToolOverlayHandler.Hide();
             document.LineToolOverlayHandler.Show(startDrawingPos, startDrawingPos, false);
             document.LineToolOverlayHandler.ShowHandles = false;
             document.LineToolOverlayHandler.IsSizeBoxEnabled = true;

+ 1 - 0
src/PixiEditor/ViewModels/Document/TransformOverlays/LineToolOverlayViewModel.cs

@@ -106,6 +106,7 @@ internal class LineToolOverlayViewModel : ObservableObject, ILineOverlayHandler
         undoStack = null;
         IsEnabled = false;
         ShowApplyButton = false;
+        IsSizeBoxEnabled = false;
     }
 
     public bool Nudge(VecD distance)

+ 11 - 6
src/PixiEditor/Views/Overlays/LineToolOverlay/LineToolOverlay.cs

@@ -82,8 +82,6 @@ internal class LineToolOverlay : Overlay
     }
 
 
-    private DashedStroke dashedStroke = new DashedStroke();
-
     private Paint blackPaint = new Paint()
     {
         Color = Colors.Black, StrokeWidth = 1, Style = PaintStyle.Stroke, IsAntiAliased = true
@@ -131,7 +129,7 @@ internal class LineToolOverlay : Overlay
         moveHandle.StrokePaint = blackPaint;
         moveHandle.OnDrag += MoveHandleOnDrag;
         endHandle.Cursor = new Cursor(StandardCursorType.Arrow);
-        moveHandle.OnHover += (handle, _)=> Refresh();
+        moveHandle.OnHover += (handle, _) => Refresh();
         moveHandle.OnRelease += OnHandleRelease;
         AddHandle(moveHandle);
 
@@ -141,9 +139,15 @@ internal class LineToolOverlay : Overlay
     protected override void OnOverlayPointerMoved(OverlayPointerArgs args)
     {
         base.OnOverlayPointerMoved(args);
+
         lastMousePos = args.Point;
     }
 
+    public override bool TestHit(VecD point)
+    {
+        return IsVisible;
+    }
+
     private void OnHandleRelease(Handle obj, OverlayPointerArgs args)
     {
         if (SnappingController != null)
@@ -160,7 +164,6 @@ internal class LineToolOverlay : Overlay
     protected override void ZoomChanged(double newZoom)
     {
         blackPaint.StrokeWidth = 1 / (float)newZoom;
-        dashedStroke.UpdateZoom((float)newZoom);
         infoBox.ZoomScale = newZoom;
     }
 
@@ -177,8 +180,6 @@ internal class LineToolOverlay : Overlay
 
         moveHandle.Position = TransformHelper.GetHandlePos(new ShapeCorners(center, size), ZoomScale, moveHandle.Size);
 
-        dashedStroke.Draw(context, mappedStart, mappedEnd);
-
         if (ShowHandles)
         {
             startHandle.Draw(context);
@@ -200,6 +201,7 @@ internal class LineToolOverlay : Overlay
 
         movedWhileMouseDown = false;
         mouseDownPos = args.Point;
+        
         lineStartOnMouseDown = LineStart;
         lineEndOnMouseDown = LineEnd;
 
@@ -278,11 +280,14 @@ internal class LineToolOverlay : Overlay
 
     protected override void OnOverlayPointerReleased(OverlayPointerArgs args)
     {
+        IsSizeBoxEnabled = false;
+        
         if (args.InitialPressMouseButton != MouseButton.Left)
             return;
 
         if (movedWhileMouseDown && ActionCompleted is not null && ActionCompleted.CanExecute(null))
             ActionCompleted.Execute(null);
+        
     }
 
     private ((string, string), VecD) TrySnapLine(VecD originalStart, VecD originalEnd, VecD delta)