1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Cleaned up anchor movement

This commit is contained in:
SpoinkyNL 2020-01-22 00:10:29 +01:00
parent 8bc2801836
commit 2fb92de0ea

View File

@ -19,7 +19,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
private bool _draggingVertically; private bool _draggingVertically;
private bool _isDragging; private bool _isDragging;
private Point _dragStart; private Point _dragStart;
private Point _dragOffset; private SKPoint _dragOffset;
private SKPoint _dragStartAnchor; private SKPoint _dragStartAnchor;
public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService) public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
@ -60,7 +60,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
Execute.PostToUIThread(() => Execute.PostToUIThread(() =>
{ {
var shapeGeometry = new RectangleGeometry(_layerEditorService.GetShapeRenderRect(layer.LayerShape)); var shapeGeometry = new RectangleGeometry(_layerEditorService.GetShapeRenderRect(layer.LayerShape));
// shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(layer); shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(layer);
shapeGeometry.Freeze(); shapeGeometry.Freeze();
ShapeGeometry = shapeGeometry; ShapeGeometry = shapeGeometry;
ShapeTransformCollection = _layerEditorService.GetLayerTransformGroup(layer).Children; ShapeTransformCollection = _layerEditorService.GetLayerTransformGroup(layer).Children;
@ -92,7 +92,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
var dragStartPosition = GetRelativePosition(sender, e); var dragStartPosition = GetRelativePosition(sender, e);
var anchor = _layerEditorService.GetLayerAnchor(layer, true); var anchor = _layerEditorService.GetLayerAnchor(layer, true);
_dragOffset = new Point(dragStartPosition.X - anchor.X - 1.45, dragStartPosition.Y - anchor.Y - 1.45); // _dragOffset = new Point(dragStartPosition.X - anchor.X - 1.45, dragStartPosition.Y - anchor.Y - 1.45);
_dragStart = dragStartPosition; _dragStart = dragStartPosition;
} }
@ -112,11 +112,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
if (ProfileEditorService.SelectedProfileElement is Layer layer) 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 // 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); var dragStartPosition = GetRelativePosition(sender, e).ToSKPoint();
_dragOffset = TopLeft + (dragStartPosition - TopLeft);
_dragOffset = new Point(TopLeft.X + (dragStartPosition.X - TopLeft.X), TopLeft.Y + (dragStartPosition.Y - TopLeft.Y));
_dragStartAnchor = _layerEditorService.GetLayerAnchor(layer, false); _dragStartAnchor = _layerEditorService.GetLayerAnchor(layer, false);
_dragStart = dragStartPosition;
} }
_isDragging = true; _isDragging = true;
@ -146,25 +144,33 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
var position = GetRelativePosition(sender, e); var position = GetRelativePosition(sender, e);
var start = new SKPoint(_dragStartAnchor.X, _dragStartAnchor.Y); var start = _dragStartAnchor;
var current = position.ToSKPoint() - _dragOffset.ToSKPoint(); var current = position.ToSKPoint() - _dragOffset;
var counterRotatePath = new SKPath();
counterRotatePath.AddPoly(new[] {start, current}, false);
counterRotatePath.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue * -1, start.X, start.Y));
var scaled = _layerEditorService.GetScaledPoint(layer, counterRotatePath.Points[0] + counterRotatePath.Points[1], false); var transformedPoints = TransformPoints(new[] {start, current}, layer, start);
var scaled = _layerEditorService.GetScaledPoint(layer, transformedPoints[0] + transformedPoints[1], false);
var topLeft = new SKPoint(TopLeft.X, TopLeft.Y); var before = TopLeft;
layer.AnchorPointProperty.SetCurrentValue(scaled, ProfileEditorService.CurrentTime); layer.AnchorPointProperty.SetCurrentValue(scaled, ProfileEditorService.CurrentTime);
var path = _layerEditorService.GetLayerPath(layer); var path = _layerEditorService.GetLayerPath(layer);
var difference = topLeft - path.Points[0]; var difference = before - path.Points[0];
var scaledDifference = _layerEditorService.GetScaledPoint(layer, difference, false); var scaledDifference = _layerEditorService.GetScaledPoint(layer, difference, false);
layer.PositionProperty.SetCurrentValue(layer.PositionProperty.CurrentValue + scaledDifference, ProfileEditorService.CurrentTime); layer.PositionProperty.SetCurrentValue(layer.PositionProperty.CurrentValue + scaledDifference, ProfileEditorService.CurrentTime);
ProfileEditorService.UpdateProfilePreview(); ProfileEditorService.UpdateProfilePreview();
} }
private SKPoint[] TransformPoints(SKPoint[] skPoints, Layer layer, SKPoint pivot)
{
var counterRotatePath = new SKPath();
counterRotatePath.AddPoly(skPoints, false);
counterRotatePath.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue * -1, pivot.X, pivot.Y));
counterRotatePath.Transform(SKMatrix.MakeScale(1f / layer.SizeProperty.CurrentValue.Width, 1f / layer.SizeProperty.CurrentValue.Height));
return counterRotatePath.Points;
}
public void Move(object sender, MouseEventArgs e) public void Move(object sender, MouseEventArgs e)
{ {
if (!_isDragging || !(ProfileEditorService.SelectedProfileElement is Layer layer)) if (!_isDragging || !(ProfileEditorService.SelectedProfileElement is Layer layer))