diff --git a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
index e666f6f..83597ce 100644
--- a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
+++ b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
@@ -2,23 +2,6 @@
{
public class DefaultColorBehavior : IColorBehavior
{
- #region Properties & Fields
-
- private static DefaultColorBehavior _instance = new DefaultColorBehavior();
- ///
- /// Gets the singleton instance of .
- ///
- public static DefaultColorBehavior Instance { get; } = _instance;
-
- #endregion
-
- #region Constructors
-
- private DefaultColorBehavior()
- { }
-
- #endregion
-
#region Methods
///
diff --git a/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs
index 630aca5..3ee7b78 100644
--- a/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs
+++ b/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs
@@ -4,7 +4,7 @@
{
string ToString(Color color);
- bool Equals(Color color, object obj);
+ bool Equals(Color color, object? obj);
int GetHashCode(Color color);
diff --git a/RGB.NET.Core/Color/Color.cs b/RGB.NET.Core/Color/Color.cs
index 81a3a33..e389f19 100644
--- a/RGB.NET.Core/Color/Color.cs
+++ b/RGB.NET.Core/Color/Color.cs
@@ -7,33 +7,27 @@ using System.Diagnostics;
namespace RGB.NET.Core
{
- ///
///
/// Represents an ARGB (alpha, red, green, blue) color.
///
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
- public struct Color
+ public readonly struct Color
{
#region Constants
///
/// Gets an transparent color [A: 0, R: 0, G: 0, B: 0]
///
- public static Color Transparent => new Color(0, 0, 0, 0);
+ public static Color Transparent => new(0, 0, 0, 0);
#endregion
#region Properties & Fields
- private static IColorBehavior _behavior = DefaultColorBehavior.Instance;
///
/// Gets or sets the used to perform operations on colors.
///
- public static IColorBehavior Behavior
- {
- get => _behavior;
- set => _behavior = value ?? DefaultColorBehavior.Instance;
- }
+ public static IColorBehavior Behavior { get; set; } = new DefaultColorBehavior();
///
/// Gets the alpha component value of this as percentage in the range [0..1].
@@ -199,12 +193,13 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj) => Behavior.Equals(this, obj);
+ public override bool Equals(object? obj) => Behavior.Equals(this, obj);
///
/// Returns a hash code for this , as defined by the current .
///
/// An integer value that specifies the hash code for this .
+ // ReSharper disable once NonReadonlyMemberInGetHashCode
public override int GetHashCode() => Behavior.GetHashCode(this);
///
@@ -246,42 +241,42 @@ namespace RGB.NET.Core
///
/// The containing the components.
/// The color.
- public static implicit operator Color((byte r, byte g, byte b) components) => new Color(components.r, components.g, components.b);
+ public static implicit operator Color((byte r, byte g, byte b) components) => new(components.r, components.g, components.b);
///
/// Converts a of ARGB-components to a .
///
/// The containing the components.
/// The color.
- public static implicit operator Color((byte a, byte r, byte g, byte b) components) => new Color(components.a, components.r, components.g, components.b);
+ public static implicit operator Color((byte a, byte r, byte g, byte b) components) => new(components.a, components.r, components.g, components.b);
///
/// Converts a of ARGB-components to a .
///
/// The containing the components.
/// The color.
- public static implicit operator Color((int r, int g, int b) components) => new Color(components.r, components.g, components.b);
+ public static implicit operator Color((int r, int g, int b) components) => new(components.r, components.g, components.b);
///
/// Converts a of ARGB-components to a .
///
/// The containing the components.
/// The color.
- public static implicit operator Color((int a, int r, int g, int b) components) => new Color(components.a, components.r, components.g, components.b);
+ public static implicit operator Color((int a, int r, int g, int b) components) => new(components.a, components.r, components.g, components.b);
///
/// Converts a of ARGB-components to a .
///
/// The containing the components.
/// The color.
- public static implicit operator Color((double r, double g, double b) components) => new Color(components.r, components.g, components.b);
+ public static implicit operator Color((double r, double g, double b) components) => new(components.r, components.g, components.b);
///
/// Converts a of ARGB-components to a .
///
/// The containing the components.
/// The color.
- public static implicit operator Color((double a, double r, double g, double b) components) => new Color(components.a, components.r, components.g, components.b);
+ public static implicit operator Color((double a, double r, double g, double b) components) => new(components.a, components.r, components.g, components.b);
#endregion
}
diff --git a/RGB.NET.Core/Color/HSVColor.cs b/RGB.NET.Core/Color/HSVColor.cs
index f99581c..741a654 100644
--- a/RGB.NET.Core/Color/HSVColor.cs
+++ b/RGB.NET.Core/Color/HSVColor.cs
@@ -82,7 +82,7 @@ namespace RGB.NET.Core
(double cHue, double cSaturation, double cValue) = color.GetHSV();
return Create(color.A, cHue * hue, cSaturation * saturation, cValue * value);
}
-
+
///
/// Divides the given HSV values to this color.
///
@@ -180,7 +180,7 @@ namespace RGB.NET.Core
else // b is max
hue = 4.0 + ((r - g) / (max - min));
- hue = hue * 60.0;
+ hue *= 60.0;
hue = hue.Wrap(0, 360);
double saturation = max.EqualsInTolerance(0) ? 0 : 1.0 - (min / max);
@@ -205,21 +205,15 @@ namespace RGB.NET.Core
double q = v * (1.0 - (s * ff));
double t = v * (1.0 - (s * (1.0 - ff)));
- switch (i)
+ return i switch
{
- case 0:
- return (v, t, p);
- case 1:
- return (q, v, p);
- case 2:
- return (p, v, t);
- case 3:
- return (p, q, v);
- case 4:
- return (t, p, v);
- default:
- return (v, p, q);
- }
+ 0 => (v, t, p),
+ 1 => (q, v, p),
+ 2 => (p, v, t),
+ 3 => (p, q, v),
+ 4 => (t, p, v),
+ _ => (v, p, q)
+ };
}
#endregion
diff --git a/RGB.NET.Core/Color/RGBColor.cs b/RGB.NET.Core/Color/RGBColor.cs
index b196076..ec7fbb2 100644
--- a/RGB.NET.Core/Color/RGBColor.cs
+++ b/RGB.NET.Core/Color/RGBColor.cs
@@ -66,7 +66,7 @@ namespace RGB.NET.Core
/// The blue value to add.
/// The new color after the modification.
public static Color AddRGB(this Color color, int r = 0, int g = 0, int b = 0)
- => new Color(color.A, color.GetR() + r, color.GetG() + g, color.GetB() + b);
+ => new(color.A, color.GetR() + r, color.GetG() + g, color.GetB() + b);
///
/// Adds the given RGB-percent values to this color.
@@ -76,7 +76,7 @@ namespace RGB.NET.Core
/// The blue value to add.
/// The new color after the modification.
public static Color AddRGB(this Color color, double r = 0, double g = 0, double b = 0)
- => new Color(color.A, color.R + r, color.G + g, color.B + b);
+ => new(color.A, color.R + r, color.G + g, color.B + b);
///
/// Adds the given alpha value to this color.
@@ -84,7 +84,7 @@ namespace RGB.NET.Core
/// The alpha value to add.
/// The new color after the modification.
public static Color AddA(this Color color, int a)
- => new Color(color.GetA() + a, color.R, color.G, color.B);
+ => new(color.GetA() + a, color.R, color.G, color.B);
///
/// Adds the given alpha-percent value to this color.
@@ -92,7 +92,7 @@ namespace RGB.NET.Core
/// The alpha value to add.
/// The new color after the modification.
public static Color AddA(this Color color, double a)
- => new Color(color.A + a, color.R, color.G, color.B);
+ => new(color.A + a, color.R, color.G, color.B);
#endregion
@@ -106,7 +106,7 @@ namespace RGB.NET.Core
/// The blue value to subtract.
/// The new color after the modification.
public static Color SubtractRGB(this Color color, int r = 0, int g = 0, int b = 0)
- => new Color(color.A, color.GetR() - r, color.GetG() - g, color.GetB() - b);
+ => new(color.A, color.GetR() - r, color.GetG() - g, color.GetB() - b);
///
/// Subtracts the given RGB values to this color.
@@ -116,7 +116,7 @@ namespace RGB.NET.Core
/// The blue value to subtract.
/// The new color after the modification.
public static Color SubtractRGB(this Color color, double r = 0, double g = 0, double b = 0)
- => new Color(color.A, color.R - r, color.G - g, color.B - b);
+ => new(color.A, color.R - r, color.G - g, color.B - b);
///
/// Subtracts the given alpha value to this color.
@@ -124,7 +124,7 @@ namespace RGB.NET.Core
/// The alpha value to subtract.
/// The new color after the modification.
public static Color SubtractA(this Color color, int a)
- => new Color(color.GetA() - a, color.R, color.G, color.B);
+ => new(color.GetA() - a, color.R, color.G, color.B);
///
/// Subtracts the given alpha-percent value to this color.
@@ -132,7 +132,7 @@ namespace RGB.NET.Core
/// The alpha value to subtract.
/// The new color after the modification.
public static Color SubtractA(this Color color, double aPercent)
- => new Color(color.A - aPercent, color.R, color.G, color.B);
+ => new(color.A - aPercent, color.R, color.G, color.B);
#endregion
@@ -146,7 +146,7 @@ namespace RGB.NET.Core
/// The blue value to multiply.
/// The new color after the modification.
public static Color MultiplyRGB(this Color color, double r = 1, double g = 1, double b = 1)
- => new Color(color.A, color.R * r, color.G * g, color.B * b);
+ => new(color.A, color.R * r, color.G * g, color.B * b);
///
/// Multiplies the given alpha value to this color.
@@ -154,7 +154,7 @@ namespace RGB.NET.Core
/// The alpha value to multiply.
/// The new color after the modification.
public static Color MultiplyA(this Color color, double a)
- => new Color(color.A * a, color.R, color.G, color.B);
+ => new(color.A * a, color.R, color.G, color.B);
#endregion
@@ -168,7 +168,7 @@ namespace RGB.NET.Core
/// The blue value to divide.
/// The new color after the modification.
public static Color DivideRGB(this Color color, double r = 1, double g = 1, double b = 1)
- => new Color(color.A, color.R / r, color.G / g, color.B / b);
+ => new(color.A, color.R / r, color.G / g, color.B / b);
///
/// Divides the given alpha value to this color.
@@ -176,7 +176,7 @@ namespace RGB.NET.Core
/// The alpha value to divide.
/// The new color after the modification.
public static Color DivideA(this Color color, double a)
- => new Color(color.A / a, color.R, color.G, color.B);
+ => new(color.A / a, color.R, color.G, color.B);
#endregion
@@ -190,7 +190,7 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, byte? r = null, byte? g = null, byte? b = null)
- => new Color(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
+ => new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
///
/// Sets the given RGB value of this color.
@@ -200,7 +200,7 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, int? r = null, int? g = null, int? b = null)
- => new Color(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
+ => new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
///
/// Sets the given RGB value of this color.
@@ -210,21 +210,21 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, double? r = null, double? g = null, double? b = null)
- => new Color(color.A, r ?? color.R, g ?? color.G, b ?? color.B);
+ => new(color.A, r ?? color.R, g ?? color.G, b ?? color.B);
///
/// Sets the given alpha value of this color.
///
/// The alpha value to set.
/// The new color after the modification.
- public static Color SetA(this Color color, int a) => new Color(a, color.R, color.G, color.B);
+ public static Color SetA(this Color color, int a) => new(a, color.R, color.G, color.B);
///
/// Sets the given alpha value of this color.
///
/// The alpha value to set.
/// The new color after the modification.
- public static Color SetA(this Color color, double a) => new Color(a, color.R, color.G, color.B);
+ public static Color SetA(this Color color, double a) => new(a, color.R, color.G, color.B);
#endregion
@@ -262,12 +262,12 @@ namespace RGB.NET.Core
hexString = hexString.Substring(1);
byte[] data = ConversionHelper.HexToBytes(hexString);
- if (data.Length == 3)
- return new Color(data[0], data[1], data[2]);
- if (data.Length == 4)
- return new Color(data[0], data[1], data[2], data[3]);
-
- throw new ArgumentException("Invalid hex string", nameof(hexString));
+ return data.Length switch
+ {
+ 3 => new Color(data[0], data[1], data[2]),
+ 4 => new Color(data[0], data[1], data[2], data[3]),
+ _ => throw new ArgumentException($"Invalid hex string '{hexString}'", nameof(hexString))
+ };
}
#endregion
diff --git a/RGB.NET.Core/Decorators/AbstractDecorateable.cs b/RGB.NET.Core/Decorators/AbstractDecorateable.cs
index d12afcd..8acfc54 100644
--- a/RGB.NET.Core/Decorators/AbstractDecorateable.cs
+++ b/RGB.NET.Core/Decorators/AbstractDecorateable.cs
@@ -11,7 +11,7 @@ namespace RGB.NET.Core
{
#region Properties & Fields
- private readonly List _decorators = new List();
+ private readonly List _decorators = new();
///
public IReadOnlyCollection Decorators
diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
index 7979542..f9c88d4 100644
--- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs
+++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
@@ -21,13 +21,15 @@ namespace RGB.NET.Core
{
#region Properties & Fields
+ RGBSurface? IRGBDevice.Surface { get; set; }
+
///
public abstract TDeviceInfo DeviceInfo { get; }
///
IRGBDeviceInfo IRGBDevice.DeviceInfo => DeviceInfo;
- private Point _location = new Point(0, 0);
+ private Point _location = new(0, 0);
///
public Point Location
{
@@ -67,7 +69,7 @@ namespace RGB.NET.Core
private set => SetProperty(ref _deviceRectangle, value);
}
- private Scale _scale = new Scale(1);
+ private Scale _scale = new(1);
///
public Scale Scale
{
@@ -79,7 +81,7 @@ namespace RGB.NET.Core
}
}
- private Rotation _rotation = new Rotation(0);
+ private Rotation _rotation = new(0);
///
public Rotation Rotation
{
@@ -96,13 +98,10 @@ namespace RGB.NET.Core
///
protected bool RequiresFlush { get; set; } = false;
- ///
- public DeviceUpdateMode UpdateMode { get; set; } = DeviceUpdateMode.Sync;
-
///
/// Gets a dictionary containing all of the .
///
- protected Dictionary LedMapping { get; } = new Dictionary();
+ protected Dictionary LedMapping { get; } = new();
#region Indexer
@@ -139,8 +138,7 @@ namespace RGB.NET.Core
foreach (Led ledToUpdate in ledsToUpdate)
ledToUpdate.Update();
- if (UpdateMode.HasFlag(DeviceUpdateMode.Sync))
- UpdateLeds(ledsToUpdate);
+ UpdateLeds(ledsToUpdate);
}
protected virtual IEnumerable GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty));
diff --git a/RGB.NET.Core/Devices/DeviceUpdateMode.cs b/RGB.NET.Core/Devices/DeviceUpdateMode.cs
deleted file mode 100644
index 1a60c67..0000000
--- a/RGB.NET.Core/Devices/DeviceUpdateMode.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-
-namespace RGB.NET.Core
-{
- ///
- /// Contains a list of different device device update modes.
- ///
- [Flags]
- public enum DeviceUpdateMode
- {
- ///
- /// Represents nothing.
- ///
- None = 0,
-
- ///
- /// Represents a mode which updates the leds of the device.
- ///
- Sync = 1 << 0,
-
- ///
- /// Represents all update modes.
- ///
- NoUpdate = 1 << 0xFF
- }
-}
diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs
index c21a06e..d526bae 100644
--- a/RGB.NET.Core/Devices/IRGBDevice.cs
+++ b/RGB.NET.Core/Devices/IRGBDevice.cs
@@ -13,6 +13,8 @@ namespace RGB.NET.Core
{
#region Properties
+ RGBSurface? Surface { get; internal set; }
+
///
/// Gets generic information about the .
///
@@ -49,11 +51,6 @@ namespace RGB.NET.Core
///
Rotation Rotation { get; set; }
- ///
- /// Gets or sets the of the .
- ///
- DeviceUpdateMode UpdateMode { get; set; }
-
#endregion
#region Indexer
diff --git a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
index f0c9ef3..00610bd 100644
--- a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
+++ b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs
@@ -33,7 +33,7 @@ namespace RGB.NET.Core
/// Gets the lighting capability of the
///
RGBDeviceLighting Lighting { get; }
-
+
///
/// Gets the URI of an image of the or null if there is no image.
///
diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs
index 0007614..cac84e5 100644
--- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs
+++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs
@@ -20,29 +20,6 @@ namespace RGB.NET.Core
///
IEnumerable Devices { get; }
- ///
- /// Gets whether the application has exclusive access to devices or not.
- ///
- bool HasExclusiveAccess { get; }
-
- #endregion
-
- #region Methods
-
- ///
- /// Initializes the if not already happened or reloads it if it is already initialized.
- ///
- /// Specifies which types of devices to load.
- /// Specifies whether the application should request exclusive access of possible or not.
- /// Specifies whether exception during the initialization sequence should be thrown or not.
- ///
- bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false);
-
- ///
- /// Resets all handled back to default.
- ///
- void ResetDevices();
-
#endregion
}
}
diff --git a/RGB.NET.Core/Devices/IRGBDeviceProviderLoader.cs b/RGB.NET.Core/Devices/IRGBDeviceProviderLoader.cs
deleted file mode 100644
index 14a60cb..0000000
--- a/RGB.NET.Core/Devices/IRGBDeviceProviderLoader.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace RGB.NET.Core
-{
- ///
- /// Represents a generic device provider loaded used to dynamically load devices into an application.
- /// This class should always provide an empty public constructor!
- ///
- public interface IRGBDeviceProviderLoader
- {
- ///
- /// Indicates if the returned device-provider needs some specific initialization before use.
- ///
- bool RequiresInitialization { get; }
-
- ///
- /// Gets the device-provider.
- ///
- /// The device-provider.
- IRGBDeviceProvider GetDeviceProvider();
- }
-}
diff --git a/RGB.NET.Core/Events/ResolvePathEventArgs.cs b/RGB.NET.Core/Events/ResolvePathEventArgs.cs
index 2b73a2e..7257bf2 100644
--- a/RGB.NET.Core/Events/ResolvePathEventArgs.cs
+++ b/RGB.NET.Core/Events/ResolvePathEventArgs.cs
@@ -8,23 +8,21 @@ namespace RGB.NET.Core
///
/// Gets the filename used to resolve the path.
- /// This has to be checked for null since it'S possible that only is used.
/// Also check before use.
///
- public string RelativePart { get; }
+ public string? RelativePart { get; }
///
/// Gets the filename used to resolve the path.
- /// This has to be checked for null since it'S possible that only is used.
/// Also check before use.
///
- public string FileName { get; }
+ public string? FileName { get; }
///
/// Gets the relative path used to resolve the path.
/// If this is set and are unused.
///
- public string RelativePath { get; }
+ public string? RelativePath { get; }
///
/// Gets or sets the resolved path.
diff --git a/RGB.NET.Core/Events/UpdatingEventArgs.cs b/RGB.NET.Core/Events/UpdatingEventArgs.cs
index 46e1f73..193db2a 100644
--- a/RGB.NET.Core/Events/UpdatingEventArgs.cs
+++ b/RGB.NET.Core/Events/UpdatingEventArgs.cs
@@ -21,8 +21,8 @@ namespace RGB.NET.Core
///
/// Gets the trigger causing this update.
///
- public IUpdateTrigger Trigger { get; }
-
+ public IUpdateTrigger? Trigger { get; }
+
///
/// Gets the custom-data provided by the trigger for this update.
///
@@ -39,7 +39,7 @@ namespace RGB.NET.Core
/// The elapsed time (in seconds) since the last update.
/// The trigger causing this update.
/// The custom-data provided by the trigger for this update.
- public UpdatingEventArgs(double deltaTime, IUpdateTrigger trigger, CustomUpdateData customData)
+ public UpdatingEventArgs(double deltaTime, IUpdateTrigger? trigger, CustomUpdateData customData)
{
this.DeltaTime = deltaTime;
this.Trigger = trigger;
diff --git a/RGB.NET.Core/Exceptions/RGBDeviceException.cs b/RGB.NET.Core/Exceptions/RGBDeviceException.cs
index 735b0c4..d64275d 100644
--- a/RGB.NET.Core/Exceptions/RGBDeviceException.cs
+++ b/RGB.NET.Core/Exceptions/RGBDeviceException.cs
@@ -16,7 +16,7 @@ namespace RGB.NET.Core
///
/// The message which describes the reason of throwing this exception.
/// Optional inner exception, which lead to this exception.
- public RGBDeviceException(string message, Exception innerException = null)
+ public RGBDeviceException(string message, Exception? innerException = null)
: base(message, innerException)
{ }
diff --git a/RGB.NET.Core/Exceptions/RGBSurfaceException.cs b/RGB.NET.Core/Exceptions/RGBSurfaceException.cs
new file mode 100644
index 0000000..c00aa65
--- /dev/null
+++ b/RGB.NET.Core/Exceptions/RGBSurfaceException.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace RGB.NET.Core
+{
+ ///
+ ///
+ /// Represents an exception thrown by an .
+ ///
+ public class RGBSurfaceException : ApplicationException
+ {
+ #region Constructors
+
+ ///
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The message which describes the reason of throwing this exception.
+ /// Optional inner exception, which lead to this exception.
+ public RGBSurfaceException(string message, Exception? innerException = null)
+ : base(message, innerException)
+ { }
+
+ #endregion
+ }
+}
diff --git a/RGB.NET.Core/Extensions/RectangleExtensions.cs b/RGB.NET.Core/Extensions/RectangleExtensions.cs
index aae9b04..de09fc0 100644
--- a/RGB.NET.Core/Extensions/RectangleExtensions.cs
+++ b/RGB.NET.Core/Extensions/RectangleExtensions.cs
@@ -12,7 +12,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new location of the rectangle.
/// The modified .
- public static Rectangle SetLocation(this Rectangle rect, Point location) => new Rectangle(location, rect.Size);
+ public static Rectangle SetLocation(this Rectangle rect, Point location) => new(location, rect.Size);
///
/// Sets the of the of the given rectangle.
@@ -20,7 +20,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new x-location of the rectangle.
/// The modified .
- public static Rectangle SetX(this Rectangle rect, double x) => new Rectangle(new Point(x, rect.Location.Y), rect.Size);
+ public static Rectangle SetX(this Rectangle rect, double x) => new(new Point(x, rect.Location.Y), rect.Size);
///
/// Sets the of the of the given rectangle.
@@ -28,7 +28,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new y-location of the rectangle.
/// The modified .
- public static Rectangle SetY(this Rectangle rect, double y) => new Rectangle(new Point(rect.Location.X, y), rect.Size);
+ public static Rectangle SetY(this Rectangle rect, double y) => new(new Point(rect.Location.X, y), rect.Size);
///
/// Sets the of the given rectangle.
@@ -36,7 +36,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new size of the rectangle.
/// The modified .
- public static Rectangle SetSize(this Rectangle rect, Size size) => new Rectangle(rect.Location, size);
+ public static Rectangle SetSize(this Rectangle rect, Size size) => new(rect.Location, size);
///
/// Sets the of the of the given rectangle.
@@ -44,7 +44,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new width of the rectangle.
/// The modified .
- public static Rectangle SetWidth(this Rectangle rect, double width) => new Rectangle(rect.Location, new Size(width, rect.Size.Height));
+ public static Rectangle SetWidth(this Rectangle rect, double width) => new(rect.Location, new Size(width, rect.Size.Height));
///
/// Sets the of the of the given rectangle.
@@ -52,7 +52,7 @@ namespace RGB.NET.Core
/// The rectangle to modify.
/// The new height of the rectangle.
/// The modified .
- public static Rectangle SetHeight(this Rectangle rect, double height) => new Rectangle(rect.Location, new Size(rect.Size.Width, height));
+ public static Rectangle SetHeight(this Rectangle rect, double height) => new(rect.Location, new Size(rect.Size.Width, height));
///
/// Calculates the percentage of intersection of a rectangle.
@@ -125,7 +125,7 @@ namespace RGB.NET.Core
/// The x-ammount to move.
/// The y-ammount to move.
/// The moved rectangle.
- public static Rectangle Translate(this Rectangle rect, double x = 0, double y = 0) => new Rectangle(rect.Location.Translate(x, y), rect.Size);
+ public static Rectangle Translate(this Rectangle rect, double x = 0, double y = 0) => new(rect.Location.Translate(x, y), rect.Size);
///
/// Rotates the specified by the given amuont around the given origin.
@@ -141,13 +141,13 @@ namespace RGB.NET.Core
/// The rotation.
/// The origin to rotate around. [0,0] if not set.
/// A array of containing the new locations of the corners of the original rectangle.
- public static Point[] Rotate(this Rectangle rect, Rotation rotation, Point origin = new Point())
+ public static Point[] Rotate(this Rectangle rect, Rotation rotation, Point origin = new())
{
Point[] points = {
rect.Location, // top left
- new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right
- new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right
- new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
+ new(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right
+ new(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right
+ new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
};
double sin = Math.Sin(rotation.Radians);
diff --git a/RGB.NET.Core/Groups/AbstractLedGroup.cs b/RGB.NET.Core/Groups/AbstractLedGroup.cs
index 7bacd0c..3720302 100644
--- a/RGB.NET.Core/Groups/AbstractLedGroup.cs
+++ b/RGB.NET.Core/Groups/AbstractLedGroup.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Core
public RGBSurface? Surface { get; private set; }
///
- public IBrush Brush { get; set; }
+ public IBrush? Brush { get; set; }
///
public int ZIndex { get; set; } = 0;
@@ -39,16 +39,10 @@ namespace RGB.NET.Core
public abstract IList GetLeds();
///
- public virtual void OnAttach(RGBSurface surface)
- {
- Surface = surface;
- }
+ public virtual void OnAttach(RGBSurface surface) => Surface = surface;
///
- public virtual void OnDetach(RGBSurface surface)
- {
- Surface = null;
- }
+ public virtual void OnDetach(RGBSurface surface) => Surface = null;
#endregion
}
diff --git a/RGB.NET.Core/Groups/ILedGroup.cs b/RGB.NET.Core/Groups/ILedGroup.cs
index 6d56a0f..3985f8a 100644
--- a/RGB.NET.Core/Groups/ILedGroup.cs
+++ b/RGB.NET.Core/Groups/ILedGroup.cs
@@ -16,7 +16,7 @@ namespace RGB.NET.Core
///
/// Gets or sets the which should be drawn over this .
///
- IBrush Brush { get; set; }
+ IBrush? Brush { get; set; }
///
/// Gets or sets the z-index of this to allow ordering them before drawing. (lowest first) (default: 0)
diff --git a/RGB.NET.Core/Helper/ConversionHelper.cs b/RGB.NET.Core/Helper/ConversionHelper.cs
index cf96a36..b6355af 100644
--- a/RGB.NET.Core/Helper/ConversionHelper.cs
+++ b/RGB.NET.Core/Helper/ConversionHelper.cs
@@ -1,4 +1,6 @@
-namespace RGB.NET.Core
+using System;
+
+namespace RGB.NET.Core
{
///
/// Contains helper methods for converting things.
@@ -20,10 +22,10 @@
for (int bx = 0, cx = 0; bx < bytes.Length; ++bx, ++cx)
{
byte b = ((byte)(bytes[bx] >> 4));
- c[cx] = (char)(b > 9 ? b + 0x37: b + 0x30);
+ c[cx] = (char)(b > 9 ? b + 0x37 : b + 0x30);
b = ((byte)(bytes[bx] & 0x0F));
- c[++cx] = (char)(b > 9 ? b + 0x37: b + 0x30);
+ c[++cx] = (char)(b > 9 ? b + 0x37 : b + 0x30);
}
return new string(c);
@@ -38,7 +40,7 @@
public static byte[] HexToBytes(string hexString)
{
if ((hexString.Length == 0) || ((hexString.Length % 2) != 0))
- return new byte[0];
+ return Array.Empty();
byte[] buffer = new byte[hexString.Length / 2];
for (int bx = 0, sx = 0; bx < buffer.Length; ++bx, ++sx)
diff --git a/RGB.NET.Core/Helper/PathHelper.cs b/RGB.NET.Core/Helper/PathHelper.cs
index d67e5b7..f61189a 100644
--- a/RGB.NET.Core/Helper/PathHelper.cs
+++ b/RGB.NET.Core/Helper/PathHelper.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Core
///
/// Occurs when a path is resolving.
///
- public static event EventHandler ResolvingAbsolutePath;
+ public static event EventHandler? ResolvingAbsolutePath;
#endregion
@@ -25,7 +25,7 @@ namespace RGB.NET.Core
///
/// The relative part of the path to convert.
/// The absolute path.
- public static string GetAbsolutePath(string relativePath) => GetAbsolutePath((object)null, relativePath);
+ public static string GetAbsolutePath(string relativePath) => GetAbsolutePath((object?)null, relativePath);
///
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
@@ -42,17 +42,17 @@ namespace RGB.NET.Core
/// The relative path to convert.
/// The file name of the path to convert.
/// The absolute path.
- public static string GetAbsolutePath(object sender, string relativePath, string fileName)
+ public static string GetAbsolutePath(object? sender, string relativePath, string fileName)
{
string relativePart = Path.Combine(relativePath, fileName);
- string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
+ string? assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePart;
- string directoryName = Path.GetDirectoryName(assemblyLocation);
- string path = directoryName == null ? null : Path.Combine(directoryName, relativePart);
+ string? directoryName = Path.GetDirectoryName(assemblyLocation);
+ string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePart);
- ResolvePathEventArgs args = new ResolvePathEventArgs(relativePath, fileName, path);
+ ResolvePathEventArgs args = new(relativePath, fileName, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
@@ -64,15 +64,15 @@ namespace RGB.NET.Core
/// The requester of this path. (Used for better control when using the event to override this behavior.)
/// The relative path to convert.
/// The absolute path.
- public static string GetAbsolutePath(object sender, string relativePath)
+ public static string GetAbsolutePath(object? sender, string relativePath)
{
- string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
+ string? assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
- string directoryName = Path.GetDirectoryName(assemblyLocation);
- string path = directoryName == null ? null : Path.Combine(directoryName, relativePath);
+ string? directoryName = Path.GetDirectoryName(assemblyLocation);
+ string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePath);
- ResolvePathEventArgs args = new ResolvePathEventArgs(relativePath, path);
+ ResolvePathEventArgs args = new(relativePath, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs
index 67cea33..a7947a3 100644
--- a/RGB.NET.Core/Leds/Led.cs
+++ b/RGB.NET.Core/Leds/Led.cs
@@ -35,11 +35,11 @@ namespace RGB.NET.Core
set => SetProperty(ref _shape, value);
}
- private string _shapeData;
+ private string? _shapeData;
///
/// Gets or sets the data used for by the -.
///
- public string ShapeData
+ public string? ShapeData
{
get => _shapeData;
set => SetProperty(ref _shapeData, value);
@@ -155,7 +155,7 @@ namespace RGB.NET.Core
if (!IsLocked)
{
if (RequestedColor.HasValue)
- RequestedColor += value;
+ RequestedColor = RequestedColor.Value + value;
else
RequestedColor = value;
}
@@ -185,12 +185,12 @@ namespace RGB.NET.Core
///
/// Gets the URI of an image of the or null if there is no image.
///
- public Uri Image { get; set; }
+ public Uri? Image { get; set; }
///
/// Gets the provider-specific data associated with this led.
///
- public object CustomData { get; }
+ public object? CustomData { get; }
#endregion
@@ -204,7 +204,7 @@ namespace RGB.NET.Core
/// The physical location of the relative to the .
/// The size of the .
/// The provider-specific data associated with this led.
- internal Led(IRGBDevice device, LedId id, Point location, Size size, object customData = null)
+ internal Led(IRGBDevice device, LedId id, Point location, Size size, object? customData = null)
{
this.Device = device;
this.Id = id;
@@ -219,14 +219,18 @@ namespace RGB.NET.Core
#region Methods
- private void DevicePropertyChanged(object sender, PropertyChangedEventArgs e)
+ private void DevicePropertyChanged(object? sender, PropertyChangedEventArgs e)
{
- if ((e.PropertyName == nameof(IRGBDevice.Location)))
- UpdateAbsoluteData();
- else if (e.PropertyName == nameof(IRGBDevice.DeviceRectangle))
+ switch (e.PropertyName)
{
- UpdateActualData();
- UpdateAbsoluteData();
+ case nameof(IRGBDevice.Location):
+ UpdateAbsoluteData();
+ break;
+
+ case nameof(IRGBDevice.DeviceRectangle):
+ UpdateActualData();
+ UpdateAbsoluteData();
+ break;
}
}
@@ -235,13 +239,13 @@ namespace RGB.NET.Core
ActualSize = Size * Device.Scale;
Point actualLocation = (Location * Device.Scale);
- Rectangle ledRectangle = new Rectangle(Location * Device.Scale, Size * Device.Scale);
+ Rectangle ledRectangle = new(Location * Device.Scale, Size * Device.Scale);
if (Device.Rotation.IsRotated)
{
Point deviceCenter = new Rectangle(Device.ActualSize).Center;
Point actualDeviceCenter = new Rectangle(Device.DeviceRectangle.Size).Center;
- Point centerOffset = new Point(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
+ Point centerOffset = new(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
actualLocation = actualLocation.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center) + centerOffset;
ledRectangle = new Rectangle(ledRectangle.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center)).Translate(centerOffset);
diff --git a/RGB.NET.Core/MVVM/AbstractBindable.cs b/RGB.NET.Core/MVVM/AbstractBindable.cs
index ab36978..5d41f1c 100644
--- a/RGB.NET.Core/MVVM/AbstractBindable.cs
+++ b/RGB.NET.Core/MVVM/AbstractBindable.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Core
///
/// Occurs when a property value changes.
///
- public event PropertyChangedEventHandler PropertyChanged;
+ public event PropertyChangedEventHandler? PropertyChanged;
#endregion
@@ -28,10 +28,7 @@ namespace RGB.NET.Core
/// Value to apply.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected virtual bool RequiresUpdate(ref T storage, T value)
- {
- return !Equals(storage, value);
- }
+ protected virtual bool RequiresUpdate(ref T storage, T value) => !Equals(storage, value);
///
/// Checks if the property already matches the desired value and updates it if not.
@@ -42,13 +39,13 @@ namespace RGB.NET.Core
/// Name of the property used to notify listeners. This value is optional
/// and can be provided automatically when invoked from compilers that support .
/// true if the value was changed, false if the existing value matched the desired value.
- protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
+ protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string? propertyName = null)
{
- if (!this.RequiresUpdate(ref storage, value)) return false;
+ if (!RequiresUpdate(ref storage, value)) return false;
storage = value;
// ReSharper disable once ExplicitCallerInfoArgument
- this.OnPropertyChanged(propertyName);
+ OnPropertyChanged(propertyName);
return true;
}
@@ -57,10 +54,8 @@ namespace RGB.NET.Core
///
/// Name of the property used to notify listeners. This value is optional
/// and can be provided automatically when invoked from compilers that support .
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
+ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
+ => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
#endregion
}
diff --git a/RGB.NET.Core/Positioning/Point.cs b/RGB.NET.Core/Positioning/Point.cs
index 9583863..d546994 100644
--- a/RGB.NET.Core/Positioning/Point.cs
+++ b/RGB.NET.Core/Positioning/Point.cs
@@ -9,14 +9,14 @@ namespace RGB.NET.Core
/// Represents a point consisting of a X- and a Y-position.
///
[DebuggerDisplay("[X: {X}, Y: {Y}]")]
- public struct Point
+ public readonly struct Point
{
#region Constants
///
/// Gets a [NaN,NaN]-Point.
///
- public static Point Invalid => new Point(double.NaN, double.NaN);
+ public static Point Invalid => new(double.NaN, double.NaN);
#endregion
@@ -62,13 +62,13 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is Point)) return false;
Point comparePoint = (Point)obj;
return ((double.IsNaN(X) && double.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
- && ((double.IsNaN(Y) && double.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
+ && ((double.IsNaN(Y) && double.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
}
///
@@ -111,7 +111,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the addition of the two provided .
- public static Point operator +(Point point1, Point point2) => new Point(point1.X + point2.X, point1.Y + point2.Y);
+ public static Point operator +(Point point1, Point point2) => new(point1.X + point2.X, point1.Y + point2.Y);
///
/// Returns a new created from the provided and .
@@ -119,7 +119,7 @@ namespace RGB.NET.Core
/// The of the rectangle.
/// The of the rectangle.
/// The rectangle created from the provided and .
- public static Rectangle operator +(Point point, Size size) => new Rectangle(point, size);
+ public static Rectangle operator +(Point point, Size size) => new(point, size);
///
/// Returns a new representing the subtraction of the two provided .
@@ -127,7 +127,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the subtraction of the two provided .
- public static Point operator -(Point point1, Point point2) => new Point(point1.X - point2.X, point1.Y - point2.Y);
+ public static Point operator -(Point point1, Point point2) => new(point1.X - point2.X, point1.Y - point2.Y);
///
/// Returns a new representing the multiplication of the two provided .
@@ -135,7 +135,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the multiplication of the two provided .
- public static Point operator *(Point point1, Point point2) => new Point(point1.X * point2.X, point1.Y * point2.Y);
+ public static Point operator *(Point point1, Point point2) => new(point1.X * point2.X, point1.Y * point2.Y);
///
/// Returns a new representing the division of the two provided .
@@ -155,7 +155,7 @@ namespace RGB.NET.Core
/// The .
/// The .
/// A new representing the multiplication of the and the provided .
- public static Point operator *(Point point, Scale scale) => new Point(point.X * scale.Horizontal, point.Y * scale.Vertical);
+ public static Point operator *(Point point, Scale scale) => new(point.X * scale.Horizontal, point.Y * scale.Vertical);
#endregion
}
diff --git a/RGB.NET.Core/Positioning/Rectangle.cs b/RGB.NET.Core/Positioning/Rectangle.cs
index d3b1618..cbf80ab 100644
--- a/RGB.NET.Core/Positioning/Rectangle.cs
+++ b/RGB.NET.Core/Positioning/Rectangle.cs
@@ -12,7 +12,7 @@ namespace RGB.NET.Core
/// Represents a rectangle defined by it's position and it's size.
///
[DebuggerDisplay("[Location: {Location}, Size: {Size}]")]
- public struct Rectangle
+ public readonly struct Rectangle
{
#region Properties & Fields
@@ -69,6 +69,7 @@ namespace RGB.NET.Core
{
this.Location = location;
this.Size = size;
+
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0));
}
@@ -95,15 +96,14 @@ namespace RGB.NET.Core
double posX2 = double.MinValue;
double posY2 = double.MinValue;
- if (rectangles != null)
- foreach (Rectangle rectangle in rectangles)
- {
- hasPoint = true;
- posX = Math.Min(posX, rectangle.Location.X);
- posY = Math.Min(posY, rectangle.Location.Y);
- posX2 = Math.Max(posX2, rectangle.Location.X + rectangle.Size.Width);
- posY2 = Math.Max(posY2, rectangle.Location.Y + rectangle.Size.Height);
- }
+ foreach (Rectangle rectangle in rectangles)
+ {
+ hasPoint = true;
+ posX = Math.Min(posX, rectangle.Location.X);
+ posY = Math.Min(posY, rectangle.Location.Y);
+ posX2 = Math.Max(posX2, rectangle.Location.X + rectangle.Size.Width);
+ posY2 = Math.Max(posY2, rectangle.Location.Y + rectangle.Size.Height);
+ }
(Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0));
Location = location;
@@ -136,15 +136,14 @@ namespace RGB.NET.Core
double posX2 = double.MinValue;
double posY2 = double.MinValue;
- if (points != null)
- foreach (Point point in points)
- {
- hasPoint = true;
- posX = Math.Min(posX, point.X);
- posY = Math.Min(posY, point.Y);
- posX2 = Math.Max(posX2, point.X);
- posY2 = Math.Max(posY2, point.Y);
- }
+ foreach (Point point in points)
+ {
+ hasPoint = true;
+ posX = Math.Min(posX, point.X);
+ posY = Math.Min(posY, point.Y);
+ posX2 = Math.Max(posX2, point.X);
+ posY2 = Math.Max(posY2, point.Y);
+ }
(Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0));
@@ -178,7 +177,7 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is Rectangle compareRect))
return false;
diff --git a/RGB.NET.Core/Positioning/Rotation.cs b/RGB.NET.Core/Positioning/Rotation.cs
index 0f638ec..a2f9219 100644
--- a/RGB.NET.Core/Positioning/Rotation.cs
+++ b/RGB.NET.Core/Positioning/Rotation.cs
@@ -10,7 +10,7 @@ namespace RGB.NET.Core
/// Represents an angular rotation.
///
[DebuggerDisplay("[{Degrees}°]")]
- public struct Rotation
+ public readonly struct Rotation
{
#region Constants
@@ -64,14 +64,14 @@ namespace RGB.NET.Core
///
/// The angle in degrees.
/// The new rotation.
- public static Rotation FromDegrees(double degrees) => new Rotation(degrees);
+ public static Rotation FromDegrees(double degrees) => new(degrees);
///
/// Creates a new Rotation out of the given radian-angle.
///
/// The angle in radians.
/// The new rotation.
- public static Rotation FromRadians(double radians) => new Rotation(radians * RADIANS_DEGREES_CONVERSION, radians);
+ public static Rotation FromRadians(double radians) => new(radians * RADIANS_DEGREES_CONVERSION, radians);
///
/// Tests whether the specified is equivalent to this .
@@ -85,7 +85,7 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj) => obj is Rotation other && Equals(other);
+ public override bool Equals(object? obj) => obj is Rotation other && Equals(other);
///
/// Returns a hash code for this .
@@ -119,7 +119,7 @@ namespace RGB.NET.Core
/// The .
/// The value to add.
/// A new representing the addition of the and the provided value.
- public static Rotation operator +(Rotation rotation, double value) => new Rotation(rotation.Degrees + value);
+ public static Rotation operator +(Rotation rotation, double value) => new(rotation.Degrees + value);
///
/// Returns a new representing the subtraction of the and the provided value.
@@ -127,7 +127,7 @@ namespace RGB.NET.Core
/// The .
/// The value to substract.
/// A new representing the subtraction of the and the provided value.
- public static Rotation operator -(Rotation rotation, double value) => new Rotation(rotation.Degrees - value);
+ public static Rotation operator -(Rotation rotation, double value) => new(rotation.Degrees - value);
///
/// Returns a new representing the multiplication of the and the provided value.
@@ -135,7 +135,7 @@ namespace RGB.NET.Core
/// The .
/// The value to multiply with.
/// A new representing the multiplication of the and the provided value.
- public static Rotation operator *(Rotation rotation, double value) => new Rotation(rotation.Degrees * value);
+ public static Rotation operator *(Rotation rotation, double value) => new(rotation.Degrees * value);
///
/// Returns a new representing the division of the and the provided value.
@@ -149,7 +149,7 @@ namespace RGB.NET.Core
/// Converts a double to a .
///
/// The rotation in degrees to convert.
- public static implicit operator Rotation(double rotation) => new Rotation(rotation);
+ public static implicit operator Rotation(double rotation) => new(rotation);
///
/// Converts to a double representing the rotation in degrees.
diff --git a/RGB.NET.Core/Positioning/Scale.cs b/RGB.NET.Core/Positioning/Scale.cs
index 04b8f09..b12af17 100644
--- a/RGB.NET.Core/Positioning/Scale.cs
+++ b/RGB.NET.Core/Positioning/Scale.cs
@@ -9,7 +9,7 @@ namespace RGB.NET.Core
/// Represents a scaling.
///
[DebuggerDisplay("[Horizontal: {Horizontal}, Vertical: {Vertical}]")]
- public struct Scale
+ public readonly struct Scale
{
#region Properties & Fields
@@ -61,7 +61,7 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj) => obj is Scale other && Equals(other);
+ public override bool Equals(object? obj) => obj is Scale other && Equals(other);
///
/// Returns a hash code for this .
@@ -106,7 +106,7 @@ namespace RGB.NET.Core
/// The .
/// The value to add.
/// A new representing the addition of the and the provided value.
- public static Scale operator +(Scale scale, double value) => new Scale(scale.Horizontal + value, scale.Vertical + value);
+ public static Scale operator +(Scale scale, double value) => new(scale.Horizontal + value, scale.Vertical + value);
///
/// Returns a new representing the subtraction of the and the provided value.
@@ -114,7 +114,7 @@ namespace RGB.NET.Core
/// The .
/// The value to substract.
/// A new representing the subtraction of the and the provided value.
- public static Scale operator -(Scale scale, double value) => new Scale(scale.Horizontal - value, scale.Vertical - value);
+ public static Scale operator -(Scale scale, double value) => new(scale.Horizontal - value, scale.Vertical - value);
///
/// Returns a new representing the multiplication of the and the provided value.
@@ -122,7 +122,7 @@ namespace RGB.NET.Core
/// The .
/// The value to multiply with.
/// A new representing the multiplication of the and the provided value.
- public static Scale operator *(Scale scale, double value) => new Scale(scale.Horizontal * value, scale.Vertical * value);
+ public static Scale operator *(Scale scale, double value) => new(scale.Horizontal * value, scale.Vertical * value);
///
/// Returns a new representing the division of the and the provided value.
@@ -137,7 +137,7 @@ namespace RGB.NET.Core
/// Converts a double to a .
///
/// The scale value to convert.
- public static implicit operator Scale(double scale) => new Scale(scale);
+ public static implicit operator Scale(double scale) => new(scale);
#endregion
}
diff --git a/RGB.NET.Core/Positioning/Size.cs b/RGB.NET.Core/Positioning/Size.cs
index 74f9153..7ed7887 100644
--- a/RGB.NET.Core/Positioning/Size.cs
+++ b/RGB.NET.Core/Positioning/Size.cs
@@ -9,14 +9,14 @@ namespace RGB.NET.Core
/// Represents a size consisting of a width and a height.
///
[DebuggerDisplay("[Width: {Width}, Height: {Height}]")]
- public struct Size
+ public readonly struct Size
{
#region Constants
///
/// Gets a [NaN,NaN]-Size.
///
- public static Size Invalid => new Size(double.NaN, double.NaN);
+ public static Size Invalid => new(double.NaN, double.NaN);
#endregion
@@ -71,13 +71,13 @@ namespace RGB.NET.Core
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
- if (!(obj is Size)) return false;
+ if (!(obj is Size size)) return false;
- Size compareSize = (Size)obj;
- return ((double.IsNaN(Width) && double.IsNaN(compareSize.Width)) || Width.EqualsInTolerance(compareSize.Width))
- && ((double.IsNaN(Height) && double.IsNaN(compareSize.Height)) || Height.EqualsInTolerance(compareSize.Height));
+ (double width, double height) = size;
+ return ((double.IsNaN(Width) && double.IsNaN(width)) || Width.EqualsInTolerance(width))
+ && ((double.IsNaN(Height) && double.IsNaN(height)) || Height.EqualsInTolerance(height));
}
///
@@ -131,7 +131,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the addition of the two provided .
- public static Size operator +(Size size1, Size size2) => new Size(size1.Width + size2.Width, size1.Height + size2.Height);
+ public static Size operator +(Size size1, Size size2) => new(size1.Width + size2.Width, size1.Height + size2.Height);
///
/// Returns a new created from the provided and .
@@ -139,7 +139,7 @@ namespace RGB.NET.Core
/// The of the rectangle.
/// The of the rectangle.
/// The rectangle created from the provided and .
- public static Rectangle operator +(Size size, Point point) => new Rectangle(point, size);
+ public static Rectangle operator +(Size size, Point point) => new(point, size);
///
/// Returns a new representing the subtraction of the two provided .
@@ -147,7 +147,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the subtraction of the two provided .
- public static Size operator -(Size size1, Size size2) => new Size(size1.Width - size2.Width, size1.Height - size2.Height);
+ public static Size operator -(Size size1, Size size2) => new(size1.Width - size2.Width, size1.Height - size2.Height);
///
/// Returns a new representing the multiplication of the two provided .
@@ -155,7 +155,7 @@ namespace RGB.NET.Core
/// The first .
/// The second .
/// A new representing the multiplication of the two provided .
- public static Size operator *(Size size1, Size size2) => new Size(size1.Width * size2.Width, size1.Height * size2.Height);
+ public static Size operator *(Size size1, Size size2) => new(size1.Width * size2.Width, size1.Height * size2.Height);
///
/// Returns a new representing the multiplication of the and the provided factor.
@@ -163,7 +163,7 @@ namespace RGB.NET.Core
/// The .
/// The factor by which the should be multiplied.
/// A new representing the multiplication of the and the provided factor.
- public static Size operator *(Size size, double factor) => new Size(size.Width * factor, size.Height * factor);
+ public static Size operator *(Size size, double factor) => new(size.Width * factor, size.Height * factor);
///
/// Returns a new representing the division of the two provided .
@@ -189,7 +189,7 @@ namespace RGB.NET.Core
/// The to scale.
/// The scaling factor.
/// A new representing the multiplication of the and the given .
- public static Size operator *(Size size, Scale scale) => new Size(size.Width * scale.Horizontal, size.Height * scale.Vertical);
+ public static Size operator *(Size size, Scale scale) => new(size.Width * scale.Horizontal, size.Height * scale.Vertical);
#endregion
}
diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs
index fdc92bb..4c6ec12 100644
--- a/RGB.NET.Core/RGBSurface.cs
+++ b/RGB.NET.Core/RGBSurface.cs
@@ -21,13 +21,12 @@ namespace RGB.NET.Core
private Stopwatch _deltaTimeCounter;
- private IList _deviceProvider = new List();
private IList _devices = new List();
private IList _updateTriggers = new List();
// ReSharper disable InconsistentNaming
- private readonly LinkedList _ledGroups = new LinkedList();
+ private readonly LinkedList _ledGroups = new();
// ReSharper restore InconsistentNaming
@@ -102,22 +101,22 @@ namespace RGB.NET.Core
///
/// Occurs when a catched exception is thrown inside the .
///
- public event ExceptionEventHandler Exception;
+ public event ExceptionEventHandler? Exception;
///
/// Occurs when the starts updating.
///
- public event UpdatingEventHandler Updating;
+ public event UpdatingEventHandler? Updating;
///
/// Occurs when the update is done.
///
- public event UpdatedEventHandler Updated;
+ public event UpdatedEventHandler? Updated;
///
/// Occurs when the layout of this changed.
///
- public event SurfaceLayoutChangedEventHandler SurfaceLayoutChanged;
+ public event SurfaceLayoutChangedEventHandler? SurfaceLayoutChanged;
// ReSharper restore EventNeverSubscribedTo.Global
@@ -143,13 +142,10 @@ namespace RGB.NET.Core
/// Specifies whether all , (including clean ones) should be updated.
public void Update(bool flushLeds = false) => Update(null, new CustomUpdateData(("flushLeds", flushLeds)));
- private void Update(object updateTrigger, CustomUpdateData customData) => Update(updateTrigger as IUpdateTrigger, customData);
+ private void Update(object? updateTrigger, CustomUpdateData customData) => Update(updateTrigger as IUpdateTrigger, customData);
- private void Update(IUpdateTrigger updateTrigger, CustomUpdateData customData)
+ private void Update(IUpdateTrigger? updateTrigger, CustomUpdateData customData)
{
- if (customData == null)
- customData = new CustomUpdateData();
-
try
{
bool flushLeds = customData["flushLeds"] as bool? ?? false;
@@ -172,9 +168,8 @@ namespace RGB.NET.Core
if (updateDevices)
foreach (IRGBDevice device in _devices)
- if (!device.UpdateMode.HasFlag(DeviceUpdateMode.NoUpdate))
- try { device.Update(flushLeds); }
- catch (Exception ex) { OnException(ex); }
+ try { device.Update(flushLeds); }
+ catch (Exception ex) { OnException(ex); }
OnUpdated();
}
@@ -188,23 +183,19 @@ namespace RGB.NET.Core
///
public void Dispose()
{
+ List devices;
lock (_devices)
- foreach (IRGBDevice device in _devices)
- try { device.Dispose(); }
- catch { /* We do what we can */}
+ devices = new List(_devices);
- lock (_deviceProvider)
- foreach (IRGBDeviceProvider deviceProvider in _deviceProvider)
- try { deviceProvider.Dispose(); }
- catch { /* We do what we can */}
+ foreach (IRGBDevice device in devices)
+ try { Detach(device); }
+ catch { /* We do what we can */}
foreach (IUpdateTrigger updateTrigger in _updateTriggers)
try { updateTrigger.Dispose(); }
catch { /* We do what we can */}
_ledGroups.Clear();
- _devices = null;
- _deviceProvider = null;
}
///
@@ -214,15 +205,15 @@ namespace RGB.NET.Core
private void Render(ILedGroup ledGroup)
{
IList leds = ledGroup.GetLeds().ToList();
- IBrush brush = ledGroup.Brush;
+ IBrush? brush = ledGroup.Brush;
if ((brush == null) || !brush.IsEnabled) return;
switch (brush.BrushCalculationMode)
{
case BrushCalculationMode.Relative:
- Rectangle brushRectangle = new Rectangle(leds.Select(led => led.AbsoluteLedRectangle));
- Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
+ Rectangle brushRectangle = new(leds.Select(led => led.AbsoluteLedRectangle));
+ Point offset = new(-brushRectangle.Location.X, -brushRectangle.Location.Y);
brushRectangle = brushRectangle.SetLocation(new Point(0, 0));
brush.PerformRender(brushRectangle, leds.Select(led => new BrushRenderTarget(led, led.AbsoluteLedRectangle.Translate(offset))));
break;
@@ -247,8 +238,6 @@ namespace RGB.NET.Core
/// true if the could be attached; otherwise, false.
public bool AttachLedGroup(ILedGroup ledGroup)
{
- if (ledGroup == null) return false;
-
lock (_ledGroups)
{
if (_ledGroups.Contains(ledGroup)) return false;
@@ -267,11 +256,9 @@ namespace RGB.NET.Core
/// true if the could be detached; otherwise, false.
public bool DetachLedGroup(ILedGroup ledGroup)
{
- if (ledGroup == null) return false;
-
lock (_ledGroups)
{
- LinkedListNode node = _ledGroups.Find(ledGroup);
+ LinkedListNode? node = _ledGroups.Find(ledGroup);
if (node == null) return false;
_ledGroups.Remove(node);
@@ -280,52 +267,46 @@ namespace RGB.NET.Core
return true;
}
}
- // ReSharper disable UnusedMember.Global
- ///
- /// Loads all devices the given by the provided by the give .
- ///
- /// The which provides the to load the devices from.
- /// Specifies which types of devices to load.
- /// Specifies whether the application should request exclusive access of possible or not.
- /// Specifies whether exception during the initialization sequence should be thrown or not.
- public void LoadDevices(IRGBDeviceProviderLoader deviceProviderLoader, RGBDeviceType loadFilter = RGBDeviceType.All,
- bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
- => LoadDevices(deviceProviderLoader.GetDeviceProvider(), loadFilter, exclusiveAccessIfPossible, throwExceptions);
- ///
- /// Loads all devices the given is able to provide.
- ///
- /// The to load the devices from.
- /// Specifies which types of devices to load.
- /// Specifies whether the application should request exclusive access of possible or not.
- /// Specifies whether exception during the initialization sequence should be thrown or not.
- public void LoadDevices(IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
+ public void Attach(IEnumerable devices)
{
- lock (_deviceProvider)
+ lock (_devices)
{
- if (_deviceProvider.Contains(deviceProvider) || _deviceProvider.Any(x => x.GetType() == deviceProvider.GetType())) return;
+ foreach (IRGBDevice device in devices)
+ Attach(device);
+ }
+ }
- List addedDevices = new List();
- if (deviceProvider.IsInitialized || deviceProvider.Initialize(loadFilter, exclusiveAccessIfPossible, throwExceptions))
- {
- _deviceProvider.Add(deviceProvider);
- lock (_devices)
- foreach (IRGBDevice device in deviceProvider.Devices)
- {
- if (_devices.Contains(device)) continue;
+ public void Attach(IRGBDevice device)
+ {
+ lock (_devices)
+ {
+ if (_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' is already attached.");
- addedDevices.Add(device);
+ device.Surface = this;
- device.PropertyChanged += DeviceOnPropertyChanged;
- _devices.Add(device);
- }
- }
+ _devices.Add(device);
+ }
+ }
- if (addedDevices.Any())
- {
- UpdateSurfaceRectangle();
- SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(addedDevices, true, false));
- }
+ public void Detach(IEnumerable devices)
+ {
+ lock (_devices)
+ {
+ foreach (IRGBDevice device in devices)
+ Detach(device);
+ }
+ }
+
+ public void Detach(IRGBDevice device)
+ {
+ lock (_devices)
+ {
+ if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' isn't attached.");
+
+ device.Surface = null;
+
+ _devices.Remove(device);
}
}
@@ -347,14 +328,14 @@ namespace RGB.NET.Core
private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
UpdateSurfaceRectangle();
- SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true));
+ SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs((sender is IRGBDevice device) ? new[] { device } : Array.Empty(), false, true));
}
private void UpdateSurfaceRectangle()
{
lock (_devices)
{
- Rectangle devicesRectangle = new Rectangle(_devices.Select(d => d.DeviceRectangle));
+ Rectangle devicesRectangle = new(_devices.Select(d => d.DeviceRectangle));
SurfaceRectangle = SurfaceRectangle.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));
}
}
@@ -368,7 +349,7 @@ namespace RGB.NET.Core
where T : class
{
lock (_devices)
- return new ReadOnlyCollection(_devices.Select(x => x as T).Where(x => x != null).ToList());
+ return new ReadOnlyCollection(_devices.Where(x => x is T).Cast().ToList());
}
///
@@ -421,7 +402,7 @@ namespace RGB.NET.Core
///
/// Handles the needed event-calls before updating.
///
- private void OnUpdating(IUpdateTrigger trigger, CustomUpdateData customData)
+ private void OnUpdating(IUpdateTrigger? trigger, CustomUpdateData customData)
{
try
{
diff --git a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs
index e311037..722c30e 100644
--- a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs
+++ b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs
@@ -10,9 +10,9 @@ namespace RGB.NET.Core
#region Events
///
- public event EventHandler Starting;
+ public event EventHandler? Starting;
///
- public event EventHandler Update;
+ public event EventHandler? Update;
#endregion
@@ -22,13 +22,13 @@ namespace RGB.NET.Core
/// Invokes the -event.
///
/// Optional custom-data passed to the subscribers of the .event.
- protected virtual void OnStartup(CustomUpdateData updateData = null) => Starting?.Invoke(this, updateData);
+ protected virtual void OnStartup(CustomUpdateData? updateData = null) => Starting?.Invoke(this, updateData ?? new CustomUpdateData());
///
/// Invokes the -event.
///
/// Optional custom-data passed to the subscribers of the .event.
- protected virtual void OnUpdate(CustomUpdateData updateData = null) => Update?.Invoke(this, updateData);
+ protected virtual void OnUpdate(CustomUpdateData? updateData = null) => Update?.Invoke(this, updateData ?? new CustomUpdateData());
///
public abstract void Dispose();
diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs
index 0ecfc7f..0c14e77 100644
--- a/RGB.NET.Core/Update/CustomUpdateData.cs
+++ b/RGB.NET.Core/Update/CustomUpdateData.cs
@@ -9,7 +9,7 @@ namespace RGB.NET.Core
{
#region Properties & Fields
- private Dictionary _data = new Dictionary();
+ private Dictionary _data = new();
#endregion
@@ -20,10 +20,10 @@ namespace RGB.NET.Core
///
/// The key of the value.
/// The value represented by the given key.
- public object this[string key]
+ public object? this[string key]
{
- get => _data.TryGetValue(key?.ToUpperInvariant() ?? string.Empty, out object data) ? data : default;
- set => _data[key?.ToUpperInvariant() ?? string.Empty] = value;
+ get => _data.TryGetValue(key.ToUpperInvariant(), out object? data) ? data : default;
+ set => _data[key.ToUpperInvariant()] = value;
}
#endregion
diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs
index 8f4beba..43caf4c 100644
--- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs
+++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs
@@ -53,12 +53,12 @@ namespace RGB.NET.Core
}
}
- protected AutoResetEvent HasDataEvent = new AutoResetEvent(false);
+ protected AutoResetEvent HasDataEvent { get; set; } = new(false);
- protected bool IsRunning;
- protected Task UpdateTask;
- protected CancellationTokenSource UpdateTokenSource;
- protected CancellationToken UpdateToken;
+ protected bool IsRunning { get; set; }
+ protected Task? UpdateTask { get; set; }
+ protected CancellationTokenSource? UpdateTokenSource { get; set; }
+ protected CancellationToken UpdateToken { get; set; }
#endregion
@@ -106,15 +106,18 @@ namespace RGB.NET.Core
IsRunning = false;
- UpdateTokenSource.Cancel();
- await UpdateTask;
- UpdateTask.Dispose();
+ UpdateTokenSource?.Cancel();
+ if (UpdateTask != null)
+ await UpdateTask;
+
+ UpdateTask?.Dispose();
UpdateTask = null;
}
protected virtual void UpdateLoop()
{
OnStartup();
+
while (!UpdateToken.IsCancellationRequested)
{
if (HasDataEvent.WaitOne(Timeout))
diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs
index da5c82c..bd2c8ad 100644
--- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs
+++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs
@@ -10,12 +10,13 @@ namespace RGB.NET.Core
/// The type of the key used to identify some data.
/// The type of the data.
public abstract class UpdateQueue : IDisposable
+ where TIdentifier : notnull
{
#region Properties & Fields
private readonly object _dataLock = new object();
private readonly IDeviceUpdateTrigger _updateTrigger;
- private Dictionary _currentDataSet;
+ private Dictionary? _currentDataSet;
#endregion
@@ -42,16 +43,18 @@ namespace RGB.NET.Core
///
/// The causing this update.
/// provided by the trigger.
- protected virtual void OnUpdate(object sender, CustomUpdateData customData)
+ protected virtual void OnUpdate(object? sender, CustomUpdateData customData)
{
Dictionary dataSet;
lock (_dataLock)
{
+ if (_currentDataSet == null) return;
+
dataSet = _currentDataSet;
_currentDataSet = null;
}
- if ((dataSet != null) && (dataSet.Count != 0))
+ if (dataSet.Count != 0)
Update(dataSet);
}
@@ -60,7 +63,7 @@ namespace RGB.NET.Core
///
/// The starting .
/// provided by the trigger.
- protected virtual void OnStartup(object sender, CustomUpdateData customData) { }
+ protected virtual void OnStartup(object? sender, CustomUpdateData customData) { }
///
/// Performs the update this queue is responsible for.
@@ -75,7 +78,7 @@ namespace RGB.NET.Core
// ReSharper disable once MemberCanBeProtected.Global
public virtual void SetData(Dictionary dataSet)
{
- if ((dataSet == null) || (dataSet.Count == 0)) return;
+ if (dataSet.Count == 0) return;
lock (_dataLock)
{
@@ -83,8 +86,8 @@ namespace RGB.NET.Core
_currentDataSet = dataSet;
else
{
- foreach (KeyValuePair command in dataSet)
- _currentDataSet[command.Key] = command.Value;
+ foreach ((TIdentifier key, TData value) in dataSet)
+ _currentDataSet[key] = value;
}
}
@@ -132,7 +135,7 @@ namespace RGB.NET.Core
/// Calls for a data set created out of the provided list of .
///
///
- public void SetData(IEnumerable leds) => SetData(leds?.ToDictionary(x => x.CustomData ?? x.Id, x => x.Color));
+ public void SetData(IEnumerable leds) => SetData(leds.ToDictionary(x => x.CustomData ?? x.Id, x => x.Color));
#endregion
}
diff --git a/RGB.NET.Core/Update/IUpdateTrigger.cs b/RGB.NET.Core/Update/IUpdateTrigger.cs
index eed8f3d..e80c3c0 100644
--- a/RGB.NET.Core/Update/IUpdateTrigger.cs
+++ b/RGB.NET.Core/Update/IUpdateTrigger.cs
@@ -10,11 +10,11 @@ namespace RGB.NET.Core
///
/// Occurs when the trigger is starting up.
///
- event EventHandler Starting;
+ event EventHandler? Starting;
///
/// Occurs when the trigger wants to cause an update.
///
- event EventHandler Update;
+ event EventHandler? Update;
}
}
diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs
index 0171ffb..24321be 100644
--- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs
+++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs
@@ -14,12 +14,11 @@ namespace RGB.NET.Core
{
#region Properties & Fields
- private object _lock = new object();
+ private object _lock = new();
- private CancellationTokenSource _updateTokenSource;
- private CancellationToken _updateToken;
- private Task _updateTask;
- private Stopwatch _sleepCounter;
+ protected Task? UpdateTask { get; set; }
+ protected CancellationTokenSource? UpdateTokenSource { get; set; }
+ protected CancellationToken UpdateToken { get; set; }
private double _updateFrequency = 1.0 / 30.0;
///
@@ -46,8 +45,6 @@ namespace RGB.NET.Core
/// A value indicating if the trigger should automatically right after construction.
public TimerUpdateTrigger(bool autostart = true)
{
- _sleepCounter = new Stopwatch();
-
if (autostart)
Start();
}
@@ -63,11 +60,11 @@ namespace RGB.NET.Core
{
lock (_lock)
{
- if (_updateTask == null)
+ if (UpdateTask == null)
{
- _updateTokenSource?.Dispose();
- _updateTokenSource = new CancellationTokenSource();
- _updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default);
+ UpdateTokenSource?.Dispose();
+ UpdateTokenSource = new CancellationTokenSource();
+ UpdateTask = Task.Factory.StartNew(UpdateLoop, (UpdateToken = UpdateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
}
}
@@ -79,30 +76,35 @@ namespace RGB.NET.Core
{
lock (_lock)
{
- if (_updateTask != null)
+ if (UpdateTask != null)
{
- _updateTokenSource.Cancel();
+ UpdateTokenSource?.Cancel();
// ReSharper disable once MethodSupportsCancellation
- _updateTask.Wait();
- _updateTask.Dispose();
- _updateTask = null;
+ UpdateTask.Wait();
+ UpdateTask.Dispose();
+ UpdateTask = null;
}
}
}
private void UpdateLoop()
{
- while (!_updateToken.IsCancellationRequested)
+ OnStartup();
+
+ while (!UpdateToken.IsCancellationRequested)
{
- _sleepCounter.Restart();
+ long preUpdateTicks = Stopwatch.GetTimestamp();
OnUpdate();
- _sleepCounter.Stop();
- LastUpdateTime = _sleepCounter.Elapsed.TotalSeconds;
- int sleep = (int)((UpdateFrequency * 1000.0) - _sleepCounter.ElapsedMilliseconds);
- if (sleep > 0)
- Thread.Sleep(sleep);
+ if (UpdateFrequency > 0)
+ {
+ double lastUpdateTime = ((Stopwatch.GetTimestamp() - preUpdateTicks) / 10000.0);
+ LastUpdateTime = lastUpdateTime;
+ int sleep = (int)((UpdateFrequency * 1000.0) - lastUpdateTime);
+ if (sleep > 0)
+ Thread.Sleep(sleep);
+ }
}
}
diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProviderLoader.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProviderLoader.cs
deleted file mode 100644
index 4a1aa54..0000000
--- a/RGB.NET.Devices.Corsair/CorsairDeviceProviderLoader.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using RGB.NET.Core;
-
-namespace RGB.NET.Devices.Corsair
-{
- ///
- /// Represents a device provider loaded used to dynamically load corsair devices into an application.
- ///
- public class CorsairDeviceProviderLoader : IRGBDeviceProviderLoader
- {
- #region Properties & Fields
-
- ///
- public bool RequiresInitialization => false;
-
- #endregion
-
- #region Methods
-
- ///
- public IRGBDeviceProvider GetDeviceProvider() => CorsairDeviceProvider.Instance;
-
- #endregion
- }
-}
diff --git a/RGB.NET.Groups/Groups/ListLedGroup.cs b/RGB.NET.Groups/Groups/ListLedGroup.cs
index 94b0e26..06d15b8 100644
--- a/RGB.NET.Groups/Groups/ListLedGroup.cs
+++ b/RGB.NET.Groups/Groups/ListLedGroup.cs
@@ -31,7 +31,7 @@ namespace RGB.NET.Groups
public ListLedGroup(RGBSurface? surface)
: base(surface)
{ }
-
+
///
///
/// Initializes a new instance of the class.
@@ -72,8 +72,6 @@ namespace RGB.NET.Groups
/// The to add.
public void AddLeds(IEnumerable leds)
{
- if (leds == null) return;
-
lock (GroupLeds)
foreach (Led led in leds)
if ((led != null) && !ContainsLed(led))
@@ -92,8 +90,6 @@ namespace RGB.NET.Groups
/// The to remove.
public void RemoveLeds(IEnumerable leds)
{
- if (leds == null) return;
-
lock (GroupLeds)
foreach (Led led in leds)
if (led != null)
@@ -108,7 +104,7 @@ namespace RGB.NET.Groups
public bool ContainsLed(Led led)
{
lock (GroupLeds)
- return (led != null) && GroupLeds.Contains(led);
+ return GroupLeds.Contains(led);
}
///
diff --git a/RGB.NET.sln.DotSettings b/RGB.NET.sln.DotSettings
index 563aafd..20624f3 100644
--- a/RGB.NET.sln.DotSettings
+++ b/RGB.NET.sln.DotSettings
@@ -267,11 +267,13 @@
DB
DG
DMX
+ DRAM
EK
FM
GEZ
HID
HS
+ HSV
IBAN
ID
IO