mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Added layer shapes, editor is still WIP
This commit is contained in:
1 parent
8ba43ecec1
commit
580db3185e
115 files changed
+1949
-1189
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
{
|
||||
public class Ellipse : LayerShape
|
||||
{
|
||||
public Ellipse(Layer layer) : base(layer)
|
||||
{
|
||||
}
|
||||
|
||||
internal Ellipse(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
|
||||
{
|
||||
}
|
||||
|
||||
public override void CalculateRenderProperties()
|
||||
{
|
||||
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 path = new SKPath();
|
||||
path.AddOval(rect);
|
||||
|
||||
RenderPath = path;
|
||||
RenderRectangle = path.GetRect();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Ellipse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
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()
|
||||
{
|
||||
RenderPath = Layer.Path;
|
||||
RenderRectangle = Layer.Path.GetRect();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Fill;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
{
|
||||
public abstract class LayerShape
|
||||
{
|
||||
protected LayerShape(Layer layer)
|
||||
{
|
||||
Layer = layer;
|
||||
|
||||
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
|
||||
}
|
||||
|
||||
private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)
|
||||
{
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
/// <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; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the shape
|
||||
/// </summary>
|
||||
public SKSize Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A render rectangle relative to the layer
|
||||
/// </summary>
|
||||
public SKRect RenderRectangle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// A path relative to the layer
|
||||
/// </summary>
|
||||
public SKPath RenderPath { get; protected set; }
|
||||
|
||||
public abstract void CalculateRenderProperties();
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList();
|
||||
|
||||
public override void CalculateRenderProperties()
|
||||
{
|
||||
var path = new SKPath();
|
||||
path.AddPoly(RenderPoints.ToArray());
|
||||
|
||||
RenderPath = path;
|
||||
RenderRectangle = path.GetRect();
|
||||
}
|
||||
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
{
|
||||
public class Rectangle : LayerShape
|
||||
{
|
||||
public Rectangle(Layer layer) : base(layer)
|
||||
{
|
||||
}
|
||||
|
||||
internal Rectangle(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
|
||||
{
|
||||
}
|
||||
|
||||
public override void CalculateRenderProperties()
|
||||
{
|
||||
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 path = new SKPath();
|
||||
path.AddRect(rect);
|
||||
|
||||
RenderPath = path;
|
||||
RenderRectangle = path.GetRect();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Rectangle;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user