mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Layer brushes - Make enable-disable process consistent with plugins
This commit is contained in:
1 parent
a1c2e4ad5a
commit
ee37c3b836
37 files changed
+325
-128
No files matched your search
@@ -408,6 +408,23 @@ namespace Artemis.Core.Models.Profile
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
internal void Deactivate()
|
||||
{
|
||||
DeactivateLayerBrush();
|
||||
}
|
||||
|
||||
internal void DeactivateLayerBrush()
|
||||
{
|
||||
if (LayerBrush == null)
|
||||
return;
|
||||
|
||||
var brush = LayerBrush;
|
||||
LayerBrush = null;
|
||||
brush.Dispose();
|
||||
|
||||
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
|
||||
}
|
||||
|
||||
internal void PopulateLeds(ArtemisSurface surface)
|
||||
{
|
||||
var leds = new List<ArtemisLed>();
|
||||
|
||||
@@ -129,7 +129,11 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!IsActivated) return;
|
||||
if (!IsActivated)
|
||||
return;
|
||||
|
||||
foreach (var layer in GetAllLayers())
|
||||
layer.Deactivate();
|
||||
|
||||
IsActivated = false;
|
||||
OnDeactivated();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisablePlugin()
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
// Does not happen with device providers, they require Artemis to restart
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerBrush
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to create one or more <see cref="LayerEffect" />s usable by profile layers.
|
||||
/// </summary>
|
||||
public class LayerEffectProvider : Plugin
|
||||
{
|
||||
public LayerEffectProvider(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,19 +30,18 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is activated
|
||||
/// </summary>
|
||||
protected abstract void EnablePlugin();
|
||||
public abstract void EnablePlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is deactivated
|
||||
/// Called when the plugin is deactivated or when Artemis shuts down
|
||||
/// </summary>
|
||||
protected abstract void DisablePlugin();
|
||||
public abstract void DisablePlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugins configuration window is opened from the UI. The UI will only attempt to open if
|
||||
@@ -53,18 +52,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when Artemis shuts down
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void SetEnabled(bool enable)
|
||||
{
|
||||
if (enable && !Enabled)
|
||||
|
||||
@@ -44,11 +44,16 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
/// Gets a reference to the layer property group without knowing it's type
|
||||
/// </summary>
|
||||
public virtual LayerPropertyGroup BaseProperties => null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when the brush is being removed from the layer
|
||||
/// Called when the layer brush is activated
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
public abstract void EnableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layer brush is deactivated
|
||||
/// </summary>
|
||||
public abstract void DisableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called before rendering every frame, write your update logic here
|
||||
@@ -67,6 +72,11 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
/// </summary>
|
||||
/// <returns>Your RGB.NET brush</returns>
|
||||
internal abstract IBrush InternalGetBrush();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisableLayerBrush();
|
||||
}
|
||||
}
|
||||
|
||||
public enum LayerBrushType
|
||||
|
||||
@@ -43,15 +43,5 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
{
|
||||
InitializeProperties(layerService);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerBrush
|
||||
{
|
||||
|
||||
@@ -39,18 +39,11 @@ namespace Artemis.Core.Plugins.LayerBrush
|
||||
internal set => _properties = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when all layer properties in this brush have been initialized
|
||||
/// </summary>
|
||||
protected virtual void OnPropertiesInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
internal void InitializeProperties(ILayerService layerService)
|
||||
{
|
||||
Properties = Activator.CreateInstance<T>();
|
||||
Properties.InitializeProperties(layerService, Layer, "LayerBrush.");
|
||||
OnPropertiesInitialized();
|
||||
EnableLayerBrush();
|
||||
PropertiesInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerEffect" /> instead
|
||||
/// </summary>
|
||||
public abstract class BaseLayerEffect : IDisposable
|
||||
{
|
||||
protected BaseLayerEffect(Layer layer, LayerEffectDescriptor descriptor)
|
||||
{
|
||||
Layer = layer;
|
||||
Descriptor = descriptor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the layer this brush is applied to
|
||||
/// </summary>
|
||||
public Layer Layer { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the descriptor of this brush
|
||||
/// </summary>
|
||||
public LayerEffectDescriptor Descriptor { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info that defined this brush
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the layer property group without knowing it's type
|
||||
/// </summary>
|
||||
public virtual LayerPropertyGroup BaseProperties => null;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the brush is being removed from the layer
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
|
||||
/// <summary>
|
||||
/// Called before rendering every frame, write your update logic here
|
||||
/// </summary>
|
||||
/// <param name="deltaTime"></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 LayerEffect<T> and RgbNetLayerEffect<T> outside the core
|
||||
internal abstract void Initialize(ILayerService layerService);
|
||||
|
||||
internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
|
||||
|
||||
/// <summary>
|
||||
/// Called when Artemis needs an instance of the RGB.NET brush you are implementing
|
||||
/// </summary>
|
||||
/// <returns>Your RGB.NET brush</returns>
|
||||
internal abstract IBrush InternalGetBrush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerEffect" /> instead
|
||||
/// </summary>
|
||||
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
|
||||
{
|
||||
private T _properties;
|
||||
|
||||
protected LayerEffect(Layer layer, LayerEffectDescriptor descriptor) : base(layer, descriptor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether all properties on this brush are initialized
|
||||
/// </summary>
|
||||
public bool PropertiesInitialized { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override LayerPropertyGroup BaseProperties => Properties;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the properties of this brush.
|
||||
/// </summary>
|
||||
public T Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
// I imagine a null reference here can be confusing, so lets throw an exception explaining what to do
|
||||
if (_properties == null)
|
||||
throw new ArtemisPluginException("Cannot access brush properties until OnPropertiesInitialized has been called");
|
||||
return _properties;
|
||||
}
|
||||
internal set => _properties = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when all layer properties in this brush have been initialized
|
||||
/// </summary>
|
||||
protected virtual void OnPropertiesInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
internal void InitializeProperties(ILayerService layerService)
|
||||
{
|
||||
Properties = Activator.CreateInstance<T>();
|
||||
Properties.InitializeProperties(layerService, Layer, "LayerEffect.");
|
||||
OnPropertiesInitialized();
|
||||
PropertiesInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
|
||||
/// and matches it's width and height.
|
||||
/// <para>Called during rendering or layer preview, in the order configured on the layer</para>
|
||||
/// </summary>
|
||||
/// <param name="canvas">The layer canvas</param>
|
||||
/// <param name="canvasInfo"></param>
|
||||
/// <param name="path">The path to be filled, represents the shape</param>
|
||||
/// <param name="paint">The paint to be used to fill the shape</param>
|
||||
public abstract void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
|
||||
|
||||
internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
|
||||
{
|
||||
// Move the canvas to the top-left of the render path
|
||||
canvas.Translate(path.Bounds.Left, path.Bounds.Top);
|
||||
// Pass the render path to the layer brush positioned at 0,0
|
||||
path.Transform(SKMatrix.MakeTranslation(path.Bounds.Left * -1, path.Bounds.Top * -1));
|
||||
|
||||
Render(canvas, canvasInfo, path, paint);
|
||||
}
|
||||
|
||||
internal override void Initialize(ILayerService layerService)
|
||||
{
|
||||
InitializeProperties(layerService);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
|
||||
public sealed override void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
|
||||
namespace Artemis.Core.Plugins.LayerEffect
|
||||
{
|
||||
public class LayerEffectDescriptor
|
||||
{
|
||||
internal LayerEffectDescriptor(string displayName, string description, string icon, Type layerEffectType, LayerEffectProvider layerEffectProvider)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Description = description;
|
||||
Icon = icon;
|
||||
LayerEffectType = layerEffectType;
|
||||
LayerEffectProvider = layerEffectProvider;
|
||||
}
|
||||
|
||||
public string DisplayName { get; }
|
||||
public string Description { get; }
|
||||
public string Icon { get; }
|
||||
public Type LayerEffectType { get; }
|
||||
public LayerEffectProvider LayerEffectProvider { get; }
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,5 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// <param name="layer">The layer to instantiate the brush for</param>
|
||||
/// <returns></returns>
|
||||
BaseLayerBrush InstantiateLayerBrush(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the layer brush from the provided layer and disposes it
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
void RemoveLayerBrush(Layer layer);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Ninject;
|
||||
@@ -40,8 +41,8 @@ namespace Artemis.Core.Services
|
||||
|
||||
public BaseLayerBrush InstantiateLayerBrush(Layer layer)
|
||||
{
|
||||
RemoveLayerBrush(layer);
|
||||
|
||||
layer.DeactivateLayerBrush();
|
||||
|
||||
var descriptorReference = layer.General.BrushReference?.CurrentValue;
|
||||
if (descriptorReference == null)
|
||||
return null;
|
||||
@@ -66,17 +67,5 @@ namespace Artemis.Core.Services
|
||||
layer.OnLayerBrushUpdated();
|
||||
return layer.LayerBrush;
|
||||
}
|
||||
|
||||
public void RemoveLayerBrush(Layer layer)
|
||||
{
|
||||
if (layer.LayerBrush == null)
|
||||
return;
|
||||
|
||||
var brush = layer.LayerBrush;
|
||||
layer.LayerBrush = null;
|
||||
brush.Dispose();
|
||||
|
||||
layer.LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user