Started work on the keyframe engine to tie everything together!

This commit is contained in:
Robert committed 2020-01-08 14:35:29 +01:00
1 parent 7a3b5dec3e
commit acdb90897e
28 files changed
+339 -107

No files matched your search

@@ -13,11 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
public override void CalculateRenderProperties()
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{
var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height);
var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
var path = new SKPath();
path.AddOval(rect);
@@ -1,4 +1,5 @@
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
@@ -12,8 +13,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
public override void CalculateRenderProperties()
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{
// TODO: Scale the path? Not sure if desirable
RenderPath = Layer.Path;
RenderRectangle = Layer.Path.GetRect();
}
@@ -6,9 +6,6 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
private SKPoint _position;
private SKSize _size;
protected LayerShape(Layer layer)
{
Layer = layer;
@@ -17,48 +14,13 @@ namespace Artemis.Core.Models.Profile.LayerShapes
protected LayerShape(Layer layer, ShapeEntity shapeEntity)
{
Layer = layer;
Anchor = new SKPoint(shapeEntity.Anchor?.X ?? 0, shapeEntity.Anchor?.Y ?? 0);
Position = new SKPoint(shapeEntity.Position?.X ?? 0, shapeEntity.Position?.Y ?? 0);
Size = new SKSize(shapeEntity.Width, shapeEntity.Height);
}
/// <summary>
/// The layer this shape is attached to
/// </summary>
public Layer Layer { get; set; }
/// <summary>
/// At which position the shape is attached to the layer
/// </summary>
public SKPoint Anchor { get; set; }
/// <summary>
/// The position of the shape
/// </summary>
public SKPoint Position
{
get => _position;
set
{
_position = value;
Layer.CalculateRenderProperties();
}
}
/// <summary>
/// The size of the shape
/// </summary>
public SKSize Size
{
get => _size;
set
{
_size = value;
Layer.CalculateRenderProperties();
}
}
/// <summary>
/// A render rectangle relative to the layer
/// </summary>
@@ -69,17 +31,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// </summary>
public SKPath RenderPath { get; protected set; }
public abstract void CalculateRenderProperties();
public abstract void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize);
public virtual void ApplyToEntity()
{
Layer.LayerEntity.ShapeEntity = new ShapeEntity
{
Anchor = new ShapePointEntity {X = Anchor.X, Y = Anchor.Y},
Position = new ShapePointEntity {X = Position.X, Y = Position.Y},
Width = Size.Width,
Height = Size.Height
};
Layer.LayerEntity.ShapeEntity = new ShapeEntity();
}
/// <summary>
@@ -90,8 +46,8 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
if (!Layer.Leds.Any())
{
Position = SKPoint.Empty;
Size = SKSize.Empty;
Layer.PositionProperty.Value = SKPoint.Empty;
Layer.SizeProperty.Value = SKSize.Empty;
return;
}
@@ -100,8 +56,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
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);
Layer.PositionProperty.Value = new SKPoint((float) (100f / width * (rect.Left - x)) / 100f, (float) (100f / height * (rect.Top - y)) / 100f);
Layer.SizeProperty.Value = new SKSize((float) (100f / width * rect.Width) / 100f, (float) (100f / height * rect.Height) / 100f);
// TODO: Update keyframes
CalculateRenderProperties(Layer.PositionProperty.Value, Layer.SizeProperty.Value);
}
public SKRect GetUnscaledRectangle()
@@ -115,10 +74,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
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)
(float) (x + width * Layer.PositionProperty.Value.X),
(float) (y + height * Layer.PositionProperty.Value.Y),
(float) (width * Layer.SizeProperty.Value.Width),
(float) (height * Layer.SizeProperty.Value.Height)
);
}
}
@@ -25,7 +25,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// </summary>
public List<SKPoint> RenderPoints => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList();
public override void CalculateRenderProperties()
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{
var path = new SKPath();
path.AddPoly(RenderPoints.ToArray());
@@ -13,11 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
public override void CalculateRenderProperties()
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{
var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height);
var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
var path = new SKPath();
path.AddRect(rect);
path.Transform(SKMatrix.MakeTranslation(Layer.Rectangle.Left, Layer.Rectangle.Top));