From ce0024a14dd21a6f58d23cdd5b1c47586c97ee1a Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 18 Sep 2020 20:14:38 +0200 Subject: [PATCH] Profile editor - Improved anchor point visibility Profile editor - Fixed resizing if the resize handle is on the same position as the anchor Profile editor - Added shift modifier to drag anchor point in increments Profile editor - Fixed the layer sometimes moving when moving the anchor --- .../Visualization/Tools/EditToolViewModel.cs | 23 +++++++++++++++---- .../UserControls/LayerShapeControl.xaml | 15 ++++-------- .../UserControls/LayerShapeControl.xaml.cs | 6 +++-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/EditToolViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/EditToolViewModel.cs index 4dc60454c..2b3b9259b 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/EditToolViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/EditToolViewModel.cs @@ -34,7 +34,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update(); profileEditorService.ProfilePreviewUpdated += (sender, args) => Update(); } - + public SKPath ShapePath { get => _shapePath; @@ -220,6 +220,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools var anchorDistance = origin == ResizeOrigin.Left ? shapePath.Bounds.Left - ShapeAnchor.X : shapePath.Bounds.Right - ShapeAnchor.X; + + // Don't resize if the distance to the anchor is too small, that'll result in a NaN value + // this might happen if the anchor is at X -0.5 and the drag handle is on the left side or vice versa + if (Math.Abs(anchorDistance) < 0.001) + return _dragStartScale.Width; + var anchorOffset = anchorDistance / shapePath.Bounds.Width; var pixelsToAdd = (position - dragStart).X / anchorOffset; @@ -240,6 +246,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools var anchorDistance = origin == ResizeOrigin.Top ? shapePath.Bounds.Top - ShapeAnchor.Y : shapePath.Bounds.Bottom - ShapeAnchor.Y; + + // Don't resize if the distance to the anchor is too small, that'll result in a NaN value + // this might happen if the anchor is at Y -0.5 and the drag handle is on the top side or vice versa + if (Math.Abs(anchorDistance) < 0.001) + return _dragStartScale.Width; + var anchorOffset = anchorDistance / shapePath.Bounds.Height; var pixelsToAdd = (position - dragStart).Y / anchorOffset; @@ -353,16 +365,19 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools var current = start + (GetRelativePosition(sender, e).ToSKPoint() - _dragOffset); // In order to keep the mouse movement unrotated, counter-act the active rotation var countered = UnTransformPoints(new[] {start, current}, layer, start, true); - var scaled = _layerEditorService.GetScaledPoint(layer, countered[1], false); + + // If shift is held down, round down to 1 decimal to allow moving the anchor in big increments + var decimals = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? 1 : 3; + var scaled = RoundPoint(_layerEditorService.GetScaledPoint(layer, countered[1], false), decimals); // Update the anchor point, this causes the shape to move - layer.Transform.AnchorPoint.SetCurrentValue(RoundPoint(scaled, 3), ProfileEditorService.CurrentTime); + layer.Transform.AnchorPoint.SetCurrentValue(scaled, ProfileEditorService.CurrentTime); // TopLeft is not updated yet and acts as a snapshot of the top-left before changing the anchor var path = _layerEditorService.GetLayerPath(layer, true, true, true); // Calculate the (scaled) difference between the old and now position var difference = _layerEditorService.GetScaledPoint(layer, _topLeft - path.Points[0], false); // Apply the difference so that the shape effectively stays in place - layer.Transform.Position.SetCurrentValue(RoundPoint(layer.Transform.Position.CurrentValue + difference, 3), ProfileEditorService.CurrentTime); + layer.Transform.Position.SetCurrentValue(layer.Transform.Position.CurrentValue + difference, ProfileEditorService.CurrentTime); ProfileEditorService.UpdateProfilePreview(); } diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml b/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml index c1c3ed093..64608e7ac 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml @@ -46,7 +46,6 @@ + MouseMove="MoveOnMouseMove" RenderTransformOrigin="0.5 0.5"> + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml.cs index a5db20664..189d85e1e 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/UserControls/LayerShapeControl.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Shapes; using Artemis.UI.Events; using SkiaSharp; @@ -164,7 +165,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls UpdateControlPosition(control, point); } - private void UpdateRotateDimensions(FrameworkElement rotateControl) + private void UpdateRotateDimensions(Shape rotateControl) { var controlSize = Math.Max(10 / Zoom, 4); var rotateSize = controlSize * 8; @@ -174,13 +175,14 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls rotateControl.Margin = new Thickness(rotateSize / 2 * -1, rotateSize / 2 * -1, 0, 0); } - private void UpdateResizeDimensions(FrameworkElement resizeControl) + private void UpdateResizeDimensions(Shape resizeControl) { var controlSize = Math.Max(10 / Zoom, 4); resizeControl.Width = controlSize; resizeControl.Height = controlSize; resizeControl.Margin = new Thickness(controlSize / 2 * -1, controlSize / 2 * -1, 0, 0); + resizeControl.StrokeThickness = controlSize / 7.5; } #endregion