1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Plugins - Removed plugin info from constructor

This commit is contained in:
SpoinkyNL 2020-06-07 21:51:56 +02:00
parent ee37c3b836
commit 4bc6f2f16b
49 changed files with 305 additions and 390 deletions

View File

@ -8,6 +8,7 @@ using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Models.Profile.LayerShapes; using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;

View File

@ -1,6 +1,4 @@
using Artemis.Core.Plugins.Models; namespace Artemis.Core.Plugins.Abstract
namespace Artemis.Core.Plugins.Abstract
{ {
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
@ -8,10 +6,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public abstract class DataModelExpansion : Plugin public abstract class DataModelExpansion : Plugin
{ {
protected DataModelExpansion(PluginInfo pluginInfo) : base(pluginInfo)
{
}
public abstract void Update(double deltaTime); public abstract void Update(double deltaTime);
} }
} }

View File

@ -2,7 +2,7 @@
namespace Artemis.Core.Plugins.Abstract.DataModels.Attributes namespace Artemis.Core.Plugins.Abstract.DataModels.Attributes
{ {
[AttributeUsage(System.AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class DataModelPropertyAttribute : Attribute public class DataModelPropertyAttribute : Attribute
{ {
/// <summary> /// <summary>

View File

@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Models;
using Ninject; using Ninject;
using RGB.NET.Core; using RGB.NET.Core;
using Serilog; using Serilog;
@ -14,7 +13,7 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public abstract class DeviceProvider : Plugin public abstract class DeviceProvider : Plugin
{ {
protected DeviceProvider(PluginInfo pluginInfo, IRGBDeviceProvider rgbDeviceProvider) : base(pluginInfo) protected DeviceProvider(IRGBDeviceProvider rgbDeviceProvider)
{ {
RgbDeviceProvider = rgbDeviceProvider ?? throw new ArgumentNullException(nameof(rgbDeviceProvider)); RgbDeviceProvider = rgbDeviceProvider ?? throw new ArgumentNullException(nameof(rgbDeviceProvider));
} }
@ -24,6 +23,11 @@ namespace Artemis.Core.Plugins.Abstract
[Inject] [Inject]
public ILogger Logger { get; set; } 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) protected void ResolveAbsolutePath(Type type, object sender, ResolvePathEventArgs e)
{ {
if (sender.GetType().IsGenericType(type)) 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
}
} }
} }

View File

@ -1,7 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.LayerBrush.Abstract;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
@ -13,15 +14,32 @@ namespace Artemis.Core.Plugins.Abstract
{ {
private readonly List<LayerBrushDescriptor> _layerBrushDescriptors; private readonly List<LayerBrushDescriptor> _layerBrushDescriptors;
protected LayerBrushProvider(PluginInfo pluginInfo) : base(pluginInfo) protected LayerBrushProvider()
{ {
_layerBrushDescriptors = new List<LayerBrushDescriptor>(); _layerBrushDescriptors = new List<LayerBrushDescriptor>();
} }
/// <summary>
/// A read-only collection of all layer brushes added with <see cref="AddLayerBrushDescriptor{T}" />
/// </summary>
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly(); public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
/// <summary>
/// Adds a layer brush descriptor for a given layer brush, so that it appears in the UI.
/// <para>Note: You do not need to manually remove these on disable</para>
/// </summary>
/// <typeparam name="T">The type of the layer brush you wish to register</typeparam>
/// <param name="displayName">The name to display in the UI</param>
/// <param name="description">The description to display in the UI</param>
/// <param name="icon">
/// The Material icon to display in the UI, a full reference can be found
/// <see href="https://materialdesignicons.com">here</see>
/// </param>
protected void AddLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush protected void AddLayerBrushDescriptor<T>(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)); _layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
} }
} }

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
@ -11,10 +8,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public class LayerEffectProvider : Plugin public class LayerEffectProvider : Plugin
{ {
public LayerEffectProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
}
public override void EnablePlugin() public override void EnablePlugin()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -2,7 +2,6 @@
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract.DataModels; using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Plugins.Abstract.ViewModels; using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
@ -13,10 +12,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public abstract class Module : Plugin public abstract class Module : Plugin
{ {
protected Module(PluginInfo pluginInfo) : base(pluginInfo)
{
}
/// <summary> /// <summary>
/// The modules display name that's shown in the menu /// The modules display name that's shown in the menu
/// </summary> /// </summary>

View File

@ -10,11 +10,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public abstract class Plugin : IDisposable public abstract class Plugin : IDisposable
{ {
internal Plugin(PluginInfo pluginInfo)
{
PluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo));
}
public PluginInfo PluginInfo { get; internal set; } public PluginInfo PluginInfo { get; internal set; }
/// <summary> /// <summary>
@ -28,11 +23,6 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary> /// </summary>
public bool HasConfigurationViewModel { get; protected set; } public bool HasConfigurationViewModel { get; protected set; }
public void Dispose()
{
DisablePlugin();
}
/// <summary> /// <summary>
/// Called when the plugin is activated /// Called when the plugin is activated
/// </summary> /// </summary>
@ -57,16 +47,21 @@ namespace Artemis.Core.Plugins.Abstract
{ {
if (enable && !Enabled) if (enable && !Enabled)
{ {
Enabled = true;
EnablePlugin(); EnablePlugin();
OnPluginEnabled(); OnPluginEnabled();
} }
else if (!enable && Enabled) else if (!enable && Enabled)
{ {
Enabled = false;
DisablePlugin(); DisablePlugin();
OnPluginDisabled(); OnPluginDisabled();
} }
}
Enabled = enable; public void Dispose()
{
DisablePlugin();
} }
#region Events #region Events

View File

@ -2,17 +2,12 @@
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract namespace Artemis.Core.Plugins.Abstract
{ {
public abstract class ProfileModule : Module public abstract class ProfileModule : Module
{ {
protected ProfileModule(PluginInfo pluginInfo) : base(pluginInfo)
{
}
public Profile ActiveProfile { get; private set; } public Profile ActiveProfile { get; private set; }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -1,25 +1,16 @@
using System; using System;
using System.Linq;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core;
using RGB.NET.Groups;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush.Abstract
{ {
/// <summary> /// <summary>
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead /// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead
/// </summary> /// </summary>
public abstract class BaseLayerBrush : IDisposable public abstract class BaseLayerBrush : IDisposable
{ {
protected BaseLayerBrush(Layer layer, LayerBrushDescriptor descriptor)
{
Layer = layer;
Descriptor = descriptor;
}
/// <summary> /// <summary>
/// Gets the layer this brush is applied to /// Gets the layer this brush is applied to
/// </summary> /// </summary>
@ -45,6 +36,14 @@ namespace Artemis.Core.Plugins.LayerBrush
/// </summary> /// </summary>
public virtual LayerPropertyGroup BaseProperties => null; public virtual LayerPropertyGroup BaseProperties => null;
public void Dispose()
{
DisableLayerBrush();
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary> /// <summary>
/// Called when the layer brush is activated /// Called when the layer brush is activated
/// </summary> /// </summary>
@ -67,15 +66,8 @@ namespace Artemis.Core.Plugins.LayerBrush
internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint); internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
/// <summary> internal virtual void Dispose(bool disposing)
/// Called when Artemis needs an instance of the RGB.NET brush you are implementing
/// </summary>
/// <returns>Your RGB.NET brush</returns>
internal abstract IBrush InternalGetBrush();
public void Dispose()
{ {
DisableLayerBrush();
} }
} }

View File

@ -1,14 +1,12 @@
using System; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush.Abstract
{ {
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{ {
protected LayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) protected LayerBrush()
{ {
BrushType = LayerBrushType.Regular; BrushType = LayerBrushType.Regular;
} }
@ -34,11 +32,6 @@ namespace Artemis.Core.Plugins.LayerBrush
Render(canvas, canvasInfo, path, paint); 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) internal override void Initialize(ILayerService layerService)
{ {
InitializeProperties(layerService); InitializeProperties(layerService);

View File

@ -3,7 +3,7 @@ using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush.Abstract
{ {
/// <summary> /// <summary>
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead /// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="RgbNetLayerBrush{T}" /> or instead
@ -12,10 +12,6 @@ namespace Artemis.Core.Plugins.LayerBrush
{ {
private T _properties; private T _properties;
protected PropertiesLayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{
}
/// <summary> /// <summary>
/// Gets whether all properties on this brush are initialized /// Gets whether all properties on this brush are initialized
/// </summary> /// </summary>
@ -43,8 +39,9 @@ namespace Artemis.Core.Plugins.LayerBrush
{ {
Properties = Activator.CreateInstance<T>(); Properties = Activator.CreateInstance<T>();
Properties.InitializeProperties(layerService, Layer, "LayerBrush."); Properties.InitializeProperties(layerService, Layer, "LayerBrush.");
EnableLayerBrush();
PropertiesInitialized = true; PropertiesInitialized = true;
EnableLayerBrush();
} }
} }
} }

View File

@ -6,43 +6,26 @@ using RGB.NET.Core;
using RGB.NET.Groups; using RGB.NET.Groups;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush.Abstract
{ {
public abstract class RgbNetLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup public abstract class RgbNetLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{ {
protected RgbNetLayerBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor) protected RgbNetLayerBrush()
{ {
BrushType = LayerBrushType.RgbNet; BrushType = LayerBrushType.RgbNet;
LedGroup = new ListLedGroup();
Layer = layer;
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
} }
/// <summary> /// <summary>
/// The LED group this layer brush is applied to /// The LED group this layer effect is applied to
/// </summary> /// </summary>
public ListLedGroup LedGroup { get; internal set; } public ListLedGroup LedGroup { get; internal set; }
/// <summary> /// <summary>
/// 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
/// </summary> /// </summary>
/// <returns>Your RGB.NET brush</returns> /// <returns>Your RGB.NET effect</returns>
public abstract IBrush GetBrush(); 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() internal void UpdateLedGroup()
{ {
// TODO: This simply renders it on top of the rest, get a ZIndex based on layer position // 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) internal override void Initialize(ILayerService layerService)
{ {
LedGroup = new ListLedGroup();
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties(layerService); InitializeProperties(layerService);
UpdateLedGroup(); UpdateLedGroup();
} }
// Not used in this brush type internal override void Dispose(bool disposing)
internal override void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
{ {
throw new NotImplementedException("RGB.NET layer brushes do not implement InternalRender"); if (disposing)
{
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
LedGroup.Detach();
} }
internal override IBrush InternalGetBrush() base.Dispose(disposing);
}
// 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) private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)

View File

@ -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
{
/// <summary>
/// For internal use only, please use <see cref="LayerEffect" /> instead
/// </summary>
public abstract class BaseLayerEffect : IDisposable
{
/// <summary>
/// Gets the layer this effect is applied to
/// </summary>
public Layer Layer { get; internal set; }
/// <summary>
/// Gets the folder this effect is applied to
/// </summary>
public Folder Folder { get; internal set; }
/// <summary>
/// Gets the descriptor of this effect
/// </summary>
public LayerEffectDescriptor Descriptor { get; internal set; }
/// <summary>
/// Gets the plugin info that defined this effect
/// </summary>
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo;
/// <summary>
/// Gets a reference to the layer property group without knowing it's type
/// </summary>
public virtual LayerPropertyGroup BaseProperties => null;
public void Dispose()
{
DisableLayerEffect();
}
/// <summary>
/// Called when the layer brush is activated
/// </summary>
public abstract void EnableLayerEffect();
/// <summary>
/// Called when the layer brush is deactivated
/// </summary>
public abstract void DisableLayerEffect();
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
public abstract void Update(double deltaTime);
/// <summary>
/// Called before the layer or folder will be rendered
/// </summary>
public abstract void PreProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
/// <summary>
/// Called after the layer of folder has been rendered
/// </summary>
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<T> outside the core
internal abstract void Initialize(ILayerService layerService);
}
}

View File

@ -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
{
/// <summary>
/// For internal use only, please use <see cref="LayerEffect" /> instead
/// </summary>
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
{
private T _properties;
/// <summary>
/// Gets whether all properties on this effect are initialized
/// </summary>
public bool PropertiesInitialized { get; internal set; }
/// <inheritdoc />
public override LayerPropertyGroup BaseProperties => Properties;
/// <summary>
/// Gets the properties of this effect.
/// </summary>
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;
}
/// <summary>
/// Called when all layer properties in this effect have been initialized
/// </summary>
protected virtual void OnPropertiesInitialized()
{
}
internal void InitializeProperties(ILayerService layerService)
{
Properties = Activator.CreateInstance<T>();
Properties.InitializeProperties(layerService, Layer, "LayerEffect.");
OnPropertiesInitialized();
PropertiesInitialized = true;
}
internal override void Initialize(ILayerService layerService)
{
InitializeProperties(layerService);
}
}
}

View File

@ -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
{
/// <summary>
/// For internal use only, please use <see cref="LayerEffect" /> instead
/// </summary>
public abstract class BaseLayerEffect : IDisposable
{
protected BaseLayerEffect(Layer layer, LayerEffectDescriptor descriptor)
{
Layer = layer;
Descriptor = descriptor;
}
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
public Layer Layer { get; internal set; }
/// <summary>
/// Gets the descriptor of this brush
/// </summary>
public LayerEffectDescriptor Descriptor { get; internal set; }
/// <summary>
/// Gets the plugin info that defined this brush
/// </summary>
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo;
/// <summary>
/// Gets a reference to the layer property group without knowing it's type
/// </summary>
public virtual LayerPropertyGroup BaseProperties => null;
/// <summary>
/// Called when the brush is being removed from the layer
/// </summary>
public abstract void Dispose();
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
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<T> and RgbNetLayerEffect<T> outside the core
internal abstract void Initialize(ILayerService layerService);
internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
/// <summary>
/// Called when Artemis needs an instance of the RGB.NET brush you are implementing
/// </summary>
/// <returns>Your RGB.NET brush</returns>
internal abstract IBrush InternalGetBrush();
}
}

View File

@ -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
{
/// <summary>
/// For internal use only, please use <see cref="LayerEffect" /> instead
/// </summary>
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
{
private T _properties;
protected LayerEffect(Layer layer, LayerEffectDescriptor descriptor) : base(layer, descriptor)
{
}
/// <summary>
/// Gets whether all properties on this brush are initialized
/// </summary>
public bool PropertiesInitialized { get; internal set; }
/// <inheritdoc />
public override LayerPropertyGroup BaseProperties => Properties;
/// <summary>
/// Gets the properties of this brush.
/// </summary>
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;
}
/// <summary>
/// Called when all layer properties in this brush have been initialized
/// </summary>
protected virtual void OnPropertiesInitialized()
{
}
internal void InitializeProperties(ILayerService layerService)
{
Properties = Activator.CreateInstance<T>();
Properties.InitializeProperties(layerService, Layer, "LayerEffect.");
OnPropertiesInitialized();
PropertiesInitialized = true;
}
/// <summary>
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
/// and matches it's width and height.
/// <para>Called during rendering or layer preview, in the order configured on the layer</para>
/// </summary>
/// <param name="canvas">The layer canvas</param>
/// <param name="canvasInfo"></param>
/// <param name="path">The path to be filled, represents the shape</param>
/// <param name="paint">The paint to be used to fill the shape</param>
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);
}
}
}

View File

@ -32,7 +32,8 @@ namespace Artemis.Core.Plugins.Models
public string Description { get; set; } public string Description { get; set; }
/// <summary> /// <summary>
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for available /// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
/// available
/// icons /// icons
/// </summary> /// </summary>
public string Icon { get; set; } public string Icon { get; set; }

View File

@ -1,5 +1,4 @@
using System; using System;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Plugins; using Artemis.Storage.Entities.Plugins;
using Artemis.Storage.Repositories.Interfaces; using Artemis.Storage.Repositories.Interfaces;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -10,8 +9,8 @@ namespace Artemis.Core.Plugins.Models
{ {
// ReSharper disable once NotAccessedField.Local // ReSharper disable once NotAccessedField.Local
private readonly PluginInfo _pluginInfo; private readonly PluginInfo _pluginInfo;
private readonly PluginSettingEntity _pluginSettingEntity;
private readonly IPluginRepository _pluginRepository; private readonly IPluginRepository _pluginRepository;
private readonly PluginSettingEntity _pluginSettingEntity;
private T _value; private T _value;
internal PluginSetting(PluginInfo pluginInfo, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity) internal PluginSetting(PluginInfo pluginInfo, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity)

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Plugins; using Artemis.Storage.Entities.Plugins;
using Artemis.Storage.Repositories.Interfaces; using Artemis.Storage.Repositories.Interfaces;
using Newtonsoft.Json; using Newtonsoft.Json;

View File

@ -1,5 +1,6 @@
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
namespace Artemis.Core.Services.Interfaces namespace Artemis.Core.Services.Interfaces
{ {

View File

@ -4,6 +4,7 @@ using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Ninject; using Ninject;
using Ninject.Parameters; using Ninject.Parameters;
@ -56,16 +57,16 @@ namespace Artemis.Core.Services
if (descriptor == null) if (descriptor == null)
return null; return null;
var arguments = new IParameter[] var brush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType);
{ brush.Layer = layer;
new ConstructorArgument("layer", layer), brush.Descriptor = descriptor;
new ConstructorArgument("descriptor", descriptor) layer.LayerBrush = brush;
};
layer.LayerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments); brush.Initialize(this);
layer.LayerBrush.Initialize(this); brush.Update(0);
layer.LayerBrush.Update(0);
layer.OnLayerBrushUpdated(); layer.OnLayerBrushUpdated();
return layer.LayerBrush;
return brush;
} }
} }
} }

View File

@ -267,10 +267,10 @@ namespace Artemis.Core.Services
{ {
var parameters = new IParameter[] var parameters = new IParameter[]
{ {
new ConstructorArgument("pluginInfo", pluginInfo),
new Parameter("PluginInfo", pluginInfo, false) new Parameter("PluginInfo", pluginInfo, false)
}; };
pluginInfo.Instance = (Plugin) _childKernel.Get(pluginType, constraint: null, parameters: parameters); pluginInfo.Instance = (Plugin) _childKernel.Get(pluginType, constraint: null, parameters: parameters);
pluginInfo.Instance.PluginInfo = pluginInfo;
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -21,12 +21,12 @@
<Rectangle x:Name="BorderVisual" <Rectangle x:Name="BorderVisual"
StrokeDashArray="2 2" Stroke="{DynamicResource SecondaryAccentBrush}" StrokeThickness="1" StrokeDashArray="2 2" Stroke="{DynamicResource SecondaryAccentBrush}" StrokeThickness="1"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}"> Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}" />
</Rectangle>
</VisualBrush.Visual> </VisualBrush.Visual>
</VisualBrush> </VisualBrush>
</Border.BorderBrush> </Border.BorderBrush>
<TextBlock Width="60" <TextBlock Style="{x:Null}"
Width="60"
Height="17" Height="17"
Padding="1 0" Padding="1 0"
Margin="0 4 0 0" Margin="0 4 0 0"

View File

@ -2,20 +2,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Core.Events; using Artemis.Core.Events;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes; using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.UI.Events;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Events; using Artemis.UI.Shared.Events;
using Artemis.UI.Shared.Services.Interfaces; using Artemis.UI.Shared.Services.Interfaces;
using Stylet; using Stylet;

View File

@ -7,6 +7,7 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;

View File

@ -306,6 +306,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
var device = Devices.LastOrDefault(d => PanZoomViewModel.TransformContainingRect(d.DeviceRectangle).Contains(position)); var device = Devices.LastOrDefault(d => PanZoomViewModel.TransformContainingRect(d.DeviceRectangle).Contains(position));
if (device != null) if (device != null)
{ {
_rgbService.UpdateTrigger.Stop();
_mouseDragStatus = MouseDragStatus.Dragging; _mouseDragStatus = MouseDragStatus.Dragging;
// If the device is not selected, deselect others and select only this one (if shift not held) // If the device is not selected, deselect others and select only this one (if shift not held)
if (device.SelectionStatus != SelectionStatus.Selected) if (device.SelectionStatus != SelectionStatus.Selected)
@ -350,6 +351,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true); _surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
_mouseDragStatus = MouseDragStatus.None; _mouseDragStatus = MouseDragStatus.None;
_rgbService.UpdateTrigger.Start();
} }
private void UpdateSelection(Point position) private void UpdateSelection(Point position)
@ -415,18 +417,6 @@ namespace Artemis.UI.Screens.SurfaceEditor
} }
#endregion #endregion
protected override void OnActivate()
{
_rgbService.UpdateTrigger.Stop();
base.OnActivate();
}
protected override void OnDeactivate()
{
_rgbService.UpdateTrigger.Start();
base.OnDeactivate();
}
} }
internal enum MouseDragStatus internal enum MouseDragStatus

View File

@ -1,5 +1,4 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Asus; using RGB.NET.Devices.Asus;
@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.Asus
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,7 +1,8 @@
{ {
"Guid": "c20e876f-7cb0-4fa1-b0cc-ae1afb5865d1", "Guid": "c20e876f-7cb0-4fa1-b0cc-ae1afb5865d1",
"Name": "Asus Devices", "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", "Version": "1.0.0.0",
"Main": "Artemis.Plugins.Devices.Asus.dll" "Main": "Artemis.Plugins.Devices.Asus.dll"
} }

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster; using RGB.NET.Devices.CoolerMaster;
@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.CoolerMaster
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair; using RGB.NET.Devices.Corsair;
@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Corsair
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,6 +1,5 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels; using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Devices.DMX.ViewModels; using Artemis.Plugins.Devices.DMX.ViewModels;
@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.DMX
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
HasConfigurationViewModel = true; HasConfigurationViewModel = true;

View File

@ -3,7 +3,6 @@ using System.IO;
using System.Linq; using System.Linq;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using HidSharp; using HidSharp;
using RGB.NET.Core; using RGB.NET.Core;
@ -19,7 +18,7 @@ namespace Artemis.Plugins.Devices.Logitech
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
_logger = logger; _logger = logger;

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Msi; using RGB.NET.Devices.Msi;
@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Msi
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,5 +1,4 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Novation; using RGB.NET.Devices.Novation;
@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.Novation
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,7 +1,6 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer; using RGB.NET.Devices.Razer;
@ -13,7 +12,7 @@ namespace Artemis.Plugins.Devices.Razer
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
namespace Artemis.Plugins.Devices.Roccat namespace Artemis.Plugins.Devices.Roccat
@ -10,7 +9,7 @@ namespace Artemis.Plugins.Devices.Roccat
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,5 +1,4 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.SteelSeries; using RGB.NET.Devices.SteelSeries;
@ -11,7 +10,7 @@ namespace Artemis.Plugins.Devices.SteelSeries
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -15,19 +15,20 @@ namespace Artemis.Plugins.Devices.WS281X
public class WS281XDeviceProvider : DeviceProvider public class WS281XDeviceProvider : DeviceProvider
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
HasConfigurationViewModel = true;
} }
public PluginSettings Settings { get; }
public override void EnablePlugin() public override void EnablePlugin()
{ {
var definitions = Settings.GetSetting<List<DeviceDefinition>>("DeviceDefinitions"); HasConfigurationViewModel = true;
var definitions = _settings.GetSetting<List<DeviceDefinition>>("DeviceDefinitions");
if (definitions.Value == null) if (definitions.Value == null)
definitions.Value = new List<DeviceDefinition>(); definitions.Value = new List<DeviceDefinition>();
@ -56,7 +57,7 @@ namespace Artemis.Plugins.Devices.WS281X
public override PluginConfigurationViewModel GetConfigurationViewModel() public override PluginConfigurationViewModel GetConfigurationViewModel()
{ {
return new WS281XConfigurationViewModel(this, Settings); return new WS281XConfigurationViewModel(this, _settings);
} }
} }
} }

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
@ -12,7 +11,7 @@ namespace Artemis.Plugins.Devices.Wooting
{ {
private readonly IRgbService _rgbService; 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; _rgbService = rgbService;
} }

View File

@ -1,7 +1,8 @@
{ {
"Guid": "e70fd5ba-9881-480a-8ff6-078ed5f747fa", "Guid": "e70fd5ba-9881-480a-8ff6-078ed5f747fa",
"Name": "Wooting Devices", "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", "Version": "1.0.0.0",
"Main": "Artemis.Plugins.Devices.Wooting.dll" "Main": "Artemis.Plugins.Devices.Wooting.dll"
} }

View File

@ -37,6 +37,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(BuildingInsideVisualStudio)' == 'true'"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(BuildingInsideVisualStudio)' == 'true'">
<Exec Command="echo Copying resources to plugin output directory&#xD;&#xA;XCOPY &quot;$(ProjectDir)Images&quot; &quot;$(TargetDir)Images&quot; /s /q /i /y&#xD;&#xA;XCOPY &quot;$(ProjectDir)Layouts&quot; &quot;$(TargetDir)Layouts&quot; /s /q /i /y&#xD;&#xA;echo Copying plugin to Artemis.UI output directory&#xD;&#xA;XCOPY &quot;$(TargetDir.TrimEnd('\'))&quot; &quot;$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)&quot; /s /q /i /y" /> <Exec
Command="echo Copying resources to plugin output directory&#xD;&#xA;XCOPY &quot;$(ProjectDir)Images&quot; &quot;$(TargetDir)Images&quot; /s /q /i /y&#xD;&#xA;XCOPY &quot;$(ProjectDir)Layouts&quot; &quot;$(TargetDir)Layouts&quot; /s /q /i /y&#xD;&#xA;echo Copying plugin to Artemis.UI output directory&#xD;&#xA;XCOPY &quot;$(TargetDir.TrimEnd('\'))&quot; &quot;$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)&quot; /s /q /i /y" />
</Target> </Target>
</Project> </Project>

View File

@ -1,6 +1,5 @@
using System; using System;
using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Color namespace Artemis.Plugins.LayerBrushes.Color
@ -12,13 +11,9 @@ namespace Artemis.Plugins.LayerBrushes.Color
private SKShader _shader; private SKShader _shader;
private SKRect _shaderBounds; private SKRect _shaderBounds;
public ColorBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{
Layer.RenderPropertiesUpdated += (sender, args) => CreateShader();
}
public override void EnableLayerBrush() public override void EnableLayerBrush()
{ {
Layer.RenderPropertiesUpdated += (sender, args) => CreateShader();
Properties.GradientType.BaseValueChanged += (sender, args) => CreateShader(); Properties.GradientType.BaseValueChanged += (sender, args) => CreateShader();
Properties.Color.BaseValueChanged += (sender, args) => CreateShader(); Properties.Color.BaseValueChanged += (sender, args) => CreateShader();
Properties.Gradient.BaseValue.PropertyChanged += (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), new SKPoint(_shaderBounds.Right, _shaderBounds.Top),
Properties.Gradient.BaseValue.GetColorsArray(), Properties.Gradient.BaseValue.GetColorsArray(),
Properties.Gradient.BaseValue.GetPositionsArray(), Properties.Gradient.BaseValue.GetPositionsArray(),
SKShaderTileMode.Repeat), SKShaderTileMode.Clamp),
GradientType.RadialGradient => SKShader.CreateRadialGradient( GradientType.RadialGradient => SKShader.CreateRadialGradient(
center, center,
Math.Min(_shaderBounds.Width, _shaderBounds.Height), Math.Max(_shaderBounds.Width, _shaderBounds.Height) / 2f,
Properties.Gradient.BaseValue.GetColorsArray(), Properties.Gradient.BaseValue.GetColorsArray(),
Properties.Gradient.BaseValue.GetPositionsArray(), Properties.Gradient.BaseValue.GetPositionsArray(),
SKShaderTileMode.Repeat), SKShaderTileMode.Clamp),
GradientType.SweepGradient => SKShader.CreateSweepGradient( GradientType.SweepGradient => SKShader.CreateSweepGradient(
center, center,
Properties.Gradient.BaseValue.GetColorsArray(), Properties.Gradient.BaseValue.GetColorsArray(),

View File

@ -1,18 +1,12 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerBrushes.Color namespace Artemis.Plugins.LayerBrushes.Color
{ {
public class ColorBrushProvider : LayerBrushProvider public class ColorBrushProvider : LayerBrushProvider
{ {
public ColorBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerBrushDescriptor<ColorBrush>("Color", "A color with an (optional) gradient", "Brush");
}
public override void EnablePlugin() public override void EnablePlugin()
{ {
AddLayerBrushDescriptor<ColorBrush>("Color", "A color with an (optional) gradient", "Brush");
} }
public override void DisablePlugin() public override void DisablePlugin()

View File

@ -1,6 +1,5 @@
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using RGB.NET.Brushes; using RGB.NET.Brushes;
using RGB.NET.Core; using RGB.NET.Core;
@ -8,19 +7,16 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet
{ {
public class RgbNetColorBrush : RgbNetLayerBrush<RgbNetColorBrushProperties> public class RgbNetColorBrush : RgbNetLayerBrush<RgbNetColorBrushProperties>
{ {
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); _solidBrush = new SolidColorBrush(Color.Transparent);
} }
public override void EnableLayerBrush()
{
}
public override void DisableLayerBrush() public override void DisableLayerBrush()
{ {
_solidBrush = null;
} }
public override void Update(double deltaTime) public override void Update(double deltaTime)

View File

@ -1,5 +1,4 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Plugins.LayerBrushes.ColorRgbNet.PropertyInput; using Artemis.Plugins.LayerBrushes.ColorRgbNet.PropertyInput;
using Artemis.UI.Shared.Services.Interfaces; using Artemis.UI.Shared.Services.Interfaces;
@ -9,15 +8,15 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet
{ {
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
public RgbNetColorBrushProvider(PluginInfo pluginInfo, IProfileEditorService profileEditorService) : base(pluginInfo) public RgbNetColorBrushProvider(IProfileEditorService profileEditorService)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
AddLayerBrushDescriptor<RgbNetColorBrush>("RGB.NET Color", "A RGB.NET based color", "Brush");
} }
public override void EnablePlugin() public override void EnablePlugin()
{ {
_profileEditorService.RegisterPropertyInput(PluginInfo, typeof(StringPropertyInputViewModel)); _profileEditorService.RegisterPropertyInput(PluginInfo, typeof(StringPropertyInputViewModel));
AddLayerBrushDescriptor<RgbNetColorBrush>("RGB.NET Color", "A RGB.NET based color", "Brush");
} }
public override void DisablePlugin() public override void DisablePlugin()

View File

@ -1,7 +1,6 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.LayerBrushes.Noise.Utilities; using Artemis.Plugins.LayerBrushes.Noise.Utilities;
using SkiaSharp; using SkiaSharp;
@ -11,31 +10,30 @@ namespace Artemis.Plugins.LayerBrushes.Noise
public class NoiseBrush : LayerBrush<NoiseBrushProperties> public class NoiseBrush : LayerBrush<NoiseBrushProperties>
{ {
private static readonly Random Rand = new Random(); private static readonly Random Rand = new Random();
private readonly OpenSimplexNoise _noise;
private readonly IRgbService _rgbService; private readonly IRgbService _rgbService;
private SKBitmap _bitmap; private SKBitmap _bitmap;
private SKColor[] _colorMap; private SKColor[] _colorMap;
private OpenSimplexNoise _noise;
private float _renderScale; private float _renderScale;
private float _x; private float _x;
private float _y; private float _y;
private float _z; private float _z;
public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor, IRgbService rgbService) : base(layer, descriptor) public NoiseBrush(IRgbService rgbService)
{ {
_rgbService = rgbService; _rgbService = rgbService;
}
public override void EnableLayerBrush()
{
_x = Rand.Next(0, 4096); _x = Rand.Next(0, 4096);
_y = Rand.Next(0, 4096); _y = Rand.Next(0, 4096);
_z = Rand.Next(0, 4096); _z = Rand.Next(0, 4096);
_noise = new OpenSimplexNoise(Rand.Next(0, 4096)); _noise = new OpenSimplexNoise(Rand.Next(0, 4096));
DetermineRenderScale();
}
public override void EnableLayerBrush()
{
Properties.GradientColor.BaseValue.PropertyChanged += GradientColorChanged; Properties.GradientColor.BaseValue.PropertyChanged += GradientColorChanged;
CreateColorMap(); CreateColorMap();
DetermineRenderScale();
} }
public override void DisableLayerBrush() public override void DisableLayerBrush()

View File

@ -1,18 +1,12 @@
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerBrushes.Noise namespace Artemis.Plugins.LayerBrushes.Noise
{ {
public class NoiseBrushProvider : LayerBrushProvider public class NoiseBrushProvider : LayerBrushProvider
{ {
public NoiseBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerBrushDescriptor<NoiseBrush>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
}
public override void EnablePlugin() public override void EnablePlugin()
{ {
AddLayerBrushDescriptor<NoiseBrush>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
} }
public override void DisablePlugin() public override void DisablePlugin()

View File

@ -11,15 +11,9 @@ namespace Artemis.Plugins.Modules.General
{ {
private readonly PluginSettings _settings; private readonly PluginSettings _settings;
public GeneralModule(PluginInfo pluginInfo, PluginSettings settings) : base(pluginInfo) public GeneralModule(PluginSettings settings)
{ {
_settings = settings; _settings = settings;
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsMainDataModel = true;
DataModel = new GeneralDataModel(this);
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
} }
public override IEnumerable<ModuleViewModel> GetViewModels() public override IEnumerable<ModuleViewModel> GetViewModels()
@ -29,6 +23,12 @@ namespace Artemis.Plugins.Modules.General
public override void EnablePlugin() 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() public override void DisablePlugin()