mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Code style - Use file scoped namespaces
Code style - Ran code cleanup
This commit is contained in:
1 parent
e68e16df4d
commit
f6090dc296
691 files changed
+37301
-38119
No files matched your search
@@ -1,9 +1,8 @@
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration dialog of a layer brush
|
||||
/// </summary>
|
||||
public interface ILayerBrushConfigurationDialog
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the configuration dialog of a layer brush
|
||||
/// </summary>
|
||||
public interface ILayerBrushConfigurationDialog
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,27 @@
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a brush preset for a brush.
|
||||
/// </summary>
|
||||
public interface ILayerBrushPreset
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a brush preset for a brush.
|
||||
/// Gets the name of the preset
|
||||
/// </summary>
|
||||
public interface ILayerBrushPreset
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the preset
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description of the preset
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
/// <summary>
|
||||
/// Gets the description of the preset
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon of the preset
|
||||
/// </summary>
|
||||
string Icon { get; }
|
||||
/// <summary>
|
||||
/// Gets the icon of the preset
|
||||
/// </summary>
|
||||
string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Applies the preset to the layer brush
|
||||
/// </summary>
|
||||
void Apply();
|
||||
}
|
||||
/// <summary>
|
||||
/// Applies the preset to the layer brush
|
||||
/// </summary>
|
||||
void Apply();
|
||||
}
|
||||
@@ -1,220 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||
/// </summary>
|
||||
public abstract class BaseLayerBrush : BreakableModel, IDisposable
|
||||
{
|
||||
private LayerBrushType _brushType;
|
||||
private ILayerBrushConfigurationDialog? _configurationDialog;
|
||||
private LayerBrushDescriptor _descriptor;
|
||||
private Layer _layer;
|
||||
private bool _supportsTransformation = true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="BaseLayerBrush" /> class
|
||||
/// </summary>
|
||||
protected BaseLayerBrush()
|
||||
{
|
||||
// Both are set right after construction to keep the constructor of inherited classes clean
|
||||
_layer = null!;
|
||||
_descriptor = null!;
|
||||
LayerBrushEntity = null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the layer this brush is applied to
|
||||
/// </summary>
|
||||
public Layer Layer
|
||||
{
|
||||
get => _layer;
|
||||
internal set => SetAndNotify(ref _layer, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the brush entity this brush uses for persistent storage
|
||||
/// </summary>
|
||||
public LayerBrushEntity LayerBrushEntity { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the descriptor of this brush
|
||||
/// </summary>
|
||||
public LayerBrushDescriptor Descriptor
|
||||
{
|
||||
get => _descriptor;
|
||||
internal set => SetAndNotify(ref _descriptor, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a configuration dialog complementing the regular properties
|
||||
/// </summary>
|
||||
public ILayerBrushConfigurationDialog? ConfigurationDialog
|
||||
{
|
||||
get => _configurationDialog;
|
||||
protected set => SetAndNotify(ref _configurationDialog, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of layer brush
|
||||
/// </summary>
|
||||
public LayerBrushType BrushType
|
||||
{
|
||||
get => _brushType;
|
||||
internal set => SetAndNotify(ref _brushType, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the <see cref="LayerBrushProvider" /> that provided this effect
|
||||
/// </summary>
|
||||
public string? ProviderId => Descriptor?.Provider.Id;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the layer property group without knowing it's type
|
||||
/// </summary>
|
||||
public virtual LayerPropertyGroup? BaseProperties => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of presets available to this layer brush
|
||||
/// </summary>
|
||||
public virtual List<ILayerBrushPreset>? Presets => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default preset used for new instances of this layer brush
|
||||
/// </summary>
|
||||
public virtual ILayerBrushPreset? DefaultPreset => Presets?.FirstOrDefault();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the layer brush is enabled or not
|
||||
/// </summary>
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the brush supports transformations
|
||||
/// <para>Note: RGB.NET brushes can never be transformed and setting this to true will throw an exception</para>
|
||||
/// </summary>
|
||||
public bool SupportsTransformation
|
||||
{
|
||||
get => _supportsTransformation;
|
||||
protected set
|
||||
{
|
||||
if (value && BrushType == LayerBrushType.RgbNet)
|
||||
throw new ArtemisPluginFeatureException(Descriptor?.Provider!, "An RGB.NET brush cannot support transformation");
|
||||
_supportsTransformation = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => Descriptor.DisplayName;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layer brush is activated
|
||||
/// </summary>
|
||||
public abstract void EnableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layer brush is deactivated
|
||||
/// </summary>
|
||||
public abstract void DisableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called before rendering every frame, write your update logic here
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public abstract void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
DisableLayerBrush();
|
||||
BaseProperties?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalUpdate(Timeline timeline)
|
||||
{
|
||||
BaseProperties?.Update(timeline);
|
||||
TryOrBreak(() => Update(timeline.Delta.TotalSeconds), "Failed to update");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the layer brush if it isn't already enabled
|
||||
/// </summary>
|
||||
internal void InternalEnable()
|
||||
{
|
||||
if (Enabled)
|
||||
return;
|
||||
|
||||
if (!TryOrBreak(EnableLayerBrush, "Failed to enable"))
|
||||
return;
|
||||
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the layer brush if it isn't already disabled
|
||||
/// </summary>
|
||||
internal void InternalDisable()
|
||||
{
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
DisableLayerBrush();
|
||||
Enabled = false;
|
||||
}
|
||||
|
||||
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
|
||||
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
|
||||
internal abstract void Initialize();
|
||||
|
||||
internal abstract void InternalRender(SKCanvas canvas, SKRect path, SKPaint paint);
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
// No need to update the type or provider ID, they're set once by the LayerBrushDescriptors CreateInstance and can't change
|
||||
BaseProperties?.ApplyToEntity();
|
||||
LayerBrushEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the type of a layer brush
|
||||
/// </summary>
|
||||
public enum LayerBrushType
|
||||
{
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||
/// A regular brush that users Artemis' SkiaSharp-based rendering engine
|
||||
/// </summary>
|
||||
public abstract class BaseLayerBrush : BreakableModel, IDisposable
|
||||
{
|
||||
private LayerBrushType _brushType;
|
||||
private ILayerBrushConfigurationDialog? _configurationDialog;
|
||||
private LayerBrushDescriptor _descriptor;
|
||||
private Layer _layer;
|
||||
private bool _supportsTransformation = true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="BaseLayerBrush" /> class
|
||||
/// </summary>
|
||||
protected BaseLayerBrush()
|
||||
{
|
||||
// Both are set right after construction to keep the constructor of inherited classes clean
|
||||
_layer = null!;
|
||||
_descriptor = null!;
|
||||
LayerBrushEntity = null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the layer this brush is applied to
|
||||
/// </summary>
|
||||
public Layer Layer
|
||||
{
|
||||
get => _layer;
|
||||
internal set => SetAndNotify(ref _layer, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the brush entity this brush uses for persistent storage
|
||||
/// </summary>
|
||||
public LayerBrushEntity LayerBrushEntity { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the descriptor of this brush
|
||||
/// </summary>
|
||||
public LayerBrushDescriptor Descriptor
|
||||
{
|
||||
get => _descriptor;
|
||||
internal set => SetAndNotify(ref _descriptor, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a configuration dialog complementing the regular properties
|
||||
/// </summary>
|
||||
public ILayerBrushConfigurationDialog? ConfigurationDialog
|
||||
{
|
||||
get => _configurationDialog;
|
||||
protected set => SetAndNotify(ref _configurationDialog, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of layer brush
|
||||
/// </summary>
|
||||
public LayerBrushType BrushType
|
||||
{
|
||||
get => _brushType;
|
||||
internal set => SetAndNotify(ref _brushType, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the <see cref="LayerBrushProvider" /> that provided this effect
|
||||
/// </summary>
|
||||
public string? ProviderId => Descriptor?.Provider.Id;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the layer property group without knowing it's type
|
||||
/// </summary>
|
||||
public virtual LayerPropertyGroup? BaseProperties => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of presets available to this layer brush
|
||||
/// </summary>
|
||||
public virtual List<ILayerBrushPreset>? Presets => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default preset used for new instances of this layer brush
|
||||
/// </summary>
|
||||
public virtual ILayerBrushPreset? DefaultPreset => Presets?.FirstOrDefault();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the layer brush is enabled or not
|
||||
/// </summary>
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the brush supports transformations
|
||||
/// <para>Note: RGB.NET brushes can never be transformed and setting this to true will throw an exception</para>
|
||||
/// </summary>
|
||||
public bool SupportsTransformation
|
||||
{
|
||||
get => _supportsTransformation;
|
||||
protected set
|
||||
{
|
||||
if (value && BrushType == LayerBrushType.RgbNet)
|
||||
throw new ArtemisPluginFeatureException(Descriptor?.Provider!, "An RGB.NET brush cannot support transformation");
|
||||
_supportsTransformation = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layer brush is activated
|
||||
/// </summary>
|
||||
public abstract void EnableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layer brush is deactivated
|
||||
/// </summary>
|
||||
public abstract void DisableLayerBrush();
|
||||
|
||||
/// <summary>
|
||||
/// Called before rendering every frame, write your update logic here
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Seconds passed since last update</param>
|
||||
public abstract void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
DisableLayerBrush();
|
||||
BaseProperties?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalUpdate(Timeline timeline)
|
||||
{
|
||||
BaseProperties?.Update(timeline);
|
||||
TryOrBreak(() => Update(timeline.Delta.TotalSeconds), "Failed to update");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the layer brush if it isn't already enabled
|
||||
/// </summary>
|
||||
internal void InternalEnable()
|
||||
{
|
||||
if (Enabled)
|
||||
return;
|
||||
|
||||
if (!TryOrBreak(EnableLayerBrush, "Failed to enable"))
|
||||
return;
|
||||
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the layer brush if it isn't already disabled
|
||||
/// </summary>
|
||||
internal void InternalDisable()
|
||||
{
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
DisableLayerBrush();
|
||||
Enabled = false;
|
||||
}
|
||||
|
||||
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
|
||||
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
|
||||
internal abstract void Initialize();
|
||||
|
||||
internal abstract void InternalRender(SKCanvas canvas, SKRect path, SKPaint paint);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => Descriptor.DisplayName;
|
||||
|
||||
#endregion
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
// No need to update the type or provider ID, they're set once by the LayerBrushDescriptors CreateInstance and can't change
|
||||
BaseProperties?.ApplyToEntity();
|
||||
LayerBrushEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
|
||||
}
|
||||
}
|
||||
Regular,
|
||||
|
||||
/// <summary>
|
||||
/// Describes the type of a layer brush
|
||||
/// An RGB.NET brush that uses RGB.NET's per-LED rendering engine.
|
||||
/// </summary>
|
||||
public enum LayerBrushType
|
||||
{
|
||||
/// <summary>
|
||||
/// A regular brush that users Artemis' SkiaSharp-based rendering engine
|
||||
/// </summary>
|
||||
Regular,
|
||||
|
||||
/// <summary>
|
||||
/// An RGB.NET brush that uses RGB.NET's per-LED rendering engine.
|
||||
/// </summary>
|
||||
RgbNet
|
||||
}
|
||||
RgbNet
|
||||
}
|
||||
@@ -1,44 +1,42 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||
/// </summary>
|
||||
public abstract class PropertiesLayerBrush<T> : BaseLayerBrush where T : LayerPropertyGroup, new()
|
||||
{
|
||||
private T _properties = null!;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||
/// Gets whether all properties on this brush are initialized
|
||||
/// </summary>
|
||||
public abstract class PropertiesLayerBrush<T> : BaseLayerBrush where T : LayerPropertyGroup, new()
|
||||
public bool PropertiesInitialized { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override LayerPropertyGroup BaseProperties => Properties;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the properties of this brush.
|
||||
/// </summary>
|
||||
public T Properties
|
||||
{
|
||||
private T _properties = null!;
|
||||
|
||||
/// <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
|
||||
{
|
||||
get
|
||||
{
|
||||
// I imagine a null reference here can be confusing, so lets throw an exception explaining what to do
|
||||
if (_properties == null)
|
||||
throw new InvalidOperationException("Cannot access brush properties until OnPropertiesInitialized has been called");
|
||||
return _properties;
|
||||
}
|
||||
internal set => _properties = value;
|
||||
// I imagine a null reference here can be confusing, so lets throw an exception explaining what to do
|
||||
if (_properties == null)
|
||||
throw new InvalidOperationException("Cannot access brush properties until OnPropertiesInitialized has been called");
|
||||
return _properties;
|
||||
}
|
||||
internal set => _properties = value;
|
||||
}
|
||||
|
||||
internal void InitializeProperties()
|
||||
{
|
||||
Properties = new T();
|
||||
PropertyGroupDescriptionAttribute groupDescription = new() {Identifier = "Brush", Name = Descriptor.DisplayName, Description = Descriptor.Description};
|
||||
Properties.Initialize(Layer, null, groupDescription, LayerBrushEntity.PropertyGroup);
|
||||
PropertiesInitialized = true;
|
||||
}
|
||||
internal void InitializeProperties()
|
||||
{
|
||||
Properties = new T();
|
||||
PropertyGroupDescriptionAttribute groupDescription = new() {Identifier = "Brush", Name = Descriptor.DisplayName, Description = Descriptor.Description};
|
||||
Properties.Initialize(Layer, null, groupDescription, LayerBrushEntity.PropertyGroup);
|
||||
PropertiesInitialized = true;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,38 @@
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a layer
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a layer
|
||||
/// Creates a new instance of the <see cref="LayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup, new()
|
||||
protected LayerBrush()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="LayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
protected LayerBrush()
|
||||
{
|
||||
BrushType = LayerBrushType.Regular;
|
||||
}
|
||||
BrushType = LayerBrushType.Regular;
|
||||
}
|
||||
|
||||
/// <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="bounds">The area to be filled, covers the shape</param>
|
||||
/// <param name="paint">The paint to be used to fill the shape</param>
|
||||
public abstract void Render(SKCanvas canvas, SKRect bounds, SKPaint paint);
|
||||
/// <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="bounds">The area to be filled, covers the shape</param>
|
||||
/// <param name="paint">The paint to be used to fill the shape</param>
|
||||
public abstract void Render(SKCanvas canvas, SKRect bounds, SKPaint paint);
|
||||
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
{
|
||||
TryOrBreak(() => Render(canvas, bounds, paint), "Failed to render");
|
||||
}
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
{
|
||||
TryOrBreak(() => Render(canvas, bounds, paint), "Failed to render");
|
||||
}
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
}
|
||||
@@ -2,74 +2,73 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// A class that describes a layer brush
|
||||
/// </summary>
|
||||
public class LayerBrushDescriptor
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that describes a layer brush
|
||||
/// </summary>
|
||||
public class LayerBrushDescriptor
|
||||
internal LayerBrushDescriptor(string displayName, string description, string icon, Type layerBrushType, LayerBrushProvider provider)
|
||||
{
|
||||
internal LayerBrushDescriptor(string displayName, string description, string icon, Type layerBrushType, LayerBrushProvider provider)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Description = description;
|
||||
Icon = icon;
|
||||
LayerBrushType = layerBrushType;
|
||||
Provider = provider;
|
||||
}
|
||||
DisplayName = displayName;
|
||||
Description = description;
|
||||
Icon = icon;
|
||||
LayerBrushType = layerBrushType;
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name that is displayed in the UI
|
||||
/// </summary>
|
||||
public string DisplayName { get; }
|
||||
/// <summary>
|
||||
/// The name that is displayed in the UI
|
||||
/// </summary>
|
||||
public string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The description that is displayed in the UI
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
/// <summary>
|
||||
/// The description that is displayed in the UI
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Material icon to display in the UI, a full reference can be found
|
||||
/// <see href="https://materialdesignicons.com">here</see>
|
||||
/// </summary>
|
||||
public string Icon { get; }
|
||||
/// <summary>
|
||||
/// The Material icon to display in the UI, a full reference can be found
|
||||
/// <see href="https://materialdesignicons.com">here</see>
|
||||
/// </summary>
|
||||
public string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of the layer brush
|
||||
/// </summary>
|
||||
public Type LayerBrushType { get; }
|
||||
/// <summary>
|
||||
/// The type of the layer brush
|
||||
/// </summary>
|
||||
public Type LayerBrushType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The plugin that provided this <see cref="LayerBrushDescriptor" />
|
||||
/// </summary>
|
||||
public LayerBrushProvider Provider { get; }
|
||||
/// <summary>
|
||||
/// The plugin that provided this <see cref="LayerBrushDescriptor" />
|
||||
/// </summary>
|
||||
public LayerBrushProvider Provider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided <paramref name="reference" /> references to a brush provided by this descriptor
|
||||
/// </summary>
|
||||
public bool MatchesLayerBrushReference(LayerBrushReference? reference)
|
||||
{
|
||||
if (reference == null)
|
||||
return false;
|
||||
/// <summary>
|
||||
/// Determines whether the provided <paramref name="reference" /> references to a brush provided by this descriptor
|
||||
/// </summary>
|
||||
public bool MatchesLayerBrushReference(LayerBrushReference? reference)
|
||||
{
|
||||
if (reference == null)
|
||||
return false;
|
||||
|
||||
return Provider.Id == reference.LayerBrushProviderId && LayerBrushType.Name == reference.BrushType;
|
||||
}
|
||||
return Provider.Id == reference.LayerBrushProviderId && LayerBrushType.Name == reference.BrushType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the described brush and applies it to the layer
|
||||
/// </summary>
|
||||
public BaseLayerBrush CreateInstance(Layer layer, LayerBrushEntity? entity)
|
||||
{
|
||||
if (layer == null)
|
||||
throw new ArgumentNullException(nameof(layer));
|
||||
/// <summary>
|
||||
/// Creates an instance of the described brush and applies it to the layer
|
||||
/// </summary>
|
||||
public BaseLayerBrush CreateInstance(Layer layer, LayerBrushEntity? entity)
|
||||
{
|
||||
if (layer == null)
|
||||
throw new ArgumentNullException(nameof(layer));
|
||||
|
||||
BaseLayerBrush brush = (BaseLayerBrush) Provider.Plugin.Kernel!.Get(LayerBrushType);
|
||||
brush.Layer = layer;
|
||||
brush.Descriptor = this;
|
||||
brush.LayerBrushEntity = entity ?? new LayerBrushEntity { ProviderId = Provider.Id, BrushType = LayerBrushType.FullName };
|
||||
|
||||
brush.Initialize();
|
||||
return brush;
|
||||
}
|
||||
BaseLayerBrush brush = (BaseLayerBrush) Provider.Plugin.Kernel!.Get(LayerBrushType);
|
||||
brush.Layer = layer;
|
||||
brush.Descriptor = this;
|
||||
brush.LayerBrushEntity = entity ?? new LayerBrushEntity {ProviderId = Provider.Id, BrushType = LayerBrushType.FullName};
|
||||
|
||||
brush.Initialize();
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to create one or more <see cref="LayerBrush{T}" />s usable by profile layers.
|
||||
/// </summary>
|
||||
public abstract class LayerBrushProvider : PluginFeature
|
||||
{
|
||||
private readonly List<LayerBrushDescriptor> _layerBrushDescriptors;
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to create one or more <see cref="LayerBrush{T}" />s usable by profile layers.
|
||||
/// Allows you to register one or more <see cref="LayerBrush{T}" />s usable by profile layers.
|
||||
/// </summary>
|
||||
public abstract class LayerBrushProvider : PluginFeature
|
||||
protected LayerBrushProvider()
|
||||
{
|
||||
private readonly List<LayerBrushDescriptor> _layerBrushDescriptors;
|
||||
_layerBrushDescriptors = new List<LayerBrushDescriptor>();
|
||||
LayerBrushDescriptors = new ReadOnlyCollection<LayerBrushDescriptor>(_layerBrushDescriptors);
|
||||
Disabled += OnDisabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to register one or more <see cref="LayerBrush{T}" />s usable by profile layers.
|
||||
/// </summary>
|
||||
protected LayerBrushProvider()
|
||||
{
|
||||
_layerBrushDescriptors = new List<LayerBrushDescriptor>();
|
||||
LayerBrushDescriptors = new ReadOnlyCollection<LayerBrushDescriptor>(_layerBrushDescriptors);
|
||||
Disabled += OnDisabled;
|
||||
}
|
||||
/// <summary>
|
||||
/// A read-only collection of all layer brushes added with <see cref="RegisterLayerBrushDescriptor{T}" />
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A read-only collection of all layer brushes added with <see cref="RegisterLayerBrushDescriptor{T}" />
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
|
||||
/// <summary>
|
||||
/// Registers 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 RegisterLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush
|
||||
{
|
||||
if (!IsEnabled)
|
||||
throw new ArtemisPluginException(Plugin, "Can only add a layer brush descriptor when the plugin is enabled");
|
||||
|
||||
/// <summary>
|
||||
/// Registers 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 RegisterLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush
|
||||
{
|
||||
if (!IsEnabled)
|
||||
throw new ArtemisPluginException(Plugin, "Can only add a layer brush descriptor when the plugin is enabled");
|
||||
if (icon.Contains('.'))
|
||||
icon = Plugin.ResolveRelativePath(icon);
|
||||
LayerBrushDescriptor descriptor = new(displayName, description, icon, typeof(T), this);
|
||||
_layerBrushDescriptors.Add(descriptor);
|
||||
LayerBrushStore.Add(descriptor);
|
||||
}
|
||||
|
||||
if (icon.Contains('.'))
|
||||
icon = Plugin.ResolveRelativePath(icon);
|
||||
LayerBrushDescriptor descriptor = new(displayName, description, icon, typeof(T), this);
|
||||
_layerBrushDescriptors.Add(descriptor);
|
||||
LayerBrushStore.Add(descriptor);
|
||||
}
|
||||
|
||||
private void OnDisabled(object? sender, EventArgs e)
|
||||
{
|
||||
// The store will clean up the registrations by itself, the plugin just needs to clear its own list
|
||||
_layerBrushDescriptors.Clear();
|
||||
}
|
||||
private void OnDisabled(object? sender, EventArgs e)
|
||||
{
|
||||
// The store will clean up the registrations by itself, the plugin just needs to clear its own list
|
||||
_layerBrushDescriptors.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,80 @@
|
||||
using System;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
namespace Artemis.Core.LayerBrushes;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a per-layer basis
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a per-layer basis
|
||||
/// Creates a new instance of the <see cref="PerLedLayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup, new()
|
||||
protected PerLedLayerBrush()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="PerLedLayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
protected PerLedLayerBrush()
|
||||
BrushType = LayerBrushType.Regular;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
|
||||
/// <para>
|
||||
/// Note: Due to transformations, the render point may not match the position of the LED, always use the render
|
||||
/// point to determine where the color will go.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="led">The LED that will receive the color</param>
|
||||
/// <param name="renderPoint">The point at which the color is located</param>
|
||||
/// <returns>The color the LED will receive</returns>
|
||||
public abstract SKColor GetColor(ArtemisLed led, SKPoint renderPoint);
|
||||
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
{
|
||||
// We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
|
||||
|
||||
using SKPath pointsPath = new();
|
||||
foreach (ArtemisLed artemisLed in Layer.Leds)
|
||||
{
|
||||
BrushType = LayerBrushType.Regular;
|
||||
pointsPath.AddPoly(new[]
|
||||
{
|
||||
new SKPoint(0, 0),
|
||||
new SKPoint(artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
|
||||
/// <para>
|
||||
/// Note: Due to transformations, the render point may not match the position of the LED, always use the render
|
||||
/// point to determine where the color will go.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="led">The LED that will receive the color</param>
|
||||
/// <param name="renderPoint">The point at which the color is located</param>
|
||||
/// <returns>The color the LED will receive</returns>
|
||||
public abstract SKColor GetColor(ArtemisLed led, SKPoint renderPoint);
|
||||
// Apply the translation to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
|
||||
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
SKPoint[] points = pointsPath.Points;
|
||||
|
||||
TryOrBreak(() =>
|
||||
{
|
||||
// We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
|
||||
|
||||
using SKPath pointsPath = new();
|
||||
foreach (ArtemisLed artemisLed in Layer.Leds)
|
||||
for (int index = 0; index < Layer.Leds.Count; index++)
|
||||
{
|
||||
pointsPath.AddPoly(new[]
|
||||
{
|
||||
new SKPoint(0, 0),
|
||||
new SKPoint(artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left, artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top)
|
||||
});
|
||||
ArtemisLed artemisLed = Layer.Leds[index];
|
||||
SKPoint renderPoint = points[index * 2 + 1];
|
||||
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
||||
continue;
|
||||
|
||||
// Let the brush determine the color
|
||||
paint.Color = GetColor(artemisLed, renderPoint);
|
||||
SKRect ledRectangle = SKRect.Create(
|
||||
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
||||
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
||||
artemisLed.AbsoluteRectangle.Width,
|
||||
artemisLed.AbsoluteRectangle.Height
|
||||
);
|
||||
|
||||
canvas.DrawRect(ledRectangle, paint);
|
||||
}
|
||||
}, "Failed to render");
|
||||
}
|
||||
|
||||
// Apply the translation to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
|
||||
|
||||
SKPoint[] points = pointsPath.Points;
|
||||
|
||||
TryOrBreak(() =>
|
||||
{
|
||||
|
||||
|
||||
for (int index = 0; index < Layer.Leds.Count; index++)
|
||||
{
|
||||
ArtemisLed artemisLed = Layer.Leds[index];
|
||||
SKPoint renderPoint = points[index * 2 + 1];
|
||||
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
||||
continue;
|
||||
|
||||
// Let the brush determine the color
|
||||
paint.Color = GetColor(artemisLed, renderPoint);
|
||||
SKRect ledRectangle = SKRect.Create(
|
||||
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
||||
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
||||
artemisLed.AbsoluteRectangle.Width,
|
||||
artemisLed.AbsoluteRectangle.Height
|
||||
);
|
||||
|
||||
canvas.DrawRect(ledRectangle, paint);
|
||||
}
|
||||
}, "Failed to render");
|
||||
}
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user