1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

More anchor stuff, it's killing me

This commit is contained in:
Robert 2020-01-22 21:56:18 +01:00
parent 2fb92de0ea
commit 20999919ab
2 changed files with 48 additions and 41 deletions

View File

@ -11,9 +11,8 @@
d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}">
<Canvas UseLayoutRounding="False">
<Canvas>
<!-- The part of the layer's shape that is inside the layer -->
<Path Data="{Binding ShapeGeometry, Mode=OneWay}"
<!-- The part of the layer's shape that is inside the layer -->
<Path Data="{Binding ShapeGeometry, Mode=OneWay}"
Fill="Transparent"
Stroke="{DynamicResource PrimaryHueMidBrush}"
StrokeThickness="1"
@ -23,37 +22,16 @@
MouseUp="{s:Action ShapeEditMouseUp}"
MouseMove="{s:Action Move}" />
<!-- Mutation points -->
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopLeft.X}" Canvas.Top="{Binding TopLeft.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopRight.X}" Canvas.Top="{Binding TopRight.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomRight.X}" Canvas.Top="{Binding BottomRight.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomLeft.X}" Canvas.Top="{Binding BottomLeft.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopCenter.X}" Canvas.Top="{Binding TopCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding RightCenter.X}" Canvas.Top="{Binding RightCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomCenter.X}" Canvas.Top="{Binding BottomCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding LeftCenter.X}" Canvas.Top="{Binding LeftCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<!-- Mutation points -->
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopLeft.X}" Canvas.Top="{Binding TopLeft.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopRight.X}" Canvas.Top="{Binding TopRight.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomRight.X}" Canvas.Top="{Binding BottomRight.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomLeft.X}" Canvas.Top="{Binding BottomLeft.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding TopCenter.X}" Canvas.Top="{Binding TopCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding RightCenter.X}" Canvas.Top="{Binding RightCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding BottomCenter.X}" Canvas.Top="{Binding BottomCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<Rectangle Width="4" Height="4" Canvas.Left="{Binding LeftCenter.X}" Canvas.Top="{Binding LeftCenter.Y}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
<!-- Anchor point -->
<materialDesign:PackIcon Kind="Crosshairs"
Width="8"
Height="8"
Foreground="{DynamicResource SecondaryAccentBrush}"
Canvas.Left="{Binding ShapeAnchor.X}"
Canvas.Top="{Binding ShapeAnchor.Y}"
Margin="-4,-4,0,0" />
<Ellipse MouseDown="{s:Action AnchorEditMouseDown}"
MouseUp="{s:Action ShapeEditMouseUp}"
MouseMove="{s:Action AnchorMove}"
Width="8"
Height="8"
Fill="Transparent"
Canvas.Left="{Binding ShapeAnchor.X}"
Canvas.Top="{Binding ShapeAnchor.Y}"
Margin="-4,-4,0,0"
Cursor="SizeAll">
</Ellipse>
</Canvas>
<Canvas>
<Canvas.RenderTransform>
<TransformGroup Children="{Binding ShapeTransformCollection}" />
@ -201,6 +179,26 @@
Margin="-5,-5,0,0"
Cursor="SizeWE" />
</Canvas>
<!-- Anchor point -->
<materialDesign:PackIcon Kind="Crosshairs"
Width="8"
Height="8"
Foreground="{DynamicResource SecondaryAccentBrush}"
Canvas.Left="{Binding ShapeAnchor.X}"
Canvas.Top="{Binding ShapeAnchor.Y}"
Margin="-4,-4,0,0" />
<Ellipse MouseDown="{s:Action AnchorEditMouseDown}"
MouseUp="{s:Action ShapeEditMouseUp}"
MouseMove="{s:Action AnchorMove}"
Width="8"
Height="8"
Fill="Transparent"
Canvas.Left="{Binding ShapeAnchor.X}"
Canvas.Top="{Binding ShapeAnchor.Y}"
Margin="-4,-4,0,0"
Cursor="SizeAll">
</Ellipse>
</Canvas>
</UserControl>

View File

@ -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))