diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 8820917a6..f328c2336 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -8,6 +8,7 @@ using Artemis.Core.Models.Profile.LayerProperties.Attributes; using Artemis.Core.Models.Profile.LayerShapes; using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; using Artemis.Core.Services; using Artemis.Core.Services.Interfaces; using Artemis.Storage.Entities.Profile; @@ -412,7 +413,7 @@ namespace Artemis.Core.Models.Profile { DeactivateLayerBrush(); } - + internal void DeactivateLayerBrush() { if (LayerBrush == null) diff --git a/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs b/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs index 60ebf3b37..d53253c8f 100644 --- a/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs +++ b/src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs @@ -1,6 +1,4 @@ -using Artemis.Core.Plugins.Models; - -namespace Artemis.Core.Plugins.Abstract +namespace Artemis.Core.Plugins.Abstract { /// /// @@ -8,10 +6,6 @@ namespace Artemis.Core.Plugins.Abstract /// public abstract class DataModelExpansion : Plugin { - protected DataModelExpansion(PluginInfo pluginInfo) : base(pluginInfo) - { - } - public abstract void Update(double deltaTime); } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/DataModels/Attributes/DataModelProperty.cs b/src/Artemis.Core/Plugins/Abstract/DataModels/Attributes/DataModelProperty.cs index 030f951c2..222491ae6 100644 --- a/src/Artemis.Core/Plugins/Abstract/DataModels/Attributes/DataModelProperty.cs +++ b/src/Artemis.Core/Plugins/Abstract/DataModels/Attributes/DataModelProperty.cs @@ -2,7 +2,7 @@ namespace Artemis.Core.Plugins.Abstract.DataModels.Attributes { - [AttributeUsage(System.AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Property)] public class DataModelPropertyAttribute : Attribute { /// diff --git a/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs b/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs index e9c5ac250..7a6c5d58b 100644 --- a/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs +++ b/src/Artemis.Core/Plugins/Abstract/DeviceProvider.cs @@ -1,7 +1,6 @@ using System; using System.IO; using Artemis.Core.Extensions; -using Artemis.Core.Plugins.Models; using Ninject; using RGB.NET.Core; using Serilog; @@ -14,7 +13,7 @@ namespace Artemis.Core.Plugins.Abstract /// public abstract class DeviceProvider : Plugin { - protected DeviceProvider(PluginInfo pluginInfo, IRGBDeviceProvider rgbDeviceProvider) : base(pluginInfo) + protected DeviceProvider(IRGBDeviceProvider rgbDeviceProvider) { RgbDeviceProvider = rgbDeviceProvider ?? throw new ArgumentNullException(nameof(rgbDeviceProvider)); } @@ -24,6 +23,11 @@ namespace Artemis.Core.Plugins.Abstract [Inject] public ILogger Logger { get; set; } + public override void DisablePlugin() + { + // Does not happen with device providers, they require Artemis to restart + } + protected void ResolveAbsolutePath(Type type, object sender, ResolvePathEventArgs e) { if (sender.GetType().IsGenericType(type)) @@ -42,10 +46,5 @@ namespace Artemis.Core.Plugins.Abstract } } } - - public override void DisablePlugin() - { - // Does not happen with device providers, they require Artemis to restart - } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs b/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs index 1256127bf..966cfe431 100644 --- a/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs +++ b/src/Artemis.Core/Plugins/Abstract/LayerBrushProvider.cs @@ -1,7 +1,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.LayerBrush; -using Artemis.Core.Plugins.Models; +using Artemis.Core.Plugins.LayerBrush.Abstract; namespace Artemis.Core.Plugins.Abstract { @@ -13,15 +14,32 @@ namespace Artemis.Core.Plugins.Abstract { private readonly List _layerBrushDescriptors; - protected LayerBrushProvider(PluginInfo pluginInfo) : base(pluginInfo) + protected LayerBrushProvider() { _layerBrushDescriptors = new List(); } + /// + /// A read-only collection of all layer brushes added with + /// public ReadOnlyCollection LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly(); + /// + /// Adds a layer brush descriptor for a given layer brush, so that it appears in the UI. + /// Note: You do not need to manually remove these on disable + /// + /// The type of the layer brush you wish to register + /// The name to display in the UI + /// The description to display in the UI + /// + /// The Material icon to display in the UI, a full reference can be found + /// here + /// protected void AddLayerBrushDescriptor(string displayName, string description, string icon) where T : BaseLayerBrush { + if (!Enabled) + throw new ArtemisPluginException(PluginInfo, "Can only add a layer brush descriptor when the plugin is enabled"); + _layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this)); } } diff --git a/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs b/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs index bc9ad1509..6d39c7fdd 100644 --- a/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs +++ b/src/Artemis.Core/Plugins/Abstract/LayerEffectProvider.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using Artemis.Core.Plugins.Models; namespace Artemis.Core.Plugins.Abstract { @@ -11,10 +8,6 @@ namespace Artemis.Core.Plugins.Abstract /// public class LayerEffectProvider : Plugin { - public LayerEffectProvider(PluginInfo pluginInfo) : base(pluginInfo) - { - } - public override void EnablePlugin() { throw new NotImplementedException(); @@ -25,4 +18,4 @@ namespace Artemis.Core.Plugins.Abstract throw new NotImplementedException(); } } -} +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/Module.cs b/src/Artemis.Core/Plugins/Abstract/Module.cs index 1e0b3951a..559fc491b 100644 --- a/src/Artemis.Core/Plugins/Abstract/Module.cs +++ b/src/Artemis.Core/Plugins/Abstract/Module.cs @@ -2,7 +2,6 @@ using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Abstract.DataModels; using Artemis.Core.Plugins.Abstract.ViewModels; -using Artemis.Core.Plugins.Models; using SkiaSharp; namespace Artemis.Core.Plugins.Abstract @@ -13,10 +12,6 @@ namespace Artemis.Core.Plugins.Abstract /// public abstract class Module : Plugin { - protected Module(PluginInfo pluginInfo) : base(pluginInfo) - { - } - /// /// The modules display name that's shown in the menu /// diff --git a/src/Artemis.Core/Plugins/Abstract/Plugin.cs b/src/Artemis.Core/Plugins/Abstract/Plugin.cs index 32a545b6d..0280a3057 100644 --- a/src/Artemis.Core/Plugins/Abstract/Plugin.cs +++ b/src/Artemis.Core/Plugins/Abstract/Plugin.cs @@ -10,11 +10,6 @@ namespace Artemis.Core.Plugins.Abstract /// public abstract class Plugin : IDisposable { - internal Plugin(PluginInfo pluginInfo) - { - PluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo)); - } - public PluginInfo PluginInfo { get; internal set; } /// @@ -28,11 +23,6 @@ namespace Artemis.Core.Plugins.Abstract /// public bool HasConfigurationViewModel { get; protected set; } - public void Dispose() - { - DisablePlugin(); - } - /// /// Called when the plugin is activated /// @@ -52,21 +42,26 @@ namespace Artemis.Core.Plugins.Abstract { return null; } - + internal void SetEnabled(bool enable) { if (enable && !Enabled) { + Enabled = true; EnablePlugin(); OnPluginEnabled(); } else if (!enable && Enabled) { + Enabled = false; DisablePlugin(); OnPluginDisabled(); } + } - Enabled = enable; + public void Dispose() + { + DisablePlugin(); } #region Events diff --git a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs index 38ef43055..1d34f53d0 100644 --- a/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs +++ b/src/Artemis.Core/Plugins/Abstract/ProfileModule.cs @@ -2,17 +2,12 @@ using Artemis.Core.Exceptions; using Artemis.Core.Models.Profile; using Artemis.Core.Models.Surface; -using Artemis.Core.Plugins.Models; using SkiaSharp; namespace Artemis.Core.Plugins.Abstract { public abstract class ProfileModule : Module { - protected ProfileModule(PluginInfo pluginInfo) : base(pluginInfo) - { - } - public Profile ActiveProfile { get; private set; } /// diff --git a/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs similarity index 82% rename from src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs rename to src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs index eb6a439fb..b60ddb7b5 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs @@ -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 { /// /// For internal use only, please use or or instead /// public abstract class BaseLayerBrush : IDisposable { - protected BaseLayerBrush(Layer layer, LayerBrushDescriptor descriptor) - { - Layer = layer; - Descriptor = descriptor; - } - /// /// Gets the layer this brush is applied to /// @@ -45,6 +36,14 @@ namespace Artemis.Core.Plugins.LayerBrush /// public virtual LayerPropertyGroup BaseProperties => null; + public void Dispose() + { + DisableLayerBrush(); + Dispose(true); + + GC.SuppressFinalize(this); + } + /// /// Called when the layer brush is activated /// @@ -67,15 +66,8 @@ namespace Artemis.Core.Plugins.LayerBrush 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(); - - public void Dispose() + internal virtual void Dispose(bool disposing) { - DisableLayerBrush(); } } diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs similarity index 79% rename from src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs rename to src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs index 89602f635..ac02786a9 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs @@ -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 : PropertiesLayerBrush 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 /// 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 @@ -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); diff --git a/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs similarity index 90% rename from src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs rename to src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs index a764cd508..81410945e 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/PropertiesLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs @@ -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 { /// /// For internal use only, please use or or instead @@ -12,10 +12,6 @@ namespace Artemis.Core.Plugins.LayerBrush { private T _properties; - protected PropertiesLayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) - { - } - /// /// Gets whether all properties on this brush are initialized /// @@ -43,8 +39,9 @@ namespace Artemis.Core.Plugins.LayerBrush { Properties = Activator.CreateInstance(); Properties.InitializeProperties(layerService, Layer, "LayerBrush."); - EnableLayerBrush(); PropertiesInitialized = true; + + EnableLayerBrush(); } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs similarity index 66% rename from src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs rename to src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs index 48c01a6f7..bb6dcef15 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/RgbNetLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs @@ -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 : PropertiesLayerBrush 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; } /// - /// The LED group this layer brush is applied to + /// The LED group this layer effect is applied to /// public ListLedGroup LedGroup { get; internal set; } /// - /// 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 /// - /// Your RGB.NET brush + /// Your RGB.NET effect 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) diff --git a/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs new file mode 100644 index 000000000..96909b9a6 --- /dev/null +++ b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs @@ -0,0 +1,94 @@ +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); + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs new file mode 100644 index 000000000..725a0e90f --- /dev/null +++ b/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs @@ -0,0 +1,58 @@ +using System; +using Artemis.Core.Models.Profile; +using Artemis.Core.Plugins.Exceptions; +using Artemis.Core.Services.Interfaces; + +namespace Artemis.Core.Plugins.LayerEffect.Abstract +{ + /// + /// For internal use only, please use instead + /// + public abstract class LayerEffect : BaseLayerEffect where T : LayerPropertyGroup + { + private T _properties; + + /// + /// Gets whether all properties on this effect are initialized + /// + public bool PropertiesInitialized { get; internal set; } + + /// + public override LayerPropertyGroup BaseProperties => Properties; + + /// + /// Gets the properties of this effect. + /// + 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 effect properties until OnPropertiesInitialized has been called"); + return _properties; + } + internal set => _properties = value; + } + + /// + /// Called when all layer properties in this effect have been initialized + /// + protected virtual void OnPropertiesInitialized() + { + } + + internal void InitializeProperties(ILayerService layerService) + { + Properties = Activator.CreateInstance(); + Properties.InitializeProperties(layerService, Layer, "LayerEffect."); + OnPropertiesInitialized(); + PropertiesInitialized = true; + } + + internal override void Initialize(ILayerService layerService) + { + InitializeProperties(layerService); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs deleted file mode 100644 index 233b0bb8b..000000000 --- a/src/Artemis.Core/Plugins/LayerEffect/BaseLayerEffect.cs +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index bdd8b9313..000000000 --- a/src/Artemis.Core/Plugins/LayerEffect/LayerEffect.cs +++ /dev/null @@ -1,95 +0,0 @@ -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/Models/PluginInfo.cs b/src/Artemis.Core/Plugins/Models/PluginInfo.cs index d129d93ab..0dfc01cf2 100644 --- a/src/Artemis.Core/Plugins/Models/PluginInfo.cs +++ b/src/Artemis.Core/Plugins/Models/PluginInfo.cs @@ -32,7 +32,8 @@ namespace Artemis.Core.Plugins.Models public string Description { get; set; } /// - /// The plugins display icon that's shown in the settings see for available + /// The plugins display icon that's shown in the settings see for + /// available /// icons /// public string Icon { get; set; } @@ -84,7 +85,7 @@ namespace Artemis.Core.Plugins.Models /// [JsonIgnore] internal PluginEntity PluginEntity { get; set; } - + public override string ToString() { return $"{nameof(Guid)}: {Guid}, {nameof(Name)}: {Name}, {nameof(Version)}: {Version}"; diff --git a/src/Artemis.Core/Plugins/Models/PluginSetting.cs b/src/Artemis.Core/Plugins/Models/PluginSetting.cs index 31c926da8..d602f6d43 100644 --- a/src/Artemis.Core/Plugins/Models/PluginSetting.cs +++ b/src/Artemis.Core/Plugins/Models/PluginSetting.cs @@ -1,5 +1,4 @@ using System; -using Artemis.Storage.Entities; using Artemis.Storage.Entities.Plugins; using Artemis.Storage.Repositories.Interfaces; using Newtonsoft.Json; @@ -10,8 +9,8 @@ namespace Artemis.Core.Plugins.Models { // ReSharper disable once NotAccessedField.Local private readonly PluginInfo _pluginInfo; - private readonly PluginSettingEntity _pluginSettingEntity; private readonly IPluginRepository _pluginRepository; + private readonly PluginSettingEntity _pluginSettingEntity; private T _value; internal PluginSetting(PluginInfo pluginInfo, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity) diff --git a/src/Artemis.Core/Plugins/Models/PluginSettings.cs b/src/Artemis.Core/Plugins/Models/PluginSettings.cs index 870410fe8..ebd3f8788 100644 --- a/src/Artemis.Core/Plugins/Models/PluginSettings.cs +++ b/src/Artemis.Core/Plugins/Models/PluginSettings.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Artemis.Storage.Entities; using Artemis.Storage.Entities.Plugins; using Artemis.Storage.Repositories.Interfaces; using Newtonsoft.Json; diff --git a/src/Artemis.Core/Services/Interfaces/ILayerService.cs b/src/Artemis.Core/Services/Interfaces/ILayerService.cs index 2db50312f..0081f6bbe 100644 --- a/src/Artemis.Core/Services/Interfaces/ILayerService.cs +++ b/src/Artemis.Core/Services/Interfaces/ILayerService.cs @@ -1,5 +1,6 @@ using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; namespace Artemis.Core.Services.Interfaces { diff --git a/src/Artemis.Core/Services/LayerService.cs b/src/Artemis.Core/Services/LayerService.cs index b2cb12b8a..01bede365 100644 --- a/src/Artemis.Core/Services/LayerService.cs +++ b/src/Artemis.Core/Services/LayerService.cs @@ -4,6 +4,7 @@ using Artemis.Core.Exceptions; using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; using Artemis.Core.Services.Interfaces; using Ninject; using Ninject.Parameters; @@ -42,7 +43,7 @@ namespace Artemis.Core.Services public BaseLayerBrush InstantiateLayerBrush(Layer layer) { layer.DeactivateLayerBrush(); - + var descriptorReference = layer.General.BrushReference?.CurrentValue; if (descriptorReference == null) return null; @@ -56,16 +57,16 @@ namespace Artemis.Core.Services if (descriptor == null) return null; - var arguments = new IParameter[] - { - new ConstructorArgument("layer", layer), - new ConstructorArgument("descriptor", descriptor) - }; - layer.LayerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments); - layer.LayerBrush.Initialize(this); - layer.LayerBrush.Update(0); + var brush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType); + brush.Layer = layer; + brush.Descriptor = descriptor; + layer.LayerBrush = brush; + + brush.Initialize(this); + brush.Update(0); layer.OnLayerBrushUpdated(); - return layer.LayerBrush; + + return brush; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/PluginService.cs b/src/Artemis.Core/Services/PluginService.cs index 94c5967ab..66728653d 100644 --- a/src/Artemis.Core/Services/PluginService.cs +++ b/src/Artemis.Core/Services/PluginService.cs @@ -267,10 +267,10 @@ namespace Artemis.Core.Services { var parameters = new IParameter[] { - new ConstructorArgument("pluginInfo", pluginInfo), new Parameter("PluginInfo", pluginInfo, false) }; pluginInfo.Instance = (Plugin) _childKernel.Get(pluginType, constraint: null, parameters: parameters); + pluginInfo.Instance.PluginInfo = pluginInfo; } catch (Exception e) { @@ -353,7 +353,7 @@ namespace Artemis.Core.Services } plugin.SetEnabled(false); - + OnPluginDisabled(new PluginEventArgs(plugin.PluginInfo)); } diff --git a/src/Artemis.UI.Shared/Controls/DraggableFloat.xaml b/src/Artemis.UI.Shared/Controls/DraggableFloat.xaml index 352ba72b4..c9c7dc315 100644 --- a/src/Artemis.UI.Shared/Controls/DraggableFloat.xaml +++ b/src/Artemis.UI.Shared/Controls/DraggableFloat.xaml @@ -21,12 +21,12 @@ - + Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}" /> - PanZoomViewModel.TransformContainingRect(d.DeviceRectangle).Contains(position)); if (device != null) { + _rgbService.UpdateTrigger.Stop(); _mouseDragStatus = MouseDragStatus.Dragging; // If the device is not selected, deselect others and select only this one (if shift not held) if (device.SelectionStatus != SelectionStatus.Selected) @@ -350,6 +351,7 @@ namespace Artemis.UI.Screens.SurfaceEditor _surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true); _mouseDragStatus = MouseDragStatus.None; + _rgbService.UpdateTrigger.Start(); } private void UpdateSelection(Point position) @@ -415,18 +417,6 @@ namespace Artemis.UI.Screens.SurfaceEditor } #endregion - - protected override void OnActivate() - { - _rgbService.UpdateTrigger.Stop(); - base.OnActivate(); - } - - protected override void OnDeactivate() - { - _rgbService.UpdateTrigger.Start(); - base.OnDeactivate(); - } } internal enum MouseDragStatus diff --git a/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs index f2bd5d9d9..cf80d3e7d 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Asus/AsusDeviceProvider.cs @@ -1,5 +1,4 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Asus; @@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.Asus { private readonly IRgbService _rgbService; - public AsusDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Asus.AsusDeviceProvider.Instance) + public AsusDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Asus.AsusDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Asus/plugin.json b/src/Plugins/Artemis.Plugins.Devices.Asus/plugin.json index a6dcf96e2..d668fc88d 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Asus/plugin.json +++ b/src/Plugins/Artemis.Plugins.Devices.Asus/plugin.json @@ -1,7 +1,8 @@ { "Guid": "c20e876f-7cb0-4fa1-b0cc-ae1afb5865d1", "Name": "Asus Devices", - "Description": "Allows Artemis to control lighting on different ASUS devices such as motherboards, GPUs, headsets, RAM, keyboards and PC cases.", + "Description": + "Allows Artemis to control lighting on different ASUS devices such as motherboards, GPUs, headsets, RAM, keyboards and PC cases.", "Version": "1.0.0.0", "Main": "Artemis.Plugins.Devices.Asus.dll" } \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 46c4f0779..3fb101bac 100644 --- a/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -1,6 +1,5 @@ using System.IO; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.CoolerMaster; @@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.CoolerMaster { private readonly IRgbService _rgbService; - public CoolerMasterDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.CoolerMaster.CoolerMasterDeviceProvider.Instance) + public CoolerMasterDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.CoolerMaster.CoolerMasterDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs index d51c8f0ca..4ba23b7f5 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Corsair/CorsairDeviceProvider.cs @@ -1,6 +1,5 @@ using System.IO; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Corsair; @@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Corsair { private readonly IRgbService _rgbService; - public CorsairDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Corsair.CorsairDeviceProvider.Instance) + public CorsairDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Corsair.CorsairDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs index b4c1a4c2c..043b23ca9 100644 --- a/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.DMX/DMXDeviceProvider.cs @@ -1,6 +1,5 @@ using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract.ViewModels; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using Artemis.Plugins.Devices.DMX.ViewModels; @@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.DMX { private readonly IRgbService _rgbService; - public DMXDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.DMX.DMXDeviceProvider.Instance) + public DMXDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.DMX.DMXDeviceProvider.Instance) { _rgbService = rgbService; HasConfigurationViewModel = true; diff --git a/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs index 2110311e7..152b4fb3f 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Logitech/LogitechDeviceProvider.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using Artemis.Core.Extensions; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using HidSharp; using RGB.NET.Core; @@ -19,7 +18,7 @@ namespace Artemis.Plugins.Devices.Logitech private readonly ILogger _logger; private readonly IRgbService _rgbService; - public LogitechDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService, ILogger logger) : base(pluginInfo, RGB.NET.Devices.Logitech.LogitechDeviceProvider.Instance) + public LogitechDeviceProvider(IRgbService rgbService, ILogger logger) : base(RGB.NET.Devices.Logitech.LogitechDeviceProvider.Instance) { _rgbService = rgbService; _logger = logger; diff --git a/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs index aa51d1e9e..4e66a980f 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Msi/MsiDeviceProvider.cs @@ -1,6 +1,5 @@ using System.IO; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Msi; @@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Msi { private readonly IRgbService _rgbService; - public MsiDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Msi.MsiDeviceProvider.Instance) + public MsiDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Msi.MsiDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs index d5c794cfd..e60b8bc3a 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Novation/NovationDeviceProvider.cs @@ -1,5 +1,4 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Novation; @@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.Novation { private readonly IRgbService _rgbService; - public NovationDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Novation.NovationDeviceProvider.Instance) + public NovationDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Novation.NovationDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs index c4d40870f..6f1233d52 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Razer/RazerDeviceProvider.cs @@ -1,7 +1,6 @@ using System.IO; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Exceptions; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Razer; @@ -13,7 +12,7 @@ namespace Artemis.Plugins.Devices.Razer { private readonly IRgbService _rgbService; - public RazerDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Razer.RazerDeviceProvider.Instance) + public RazerDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Razer.RazerDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs index c2f24c09f..9f710c3b4 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Roccat/RoccatDeviceProvider.cs @@ -1,6 +1,5 @@ using System.IO; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; namespace Artemis.Plugins.Devices.Roccat @@ -10,7 +9,7 @@ namespace Artemis.Plugins.Devices.Roccat { private readonly IRgbService _rgbService; - public RoccatDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Roccat.RoccatDeviceProvider.Instance) + public RoccatDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Roccat.RoccatDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 3e63cf3ee..d869b70d4 100644 --- a/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -1,5 +1,4 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.SteelSeries; @@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.SteelSeries { private readonly IRgbService _rgbService; - public SteelSeriesDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.SteelSeries.SteelSeriesDeviceProvider.Instance) + public SteelSeriesDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.SteelSeries.SteelSeriesDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs index fc4002fac..adbf90d73 100644 --- a/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.WS281X/WS281XDeviceProvider.cs @@ -15,19 +15,20 @@ namespace Artemis.Plugins.Devices.WS281X public class WS281XDeviceProvider : DeviceProvider { private readonly IRgbService _rgbService; + private readonly PluginSettings _settings; - public WS281XDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService, PluginSettings settings) : base(pluginInfo, RGB.NET.Devices.WS281X.WS281XDeviceProvider.Instance) + public WS281XDeviceProvider(IRgbService rgbService, PluginSettings settings) : base(RGB.NET.Devices.WS281X.WS281XDeviceProvider.Instance) { - Settings = settings; + _settings = settings; _rgbService = rgbService; - HasConfigurationViewModel = true; } - public PluginSettings Settings { get; } public override void EnablePlugin() { - var definitions = Settings.GetSetting>("DeviceDefinitions"); + HasConfigurationViewModel = true; + + var definitions = _settings.GetSetting>("DeviceDefinitions"); if (definitions.Value == null) definitions.Value = new List(); @@ -53,10 +54,10 @@ namespace Artemis.Plugins.Devices.WS281X { // TODO: Remove the device provider from the surface } - + public override PluginConfigurationViewModel GetConfigurationViewModel() { - return new WS281XConfigurationViewModel(this, Settings); + return new WS281XConfigurationViewModel(this, _settings); } } } \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs b/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs index d92d6427f..f228a7b5b 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs +++ b/src/Plugins/Artemis.Plugins.Devices.Wooting/WootingDeviceProvider.cs @@ -1,6 +1,5 @@ using System.IO; using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Generic; @@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Wooting { private readonly IRgbService _rgbService; - public WootingDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Wooting.WootingDeviceProvider.Instance) + public WootingDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.Wooting.WootingDeviceProvider.Instance) { _rgbService = rgbService; } diff --git a/src/Plugins/Artemis.Plugins.Devices.Wooting/plugin.json b/src/Plugins/Artemis.Plugins.Devices.Wooting/plugin.json index 1de81bc61..c85f7d84d 100644 --- a/src/Plugins/Artemis.Plugins.Devices.Wooting/plugin.json +++ b/src/Plugins/Artemis.Plugins.Devices.Wooting/plugin.json @@ -1,7 +1,8 @@ { "Guid": "e70fd5ba-9881-480a-8ff6-078ed5f747fa", "Name": "Wooting Devices", - "Description": "Allows Artemis to control lighting on Wooting keyboards. Will eventually also expose analog key data.", + "Description": + "Allows Artemis to control lighting on Wooting keyboards. Will eventually also expose analog key data.", "Version": "1.0.0.0", "Main": "Artemis.Plugins.Devices.Wooting.dll" } \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj index 69f924a12..852df1340 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/Artemis.Plugins.LayerBrushes.Color.csproj @@ -37,6 +37,7 @@ - + \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index 08a6503cd..f6e6e9b14 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -1,6 +1,5 @@ using System; -using Artemis.Core.Models.Profile; -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; using SkiaSharp; namespace Artemis.Plugins.LayerBrushes.Color @@ -12,13 +11,9 @@ namespace Artemis.Plugins.LayerBrushes.Color private SKShader _shader; private SKRect _shaderBounds; - public ColorBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) - { - Layer.RenderPropertiesUpdated += (sender, args) => CreateShader(); - } - public override void EnableLayerBrush() { + Layer.RenderPropertiesUpdated += (sender, args) => CreateShader(); Properties.GradientType.BaseValueChanged += (sender, args) => CreateShader(); Properties.Color.BaseValueChanged += (sender, args) => CreateShader(); Properties.Gradient.BaseValue.PropertyChanged += (sender, args) => CreateShader(); @@ -66,13 +61,13 @@ namespace Artemis.Plugins.LayerBrushes.Color new SKPoint(_shaderBounds.Right, _shaderBounds.Top), Properties.Gradient.BaseValue.GetColorsArray(), Properties.Gradient.BaseValue.GetPositionsArray(), - SKShaderTileMode.Repeat), + SKShaderTileMode.Clamp), GradientType.RadialGradient => SKShader.CreateRadialGradient( center, - Math.Min(_shaderBounds.Width, _shaderBounds.Height), + Math.Max(_shaderBounds.Width, _shaderBounds.Height) / 2f, Properties.Gradient.BaseValue.GetColorsArray(), Properties.Gradient.BaseValue.GetPositionsArray(), - SKShaderTileMode.Repeat), + SKShaderTileMode.Clamp), GradientType.SweepGradient => SKShader.CreateSweepGradient( center, Properties.Gradient.BaseValue.GetColorsArray(), diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs index 7ce8d342b..760c3e6cd 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrushProvider.cs @@ -1,18 +1,12 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.LayerBrush; -using Artemis.Core.Plugins.Models; namespace Artemis.Plugins.LayerBrushes.Color { public class ColorBrushProvider : LayerBrushProvider { - public ColorBrushProvider(PluginInfo pluginInfo) : base(pluginInfo) - { - AddLayerBrushDescriptor("Color", "A color with an (optional) gradient", "Brush"); - } - public override void EnablePlugin() { + AddLayerBrushDescriptor("Color", "A color with an (optional) gradient", "Brush"); } 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 793f54f89..ee7c9b04a 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrush.cs @@ -1,6 +1,5 @@ using Artemis.Core.Extensions; -using Artemis.Core.Models.Profile; -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; using RGB.NET.Brushes; using RGB.NET.Core; @@ -8,19 +7,16 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet { public class RgbNetColorBrush : RgbNetLayerBrush { - private readonly SolidColorBrush _solidBrush; + private SolidColorBrush _solidBrush; - public RgbNetColorBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) + public override void EnableLayerBrush() { _solidBrush = new SolidColorBrush(Color.Transparent); } - public override void EnableLayerBrush() - { - } - public override void DisableLayerBrush() { + _solidBrush = null; } public override void Update(double deltaTime) diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs index d10b8a59d..fe71aae4d 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.ColorRgbNet/RgbNetColorBrushProvider.cs @@ -1,5 +1,4 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.Models; using Artemis.Plugins.LayerBrushes.ColorRgbNet.PropertyInput; using Artemis.UI.Shared.Services.Interfaces; @@ -9,15 +8,15 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet { private readonly IProfileEditorService _profileEditorService; - public RgbNetColorBrushProvider(PluginInfo pluginInfo, IProfileEditorService profileEditorService) : base(pluginInfo) + public RgbNetColorBrushProvider(IProfileEditorService profileEditorService) { _profileEditorService = profileEditorService; - AddLayerBrushDescriptor("RGB.NET Color", "A RGB.NET based color", "Brush"); } public override void EnablePlugin() { _profileEditorService.RegisterPropertyInput(PluginInfo, typeof(StringPropertyInputViewModel)); + AddLayerBrushDescriptor("RGB.NET Color", "A RGB.NET based color", "Brush"); } 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 2304abfee..b5226d304 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; -using Artemis.Core.Models.Profile; -using Artemis.Core.Plugins.LayerBrush; +using Artemis.Core.Plugins.LayerBrush.Abstract; using Artemis.Core.Services.Interfaces; using Artemis.Plugins.LayerBrushes.Noise.Utilities; using SkiaSharp; @@ -11,31 +10,30 @@ namespace Artemis.Plugins.LayerBrushes.Noise public class NoiseBrush : LayerBrush { private static readonly Random Rand = new Random(); - private readonly OpenSimplexNoise _noise; private readonly IRgbService _rgbService; private SKBitmap _bitmap; private SKColor[] _colorMap; - + private OpenSimplexNoise _noise; private float _renderScale; private float _x; private float _y; private float _z; - public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor, IRgbService rgbService) : base(layer, descriptor) + public NoiseBrush(IRgbService rgbService) { _rgbService = rgbService; + } + + public override void EnableLayerBrush() + { _x = Rand.Next(0, 4096); _y = Rand.Next(0, 4096); _z = Rand.Next(0, 4096); _noise = new OpenSimplexNoise(Rand.Next(0, 4096)); - DetermineRenderScale(); - } - - public override void EnableLayerBrush() - { Properties.GradientColor.BaseValue.PropertyChanged += GradientColorChanged; CreateColorMap(); + DetermineRenderScale(); } public override void DisableLayerBrush() @@ -115,7 +113,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise paint.Shader = foregroundShader; canvas.DrawRect(path.Bounds, paint); } - + private void GradientColorChanged(object sender, PropertyChangedEventArgs e) { CreateColorMap(); diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs index edc3028c0..ba643df02 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrushProvider.cs @@ -1,18 +1,12 @@ using Artemis.Core.Plugins.Abstract; -using Artemis.Core.Plugins.LayerBrush; -using Artemis.Core.Plugins.Models; namespace Artemis.Plugins.LayerBrushes.Noise { public class NoiseBrushProvider : LayerBrushProvider { - public NoiseBrushProvider(PluginInfo pluginInfo) : base(pluginInfo) - { - AddLayerBrushDescriptor("Noise", "A brush of that shows an animated random noise", "ScatterPlot"); - } - public override void EnablePlugin() { + AddLayerBrushDescriptor("Noise", "A brush of that shows an animated random noise", "ScatterPlot"); } 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 7c8313d06..6e9e032c5 100644 --- a/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Plugins/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -11,15 +11,9 @@ namespace Artemis.Plugins.Modules.General { private readonly PluginSettings _settings; - public GeneralModule(PluginInfo pluginInfo, PluginSettings settings) : base(pluginInfo) + public GeneralModule(PluginSettings settings) { _settings = settings; - DisplayName = "General"; - DisplayIcon = "AllInclusive"; - ExpandsMainDataModel = true; - DataModel = new GeneralDataModel(this); - - var testSetting = _settings.GetSetting("TestSetting", DateTime.Now); } public override IEnumerable GetViewModels() @@ -29,6 +23,12 @@ namespace Artemis.Plugins.Modules.General public override void EnablePlugin() { + DisplayName = "General"; + DisplayIcon = "AllInclusive"; + ExpandsMainDataModel = true; + DataModel = new GeneralDataModel(this); + + var testSetting = _settings.GetSetting("TestSetting", DateTime.Now); } public override void DisablePlugin()