From ee37c3b836e90fe074bf29f4376bdefcd56987eb Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 7 Jun 2020 15:00:40 +0200 Subject: [PATCH] Layer brushes - Make enable-disable process consistent with plugins --- src/Artemis.Core/Models/Profile/Layer.cs | 17 ++++ src/Artemis.Core/Models/Profile/Profile.cs | 6 +- .../Plugins/Abstract/DeviceProvider.cs | 2 +- .../LayerBrushProvider.cs | 4 +- .../Plugins/Abstract/LayerEffectProvider.cs | 28 ++++++ src/Artemis.Core/Plugins/Abstract/Plugin.cs | 22 +---- .../Plugins/LayerBrush/BaseLayerBrush.cs | 16 +++- .../Plugins/LayerBrush/LayerBrush.cs | 10 -- .../LayerBrush/LayerBrushDescriptor.cs | 1 + .../LayerBrush/PropertiesLayerBrush.cs | 9 +- .../Plugins/LayerEffect/BaseLayerEffect.cs | 64 +++++++++++++ .../Plugins/LayerEffect/LayerEffect.cs | 95 +++++++++++++++++++ .../LayerEffect/LayerEffectDescriptor.cs | 23 +++++ .../Services/Interfaces/ILayerService.cs | 6 -- src/Artemis.Core/Services/LayerService.cs | 17 +--- .../BrushPropertyInputViewModel.cs | 1 + .../AsusDeviceProvider.cs | 2 +- .../CoolerMasterDeviceProvider.cs | 2 +- .../CorsairDeviceProvider.cs | 2 +- .../DMXDeviceProvider.cs | 2 +- .../LogitechDeviceProvider.cs | 2 +- .../MsiDeviceProvider.cs | 2 +- .../NovationDeviceProvider.cs | 2 +- .../RazerDeviceProvider.cs | 2 +- .../RoccatDeviceProvider.cs | 2 +- .../SteelSeriesDeviceProvider.cs | 2 +- .../WS281XDeviceProvider.cs | 4 +- .../WootingDeviceProvider.cs | 4 +- .../ColorBrush.cs | 33 +++---- .../ColorBrushProperties.cs | 3 +- .../ColorBrushProvider.cs | 7 +- .../RgbNetColorBrush.cs | 11 ++- .../RgbNetColorBrushProvider.cs | 6 +- .../NoiseBrush.cs | 30 +++--- .../NoiseBrushProperties.cs | 3 +- .../NoiseBrushProvider.cs | 7 +- .../GeneralModule.cs | 4 +- 37 files changed, 325 insertions(+), 128 deletions(-) rename src/Artemis.Core/Plugins/{LayerBrush => Abstract}/LayerBrushProvider.cs (92%) create mode 100644 src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs create mode 100644 src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs create mode 100644 src/Artemis.Core/Plugins/LayerEffect/LayerEffect.cs create mode 100644 src/Artemis.Core/Plugins/LayerEffect/LayerEffectDescriptor.cs diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index b5706b9e3..8820917a6 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -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(); diff --git a/src/Artemis.Core/Models/Profile/Profile.cs b/src/Artemis.Core/Models/Profile/Profile.cs index 2302fc436..e3e84284b 100644 --- a/src/Artemis.Core/Models/Profile/Profile.cs +++ b/src/Artemis.Core/Models/Profile/Profile.cs @@ -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(); diff --git a/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs b/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs index 8226b0cad..e9c5ac250 100644 --- a/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs +++ b/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs @@ -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 } diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs b/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs similarity index 92% rename from src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs rename to src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs index 53f505f7a..1256127bf 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs +++ b/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs @@ -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 { /// /// diff --git a/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs b/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs new file mode 100644 index 000000000..bc9ad1509 --- /dev/null +++ b/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Artemis.Core.Plugins.Models; + +namespace Artemis.Core.Plugins.Abstract +{ + /// + /// + /// Allows you to create one or more s usable by profile layers. + /// + public class LayerEffectProvider : Plugin + { + public LayerEffectProvider(PluginInfo pluginInfo) : base(pluginInfo) + { + } + + public override void EnablePlugin() + { + throw new NotImplementedException(); + } + + public override void DisablePlugin() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Artemis.Core/Plugins/Abstract/Plugin.cs b/src/Artemis.Core/Plugins/Abstract/Plugin.cs index 94f1f1b49..32a545b6d 100644 --- a/src/Artemis.Core/Plugins/Abstract/Plugin.cs +++ b/src/Artemis.Core/Plugins/Abstract/Plugin.cs @@ -30,19 +30,18 @@ namespace Artemis.Core.Plugins.Abstract public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); + DisablePlugin(); } /// /// Called when the plugin is activated /// - protected abstract void EnablePlugin(); + public abstract void EnablePlugin(); /// - /// Called when the plugin is deactivated + /// Called when the plugin is deactivated or when Artemis shuts down /// - protected abstract void DisablePlugin(); + public abstract void DisablePlugin(); /// /// 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; } - - /// - /// Called when Artemis shuts down - /// - /// - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - } - } - + internal void SetEnabled(bool enable) { if (enable && !Enabled) diff --git a/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs index 7c3c41514..eb6a439fb 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs @@ -44,11 +44,16 @@ namespace Artemis.Core.Plugins.LayerBrush /// Gets a reference to the layer property group without knowing it's type /// public virtual LayerPropertyGroup BaseProperties => null; - + /// - /// Called when the brush is being removed from the layer + /// Called when the layer brush is activated /// - public abstract void Dispose(); + 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 @@ -67,6 +72,11 @@ namespace Artemis.Core.Plugins.LayerBrush /// /// Your RGB.NET brush internal abstract IBrush InternalGetBrush(); + + public void Dispose() + { + DisableLayerBrush(); + } } public enum LayerBrushType diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs index c2285a09a..89602f635 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs @@ -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); - } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushDescriptor.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrushDescriptor.cs index 057ea173e..9e05da117 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushDescriptor.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrushDescriptor.cs @@ -1,4 +1,5 @@ using System; +using Artemis.Core.Plugins.Abstract; namespace Artemis.Core.Plugins.LayerBrush { diff --git a/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs index ee7010c3c..a764cd508 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs @@ -39,18 +39,11 @@ namespace Artemis.Core.Plugins.LayerBrush internal set => _properties = value; } - /// - /// Called when all layer properties in this brush have been initialized - /// - protected virtual void OnPropertiesInitialized() - { - } - internal void InitializeProperties(ILayerService layerService) { Properties = Activator.CreateInstance(); Properties.InitializeProperties(layerService, Layer, "LayerBrush."); - OnPropertiesInitialized(); + EnableLayerBrush(); PropertiesInitialized = true; } } diff --git a/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs new file mode 100644 index 000000000..233b0bb8b --- /dev/null +++ b/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs @@ -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 +{ + /// + /// For internal use only, please use instead + /// + public abstract class BaseLayerEffect : IDisposable + { + protected BaseLayerEffect(Layer layer, LayerEffectDescriptor descriptor) + { + Layer = layer; + Descriptor = descriptor; + } + + /// + /// Gets the layer this brush is applied to + /// + public Layer Layer { get; internal set; } + + /// + /// Gets the descriptor of this brush + /// + public LayerEffectDescriptor Descriptor { get; internal set; } + + /// + /// Gets the plugin info that defined this brush + /// + public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo; + + /// + /// Gets a reference to the layer property group without knowing it's type + /// + public virtual LayerPropertyGroup BaseProperties => null; + + /// + /// Called when the brush is being removed from the layer + /// + public abstract void Dispose(); + + /// + /// Called before rendering every frame, write your update logic here + /// + /// + 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 and RgbNetLayerEffect outside the core + internal abstract void Initialize(ILayerService layerService); + + internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint); + + /// + /// Called when Artemis needs an instance of the RGB.NET brush you are implementing + /// + /// Your RGB.NET brush + internal abstract IBrush InternalGetBrush(); + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerEffect/LayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/LayerEffect.cs new file mode 100644 index 000000000..bdd8b9313 --- /dev/null +++ b/src/Artemis.Core/Plugins/LayerEffect/LayerEffect.cs @@ -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 +{ + /// + /// For internal use only, please use instead + /// + public abstract class LayerEffect : BaseLayerEffect where T : LayerPropertyGroup + { + private T _properties; + + protected LayerEffect(Layer layer, LayerEffectDescriptor descriptor) : base(layer, descriptor) + { + } + + /// + /// Gets whether all properties on this brush are initialized + /// + public bool PropertiesInitialized { get; internal set; } + + /// + public override LayerPropertyGroup BaseProperties => Properties; + + /// + /// Gets the properties of this brush. + /// + 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; + } + + /// + /// Called when all layer properties in this brush have been initialized + /// + protected virtual void OnPropertiesInitialized() + { + } + + internal void InitializeProperties(ILayerService layerService) + { + Properties = Activator.CreateInstance(); + Properties.InitializeProperties(layerService, Layer, "LayerEffect."); + OnPropertiesInitialized(); + PropertiesInitialized = true; + } + + /// + /// The main method of rendering anything to the layer. The provided is specific to the layer + /// and matches it's width and height. + /// Called during rendering or layer preview, in the order configured on the layer + /// + /// The layer canvas + /// + /// The path to be filled, represents the shape + /// The paint to be used to fill the shape + 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); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerEffect/LayerEffectDescriptor.cs b/src/Artemis.Core/Plugins/LayerEffect/LayerEffectDescriptor.cs new file mode 100644 index 000000000..50da1da2c --- /dev/null +++ b/src/Artemis.Core/Plugins/LayerEffect/LayerEffectDescriptor.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Interfaces/ILayerService.cs b/src/Artemis.Core/Services/Interfaces/ILayerService.cs index c59245532..2db50312f 100644 --- a/src/Artemis.Core/Services/Interfaces/ILayerService.cs +++ b/src/Artemis.Core/Services/Interfaces/ILayerService.cs @@ -22,11 +22,5 @@ namespace Artemis.Core.Services.Interfaces /// The layer to instantiate the brush for /// BaseLayerBrush InstantiateLayerBrush(Layer layer); - - /// - /// Removes the layer brush from the provided layer and disposes it - /// - /// - void RemoveLayerBrush(Layer layer); } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/LayerService.cs b/src/Artemis.Core/Services/LayerService.cs index 8dac3ed62..b2cb12b8a 100644 --- a/src/Artemis.Core/Services/LayerService.cs +++ b/src/Artemis.Core/Services/LayerService.cs @@ -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); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs index d0fcafbfa..6fa40eae7 100644 --- a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs +++ b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs @@ -3,6 +3,7 @@ using System.Linq; using Artemis.Core.Events; using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile.LayerProperties; +using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Services.Interfaces; using Artemis.UI.Shared.PropertyInput; diff --git a/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs index 21397cf43..f2bd5d9d9 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs @@ -16,7 +16,7 @@ namespace Artemis.Plugins.Devices.Asus _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(AsusRGBDevice<>), sender, args); _rgbService.AddDeviceProvider(RgbDeviceProvider); diff --git a/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 7ed66a7cd..46c4f0779 100644 --- a/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -17,7 +17,7 @@ namespace Artemis.Plugins.Devices.CoolerMaster _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(CoolerMasterRGBDevice<>), sender, args); RGB.NET.Devices.CoolerMaster.CoolerMasterDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "CMSDK.dll")); diff --git a/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs index 9175a9318..d51c8f0ca 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs @@ -17,7 +17,7 @@ namespace Artemis.Plugins.Devices.Corsair _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(CorsairRGBDevice<>), sender, args); RGB.NET.Devices.Corsair.CorsairDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "CUESDK.x64_2017.dll")); diff --git a/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs index 03c7d82cc..b4c1a4c2c 100644 --- a/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs @@ -17,7 +17,7 @@ namespace Artemis.Plugins.Devices.DMX HasConfigurationViewModel = true; } - protected override void EnablePlugin() + public override void EnablePlugin() { // TODO: Load from configuration // RGB.NET.Devices.DMX.DMXDeviceProvider.Instance.AddDeviceDefinition(); diff --git a/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs index 19fbb9619..2110311e7 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs @@ -25,7 +25,7 @@ namespace Artemis.Plugins.Devices.Logitech _logger = logger; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(LogitechRGBDevice<>), sender, args); RGB.NET.Devices.Logitech.LogitechDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "LogitechLedEnginesWrapper.dll")); diff --git a/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs index 9efa7be72..aa51d1e9e 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs @@ -17,7 +17,7 @@ namespace Artemis.Plugins.Devices.Msi _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(MsiRGBDevice<>), sender, args); RGB.NET.Devices.Msi.MsiDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "MysticLight_SDK.dll")); diff --git a/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs index e05fd0446..d5c794cfd 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs @@ -16,7 +16,7 @@ namespace Artemis.Plugins.Devices.Novation _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(NovationRGBDevice<>), sender, args); _rgbService.AddDeviceProvider(RgbDeviceProvider); diff --git a/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs index 141854a29..c4d40870f 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs @@ -18,7 +18,7 @@ namespace Artemis.Plugins.Devices.Razer _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(RazerRGBDevice<>), sender, args); RGB.NET.Devices.Razer.RazerDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "RzChromaSDK.dll")); diff --git a/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs index e6cad1a44..c2f24c09f 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs @@ -15,7 +15,7 @@ namespace Artemis.Plugins.Devices.Roccat _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { // TODO: Find out why this is missing, Roccat seems unimplemented // PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(RoccatRGBDevice<>), sender, args); diff --git a/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 7ea539c09..3e63cf3ee 100644 --- a/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -16,7 +16,7 @@ namespace Artemis.Plugins.Devices.SteelSeries _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { // TODO Check to see if this works, it's usually a generic type after all PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(SteelSeriesRGBDevice), sender, args); diff --git a/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs index 80a7384f0..fc4002fac 100644 --- a/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs @@ -25,7 +25,7 @@ namespace Artemis.Plugins.Devices.WS281X public PluginSettings Settings { get; } - protected override void EnablePlugin() + public override void EnablePlugin() { var definitions = Settings.GetSetting>("DeviceDefinitions"); if (definitions.Value == null) @@ -49,7 +49,7 @@ namespace Artemis.Plugins.Devices.WS281X _rgbService.AddDeviceProvider(RgbDeviceProvider); } - protected override void DisablePlugin() + public override void DisablePlugin() { // TODO: Remove the device provider from the surface } diff --git a/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs index f4827d031..d92d6427f 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs @@ -17,7 +17,7 @@ namespace Artemis.Plugins.Devices.Wooting _rgbService = rgbService; } - protected override void EnablePlugin() + public override void EnablePlugin() { PathHelper.ResolvingAbsolutePath += (sender, args) => ResolveAbsolutePath(typeof(WootingRGBDevice<>), sender, args); RGB.NET.Devices.Wooting.WootingDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "wooting-rgb-sdk64.dll")); @@ -25,7 +25,7 @@ namespace Artemis.Plugins.Devices.Wooting _rgbService.AddDeviceProvider(RgbDeviceProvider); } - protected override void DisablePlugin() + public override void DisablePlugin() { // TODO: Remove the device provider from the surface } diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index f3f9685a3..08a6503cd 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -17,6 +17,21 @@ namespace Artemis.Plugins.LayerBrushes.Color Layer.RenderPropertiesUpdated += (sender, args) => CreateShader(); } + public override void EnableLayerBrush() + { + Properties.GradientType.BaseValueChanged += (sender, args) => CreateShader(); + Properties.Color.BaseValueChanged += (sender, args) => CreateShader(); + Properties.Gradient.BaseValue.PropertyChanged += (sender, args) => CreateShader(); + } + + public override void DisableLayerBrush() + { + _paint?.Dispose(); + _shader?.Dispose(); + _paint = null; + _shader = null; + } + public override void Update(double deltaTime) { // Only check if a solid is being drawn, because that can be changed by keyframes @@ -40,24 +55,6 @@ namespace Artemis.Plugins.LayerBrushes.Color canvas.DrawPath(path, paint); } - protected override void Dispose(bool disposing) - { - if (disposing) - { - _paint?.Dispose(); - _shader?.Dispose(); - } - - base.Dispose(disposing); - } - - protected override void OnPropertiesInitialized() - { - Properties.GradientType.BaseValueChanged += (sender, args) => CreateShader(); - Properties.Color.BaseValueChanged += (sender, args) => CreateShader(); - Properties.Gradient.BaseValue.PropertyChanged += (sender, args) => CreateShader(); - } - private void CreateShader() { var center = new SKPoint(_shaderBounds.MidX, _shaderBounds.MidY); diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs index bb9b05181..45f2b812b 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProperties.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile.Colors; using Artemis.Core.Models.Profile.LayerProperties.Attributes; diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs index b0e5e73fb..7ce8d342b 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs @@ -1,4 +1,5 @@ -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.Abstract; +using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.Models; namespace Artemis.Plugins.LayerBrushes.Color @@ -10,11 +11,11 @@ namespace Artemis.Plugins.LayerBrushes.Color AddLayerBrushDescriptor("Color", "A color with an (optional) gradient", "Brush"); } - protected override void EnablePlugin() + public override void EnablePlugin() { } - protected override void DisablePlugin() + public override void DisablePlugin() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs index a9f88ca25..793f54f89 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs @@ -1,5 +1,4 @@ -using System; -using Artemis.Core.Extensions; +using Artemis.Core.Extensions; using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush; using RGB.NET.Brushes; @@ -16,6 +15,14 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet _solidBrush = new SolidColorBrush(Color.Transparent); } + public override void EnableLayerBrush() + { + } + + public override void DisableLayerBrush() + { + } + public override void Update(double deltaTime) { _solidBrush.Color = Properties.Color.CurrentValue.ToRgbColor(); diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs index 06c28000f..d10b8a59d 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs @@ -1,4 +1,4 @@ -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; using Artemis.Plugins.LayerBrushes.ColorRgbNet.PropertyInput; using Artemis.UI.Shared.Services.Interfaces; @@ -15,12 +15,12 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet AddLayerBrushDescriptor("RGB.NET Color", "A RGB.NET based color", "Brush"); } - protected override void EnablePlugin() + public override void EnablePlugin() { _profileEditorService.RegisterPropertyInput(PluginInfo, typeof(StringPropertyInputViewModel)); } - protected override void DisablePlugin() + public override void DisablePlugin() { } } diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs index 3b4633e22..2304abfee 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -32,6 +32,18 @@ namespace Artemis.Plugins.LayerBrushes.Noise DetermineRenderScale(); } + public override void EnableLayerBrush() + { + Properties.GradientColor.BaseValue.PropertyChanged += GradientColorChanged; + CreateColorMap(); + } + + public override void DisableLayerBrush() + { + _bitmap?.Dispose(); + _bitmap = null; + } + public override void Update(double deltaTime) { _x += Properties.ScrollSpeed.CurrentValue.X / 500f / (float) deltaTime; @@ -103,23 +115,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise paint.Shader = foregroundShader; canvas.DrawRect(path.Bounds, paint); } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - _bitmap?.Dispose(); - } - - base.Dispose(disposing); - } - - protected override void OnPropertiesInitialized() - { - Properties.GradientColor.BaseValue.PropertyChanged += GradientColorChanged; - CreateColorMap(); - } - + private void GradientColorChanged(object sender, PropertyChangedEventArgs e) { CreateColorMap(); diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs index 61b39c038..c6318a8ec 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProperties.cs @@ -1,5 +1,4 @@ -using System; -using Artemis.Core.Models.Profile; +using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile.Colors; using Artemis.Core.Models.Profile.LayerProperties.Attributes; using Artemis.Core.Models.Profile.LayerProperties.Types; diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs index d55370b7d..edc3028c0 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs @@ -1,4 +1,5 @@ -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.Abstract; +using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.Models; namespace Artemis.Plugins.LayerBrushes.Noise @@ -10,11 +11,11 @@ namespace Artemis.Plugins.LayerBrushes.Noise AddLayerBrushDescriptor("Noise", "A brush of that shows an animated random noise", "ScatterPlot"); } - protected override void EnablePlugin() + public override void EnablePlugin() { } - protected override void DisablePlugin() + public override void DisablePlugin() { } } diff --git a/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs index d5cb76f93..7c8313d06 100644 --- a/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -27,11 +27,11 @@ namespace Artemis.Plugins.Modules.General return new List {new GeneralViewModel(this)}; } - protected override void EnablePlugin() + public override void EnablePlugin() { } - protected override void DisablePlugin() + public override void DisablePlugin() { } }