using System;
using Artemis.Core.Models.Profile;
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
{
///
/// For internal use only, please use or or instead
///
public abstract class BaseLayerBrush : PropertyChangedBase, IDisposable
{
private LayerBrushType _brushType;
private LayerBrushConfigurationDialog _configurationDialog;
private LayerBrushDescriptor _descriptor;
private Layer _layer;
private bool _supportsTransformation = true;
///
/// Gets the layer this brush is applied to
///
public Layer Layer
{
get => _layer;
internal set => SetAndNotify(ref _layer, value);
}
///
/// Gets the descriptor of this brush
///
public LayerBrushDescriptor Descriptor
{
get => _descriptor;
internal set => SetAndNotify(ref _descriptor, value);
}
///
/// Gets or sets a configuration dialog complementing the regular properties
///
public LayerBrushConfigurationDialog ConfigurationDialog
{
get => _configurationDialog;
protected set => SetAndNotify(ref _configurationDialog, value);
}
///
/// Gets the type of layer brush
///
public LayerBrushType BrushType
{
get => _brushType;
internal set => SetAndNotify(ref _brushType, value);
}
///
/// Gets the plugin info that defined this brush
///
public PluginInfo PluginInfo => Descriptor.LayerBrushProvider.PluginInfo;
///
/// Gets a reference to the layer property group without knowing it's type
///
public virtual LayerPropertyGroup BaseProperties => null;
///
/// Gets or sets whether the brush supports transformations
/// Note: RGB.NET brushes can never be transformed and setting this to true will throw an exception
///
public bool SupportsTransformation
{
get => _supportsTransformation;
protected set
{
if (value && BrushType == LayerBrushType.RgbNet)
throw new ArtemisPluginException(PluginInfo, "An RGB.NET brush cannot support transformation");
_supportsTransformation = value;
}
}
///
public void Dispose()
{
DisableLayerBrush();
BaseProperties.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Called when the layer brush is activated
///
public abstract void EnableLayerBrush();
///
/// Called when the layer brush is deactivated
///
public abstract void DisableLayerBrush();
///
/// Called before rendering every frame, write your update logic here
///
/// Seconds passed since last update
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 and RgbNetLayerBrush outside the core
internal abstract void Initialize(IRenderElementService renderElementService);
internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
internal virtual void Dispose(bool disposing)
{
}
}
///
/// Describes the type of a layer brush
///
public enum LayerBrushType
{
///
/// A regular brush that users Artemis' SkiaSharp-based rendering engine
///
Regular,
///
/// An RGB.NET brush that uses RGB.NET's per-LED rendering engine.
///
RgbNet
}
}