using System; using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.Abstract.ViewModels; 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 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 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; } } /// /// Gets or sets whether this plugin has a configuration view model. /// If set to true, will be called when the plugin is configured from the UI. /// public bool HasConfigurationViewModel { get; protected set; } 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); /// /// Called when the brush configuration window is opened from the UI. The UI will only attempt to open if /// is set to True. /// /// public virtual BrushConfigurationViewModel GetConfigurationViewModel() { return null; } // 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) { } } public enum LayerBrushType { Regular, RgbNet } }