Implemented ellipse shape application

This commit is contained in:
SpoinkyNL committed 2019-12-17 22:42:17 +01:00
1 parent 94df1544c5
commit 8dc15f6894
11 files changed
+104 -54

No files matched your search

+3 -3
View File
@@ -39,6 +39,8 @@ namespace Artemis.Core.Models.Profile
Name = layerEntity.Name;
Order = layerEntity.Order;
_leds = new List<ArtemisLed>();
switch (layerEntity.ShapeEntity?.Type)
{
case ShapeEntityType.Ellipse:
@@ -59,8 +61,6 @@ namespace Artemis.Core.Models.Profile
default:
throw new ArgumentOutOfRangeException();
}
_leds = new List<ArtemisLed>();
}
internal LayerEntity LayerEntity { get; set; }
@@ -243,7 +243,7 @@ namespace Artemis.Core.Models.Profile
path.AddRect(artemisLed.AbsoluteRenderRectangle);
Path = path;
LayerShape.CalculateRenderProperties();
LayerShape?.CalculateRenderProperties();
OnRenderPropertiesUpdated();
}
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
@@ -6,6 +7,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
private SKPoint _position;
private SKSize _size;
protected LayerShape(Layer layer)
{
Layer = layer;
@@ -33,12 +37,28 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// <summary>
/// The position of the shape
/// </summary>
public SKPoint Position { get; set; }
public SKPoint Position
{
get => _position;
set
{
_position = value;
Layer.CalculateRenderProperties();
}
}
/// <summary>
/// The size of the shape
/// </summary>
public SKSize Size { get; set; }
public SKSize Size
{
get => _size;
set
{
_size = value;
Layer.CalculateRenderProperties();
}
}
/// <summary>
/// A render rectangle relative to the layer
@@ -56,11 +76,48 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
Layer.LayerEntity.ShapeEntity = new ShapeEntity
{
Anchor = new ShapePointEntity { X = Anchor.X, Y = Anchor.Y },
Position = new ShapePointEntity { X = Position.X, Y = Position.Y },
Anchor = new ShapePointEntity {X = Anchor.X, Y = Anchor.Y},
Position = new ShapePointEntity {X = Position.X, Y = Position.Y},
Width = Size.Width,
Height = Size.Height
};
}
/// <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())
{
Position = SKPoint.Empty;
Size = SKSize.Empty;
return;
}
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;
Position = new SKPoint((float) (100f / width * (rect.Left - x)) / 100f, (float) (100f / height * (rect.Top - y)) / 100f);
Size = new SKSize((float) (100f / width * rect.Width) / 100f, (float) (100f / height * rect.Height) / 100f);
}
public SKRect GetUnscaledRectangle()
{
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 SKRect.Create(
(float) (x + width * Position.X),
(float) (y + height * Position.Y),
(float) (width * Size.Width),
(float) (height * Size.Height)
);
}
}
}