mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Some attempts at proper anchor movement..
This commit is contained in:
1 parent
d79437b3fd
commit
41fbbbd87a
6 files changed
+269
-153
No files matched your search
@@ -160,18 +160,22 @@ namespace Artemis.Core.Models.Profile
|
||||
canvas.ClipPath(Path);
|
||||
|
||||
// Apply transformations
|
||||
var anchor = AnchorPointProperty.CurrentValue;
|
||||
var position = PositionProperty.CurrentValue;
|
||||
var size = SizeProperty.CurrentValue;
|
||||
var rotation = RotationProperty.CurrentValue;
|
||||
// Scale the anchor and make it originate from the center of the untranslated layer shape
|
||||
anchor.X = anchor.X * AbsoluteRectangle.Width + LayerShape.RenderRectangle.MidX;
|
||||
anchor.Y = anchor.Y * AbsoluteRectangle.Height + LayerShape.RenderRectangle.MidY;
|
||||
|
||||
canvas.Translate(position.X * AbsoluteRectangle.Width, position.Y * AbsoluteRectangle.Height);
|
||||
var anchor = GetLayerAnchor(true);
|
||||
var relativeAnchor = GetLayerAnchor(false);
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = position.X * Rectangle.Width - LayerShape.RenderRectangle.Width / 2 - relativeAnchor.X;
|
||||
var y = position.Y * Rectangle.Height - LayerShape.RenderRectangle.Height / 2 - relativeAnchor.Y;
|
||||
|
||||
|
||||
canvas.RotateDegrees(rotation, anchor.X, anchor.Y);
|
||||
canvas.Scale(size.Width, size.Height, anchor.X, anchor.Y);
|
||||
|
||||
canvas.Translate(x, y);
|
||||
|
||||
// Placeholder
|
||||
if (LayerShape?.RenderPath != null)
|
||||
{
|
||||
@@ -192,6 +196,22 @@ namespace Artemis.Core.Models.Profile
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
private SKPoint GetLayerAnchor(bool absolute)
|
||||
{
|
||||
if (!absolute)
|
||||
{
|
||||
var anchor = AnchorPointProperty.CurrentValue;
|
||||
anchor.X = anchor.X * Rectangle.Width;
|
||||
anchor.Y = anchor.Y * Rectangle.Height;
|
||||
return new SKPoint(anchor.X, anchor.Y);
|
||||
}
|
||||
|
||||
var position = PositionProperty.CurrentValue;
|
||||
position.X = position.X * Rectangle.Width;
|
||||
position.Y = position.Y * Rectangle.Height;
|
||||
return new SKPoint(position.X + LayerShape.RenderRectangle.Left, position.Y + LayerShape.RenderRectangle.Top);
|
||||
}
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
// Properties
|
||||
|
||||
@@ -58,10 +58,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
return SKRect.Empty;
|
||||
|
||||
return SKRect.Create(
|
||||
Layer.AbsoluteRectangle.Left + Layer.AbsoluteRectangle.Width * ScaledRectangle.Left,
|
||||
Layer.AbsoluteRectangle.Top + Layer.AbsoluteRectangle.Height * ScaledRectangle.Top,
|
||||
Layer.AbsoluteRectangle.Width * ScaledRectangle.Width,
|
||||
Layer.AbsoluteRectangle.Height * ScaledRectangle.Height
|
||||
Layer.Rectangle.Left + Layer.Rectangle.Width * ScaledRectangle.Left,
|
||||
Layer.Rectangle.Top + Layer.Rectangle.Height * ScaledRectangle.Top,
|
||||
Layer.Rectangle.Width * ScaledRectangle.Width,
|
||||
Layer.Rectangle.Height * ScaledRectangle.Height
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
}
|
||||
|
||||
Layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
|
||||
100f / Layer.AbsoluteRectangle.Width * (anchor.X - Layer.AbsoluteRectangle.Left - Layer.PositionProperty.CurrentValue.X) / 100f,
|
||||
100f / Layer.AbsoluteRectangle.Height * (anchor.Y - Layer.AbsoluteRectangle.Top - Layer.PositionProperty.CurrentValue.Y) / 100f
|
||||
100f / Layer.Rectangle.Width * (anchor.X - Layer.Rectangle.Left - Layer.PositionProperty.CurrentValue.X) / 100f,
|
||||
100f / Layer.Rectangle.Height * (anchor.Y - Layer.Rectangle.Top - Layer.PositionProperty.CurrentValue.Y) / 100f
|
||||
), time);
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
@@ -87,8 +87,8 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
return SKPoint.Empty;
|
||||
|
||||
return new SKPoint(
|
||||
Layer.AbsoluteRectangle.Left + Layer.AbsoluteRectangle.Width * (Layer.AnchorPointProperty.CurrentValue.X + Layer.PositionProperty.CurrentValue.X),
|
||||
Layer.AbsoluteRectangle.Top + Layer.AbsoluteRectangle.Height * (Layer.AnchorPointProperty.CurrentValue.Y + Layer.PositionProperty.CurrentValue.Y)
|
||||
Layer.Rectangle.Left + Layer.Rectangle.Width * (Layer.AnchorPointProperty.CurrentValue.X + Layer.PositionProperty.CurrentValue.X),
|
||||
Layer.Rectangle.Top + Layer.Rectangle.Height * (Layer.AnchorPointProperty.CurrentValue.Y + Layer.PositionProperty.CurrentValue.Y)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user