Refactored the edit tool

Fixed the fill shape but it might need some rethinking
This commit is contained in:
Robert committed 2020-01-29 20:56:26 +01:00
1 parent 19bbef4cad
commit 5a44e5fbe8
32 files changed
+1037 -826

No files matched your search

+16 -16
View File
@@ -81,17 +81,17 @@ namespace Artemis.Core.Models.Profile
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
/// <summary>
/// A rectangle relative to the surface that contains all the LEDs in this layer.
/// <para>For rendering, use the RenderRectangle on <see cref="LayerShape" />.</para>
/// </summary>
public SKRect Rectangle { get; private set; }
/// <summary>
/// A zero-based absolute rectangle that contains all the LEDs in this layer.
/// An absolute rectangle to the surface that contains all the LEDs in this layer.
/// <para>For rendering, use the RenderRectangle on <see cref="LayerShape" />.</para>
/// </summary>
public SKRect AbsoluteRectangle { get; private set; }
/// <summary>
/// A zero-based rectangle that contains all the LEDs in this layer.
/// <para>For rendering, use the RenderRectangle on <see cref="LayerShape" />.</para>
/// </summary>
public SKRect Rectangle { get; private set; }
/// <summary>
/// A path containing all the LEDs this layer is applied to.
/// <para>For rendering, use the RenderPath on <see cref="LayerShape" />.</para>
@@ -177,8 +177,8 @@ namespace Artemis.Core.Models.Profile
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;
var x = position.X * AbsoluteRectangle.Width - LayerShape.RenderRectangle.Width / 2 - relativeAnchor.X;
var y = position.Y * AbsoluteRectangle.Height - LayerShape.RenderRectangle.Height / 2 - relativeAnchor.Y;
canvas.RotateDegrees(rotation, anchor.X, anchor.Y);
@@ -213,14 +213,14 @@ namespace Artemis.Core.Models.Profile
if (!absolute)
{
var anchor = AnchorPointProperty.CurrentValue;
anchor.X = anchor.X * Rectangle.Width;
anchor.Y = anchor.Y * Rectangle.Height;
anchor.X = anchor.X * AbsoluteRectangle.Width;
anchor.Y = anchor.Y * AbsoluteRectangle.Height;
return new SKPoint(anchor.X, anchor.Y);
}
var position = PositionProperty.CurrentValue;
position.X = position.X * Rectangle.Width;
position.Y = position.Y * Rectangle.Height;
position.X = position.X * AbsoluteRectangle.Width;
position.Y = position.Y * AbsoluteRectangle.Height;
return new SKPoint(position.X + LayerShape.RenderRectangle.Left, position.Y + LayerShape.RenderRectangle.Top);
}
@@ -326,8 +326,8 @@ namespace Artemis.Core.Models.Profile
{
if (!Leds.Any())
{
Rectangle = SKRect.Empty;
AbsoluteRectangle = SKRect.Empty;
Rectangle = SKRect.Empty;
Path = new SKPath();
OnRenderPropertiesUpdated();
return;
@@ -339,8 +339,8 @@ namespace Artemis.Core.Models.Profile
var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.Right);
var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Bottom);
Rectangle = SKRect.Create(minX, minY, maxX - minX, maxY - minY);
AbsoluteRectangle = SKRect.Create(0, 0, maxX - minX, maxY - minY);
AbsoluteRectangle = SKRect.Create(minX, minY, maxX - minX, maxY - minY);
Rectangle = SKRect.Create(0, 0, maxX - minX, maxY - minY);
var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var artemisLed in Leds)
@@ -16,7 +16,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public override void CalculateRenderProperties()
{
RenderRectangle = GetUnscaledRectangle();
RenderPath = Layer.Path;
// Shape originates from the center so compensate the path for that
var renderPath = new SKPath(Layer.Path);
renderPath.Transform(SKMatrix.MakeTranslation(RenderRectangle.Left - Layer.Path.Bounds.Left, RenderRectangle.Top - Layer.Path.Bounds.Top));
RenderPath = renderPath;
}
public override void ApplyToEntity()
@@ -58,37 +58,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
return SKRect.Empty;
return SKRect.Create(
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
);
}
public void SetFromUnscaledAnchor(SKPoint anchor, TimeSpan? time)
{
if (!Layer.Leds.Any())
{
Layer.PositionProperty.SetCurrentValue(SKPoint.Empty, time);
Layer.SizeProperty.SetCurrentValue(SKSize.Empty, time);
return;
}
Layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
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();
}
public SKPoint GetUnscaledAnchor()
{
if (!Layer.Leds.Any())
return SKPoint.Empty;
return new SKPoint(
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)
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
);
}
}