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

Found the solution to anchor movement ^^

This commit is contained in:
Robert 2020-01-21 19:58:52 +01:00
parent 41fbbbd87a
commit 8bc2801836

View File

@ -2,6 +2,7 @@
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.UI.Services; using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
@ -59,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;
@ -144,19 +145,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
return; return;
var position = GetRelativePosition(sender, e); var position = GetRelativePosition(sender, e);
var x = (float)(position.X - _dragOffset.X + _dragStartAnchor.X);
var y = (float)(position.Y - _dragOffset.Y + _dragStartAnchor.Y);
// Convert the desired X and Y position to a translation var start = new SKPoint(_dragStartAnchor.X, _dragStartAnchor.Y);
var scaled = _layerEditorService.GetScaledPoint(layer, new SKPoint(x, y), false); var current = position.ToSKPoint() - _dragOffset.ToSKPoint();
var currentAnchor = layer.AnchorPointProperty.CurrentValue;
var currentPos = layer.PositionProperty.CurrentValue;
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 topLeft = new SKPoint(TopLeft.X, TopLeft.Y);
layer.AnchorPointProperty.SetCurrentValue(scaled, ProfileEditorService.CurrentTime); layer.AnchorPointProperty.SetCurrentValue(scaled, ProfileEditorService.CurrentTime);
var path = _layerEditorService.GetLayerPath(layer);
var difference = topLeft - path.Points[0];
var scaledDifference = _layerEditorService.GetScaledPoint(layer, difference, false);
var positionOffsetX = (scaled.X - currentAnchor.X) * layer.SizeProperty.CurrentValue.Width; layer.PositionProperty.SetCurrentValue(layer.PositionProperty.CurrentValue + scaledDifference, ProfileEditorService.CurrentTime);
var positionOffsetY = (scaled.Y - currentAnchor.Y) * layer.SizeProperty.CurrentValue.Height;
layer.PositionProperty.SetCurrentValue(new SKPoint(currentPos.X + positionOffsetX, currentPos.Y + positionOffsetY), ProfileEditorService.CurrentTime);
ProfileEditorService.UpdateProfilePreview(); ProfileEditorService.UpdateProfilePreview();
} }