Simplified the different properties used for layer/shape rendering

Cleaned up UI layer shape service
This commit is contained in:
SpoinkyNL committed 2020-01-31 00:02:01 +01:00
1 parent 0794966e38
commit f2df51d40c
17 files changed
+192 -284

No files matched your search

@@ -15,12 +15,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public override void CalculateRenderProperties()
{
var unscaled = GetUnscaledRectangle();
RenderRectangle = SKRect.Create(0,0 , unscaled.Width, unscaled.Height);
var path = new SKPath();
path.AddOval(RenderRectangle);
RenderPath = path;
path.AddOval(GetUnscaledRectangle());
Path = path;
}
internal override void ApplyToEntity()
@@ -15,12 +15,8 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public override void CalculateRenderProperties()
{
RenderRectangle = GetUnscaledRectangle();
// 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;
Path = new SKPath(Layer.Path);
}
internal override void ApplyToEntity()
@@ -1,12 +1,13 @@
using System.Linq;
using Artemis.Storage.Entities.Profile;
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
private SKPath _path;
protected LayerShape(Layer layer)
{
Layer = layer;
@@ -30,19 +31,27 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public SKRect ScaledRectangle { get; set; }
/// <summary>
/// An absolute and scaled render rectangle
/// A path outlining the shape
/// </summary>
public SKRect RenderRectangle { get; protected set; }
public SKPath Path
{
get => _path;
protected set
{
_path = value;
Bounds = value?.Bounds ?? SKRect.Empty;
}
}
/// <summary>
/// A path relative to the layer
/// The bounds of this shape
/// </summary>
public SKPath RenderPath { get; protected set; }
public SKRect Bounds { get; private set; }
public abstract void CalculateRenderProperties();
/// <summary>
/// Updates Position and Size using the provided unscaled rectangle
/// Updates Position and Size using the provided unscaled rectangle
/// </summary>
/// <param name="rect">An unscaled rectangle where 1px = 1mm</param>
public void SetFromUnscaledRectangle(SKRect rect)
@@ -54,10 +63,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
}
ScaledRectangle = SKRect.Create(
100f / Layer.AbsoluteRectangle.Width * (rect.Left - Layer.AbsoluteRectangle.Left) / 100f,
100f / Layer.AbsoluteRectangle.Height * (rect.Top - Layer.AbsoluteRectangle.Top) / 100f,
100f / Layer.AbsoluteRectangle.Width * rect.Width / 100f,
100f / Layer.AbsoluteRectangle.Height * rect.Height / 100f
100f / Layer.Bounds.Width * rect.Left / 100f,
100f / Layer.Bounds.Height * rect.Top / 100f,
100f / Layer.Bounds.Width * rect.Width / 100f,
100f / Layer.Bounds.Height * rect.Height / 100f
);
}
@@ -67,10 +76,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.Bounds.Width * ScaledRectangle.Left,
Layer.Bounds.Height * ScaledRectangle.Top,
Layer.Bounds.Width * ScaledRectangle.Width,
Layer.Bounds.Height * ScaledRectangle.Height
);
}
@@ -25,23 +25,14 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// </summary>
public List<SKPoint> RenderPoints
{
get
{
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
return Points.Select(p => new SKPoint((float) (p.X * width), (float) (p.Y * height))).ToList();
}
get { return Points.Select(p => new SKPoint(p.X * Layer.Bounds.Width, p.Y * Layer.Bounds.Height)).ToList(); }
}
public override void CalculateRenderProperties()
{
var path = new SKPath();
path.AddPoly(RenderPoints.ToArray());
RenderPath = path;
RenderRectangle = path.GetRect();
Path = path;
}
internal override void ApplyToEntity()
@@ -15,11 +15,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
public override void CalculateRenderProperties()
{
RenderRectangle = GetUnscaledRectangle();
var path = new SKPath();
path.AddRect(RenderRectangle);
RenderPath = path;
path.AddRect(GetUnscaledRectangle());
Path = path;
}
internal override void ApplyToEntity()