Layers - Seperated activation and removal of layers/effects

Effects - Added effects UI, order is still a bit messed up and reordering is missed
Effects - Added renaming of effects on the layer
This commit is contained in:
SpoinkyNL committed 2020-06-13 22:23:33 +02:00
1 parent f917728ac8
commit b2ab142dbd
39 files changed
+691 -334

No files matched your search

+4
View File
@@ -26,6 +26,10 @@
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Fody" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="HidSharp" Version="2.1.0" />
<PackageReference Include="LiteDB" Version="5.0.8" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.3.0" />
+12 -1
View File
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
@@ -8,6 +10,8 @@ namespace Artemis.Core.Models.Profile
{
public sealed class Folder : ProfileElement
{
private readonly List<BaseLayerEffect> _layerEffects;
public Folder(Profile profile, ProfileElement parent, string name)
{
FolderEntity = new FolderEntity();
@@ -16,6 +20,7 @@ namespace Artemis.Core.Models.Profile
Profile = profile;
Parent = parent;
Name = name;
_layerEffects = new List<BaseLayerEffect>();
}
internal Folder(Profile profile, ProfileElement parent, FolderEntity folderEntity)
@@ -27,6 +32,7 @@ namespace Artemis.Core.Models.Profile
Parent = parent;
Name = folderEntity.Name;
Order = folderEntity.Order;
_layerEffects = new List<BaseLayerEffect>();
// TODO: Load conditions
@@ -45,6 +51,11 @@ namespace Artemis.Core.Models.Profile
internal FolderEntity FolderEntity { get; set; }
/// <summary>
/// Gets a read-only collection of the layer effects on this layer
/// </summary>
public ReadOnlyCollection<BaseLayerEffect> LayerEffects => _layerEffects.AsReadOnly();
public override void Update(double deltaTime)
{
// Iterate the children in reverse because that's how they must be rendered too
+112 -45
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Annotations;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
@@ -23,6 +24,7 @@ namespace Artemis.Core.Models.Profile
public sealed class Layer : ProfileElement
{
private readonly List<string> _expandedPropertyGroups;
private readonly List<BaseLayerEffect> _layerEffects;
private LayerShape _layerShape;
private List<ArtemisLed> _leds;
private SKPath _path;
@@ -38,6 +40,7 @@ namespace Artemis.Core.Models.Profile
General = new LayerGeneralProperties {IsCorePropertyGroup = true};
Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_layerEffects = new List<BaseLayerEffect>();
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
@@ -56,6 +59,7 @@ namespace Artemis.Core.Models.Profile
General = new LayerGeneralProperties {IsCorePropertyGroup = true};
Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_layerEffects = new List<BaseLayerEffect>();
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
_expandedPropertyGroups.AddRange(layerEntity.ExpandedPropertyGroups);
@@ -65,6 +69,11 @@ namespace Artemis.Core.Models.Profile
internal LayerEntity LayerEntity { get; set; }
/// <summary>
/// Gets a read-only collection of the layer effects on this layer
/// </summary>
public ReadOnlyCollection<BaseLayerEffect> LayerEffects => _layerEffects.AsReadOnly();
/// <summary>
/// A collection of all the LEDs this layer is assigned to.
/// </summary>
@@ -116,11 +125,6 @@ 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}";
@@ -155,7 +159,22 @@ namespace Artemis.Core.Models.Profile
General.ApplyToEntity();
Transform.ApplyToEntity();
LayerBrush?.BaseProperties.ApplyToEntity();
LayerEffect?.BaseProperties.ApplyToEntity();
// Effects
LayerEntity.LayerEffects.Clear();
foreach (var layerEffect in LayerEffects)
{
var layerEffectEntity = new LayerEffectEntity()
{
PluginGuid = layerEffect.PluginInfo.Guid,
EffectType = layerEffect.GetType().Name,
Name = layerEffect.Name,
HasBeenRenamed = layerEffect.HasBeenRenamed,
Order = layerEffect.Order
};
LayerEntity.LayerEffects.Add(layerEffectEntity);
layerEffect.BaseProperties.ApplyToEntity();
}
// LEDs
LayerEntity.Leds.Clear();
@@ -226,18 +245,21 @@ namespace Artemis.Core.Models.Profile
General.Override(TimeSpan.Zero);
Transform.Override(TimeSpan.Zero);
LayerBrush.BaseProperties.Override(TimeSpan.Zero);
LayerEffect?.BaseProperties?.Override(TimeSpan.Zero);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.BaseProperties?.Override(TimeSpan.Zero);
}
else
{
General.Update(deltaTime);
Transform.Update(deltaTime);
LayerBrush.BaseProperties.Update(deltaTime);
LayerEffect?.BaseProperties?.Update(deltaTime);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.BaseProperties?.Update(deltaTime);
}
LayerBrush.Update(deltaTime);
LayerEffect?.Update(deltaTime);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.Update(deltaTime);
}
public void OverrideProgress(TimeSpan timeOverride)
@@ -245,7 +267,8 @@ namespace Artemis.Core.Models.Profile
General.Override(timeOverride);
Transform.Override(timeOverride);
LayerBrush?.BaseProperties?.Override(timeOverride);
LayerEffect?.BaseProperties?.Override(timeOverride);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.BaseProperties?.Override(timeOverride);
}
/// <inheritdoc />
@@ -266,7 +289,8 @@ namespace Artemis.Core.Models.Profile
paint.BlendMode = General.BlendMode.CurrentValue;
paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));
LayerEffect?.PreProcess(canvas, canvasInfo, Path, paint);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.PreProcess(canvas, canvasInfo, Path, paint);
if (!LayerBrush.SupportsTransformation)
SimpleRender(canvas, canvasInfo, paint);
@@ -275,7 +299,8 @@ namespace Artemis.Core.Models.Profile
else if (General.FillType.CurrentValue == LayerFillType.Clip)
ClipRender(canvas, canvasInfo, paint);
LayerEffect?.PostProcess(canvas, canvasInfo, Path, paint);
foreach (var baseLayerEffect in LayerEffects)
baseLayerEffect.PostProcess(canvas, canvasInfo, Path, paint);
}
canvas.Restore();
@@ -382,6 +407,10 @@ namespace Artemis.Core.Models.Profile
#endregion
#region Effect management
#endregion
#region LED management
/// <summary>
@@ -423,36 +452,6 @@ namespace Artemis.Core.Models.Profile
CalculateRenderProperties();
}
internal void Deactivate()
{
DeactivateLayerBrush();
DeactivateLayerEffect();
}
internal void DeactivateLayerBrush()
{
if (LayerBrush == null)
return;
var brush = LayerBrush;
LayerBrush = null;
brush.Dispose();
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)
{
var leds = new List<ArtemisLed>();
@@ -473,12 +472,80 @@ namespace Artemis.Core.Models.Profile
#endregion
#region Activation
internal void Deactivate()
{
DeactivateLayerBrush();
var layerEffects = new List<BaseLayerEffect>(LayerEffects);
foreach (var baseLayerEffect in layerEffects)
DeactivateLayerEffect(baseLayerEffect);
}
private void DeactivateLayerBrush()
{
if (LayerBrush == null)
return;
var brush = LayerBrush;
LayerBrush = null;
brush.Dispose();
}
private void DeactivateLayerEffect([NotNull] BaseLayerEffect effect)
{
if (effect == null) throw new ArgumentNullException(nameof(effect));
// Remove the effect from the layer and dispose it
_layerEffects.Remove(effect);
effect.Dispose();
}
internal void RemoveLayerBrush()
{
if (LayerBrush == null)
return;
var brush = LayerBrush;
DeactivateLayerBrush();
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid && p.Path.StartsWith("LayerBrush."));
}
internal void RemoveLayerEffect([NotNull] BaseLayerEffect effect)
{
if (effect == null) throw new ArgumentNullException(nameof(effect));
DeactivateLayerEffect(effect);
// Clean up properties
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == effect.PluginInfo.Guid && p.Path.StartsWith(effect.PropertyRootPath));
// Update the order on the remaining effects
var index = 0;
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
{
baseLayerEffect.UpdateOrder(index + 1);
index++;
}
OnLayerEffectsUpdated();
}
internal void AddLayerEffect([NotNull] BaseLayerEffect effect)
{
if (effect == null) throw new ArgumentNullException(nameof(effect));
_layerEffects.Add(effect);
OnLayerEffectsUpdated();
}
#endregion
#region Events
public event EventHandler RenderPropertiesUpdated;
public event EventHandler ShapePropertiesUpdated;
public event EventHandler LayerBrushUpdated;
public event EventHandler LayerEffectUpdated;
public event EventHandler LayerEffectsUpdated;
private void OnRenderPropertiesUpdated()
{
@@ -495,9 +562,9 @@ namespace Artemis.Core.Models.Profile
LayerBrushUpdated?.Invoke(this, EventArgs.Empty);
}
internal void OnLayerEffectUpdated()
internal void OnLayerEffectsUpdated()
{
LayerEffectUpdated?.Invoke(this, EventArgs.Empty);
LayerEffectsUpdated?.Invoke(this, EventArgs.Empty);
}
#endregion
@@ -1,21 +0,0 @@
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; }
}
}
@@ -17,10 +17,7 @@ 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;
@@ -1,22 +0,0 @@
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;
}
}
@@ -233,7 +233,14 @@ namespace Artemis.Core.Models.Profile
private void InitializeProperty(Layer layer, string path, BaseLayerProperty instance)
{
var pluginGuid = IsCorePropertyGroup || instance.IsCoreProperty ? Constants.CorePluginInfo.Guid : layer.LayerBrush.PluginInfo.Guid;
Guid pluginGuid;
if (IsCorePropertyGroup || instance.IsCoreProperty)
pluginGuid = Constants.CorePluginInfo.Guid;
else if (instance.Parent.LayerBrush != null)
pluginGuid = instance.Parent.LayerBrush.PluginInfo.Guid;
else
pluginGuid = instance.Parent.LayerEffect.PluginInfo.Guid;
var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
var fromStorage = true;
if (entity == null)
@@ -273,5 +280,20 @@ namespace Artemis.Core.Models.Profile
}
#endregion
public void UpdateOrder(int oldOrder)
{
// Expanded state is tied to the path so save it before changing the path
var expanded = Layer.IsPropertyGroupExpanded(this);
Layer.SetPropertyGroupExpanded(this, false);
Path = Path.Replace($"LayerEffect.{oldOrder}.", $"LayerEffect.{LayerEffect.Order}.");
// Restore the expanded state with the new path
Layer.SetPropertyGroupExpanded(this, expanded);
// Update children
foreach (var layerPropertyGroup in LayerPropertyGroups)
layerPropertyGroup.UpdateOrder(oldOrder);
}
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerBrush;
@@ -17,6 +18,7 @@ namespace Artemis.Core.Plugins.Abstract
protected LayerBrushProvider()
{
_layerBrushDescriptors = new List<LayerBrushDescriptor>();
PluginDisabled += OnPluginDisabled;
}
/// <summary>
@@ -42,5 +44,10 @@ namespace Artemis.Core.Plugins.Abstract
_layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
}
private void OnPluginDisabled(object sender, EventArgs e)
{
_layerBrushDescriptors.Clear();
}
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerEffect;
@@ -17,6 +18,7 @@ namespace Artemis.Core.Plugins.Abstract
protected LayerEffectProvider()
{
_layerEffectDescriptors = new List<LayerEffectDescriptor>();
PluginDisabled += OnPluginDisabled;
}
/// <summary>
@@ -42,5 +44,10 @@ namespace Artemis.Core.Plugins.Abstract
_layerEffectDescriptors.Add(new LayerEffectDescriptor(displayName, description, icon, typeof(T), this));
}
private void OnPluginDisabled(object sender, EventArgs e)
{
_layerEffectDescriptors.Clear();
}
}
}
@@ -4,13 +4,14 @@ using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using SkiaSharp;
using Stylet;
namespace Artemis.Core.Plugins.LayerBrush.Abstract
{
/// <summary>
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead
/// </summary>
public abstract class BaseLayerBrush : IDisposable
public abstract class BaseLayerBrush : PropertyChangedBase, IDisposable
{
private bool _supportsTransformation = true;
@@ -48,7 +49,7 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
get => _supportsTransformation;
protected set
{
if (BrushType == LayerBrushType.RgbNet)
if (value && BrushType == LayerBrushType.RgbNet)
throw new ArtemisPluginException(PluginInfo, "An RGB.NET brush cannot support transformation");
_supportsTransformation = value;
}
@@ -3,13 +3,14 @@ using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using SkiaSharp;
using Stylet;
namespace Artemis.Core.Plugins.LayerEffect.Abstract
{
/// <summary>
/// For internal use only, please use <see cref="LayerEffect" /> instead
/// </summary>
public abstract class BaseLayerEffect : IDisposable
public abstract class BaseLayerEffect : PropertyChangedBase, IDisposable
{
/// <summary>
/// Gets the layer this effect is applied to
@@ -21,6 +22,22 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
/// </summary>
public Folder Folder { get; internal set; }
/// <summary>
/// The name which appears in the editor
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets whether the effect has been renamed by the user, if true consider refraining from changing the name
/// programatically
/// </summary>
public bool HasBeenRenamed { get; set; }
/// <summary>
/// Gets the order in which this effect appears in the update loop and editor
/// </summary>
public int Order { get; internal set; }
/// <summary>
/// Gets the descriptor of this effect
/// </summary>
@@ -36,6 +53,8 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
/// </summary>
public virtual LayerPropertyGroup BaseProperties => null;
internal string PropertyRootPath => $"LayerEffect.{Order}.{GetType().Name}.";
public void Dispose()
{
DisableLayerEffect();
@@ -67,6 +86,16 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
/// </summary>
public abstract void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
public void UpdateOrder(int newOrder)
{
if (newOrder == Order)
return;
var oldOrder = Order;
Order = newOrder;
BaseProperties.UpdateOrder(oldOrder);
}
internal void InternalPreProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
{
// Move the canvas to the top-left of the render path
@@ -39,7 +39,7 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
{
Properties = Activator.CreateInstance<T>();
Properties.LayerEffect = this;
Properties.InitializeProperties(layerService, Layer, "LayerEffect.");
Properties.InitializeProperties(layerService, Layer, PropertyRootPath);
PropertiesInitialized = true;
EnableLayerEffect();
@@ -3,13 +3,14 @@ using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Services.Interfaces
{
public interface ILayerService : IArtemisService
{
/// <summary>
/// Creates a new layer
/// Creates a new layer
/// </summary>
/// <param name="profile"></param>
/// <param name="parent"></param>
@@ -28,11 +29,20 @@ namespace Artemis.Core.Services.Interfaces
/// <summary>
/// Instantiates and adds the <see cref="BaseLayerEffect" /> described by the provided
/// <see cref="LayerEffectDescriptor" />
/// to the <see cref="Layer" />.
/// <see cref="LayerEffectDescriptor" /> to the <see cref="Layer" />.
/// </summary>
/// <param name="layer">The layer to instantiate the effect for</param>
void InstantiateLayerEffects(Layer layer);
/// <summary>
/// Adds the <see cref="BaseLayerEffect" /> described by the provided <see cref="LayerEffectDescriptor" /> to the
/// <see cref="Layer" />.
/// </summary>
/// <param name="layer">The layer to instantiate the effect for</param>
/// <param name="layerEffectDescriptor"></param>
/// <returns></returns>
BaseLayerEffect InstantiateLayerEffect(Layer layer);
BaseLayerEffect AddLayerEffect(Layer layer, LayerEffectDescriptor layerEffectDescriptor);
void RemoveLayerEffect(BaseLayerEffect layerEffect);
}
}
+52 -21
View File
@@ -1,13 +1,17 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Documents;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
using Ninject;
using Ninject.Injection;
using Ninject.Parameters;
using Serilog;
@@ -37,14 +41,15 @@ namespace Artemis.Core.Services
// With the properties loaded, the layer brush and effect can be instantiated
InstantiateLayerBrush(layer);
InstantiateLayerEffect(layer);
InstantiateLayerEffects(layer);
return layer;
}
public BaseLayerBrush InstantiateLayerBrush(Layer layer)
{
layer.DeactivateLayerBrush();
if (layer.LayerBrush != null)
throw new ArtemisCoreException("Layer already has an instantiated layer brush");
var descriptorReference = layer.General.BrushReference?.CurrentValue;
if (descriptorReference == null)
@@ -58,46 +63,72 @@ namespace Artemis.Core.Services
if (descriptor == null)
return null;
var brush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType);
brush.Layer = layer;
brush.Descriptor = descriptor;
layer.LayerBrush = brush;
brush.Initialize(this);
brush.Update(0);
layer.LayerBrush = brush;
layer.OnLayerBrushUpdated();
return brush;
}
public BaseLayerEffect InstantiateLayerEffect(Layer layer)
public void InstantiateLayerEffects(Layer layer)
{
layer.DeactivateLayerEffect();
if (layer.LayerEffects.Any())
throw new ArtemisCoreException("Layer already has instantiated layer effects");
var descriptorReference = layer.General.EffectReference?.CurrentValue;
if (descriptorReference == null)
return null;
foreach (var layerEntityLayerEffect in layer.LayerEntity.LayerEffects.OrderByDescending(e => e.Order))
{
// Get a matching descriptor
var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>();
var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList();
var descriptor = descriptors.FirstOrDefault(d => d.LayerEffectProvider.PluginInfo.Guid == layerEntityLayerEffect.PluginGuid &&
d.LayerEffectType.Name == layerEntityLayerEffect.EffectType);
// Get a matching descriptor
var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>();
var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList();
var descriptor = descriptors.FirstOrDefault(d => d.LayerEffectProvider.PluginInfo.Guid == descriptorReference.EffectPluginGuid &&
d.LayerEffectType.Name == descriptorReference.EffectType);
if (descriptor == null)
continue;
if (descriptor == null)
return null;
var effect = (BaseLayerEffect) _kernel.Get(descriptor.LayerEffectType);
effect.Layer = layer;
effect.Order = layerEntityLayerEffect.Order;
effect.Name = layerEntityLayerEffect.Name;
effect.Descriptor = descriptor;
effect.Initialize(this);
effect.Update(0);
var effect = (BaseLayerEffect)_kernel.Get(descriptor.LayerEffectType);
layer.AddLayerEffect(effect);
_logger.Debug("Added layer effect with root path {rootPath}", effect.PropertyRootPath);
}
layer.OnLayerEffectsUpdated();
}
public BaseLayerEffect AddLayerEffect(Layer layer, LayerEffectDescriptor layerEffectDescriptor)
{
var effect = (BaseLayerEffect) _kernel.Get(layerEffectDescriptor.LayerEffectType);
effect.Layer = layer;
effect.Descriptor = descriptor;
layer.LayerEffect = effect;
effect.Order = layer.LayerEffects.Count + 1;
effect.Descriptor = layerEffectDescriptor;
effect.Initialize(this);
effect.Update(0);
layer.OnLayerEffectUpdated();
layer.AddLayerEffect(effect);
_logger.Debug("Added layer effect with root path {rootPath}", effect.PropertyRootPath);
layer.OnLayerEffectsUpdated();
return effect;
}
public void RemoveLayerEffect(BaseLayerEffect layerEffect)
{
// // Make sure the group is collapsed or the effect that gets this effect's order gets expanded
// layerEffect.Layer.SetPropertyGroupExpanded(layerEffect.BaseProperties, false);
layerEffect.Layer.RemoveLayerEffect(layerEffect);
}
}
}
@@ -179,10 +179,8 @@ namespace Artemis.Core.Services.Storage
// Only instantiate brushes for layers without an existing brush/effect instance
foreach (var layer in profile.GetAllLayers())
{
if (layer.LayerBrush == null)
_layerService.InstantiateLayerBrush(layer);
if (layer.LayerEffect == null)
_layerService.InstantiateLayerEffect(layer);
_layerService.InstantiateLayerBrush(layer);
_layerService.InstantiateLayerEffects(layer);
}
}