mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Added layer properties to core and hooked it up with the UI
Implemented timeline caret scrolling logic Added special treeview style for the layer properties tree
This commit is contained in:
1 parent
8f438abe49
commit
a2efeb887a
48 files changed
+618
-381
No files matched your search
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
public sealed class Layer : ProfileElement
|
||||
{
|
||||
private readonly List<LayerProperty> _properties;
|
||||
private LayerShape _layerShape;
|
||||
private List<ArtemisLed> _leds;
|
||||
|
||||
@@ -27,6 +28,9 @@ namespace Artemis.Core.Models.Profile
|
||||
Name = name;
|
||||
|
||||
_leds = new List<ArtemisLed>();
|
||||
_properties = new List<LayerProperty>();
|
||||
|
||||
CreateDefaultProperties();
|
||||
}
|
||||
|
||||
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity)
|
||||
@@ -40,6 +44,10 @@ namespace Artemis.Core.Models.Profile
|
||||
Order = layerEntity.Order;
|
||||
|
||||
_leds = new List<ArtemisLed>();
|
||||
_properties = new List<LayerProperty>();
|
||||
|
||||
// TODO: Load properties from entity instead of creating the defaults
|
||||
CreateDefaultProperties();
|
||||
|
||||
switch (layerEntity.ShapeEntity?.Type)
|
||||
{
|
||||
@@ -89,7 +97,7 @@ namespace Artemis.Core.Models.Profile
|
||||
public SKPath Path { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the shape that is rendered by the <see cref="LayerBrush"/>.
|
||||
/// Defines the shape that is rendered by the <see cref="LayerBrush" />.
|
||||
/// </summary>
|
||||
public LayerShape LayerShape
|
||||
{
|
||||
@@ -103,7 +111,37 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The brush that will fill the <see cref="LayerShape"/>.
|
||||
/// A collection of all the properties on this layer
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<LayerProperty> Properties => _properties.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// The anchor point property of this layer, also found in <see cref="Properties" />
|
||||
/// </summary>
|
||||
public LayerProperty AnchorPointProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The position of this layer, also found in <see cref="Properties" />
|
||||
/// </summary>
|
||||
public LayerProperty PositionProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The scale property of this layer, also found in <see cref="Properties" />
|
||||
/// </summary>
|
||||
public LayerProperty ScaleProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The rotation property of this layer, also found in <see cref="Properties" />
|
||||
/// </summary>
|
||||
public LayerProperty RotationProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The opacity property of this layer, also found in <see cref="Properties" />
|
||||
/// </summary>
|
||||
public LayerProperty OpacityProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The brush that will fill the <see cref="LayerShape" />.
|
||||
/// </summary>
|
||||
public LayerBrush LayerBrush { get; internal set; }
|
||||
|
||||
@@ -121,7 +159,7 @@ namespace Artemis.Core.Models.Profile
|
||||
canvas.ClipPath(Path);
|
||||
// Placeholder
|
||||
if (LayerShape?.RenderPath != null)
|
||||
canvas.DrawPath(LayerShape.RenderPath, new SKPaint(){Color = new SKColor(255,0,0)});
|
||||
canvas.DrawPath(LayerShape.RenderPath, new SKPaint {Color = new SKColor(255, 0, 0)});
|
||||
LayerBrush?.Render(canvas);
|
||||
canvas.Restore();
|
||||
}
|
||||
@@ -134,6 +172,8 @@ namespace Artemis.Core.Models.Profile
|
||||
LayerEntity.Order = Order;
|
||||
LayerEntity.Name = Name;
|
||||
LayerEntity.ProfileId = Profile.EntityId;
|
||||
foreach (var layerProperty in Properties)
|
||||
layerProperty.ApplyToEntity();
|
||||
|
||||
// LEDs
|
||||
LayerEntity.Leds.Clear();
|
||||
@@ -251,6 +291,25 @@ namespace Artemis.Core.Models.Profile
|
||||
OnRenderPropertiesUpdated();
|
||||
}
|
||||
|
||||
private void CreateDefaultProperties()
|
||||
{
|
||||
var transformProperty = new LayerProperty(this, null, "Transform", "The default properties collection every layer has, allows you to transform the shape.", null);
|
||||
AnchorPointProperty = new LayerProperty(this, transformProperty, "Anchor Point", "The point at which the shape is attached to its position.", typeof(SKPoint));
|
||||
PositionProperty = new LayerProperty(this, transformProperty, "Position", "The position of the shape.", typeof(SKPoint));
|
||||
ScaleProperty = new LayerProperty(this, transformProperty, "Scale", "The scale of the shape.", typeof(SKSize));
|
||||
RotationProperty = new LayerProperty(this, transformProperty, "Rotation", "The rotation of the shape in degrees.", typeof(int));
|
||||
OpacityProperty = new LayerProperty(this, transformProperty, "Opacity", "The opacity of the shape from 0 to 1.", typeof(float));
|
||||
|
||||
transformProperty.Children.Add(AnchorPointProperty);
|
||||
transformProperty.Children.Add(PositionProperty);
|
||||
transformProperty.Children.Add(ScaleProperty);
|
||||
transformProperty.Children.Add(RotationProperty);
|
||||
transformProperty.Children.Add(OpacityProperty);
|
||||
|
||||
_properties.Add(transformProperty);
|
||||
_properties.AddRange(transformProperty.Children);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Exceptions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
public class LayerProperty
|
||||
{
|
||||
internal LayerProperty(Layer layer, LayerProperty parent)
|
||||
private object _baseValue;
|
||||
|
||||
internal LayerProperty(Layer layer, LayerProperty parent, string name, string description, Type type)
|
||||
{
|
||||
Layer = layer;
|
||||
Parent = parent;
|
||||
Name = name;
|
||||
Description = description;
|
||||
Type = type;
|
||||
|
||||
Children = new List<LayerProperty>();
|
||||
Keyframes = new List<Keyframe>();
|
||||
}
|
||||
|
||||
public Layer Layer { get; }
|
||||
@@ -20,7 +27,23 @@ namespace Artemis.Core.Models.Profile
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public object BaseValue { get; set; }
|
||||
|
||||
public object BaseValue
|
||||
{
|
||||
get => _baseValue;
|
||||
set
|
||||
{
|
||||
if (value != null && value.GetType() != Type)
|
||||
throw new ArtemisCoreException($"Cannot set value of type {value.GetType()} on property {Name}, expected type is {Type}.");
|
||||
_baseValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Keyframe> Keyframes { get; set; }
|
||||
|
||||
public void ApplyToEntity()
|
||||
{
|
||||
// Big o' TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
public Fill(Layer layer) : base(layer)
|
||||
{
|
||||
}
|
||||
|
||||
internal Fill(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
@@ -61,12 +60,12 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A render rectangle relative to the layer
|
||||
/// A render rectangle relative to the layer
|
||||
/// </summary>
|
||||
public SKRect RenderRectangle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// A path relative to the layer
|
||||
/// A path relative to the layer
|
||||
/// </summary>
|
||||
public SKPath RenderPath { get; protected set; }
|
||||
|
||||
@@ -84,7 +83,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
}
|
||||
|
||||
/// <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)
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
{
|
||||
public class Polygon : LayerShape
|
||||
{
|
||||
|
||||
public Polygon(Layer layer) : base(layer)
|
||||
{
|
||||
}
|
||||
@@ -39,7 +38,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Polygon;
|
||||
Layer.LayerEntity.ShapeEntity.Points = Points.Select(p => new ShapePointEntity { X = p.X, Y = p.Y }).ToList();
|
||||
Layer.LayerEntity.ShapeEntity.Points = Points.Select(p => new ShapePointEntity {X = p.X, Y = p.Y}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,5 @@ namespace Artemis.Core.Models.Profile
|
||||
child.Parent = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user