Profiles - Toggle brushes & effects when elements start/stop rendering

This commit is contained in:
Robert committed 2021-04-10 22:03:17 +02:00
1 parent 992657b0c5
commit 8ca173a119
20 files changed
+265 -86

No files matched your search

@@ -82,6 +82,11 @@ namespace Artemis.Core.LayerBrushes
/// </summary>
public virtual ILayerBrushPreset? DefaultPreset => Presets?.FirstOrDefault();
/// <summary>
/// Gets a boolean indicating whether the layer brush is enabled or not
/// </summary>
public bool Enabled { get; private set; }
/// <summary>
/// Gets or sets whether the brush supports transformations
/// <para>Note: RGB.NET brushes can never be transformed and setting this to true will throw an exception</para>
@@ -113,14 +118,6 @@ namespace Artemis.Core.LayerBrushes
/// <param name="deltaTime">Seconds passed since last update</param>
public abstract void Update(double deltaTime);
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
internal abstract void Initialize();
internal abstract void InternalRender(SKCanvas canvas, SKRect path, SKPaint paint);
#region IDisposable
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
@@ -137,14 +134,42 @@ namespace Artemis.Core.LayerBrushes
}
}
/// <summary>
/// Enables the layer brush if it isn't already enabled
/// </summary>
internal void InternalEnable()
{
if (Enabled)
return;
EnableLayerBrush();
Enabled = true;
}
/// <summary>
/// Disables the layer brush if it isn't already disabled
/// </summary>
internal void InternalDisable()
{
if (!Enabled)
return;
DisableLayerBrush();
Enabled = false;
}
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
internal abstract void Initialize();
internal abstract void InternalRender(SKCanvas canvas, SKRect path, SKPaint paint);
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
/// <summary>
@@ -71,6 +71,9 @@ namespace Artemis.Core.LayerBrushes
layer.LayerBrush = brush;
layer.OnLayerBrushUpdated();
if (layer.ShouldBeEnabled)
brush.InternalEnable();
}
}
}
@@ -11,7 +11,7 @@ namespace Artemis.Core.LayerEffects
{
private ILayerEffectConfigurationDialog? _configurationDialog;
private LayerEffectDescriptor _descriptor;
private bool _enabled;
private bool _suspended;
private Guid _entityId;
private bool _hasBeenRenamed;
private string _name;
@@ -55,12 +55,12 @@ namespace Artemis.Core.LayerEffects
}
/// <summary>
/// Gets or sets the enabled state, if not enabled the effect is skipped in render and update
/// Gets or sets the suspended state, if suspended the effect is skipped in render and update
/// </summary>
public bool Enabled
public bool Suspended
{
get => _enabled;
set => SetAndNotify(ref _enabled, value);
get => _suspended;
set => SetAndNotify(ref _suspended, value);
}
/// <summary>
@@ -112,6 +112,11 @@ namespace Artemis.Core.LayerEffects
internal string PropertyRootPath => $"LayerEffect.{EntityId}.{GetType().Name}.";
/// <summary>
/// Gets a boolean indicating whether the layer effect is enabled or not
/// </summary>
public bool Enabled { get; private set; }
#region IDisposable
/// <summary>
@@ -176,5 +181,29 @@ namespace Artemis.Core.LayerEffects
internal abstract void Initialize();
internal virtual string GetEffectTypeName() => GetType().Name;
/// <summary>
/// Enables the layer effect if it isn't already enabled
/// </summary>
internal void InternalEnable()
{
if (Enabled)
return;
EnableLayerEffect();
Enabled = true;
}
/// <summary>
/// Disables the layer effect if it isn't already disabled
/// </summary>
internal void InternalDisable()
{
if (!Enabled)
return;
DisableLayerEffect();
Enabled = false;
}
}
}
@@ -74,7 +74,7 @@ namespace Artemis.Core.LayerEffects
effect.EntityId = entity.Id;
effect.Order = entity.Order;
effect.Name = entity.Name;
effect.Enabled = entity.Enabled;
effect.Suspended = entity.Suspended;
effect.Descriptor = this;
effect.Initialize();
@@ -94,6 +94,9 @@ namespace Artemis.Core.LayerEffects
};
effect.Initialize();
renderElement.ActivateLayerEffect(effect);
if (renderElement.ShouldBeEnabled)
effect.InternalEnable();
}
}
}
@@ -16,7 +16,7 @@ namespace Artemis.Core.LayerEffects.Placeholder
EntityId = OriginalEntity.Id;
Order = OriginalEntity.Order;
Name = OriginalEntity.Name;
Enabled = OriginalEntity.Enabled;
Suspended = OriginalEntity.Suspended;
HasBeenRenamed = OriginalEntity.HasBeenRenamed;
}