Removed separate shape size

This commit is contained in:
SpoinkyNL committed 2020-02-04 22:01:02 +01:00
1 parent 436994129a
commit 2c60a42315
34 files changed
+81 -862

No files matched your search

@@ -9,21 +9,16 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
internal Ellipse(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
var path = new SKPath();
path.AddOval(GetUnscaledRectangle());
path.AddOval(Layer.Bounds);
Path = path;
}
internal override void ApplyToEntity()
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Ellipse;
Layer.LayerEntity.ShapeType = ShapeEntityType.Ellipse;
}
}
}
@@ -1,28 +0,0 @@
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Fill : LayerShape
{
public Fill(Layer layer) : base(layer)
{
}
internal Fill(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
// Shape originates from the center so compensate the path for that
Path = new SKPath(Layer.Path);
}
internal override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Fill;
}
}
}
@@ -1,97 +1,26 @@
using System.Linq;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
private SKPath _path;
protected LayerShape(Layer layer)
{
Layer = layer;
}
protected LayerShape(Layer layer, ShapeEntity shapeEntity)
{
Layer = layer;
ScaledRectangle = SKRect.Create(shapeEntity.X, shapeEntity.Y, shapeEntity.Width, shapeEntity.Height);
}
/// <summary>
/// The layer this shape is attached to
/// </summary>
public Layer Layer { get; set; }
/// <summary>
/// A relative and scaled rectangle that defines where the shape is located in relation to the layer's size
/// <para>Note: scaled means a range of 0.0 to 1.0. 1.0 being full width/height, 0.5 being half</para>
/// </summary>
public SKRect ScaledRectangle { get; set; }
/// <summary>
/// A path outlining the shape
/// </summary>
public SKPath Path
{
get => _path;
protected set
{
_path = value;
Bounds = value?.Bounds ?? SKRect.Empty;
}
}
/// <summary>
/// The bounds of this shape
/// </summary>
public SKRect Bounds { get; private set; }
public SKPath Path { get; protected set; }
public abstract void CalculateRenderProperties();
/// <summary>
/// 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)
{
if (!Layer.Leds.Any())
{
ScaledRectangle = SKRect.Empty;
return;
}
ScaledRectangle = SKRect.Create(
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
);
}
public SKRect GetUnscaledRectangle()
{
if (!Layer.Leds.Any())
return SKRect.Empty;
return SKRect.Create(
Layer.Bounds.Width * ScaledRectangle.Left,
Layer.Bounds.Height * ScaledRectangle.Top,
Layer.Bounds.Width * ScaledRectangle.Width,
Layer.Bounds.Height * ScaledRectangle.Height
);
}
internal virtual void ApplyToEntity()
{
Layer.LayerEntity.ShapeEntity = new ShapeEntity
{
X = ScaledRectangle.Left,
Y = ScaledRectangle.Top,
Width = ScaledRectangle.Width,
Height = ScaledRectangle.Height
};
}
public abstract void ApplyToEntity();
}
}
@@ -1,45 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Polygon : LayerShape
{
public Polygon(Layer layer) : base(layer)
{
}
internal Polygon(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
/// <summary>
/// The points of this polygon
/// </summary>
public List<SKPoint> Points { get; set; }
/// <summary>
/// The points of this polygon where they need to be rendered inside the layer
/// </summary>
public List<SKPoint> RenderPoints
{
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());
Path = path;
}
internal override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Polygon;
Layer.LayerEntity.ShapeEntity.Points = Points.Select(p => new ShapePointEntity {X = p.X, Y = p.Y}).ToList();
}
}
}
@@ -9,21 +9,16 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
internal Rectangle(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
var path = new SKPath();
path.AddRect(GetUnscaledRectangle());
path.AddRect(Layer.Bounds);
Path = path;
}
internal override void ApplyToEntity()
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Rectangle;
Layer.LayerEntity.ShapeType = ShapeEntityType.Rectangle;
}
}
}