Plugins - Removed plugin info from constructor

This commit is contained in:
SpoinkyNL committed 2020-06-07 21:51:56 +02:00
1 parent 33bb3ffa6c
commit 1d35a02d5b
49 files changed
+305 -390

No files matched your search

@@ -1,25 +1,16 @@
using System;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using RGB.NET.Core;
using RGB.NET.Groups;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush
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
{
protected BaseLayerBrush(Layer layer, LayerBrushDescriptor descriptor)
{
Layer = layer;
Descriptor = descriptor;
}
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
@@ -45,6 +36,14 @@ namespace Artemis.Core.Plugins.LayerBrush
/// </summary>
public virtual LayerPropertyGroup BaseProperties => null;
public void Dispose()
{
DisableLayerBrush();
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Called when the layer brush is activated
/// </summary>
@@ -67,15 +66,8 @@ namespace Artemis.Core.Plugins.LayerBrush
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();
public void Dispose()
internal virtual void Dispose(bool disposing)
{
DisableLayerBrush();
}
}
@@ -1,14 +1,12 @@
using System;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile;
using Artemis.Core.Services.Interfaces;
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush
namespace Artemis.Core.Plugins.LayerBrush.Abstract
{
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
protected LayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
protected LayerBrush()
{
BrushType = LayerBrushType.Regular;
}
@@ -23,7 +21,7 @@ namespace Artemis.Core.Plugins.LayerBrush
/// <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
@@ -34,11 +32,6 @@ namespace Artemis.Core.Plugins.LayerBrush
Render(canvas, canvasInfo, path, paint);
}
internal override IBrush InternalGetBrush()
{
throw new NotImplementedException("Regular layer brushes do not implement InternalGetBrush");
}
internal override void Initialize(ILayerService layerService)
{
InitializeProperties(layerService);
@@ -3,7 +3,7 @@ using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Plugins.LayerBrush
namespace Artemis.Core.Plugins.LayerBrush.Abstract
{
/// <summary>
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead
@@ -12,10 +12,6 @@ namespace Artemis.Core.Plugins.LayerBrush
{
private T _properties;
protected PropertiesLayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{
}
/// <summary>
/// Gets whether all properties on this brush are initialized
/// </summary>
@@ -43,8 +39,9 @@ namespace Artemis.Core.Plugins.LayerBrush
{
Properties = Activator.CreateInstance<T>();
Properties.InitializeProperties(layerService, Layer, "LayerBrush.");
EnableLayerBrush();
PropertiesInitialized = true;
EnableLayerBrush();
}
}
}
@@ -6,43 +6,26 @@ using RGB.NET.Core;
using RGB.NET.Groups;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush
namespace Artemis.Core.Plugins.LayerBrush.Abstract
{
public abstract class RgbNetLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
protected RgbNetLayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
protected RgbNetLayerBrush()
{
BrushType = LayerBrushType.RgbNet;
LedGroup = new ListLedGroup();
Layer = layer;
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
}
/// <summary>
/// The LED group this layer brush is applied to
/// The LED group this layer effect is applied to
/// </summary>
public ListLedGroup LedGroup { get; internal set; }
/// <summary>
/// Called when Artemis needs an instance of the RGB.NET brush you are implementing
/// Called when Artemis needs an instance of the RGB.NET effect you are implementing
/// </summary>
/// <returns>Your RGB.NET brush</returns>
/// <returns>Your RGB.NET effect</returns>
public abstract IBrush GetBrush();
public sealed override void Dispose()
{
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
LedGroup.Detach();
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
}
internal void UpdateLedGroup()
{
// TODO: This simply renders it on top of the rest, get a ZIndex based on layer position
@@ -57,19 +40,28 @@ namespace Artemis.Core.Plugins.LayerBrush
internal override void Initialize(ILayerService layerService)
{
LedGroup = new ListLedGroup();
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties(layerService);
UpdateLedGroup();
}
// Not used in this brush type
internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
internal override void Dispose(bool disposing)
{
throw new NotImplementedException("RGB.NET layer brushes do not implement InternalRender");
if (disposing)
{
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
LedGroup.Detach();
}
base.Dispose(disposing);
}
internal override IBrush InternalGetBrush()
// Not used in this effect type
internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
{
return GetBrush();
throw new NotImplementedException("RGB.NET layer effectes do not implement InternalRender");
}
private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)