From 20999919ab9fd32917104d7c4eb8f18744d1209a Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 22 Jan 2020 21:56:18 +0100 Subject: [PATCH] More anchor stuff, it's killing me --- .../Visualization/Tools/EditToolView.xaml | 64 +++++++++---------- .../Visualization/Tools/EditToolViewModel.cs | 25 +++++--- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml index b5eac343a..6ab6499f8 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml @@ -11,9 +11,8 @@ d:DesignWidth="800" d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}"> - - - + - - - - - - - - - + + + + + + + + + - - - - - - @@ -201,6 +179,26 @@ Margin="-5,-5,0,0" Cursor="SizeWE" /> + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs index 6b389822f..ba612c9cb 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Windows; using System.Windows.Input; using System.Windows.Media; @@ -111,7 +112,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools if (ProfileEditorService.SelectedProfileElement is Layer layer) { - // The path starts at 0,0 so there's no simple way to get the position relative to the top-left of the path var dragStartPosition = GetRelativePosition(sender, e).ToSKPoint(); _dragOffset = TopLeft + (dragStartPosition - TopLeft); _dragStartAnchor = _layerEditorService.GetLayerAnchor(layer, false); @@ -143,14 +143,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools return; var position = GetRelativePosition(sender, e); - var start = _dragStartAnchor; - var current = position.ToSKPoint() - _dragOffset; + var current = start + (position.ToSKPoint() - _dragOffset); - - var transformedPoints = TransformPoints(new[] {start, current}, layer, start); - var scaled = _layerEditorService.GetScaledPoint(layer, transformedPoints[0] + transformedPoints[1], false); - + var transformedPoints = UnTransformPoints(new[] {start, current}, layer, start); + var scaled = _layerEditorService.GetScaledPoint(layer, transformedPoints[1], false); + Debug.WriteLine("Current value before mousedown " + _dragStartAnchor); + Debug.WriteLine("Current value before move " + layer.AnchorPointProperty.CurrentValue); var before = TopLeft; layer.AnchorPointProperty.SetCurrentValue(scaled, ProfileEditorService.CurrentTime); var path = _layerEditorService.GetLayerPath(layer); @@ -161,7 +160,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools ProfileEditorService.UpdateProfilePreview(); } - private SKPoint[] TransformPoints(SKPoint[] skPoints, Layer layer, SKPoint pivot) + private SKPoint[] UnTransformPoints(SKPoint[] skPoints, Layer layer, SKPoint pivot) { var counterRotatePath = new SKPath(); counterRotatePath.AddPoly(skPoints, false); @@ -171,6 +170,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools return counterRotatePath.Points; } + private SKPoint[] TransformPoints(SKPoint[] skPoints, Layer layer, SKPoint pivot) + { + var counterRotatePath = new SKPath(); + counterRotatePath.AddPoly(skPoints, false); + counterRotatePath.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue , pivot.X, pivot.Y)); + counterRotatePath.Transform(SKMatrix.MakeScale( layer.SizeProperty.CurrentValue.Width, layer.SizeProperty.CurrentValue.Height)); + + return counterRotatePath.Points; + } + public void Move(object sender, MouseEventArgs e) { if (!_isDragging || !(ProfileEditorService.SelectedProfileElement is Layer layer))