using System; using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using SkiaSharp; namespace Artemis.Core.Plugins.LayerEffect.Abstract { /// /// For internal use only, please use instead /// public abstract class BaseLayerEffect : IDisposable { /// /// Gets the layer this effect is applied to /// public Layer Layer { get; internal set; } /// /// Gets the folder this effect is applied to /// public Folder Folder { get; internal set; } /// /// Gets the descriptor of this effect /// public LayerEffectDescriptor Descriptor { get; internal set; } /// /// Gets the plugin info that defined this effect /// public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo; /// /// Gets a reference to the layer property group without knowing it's type /// public virtual LayerPropertyGroup BaseProperties => null; public void Dispose() { DisableLayerEffect(); } /// /// Called when the layer brush is activated /// public abstract void EnableLayerEffect(); /// /// Called when the layer brush is deactivated /// public abstract void DisableLayerEffect(); /// /// Called before rendering every frame, write your update logic here /// /// public abstract void Update(double deltaTime); /// /// Called before the layer or folder will be rendered /// public abstract void PreProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint); /// /// Called after the layer of folder has been rendered /// public abstract void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint); internal void InternalPreProcess(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 effect positioned at 0,0 path.Transform(SKMatrix.MakeTranslation(path.Bounds.Left * -1, path.Bounds.Top * -1)); PreProcess(canvas, canvasInfo, path, paint); } internal void InternalPostProcess(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 effect positioned at 0,0 path.Transform(SKMatrix.MakeTranslation(path.Bounds.Left * -1, path.Bounds.Top * -1)); PostProcess(canvas, canvasInfo, path, paint); } // Not only is this needed to initialize properties on the layer effects, it also prevents implementing anything // but LayerEffect outside the core internal abstract void Initialize(ILayerService layerService); } }