Layer effects - WIP commit

Profile editor - Show brush icons at different parts in the editor
This commit is contained in:
SpoinkyNL committed 2020-06-10 00:20:43 +02:00
1 parent ac23d89f3e
commit f178c3d790
28 files changed
+618 -63

No files matched your search

+47 -14
View File
@@ -116,6 +116,11 @@ namespace Artemis.Core.Models.Profile
/// </summary>
public BaseLayerBrush LayerBrush { get; internal set; }
/// <summary>
/// The layer effect that will apply pre- and/or post-processing to the layer
/// </summary>
public BaseLayerEffect LayerEffect { get; set; }
public override string ToString()
{
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
@@ -150,6 +155,7 @@ namespace Artemis.Core.Models.Profile
General.ApplyToEntity();
Transform.ApplyToEntity();
LayerBrush?.BaseProperties.ApplyToEntity();
LayerEffect?.BaseProperties.ApplyToEntity();
// LEDs
LayerEntity.Leds.Clear();
@@ -220,22 +226,26 @@ namespace Artemis.Core.Models.Profile
General.Override(TimeSpan.Zero);
Transform.Override(TimeSpan.Zero);
LayerBrush.BaseProperties.Override(TimeSpan.Zero);
LayerEffect?.BaseProperties?.Override(TimeSpan.Zero);
}
else
{
General.Update(deltaTime);
Transform.Update(deltaTime);
LayerBrush.BaseProperties.Update(deltaTime);
LayerEffect?.BaseProperties?.Update(deltaTime);
}
LayerBrush.Update(deltaTime);
LayerEffect?.Update(deltaTime);
}
public void OverrideProgress(TimeSpan timeOverride)
{
General.Override(timeOverride);
Transform.Override(timeOverride);
LayerBrush?.BaseProperties.Override(timeOverride);
LayerBrush?.BaseProperties?.Override(timeOverride);
LayerEffect?.BaseProperties?.Override(timeOverride);
}
/// <inheritdoc />
@@ -256,22 +266,26 @@ namespace Artemis.Core.Models.Profile
paint.BlendMode = General.BlendMode.CurrentValue;
paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));
switch (General.FillType.CurrentValue)
{
case LayerFillType.Stretch:
StretchRender(canvas, canvasInfo, paint);
break;
case LayerFillType.Clip:
ClipRender(canvas, canvasInfo, paint);
break;
default:
throw new ArgumentOutOfRangeException();
}
LayerEffect?.PreProcess(canvas, canvasInfo, Path, paint);
if (!LayerBrush.SupportsTransformation)
SimpleRender(canvas, canvasInfo, paint);
else if (General.FillType.CurrentValue == LayerFillType.Stretch)
StretchRender(canvas, canvasInfo, paint);
else if (General.FillType.CurrentValue == LayerFillType.Clip)
ClipRender(canvas, canvasInfo, paint);
LayerEffect?.PostProcess(canvas, canvasInfo, Path, paint);
}
canvas.Restore();
}
private void SimpleRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
LayerBrush.InternalRender(canvas, canvasInfo, new SKPath(LayerShape.Path), paint);
}
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
@@ -295,7 +309,7 @@ namespace Artemis.Core.Models.Profile
private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
// Apply transformation
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
@@ -412,6 +426,7 @@ namespace Artemis.Core.Models.Profile
internal void Deactivate()
{
DeactivateLayerBrush();
DeactivateLayerEffect();
}
internal void DeactivateLayerBrush()
@@ -423,7 +438,19 @@ namespace Artemis.Core.Models.Profile
LayerBrush = null;
brush.Dispose();
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid && p.Path.StartsWith("LayerBrush."));
}
internal void DeactivateLayerEffect()
{
if (LayerEffect == null)
return;
var effect = LayerEffect;
LayerEffect = null;
effect.Dispose();
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == effect.PluginInfo.Guid && p.Path.StartsWith("LayerEffect."));
}
internal void PopulateLeds(ArtemisSurface surface)
@@ -451,6 +478,7 @@ namespace Artemis.Core.Models.Profile
public event EventHandler RenderPropertiesUpdated;
public event EventHandler ShapePropertiesUpdated;
public event EventHandler LayerBrushUpdated;
public event EventHandler LayerEffectUpdated;
private void OnRenderPropertiesUpdated()
{
@@ -467,6 +495,11 @@ namespace Artemis.Core.Models.Profile
LayerBrushUpdated?.Invoke(this, EventArgs.Empty);
}
internal void OnLayerEffectUpdated()
{
LayerEffectUpdated?.Invoke(this, EventArgs.Empty);
}
#endregion
}
@@ -0,0 +1,21 @@
using System;
using Artemis.Core.Plugins.LayerEffect;
namespace Artemis.Core.Models.Profile
{
/// <summary>
/// A reference to a <see cref="LayerEffectDescriptor" />
/// </summary>
public class LayerEffectReference
{
/// <summary>
/// The GUID of the plugin the effect descriptor resides in
/// </summary>
public Guid EffectPluginGuid { get; set; }
/// <summary>
/// The full type name of the effect descriptor
/// </summary>
public string EffectType { get; set; }
}
}
@@ -18,6 +18,9 @@ namespace Artemis.Core.Models.Profile
[PropertyDescription(Name = "Brush type", Description = "The type of brush to use for this layer")]
public LayerBrushReferenceLayerProperty BrushReference { get; set; }
[PropertyDescription(Name = "Effect type", Description = "The type of effect to use for this layer")]
public LayerEffectReferenceLayerProperty EffectReference { get; set; }
protected override void PopulateDefaults()
{
ShapeType.DefaultValue = LayerShapeType.Rectangle;
@@ -13,10 +13,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Attributes
/// The user-friendly description for this property, shown in the UI.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Whether to expand this property by default, this is useful for important parent properties.
/// </summary>
public bool ExpandByDefault { get; set; }
}
}
@@ -0,0 +1,22 @@
using Artemis.Core.Exceptions;
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <summary>
/// A special layer property used to configure the selected layer effect
/// </summary>
public class LayerEffectReferenceLayerProperty : LayerProperty<LayerEffectReference>
{
internal LayerEffectReferenceLayerProperty()
{
KeyframesSupported = false;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
throw new ArtemisCoreException("Layer effect references do not support keyframes.");
}
public static implicit operator LayerEffectReference(LayerEffectReferenceLayerProperty p) => p.CurrentValue;
}
}
@@ -8,6 +8,8 @@ using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
@@ -53,6 +55,16 @@ namespace Artemis.Core.Models.Profile
public PropertyGroupDescriptionAttribute GroupDescription { get; internal set; }
/// <summary>
/// The layer brush this property group belongs to
/// </summary>
public BaseLayerBrush LayerBrush { get; internal set; }
/// <summary>
/// The layer effect this property group belongs to
/// </summary>
public BaseLayerEffect LayerEffect { get; internal set; }
/// <summary>
/// Gets or sets whether the property is hidden in the UI
/// </summary>
@@ -158,6 +170,8 @@ namespace Artemis.Core.Models.Profile
instance.Parent = this;
instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription;
instance.LayerBrush = LayerBrush;
instance.LayerEffect = LayerEffect;
instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}.");
propertyInfo.SetValue(this, instance);