diff --git a/BlazorSvgEditor.SvgEditor/Shapes/Circle.cs b/BlazorSvgEditor.SvgEditor/Shapes/Circle.cs index f3234b4..08075e8 100644 --- a/BlazorSvgEditor.SvgEditor/Shapes/Circle.cs +++ b/BlazorSvgEditor.SvgEditor/Shapes/Circle.cs @@ -27,6 +27,7 @@ internal override void SnapToInteger() R = R.ToInt(); } + bool isMoved = false; internal override void HandlePointerMove(PointerEventArgs eventArgs) { @@ -47,6 +48,7 @@ internal override void HandlePointerMove(PointerEventArgs eventArgs) Cx = (Cx + result.X).Round(); Cy = (Cy + result.Y).Round(); + isMoved = true; break; case EditMode.MoveAnchor: @@ -78,9 +80,14 @@ internal override async Task HandlePointerUp(PointerEventArgs eventArgs) if (SvgEditor.EditMode == EditMode.Add) { if (R == 0) R = GetMaxRadius(SvgEditor.ImageBoundingBox, new Coord(Cx, Cy), 15); //Wenn Radius 0 ist, wurde der Kreis nur durch ein Klicken erzeugt, also wird er auf 15 gesetzt + await Complete(); + } + + if (SvgEditor.EditMode == EditMode.Move && isMoved) + { + isMoved = false; + await FireOnShapeChangedMove(); } - - if (SvgEditor.EditMode == EditMode.Move) await FireOnShapeChangedMove(); else if (SvgEditor.EditMode == EditMode.MoveAnchor) await FireOnShapeChangedEdit(); SvgEditor.EditMode = EditMode.None; @@ -91,11 +98,7 @@ internal override void HandlePointerOut(PointerEventArgs eventArgs) { throw new NotImplementedException(); } - - internal override void Complete() - { - throw new NotImplementedException(); - } + diff --git a/BlazorSvgEditor.SvgEditor/Shapes/Polygon.cs b/BlazorSvgEditor.SvgEditor/Shapes/Polygon.cs index fc3540e..cdc67dd 100644 --- a/BlazorSvgEditor.SvgEditor/Shapes/Polygon.cs +++ b/BlazorSvgEditor.SvgEditor/Shapes/Polygon.cs @@ -22,6 +22,7 @@ public Polygon(SvgEditor svgEditor) : base(svgEditor){} //Create Polygon Anchor Settings private double _polygonCompleteThreshold => 10; + bool isMoved = false; internal override void HandlePointerMove(PointerEventArgs eventArgs) { var point = SvgEditor.DetransformPoint(eventArgs.OffsetX, eventArgs.OffsetY); @@ -52,6 +53,7 @@ internal override void HandlePointerMove(PointerEventArgs eventArgs) } Points = newPoints; + isMoved = true; break; case EditMode.MoveAnchor: @@ -101,7 +103,12 @@ internal override async Task HandlePointerUp(PointerEventArgs eventArgs) } else { - if (SvgEditor.EditMode == EditMode.Move) await FireOnShapeChangedMove(); + if (SvgEditor.EditMode == EditMode.Move && isMoved) + { + isMoved = false; + await FireOnShapeChangedMove(); + } + else if (SvgEditor.EditMode == EditMode.MoveAnchor) await FireOnShapeChangedEdit(); SvgEditor.EditMode = EditMode.None; @@ -134,8 +141,9 @@ internal override void HandlePointerOut(PointerEventArgs eventArgs) throw new NotImplementedException(); } - internal override void Complete() + internal override async Task Complete() { + await base.Complete(); SvgEditor.EditMode = EditMode.None; } } \ No newline at end of file diff --git a/BlazorSvgEditor.SvgEditor/Shapes/Rectangle.cs b/BlazorSvgEditor.SvgEditor/Shapes/Rectangle.cs index 60d5b59..df671ec 100644 --- a/BlazorSvgEditor.SvgEditor/Shapes/Rectangle.cs +++ b/BlazorSvgEditor.SvgEditor/Shapes/Rectangle.cs @@ -29,6 +29,7 @@ internal override void SnapToInteger() Height = Height.ToInt(); } + bool isMoved = false; internal override void HandlePointerMove(PointerEventArgs eventArgs) { var point = SvgEditor.DetransformPoint(eventArgs.OffsetX, eventArgs.OffsetY); @@ -72,6 +73,8 @@ internal override void HandlePointerMove(PointerEventArgs eventArgs) X += result.X; Y += result.Y; + + isMoved = true; break; case EditMode.MoveAnchor: @@ -133,9 +136,14 @@ internal override async Task HandlePointerUp(PointerEventArgs eventArgs) { if (Width < 1) Width = 1; if (Height < 1) Height = 1; + await Complete(); } - if (SvgEditor.EditMode == EditMode.Move) await FireOnShapeChangedMove(); + if (SvgEditor.EditMode == EditMode.Move && isMoved) + { + isMoved = false; + await FireOnShapeChangedMove(); + } else if (SvgEditor.EditMode == EditMode.MoveAnchor) await FireOnShapeChangedEdit(); SvgEditor.EditMode = EditMode.None; @@ -145,8 +153,4 @@ internal override void HandlePointerOut(PointerEventArgs eventArgs) { throw new NotImplementedException(); } - - internal override void Complete() - { - } } \ No newline at end of file diff --git a/BlazorSvgEditor.SvgEditor/Shapes/Shape.cs b/BlazorSvgEditor.SvgEditor/Shapes/Shape.cs index 10a05ed..440033a 100644 --- a/BlazorSvgEditor.SvgEditor/Shapes/Shape.cs +++ b/BlazorSvgEditor.SvgEditor/Shapes/Shape.cs @@ -96,7 +96,12 @@ internal void UnHoverShape() internal abstract void HandlePointerMove(PointerEventArgs eventArgs); internal abstract Task HandlePointerUp(PointerEventArgs eventArgs); internal abstract void HandlePointerOut(PointerEventArgs eventArgs); - internal abstract void Complete(); + + internal virtual async Task Complete() + { + await SvgEditor.ShapeAddedCompleted(this); + } + protected async Task FireOnShapeChangedMove() => await SvgEditor.OnShapeChanged.InvokeAsync(ShapeChangedEventArgs.ShapeMoved(this)); diff --git a/BlazorSvgEditor.SvgEditor/SvgEditor.AddEditLogic.cs b/BlazorSvgEditor.SvgEditor/SvgEditor.AddEditLogic.cs index 8481e20..ee5f271 100644 --- a/BlazorSvgEditor.SvgEditor/SvgEditor.AddEditLogic.cs +++ b/BlazorSvgEditor.SvgEditor/SvgEditor.AddEditLogic.cs @@ -75,12 +75,18 @@ private async Task AddToolPointerDown(PointerEventArgs e) newShape.CustomId = newShapeId; Shapes.Add(newShape); - await OnShapeChanged.InvokeAsync(ShapeChangedEventArgs.ShapeAdded(newShape)); SelectedShape = newShape; SelectedShape.SelectShape(); EditMode = EditMode.Add; } + + public async Task ShapeAddedCompleted(Shape shape) + { + await OnShapeChanged.InvokeAsync(ShapeChangedEventArgs.ShapeAdded(shape)); + SelectedShape = shape; + SelectedShape.SelectShape(); + } } \ No newline at end of file diff --git a/BlazorSvgEditor.SvgEditor/SvgEditor.Main.cs b/BlazorSvgEditor.SvgEditor/SvgEditor.Main.cs index efd9481..19d66db 100644 --- a/BlazorSvgEditor.SvgEditor/SvgEditor.Main.cs +++ b/BlazorSvgEditor.SvgEditor/SvgEditor.Main.cs @@ -48,6 +48,7 @@ public Shape? SelectedShape { if (_selectedShape != value) { + Console.WriteLine("SelectedShape changed from " + _selectedShape?.CustomId + " to " + value?.CustomId); _selectedShape = value; SelectedShapeIdChanged.InvokeAsync(SelectedShapeId); } @@ -160,6 +161,7 @@ public void AddNewShape(ShapeType shapeType) SelectedShape?.UnSelectShape(); SelectedShape = null; + Console.WriteLine("AddNewShape"); } public async Task RemoveSelectedShape()