mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Merge pull request #227 from DarthAffe/CodeIssues
Preparing for first major release
This commit is contained in:
commit
1bae7fd3de
@ -1,5 +1,11 @@
|
||||
namespace RGB.NET.Core
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents the default-behavior for the work with colors.
|
||||
/// </summary>
|
||||
public class DefaultColorBehavior : IColorBehavior
|
||||
{
|
||||
#region Methods
|
||||
@ -13,11 +19,12 @@
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to test.</param>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Color" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
public virtual bool Equals(in Color color, object? obj)
|
||||
{
|
||||
if (!(obj is Color color2)) return false;
|
||||
if (obj is not Color color2) return false;
|
||||
|
||||
(float a, float r, float g, float b) = color2.GetRGB();
|
||||
return color.A.EqualsInTolerance(a) && color.R.EqualsInTolerance(r) && color.G.EqualsInTolerance(g) && color.B.EqualsInTolerance(b);
|
||||
@ -27,22 +34,13 @@
|
||||
/// Returns a hash code for this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Color" />.</returns>
|
||||
public virtual int GetHashCode(in Color color)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = color.A.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ color.R.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ color.G.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ color.B.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
public virtual int GetHashCode(in Color color) => HashCode.Combine(color.A, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Blends a <see cref="Color"/> over this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to blend.</param>
|
||||
/// <param name="baseColor">The <see cref="Color"/> to to blend over.</param>
|
||||
/// <param name="blendColor">The <see cref="Color"/> to blend.</param>
|
||||
public virtual Color Blend(in Color baseColor, in Color blendColor)
|
||||
{
|
||||
if (blendColor.A.EqualsInTolerance(0)) return baseColor;
|
||||
|
||||
@ -1,13 +1,36 @@
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a behavior of a color for base operations.
|
||||
/// </summary>
|
||||
public interface IColorBehavior
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the specified <see cref="Color"/> to a string representation.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to convert.</param>
|
||||
/// <returns>The string representation of the specified color.</returns>
|
||||
string ToString(in Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to test.</param>
|
||||
/// <param name="obj">The object to test.</param>
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Color" /> equivalent to this <see cref="Color" />; otherwise, <c>false</c>.</returns>
|
||||
bool Equals(in Color color, object? obj);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this <see cref="Color" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Color" />.</returns>
|
||||
int GetHashCode(in Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Blends a <see cref="Color"/> over this color.
|
||||
/// </summary>
|
||||
/// <param name="baseColor">The <see cref="Color"/> to to blend over.</param>
|
||||
/// <param name="blendColor">The <see cref="Color"/> to blend.</param>
|
||||
Color Blend(in Color baseColor, in Color blendColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper-methods and extension for the <see cref="Color"/>-type to work in the HSV color space.
|
||||
/// </summary>
|
||||
public static class HSVColor
|
||||
{
|
||||
#region Getter
|
||||
@ -11,22 +14,22 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the hue component value (HSV-color space) of this <see cref="Color"/> as degree in the range [0..360].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The hue component value of the color.</returns>
|
||||
public static float GetHue(this in Color color) => color.GetHSV().hue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the saturation component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The saturation component value of the color.</returns>
|
||||
public static float GetSaturation(this in Color color) => color.GetHSV().saturation;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value component value (HSV-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The value component value of the color.</returns>
|
||||
public static float GetValue(this in Color color) => color.GetHSV().value;
|
||||
|
||||
/// <summary>
|
||||
@ -35,8 +38,8 @@ namespace RGB.NET.Core
|
||||
/// Saturation in the range [0..1].
|
||||
/// Value in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the hue, saturation and value component value of the color.</returns>
|
||||
public static (float hue, float saturation, float value) GetHSV(this in Color color)
|
||||
=> CaclulateHSVFromRGB(color.R, color.G, color.B);
|
||||
|
||||
@ -45,8 +48,9 @@ namespace RGB.NET.Core
|
||||
#region Manipulation
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given HSV values to this color.
|
||||
/// Adds the specified HSV values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="hue">The hue value to add.</param>
|
||||
/// <param name="saturation">The saturation value to add.</param>
|
||||
/// <param name="value">The value value to add.</param>
|
||||
@ -58,8 +62,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given HSV values to this color.
|
||||
/// Subtracts the specified HSV values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="hue">The hue value to subtract.</param>
|
||||
/// <param name="saturation">The saturation value to subtract.</param>
|
||||
/// <param name="value">The value value to subtract.</param>
|
||||
@ -71,8 +76,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given HSV values to this color.
|
||||
/// Multiplies the specified HSV values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="hue">The hue value to multiply.</param>
|
||||
/// <param name="saturation">The saturation value to multiply.</param>
|
||||
/// <param name="value">The value value to multiply.</param>
|
||||
@ -84,8 +90,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given HSV values to this color.
|
||||
/// Divides the specified HSV values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="hue">The hue value to divide.</param>
|
||||
/// <param name="saturation">The saturation value to divide.</param>
|
||||
/// <param name="value">The value value to divide.</param>
|
||||
@ -97,8 +104,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given hue value of this color.
|
||||
/// Sets the specified hue value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="hue">The hue value to set.</param>
|
||||
/// <param name="saturation">The saturation value to set.</param>
|
||||
/// <param name="value">The value value to set.</param>
|
||||
|
||||
@ -4,6 +4,9 @@ using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper-methods and extension for the <see cref="Color"/>-type to work in the Hcl color space.
|
||||
/// </summary>
|
||||
public static class HclColor
|
||||
{
|
||||
#region Getter
|
||||
@ -11,23 +14,23 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the H component value (Hcl-color space) of this <see cref="Color"/> in the range [0..360].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetHclH(this in Color color) => color.GetHcl().l;
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The H component value of the color. </returns>
|
||||
public static float GetHclH(this in Color color) => color.GetHcl().h;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the c component value (Hcl-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The c component value of the color. </returns>
|
||||
public static float GetHclC(this in Color color) => color.GetHcl().c;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the l component value (Hcl-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetHclL(this in Color color) => color.GetHcl().h;
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The l component value of the color. </returns>
|
||||
public static float GetHclL(this in Color color) => color.GetHcl().l;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the H, c and l component values (Hcl-color space) of this <see cref="Color"/>.
|
||||
@ -35,8 +38,8 @@ namespace RGB.NET.Core
|
||||
/// c in the range [0..1].
|
||||
/// l in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the H, c and l component value of the color.</returns>
|
||||
public static (float h, float c, float l) GetHcl(this in Color color)
|
||||
=> CalculateHclFromRGB(color.R, color.G, color.B);
|
||||
|
||||
@ -45,8 +48,9 @@ namespace RGB.NET.Core
|
||||
#region Manipulation
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given Hcl values to this color.
|
||||
/// Adds the specified Hcl values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="h">The H value to add.</param>
|
||||
/// <param name="c">The c value to add.</param>
|
||||
/// <param name="l">The l value to add.</param>
|
||||
@ -58,8 +62,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given Hcl values to this color.
|
||||
/// Subtracts the specified Hcl values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="h">The H value to subtract.</param>
|
||||
/// <param name="c">The c value to subtract.</param>
|
||||
/// <param name="l">The l value to subtract.</param>
|
||||
@ -71,8 +76,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given Hcl values to this color.
|
||||
/// Multiplies the specified Hcl values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="h">The H value to multiply.</param>
|
||||
/// <param name="c">The c value to multiply.</param>
|
||||
/// <param name="l">The l value to multiply.</param>
|
||||
@ -84,8 +90,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given Hcl values to this color.
|
||||
/// Divides the specified Hcl values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="h">The H value to divide.</param>
|
||||
/// <param name="c">The c value to divide.</param>
|
||||
/// <param name="l">The l value to divide.</param>
|
||||
@ -97,8 +104,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given X value of this color.
|
||||
/// Sets the specified X value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="h">The H value to set.</param>
|
||||
/// <param name="c">The c value to set.</param>
|
||||
/// <param name="l">The l value to set.</param>
|
||||
@ -155,8 +163,8 @@ namespace RGB.NET.Core
|
||||
/// <returns>The color created from the values.</returns>
|
||||
public static Color Create(float alpha, float h, float c, float l)
|
||||
{
|
||||
(float r, float g, float _b) = CalculateRGBFromHcl(h, c, l);
|
||||
return new Color(alpha, r, g, _b);
|
||||
(float r, float g, float b) = CalculateRGBFromHcl(h, c, l);
|
||||
return new Color(alpha, r, g, b);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -167,6 +175,7 @@ namespace RGB.NET.Core
|
||||
{
|
||||
const float RADIANS_DEGREES_CONVERSION = 180.0f / MathF.PI;
|
||||
|
||||
// ReSharper disable once InconsistentNaming - b is used above
|
||||
(float l, float a, float _b) = LabColor.CalculateLabFromRGB(r, g, b);
|
||||
|
||||
float h, c;
|
||||
|
||||
@ -4,6 +4,9 @@ using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper-methods and extension for the <see cref="Color"/>-type to work in the Lab color space.
|
||||
/// </summary>
|
||||
public static class LabColor
|
||||
{
|
||||
#region Getter
|
||||
@ -11,22 +14,22 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the L component value (Lab-color space) of this <see cref="Color"/> in the range [0..100].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The L component value of the color.</returns>
|
||||
public static float GetLabL(this in Color color) => color.GetLab().l;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the a component value (Lab-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The a component value of the color.</returns>
|
||||
public static float GetLabA(this in Color color) => color.GetLab().a;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the b component value (Lab-color space) of this <see cref="Color"/> in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The b component value of the color.</returns>
|
||||
public static float GetLabB(this in Color color) => color.GetLab().b;
|
||||
|
||||
/// <summary>
|
||||
@ -35,8 +38,8 @@ namespace RGB.NET.Core
|
||||
/// a in the range [0..1].
|
||||
/// b in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the L, a and b component value of the color.</returns>
|
||||
public static (float l, float a, float b) GetLab(this in Color color)
|
||||
=> CalculateLabFromRGB(color.R, color.G, color.B);
|
||||
|
||||
@ -45,8 +48,9 @@ namespace RGB.NET.Core
|
||||
#region Manipulation
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given Lab values to this color.
|
||||
/// Adds the specified Lab values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="l">The L value to add.</param>
|
||||
/// <param name="a">The a value to add.</param>
|
||||
/// <param name="b">The b value to add.</param>
|
||||
@ -58,8 +62,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given Lab values to this color.
|
||||
/// Subtracts the specified Lab values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="l">The L value to subtract.</param>
|
||||
/// <param name="a">The a value to subtract.</param>
|
||||
/// <param name="b">The b value to subtract.</param>
|
||||
@ -71,8 +76,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given Lab values to this color.
|
||||
/// Multiplies the specified Lab values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="l">The L value to multiply.</param>
|
||||
/// <param name="a">The a value to multiply.</param>
|
||||
/// <param name="b">The b value to multiply.</param>
|
||||
@ -84,8 +90,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given Lab values to this color.
|
||||
/// Divides the specified Lab values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="l">The L value to divide.</param>
|
||||
/// <param name="a">The a value to divide.</param>
|
||||
/// <param name="b">The b value to divide.</param>
|
||||
@ -97,8 +104,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given X valueof this color.
|
||||
/// Sets the specified X valueof this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="l">The L value to set.</param>
|
||||
/// <param name="a">The a value to set.</param>
|
||||
/// <param name="b">The b value to set.</param>
|
||||
@ -155,6 +163,7 @@ namespace RGB.NET.Core
|
||||
/// <returns>The color created from the values.</returns>
|
||||
public static Color Create(float alpha, float l, float a, float b)
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming - b is used above
|
||||
(float r, float g, float _b) = CalculateRGBFromLab(l, a, b);
|
||||
return new Color(alpha, r, g, _b);
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper-methods and extension for the <see cref="Color"/>-type to work in the RGB color space.
|
||||
/// </summary>
|
||||
public static class RGBColor
|
||||
{
|
||||
#region Getter
|
||||
@ -11,44 +14,44 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the A component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The A component value of the color.</returns>
|
||||
public static byte GetA(this in Color color) => color.A.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the R component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The R component value of the color.</returns>
|
||||
public static byte GetR(this in Color color) => color.R.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the G component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The G component value of the color.</returns>
|
||||
public static byte GetG(this in Color color) => color.G.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The B component value of the color.</returns>
|
||||
public static byte GetB(this in Color color) => color.B.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A, R, G and B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the A, R, G and B component value of the color.</returns>
|
||||
public static (byte a, byte r, byte g, byte b) GetRGBBytes(this in Color color)
|
||||
=> (color.GetA(), color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A, R, G and B component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the A, R, G and B component value of the color.</returns>
|
||||
public static (float a, float r, float g, float b) GetRGB(this in Color color)
|
||||
=> (color.A, color.R, color.G, color.B);
|
||||
|
||||
@ -59,8 +62,9 @@ namespace RGB.NET.Core
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given RGB values to this color.
|
||||
/// Adds the specified RGB values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to add.</param>
|
||||
/// <param name="g">The green value to add.</param>
|
||||
/// <param name="b">The blue value to add.</param>
|
||||
@ -69,8 +73,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.GetR() + r, color.GetG() + g, color.GetB() + b);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given RGB-percent values to this color.
|
||||
/// Adds the specified RGB-percent values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to add.</param>
|
||||
/// <param name="g">The green value to add.</param>
|
||||
/// <param name="b">The blue value to add.</param>
|
||||
@ -79,16 +84,18 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.R + r, color.G + g, color.B + b);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given alpha value to this color.
|
||||
/// Adds the specified alpha value to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddA(this in Color color, int a)
|
||||
=> new(color.GetA() + a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given alpha-percent value to this color.
|
||||
/// Adds the specified alpha-percent value to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color AddA(this in Color color, float a)
|
||||
@ -99,8 +106,9 @@ namespace RGB.NET.Core
|
||||
#region Subtract
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given RGB values to this color.
|
||||
/// Subtracts the specified RGB values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to subtract.</param>
|
||||
/// <param name="g">The green value to subtract.</param>
|
||||
/// <param name="b">The blue value to subtract.</param>
|
||||
@ -109,8 +117,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.GetR() - r, color.GetG() - g, color.GetB() - b);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given RGB values to this color.
|
||||
/// Subtracts the specified RGB values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to subtract.</param>
|
||||
/// <param name="g">The green value to subtract.</param>
|
||||
/// <param name="b">The blue value to subtract.</param>
|
||||
@ -119,17 +128,19 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.R - r, color.G - g, color.B - b);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given alpha value to this color.
|
||||
/// Subtracts the specified alpha value to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractA(this in Color color, int a)
|
||||
=> new(color.GetA() - a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given alpha-percent value to this color.
|
||||
/// Subtracts the specified alpha-percent value to this color.
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="aPercent">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SubtractA(this in Color color, float aPercent)
|
||||
=> new(color.A - aPercent, color.R, color.G, color.B);
|
||||
@ -139,8 +150,9 @@ namespace RGB.NET.Core
|
||||
#region Multiply
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given RGB values to this color.
|
||||
/// Multiplies the specified RGB values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to multiply.</param>
|
||||
/// <param name="g">The green value to multiply.</param>
|
||||
/// <param name="b">The blue value to multiply.</param>
|
||||
@ -149,8 +161,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.R * r, color.G * g, color.B * b);
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given alpha value to this color.
|
||||
/// Multiplies the specified alpha value to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color MultiplyA(this in Color color, float a)
|
||||
@ -161,8 +174,9 @@ namespace RGB.NET.Core
|
||||
#region Divide
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given RGB values to this color.
|
||||
/// Divides the specified RGB values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to divide.</param>
|
||||
/// <param name="g">The green value to divide.</param>
|
||||
/// <param name="b">The blue value to divide.</param>
|
||||
@ -171,8 +185,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, color.R / r, color.G / g, color.B / b);
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given alpha value to this color.
|
||||
/// Divides the specified alpha value to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color DivideA(this in Color color, float a)
|
||||
@ -183,8 +198,9 @@ namespace RGB.NET.Core
|
||||
#region Set
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given RGB value of this color.
|
||||
/// Sets the specified RGB value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to set.</param>
|
||||
/// <param name="g">The green value to set.</param>
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
@ -193,8 +209,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given RGB value of this color.
|
||||
/// Sets the specified RGB value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to set.</param>
|
||||
/// <param name="g">The green value to set.</param>
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
@ -203,8 +220,9 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given RGB value of this color.
|
||||
/// Sets the specified RGB value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="r">The red value to set.</param>
|
||||
/// <param name="g">The green value to set.</param>
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
@ -213,15 +231,17 @@ namespace RGB.NET.Core
|
||||
=> new(color.A, r ?? color.R, g ?? color.G, b ?? color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given alpha value of this color.
|
||||
/// Sets the specified alpha value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetA(this in Color color, int a) => new(a, color.R, color.G, color.B);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given alpha value of this color.
|
||||
/// Sets the specified alpha value of this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetA(this in Color color, float a) => new(a, color.R, color.G, color.B);
|
||||
|
||||
@ -4,6 +4,9 @@ using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains helper-methods and extension for the <see cref="Color"/>-type to work in the XYZ color space.
|
||||
/// </summary>
|
||||
public static class XYZColor
|
||||
{
|
||||
#region Getter
|
||||
@ -11,22 +14,22 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets the X component value (XYZ-color space) of this <see cref="Color"/> in the range [0..95.047].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The X component value of the color.</returns>
|
||||
public static float GetX(this in Color color) => color.GetXYZ().x;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y component value (XYZ-color space) of this <see cref="Color"/> in the range [0..100].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The Y component value of the color.</returns>
|
||||
public static float GetY(this in Color color) => color.GetXYZ().y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z component value (XYZ-color space) of this <see cref="Color"/> in the range [0..108.883].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>The Z component value of the color.</returns>
|
||||
public static float GetZ(this in Color color) => color.GetXYZ().z;
|
||||
|
||||
/// <summary>
|
||||
@ -35,8 +38,8 @@ namespace RGB.NET.Core
|
||||
/// Y in the range [0..100].
|
||||
/// Z in the range [0..108.883].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="color">The color to get the value from.</param>
|
||||
/// <returns>A tuple containing the X, Y and Z component value of the color.</returns>
|
||||
public static (float x, float y, float z) GetXYZ(this in Color color)
|
||||
=> CaclulateXYZFromRGB(color.R, color.G, color.B);
|
||||
|
||||
@ -45,8 +48,9 @@ namespace RGB.NET.Core
|
||||
#region Manipulation
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given XYZ values to this color.
|
||||
/// Adds the specified XYZ values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="x">The X value to add.</param>
|
||||
/// <param name="y">The Y value to add.</param>
|
||||
/// <param name="z">The Z value to add.</param>
|
||||
@ -58,8 +62,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given XYZ values to this color.
|
||||
/// Subtracts the specified XYZ values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="x">The X value to subtract.</param>
|
||||
/// <param name="y">The Y value to subtract.</param>
|
||||
/// <param name="z">The Z value to subtract.</param>
|
||||
@ -71,8 +76,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given XYZ values to this color.
|
||||
/// Multiplies the specified XYZ values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="x">The X value to multiply.</param>
|
||||
/// <param name="y">The Y value to multiply.</param>
|
||||
/// <param name="z">The Z value to multiply.</param>
|
||||
@ -84,8 +90,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given XYZ values to this color.
|
||||
/// Divides the specified XYZ values to this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="x">The X value to divide.</param>
|
||||
/// <param name="y">The Y value to divide.</param>
|
||||
/// <param name="z">The Z value to divide.</param>
|
||||
@ -97,16 +104,17 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given X valueof this color.
|
||||
/// Sets the specified X valueof this color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color to modify.</param>
|
||||
/// <param name="x">The X value to set.</param>
|
||||
/// <param name="y">The Y value to set.</param>
|
||||
/// <param name="z">The Z value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public static Color SetXYZ(this in Color color, float? x = null, float? y = null, float? value = null)
|
||||
public static Color SetXYZ(this in Color color, float? x = null, float? y = null, float? z = null)
|
||||
{
|
||||
(float cX, float cY, float cZ) = color.GetXYZ();
|
||||
return Create(color.A, x ?? cX, y ?? cY, value ?? cZ);
|
||||
return Create(color.A, x ?? cX, y ?? cY, z ?? cZ);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -8,7 +8,7 @@ namespace RGB.NET.Core
|
||||
public interface IColorCorrection
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the <see cref="IColorCorrection"/> to the given <see cref="Color"/>.
|
||||
/// Applies the <see cref="IColorCorrection"/> to the specified <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to correct.</param>
|
||||
void ApplyTo(ref Color color);
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the surface this decorator is attached to.
|
||||
/// </summary>
|
||||
protected RGBSurface Surface { get; }
|
||||
|
||||
/// <summary>
|
||||
@ -22,6 +25,7 @@
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractUpdateAwareDecorator"/> class.
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface this decorator is attached to.</param>
|
||||
/// <param name="updateIfDisabled">Bool indicating if the <see cref="AbstractUpdateAwareDecorator"/> should call <see cref="Update"/> even if the Decorator is disabled.</param>
|
||||
protected AbstractUpdateAwareDecorator(RGBSurface surface, bool updateIfDisabled = false)
|
||||
{
|
||||
|
||||
@ -13,7 +13,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Represents a basic decoratable for a specific type of <see cref="T:RGB.NET.Core.IDecorator" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="T">The type of decorators this decoratable can be decorated with.</typeparam>
|
||||
public interface IDecoratable<T> : IDecoratable
|
||||
where T : IDecorator
|
||||
{
|
||||
|
||||
@ -23,13 +23,13 @@
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Attaches this <see cref="IDecorator"/> to the given target.
|
||||
/// Attaches this <see cref="IDecorator"/> to the specified target.
|
||||
/// </summary>
|
||||
/// <param name="decoratable">The object this <see cref="IDecorator"/> should be attached to.</param>
|
||||
void OnAttached(IDecoratable decoratable);
|
||||
|
||||
/// <summary>
|
||||
/// Detaches this <see cref="IDecorator"/> from the given target.
|
||||
/// Detaches this <see cref="IDecorator"/> from the specified target.
|
||||
/// </summary>
|
||||
/// <param name="decoratable">The object this <see cref="IDecorator"/> should be detached from.</param>
|
||||
void OnDetached(IDecoratable decoratable);
|
||||
|
||||
@ -52,6 +52,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
protected Dictionary<LedId, Led> LedMapping { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the update queue used to update this device.
|
||||
/// </summary>
|
||||
protected IUpdateQueue UpdateQueue { get; }
|
||||
|
||||
#region Indexer
|
||||
@ -72,6 +75,11 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractRGBDevice{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="deviceInfo">The device info of this device.</param>
|
||||
/// <param name="updateQueue">The queue used to update this device.</param>
|
||||
protected AbstractRGBDevice(TDeviceInfo deviceInfo, IUpdateQueue updateQueue)
|
||||
{
|
||||
this.DeviceInfo = deviceInfo;
|
||||
@ -97,7 +105,22 @@ namespace RGB.NET.Core
|
||||
UpdateLeds(ledsToUpdate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerable of LEDs that are changed and requires an update.
|
||||
/// </summary>
|
||||
/// <param name="flushLeds">Forces all LEDs to be treated as dirty.</param>
|
||||
/// <returns>The collection LEDs to update.</returns>
|
||||
protected virtual IEnumerable<Led> GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty)).Where(led => led.RequestedColor?.A > 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerable of a custom data and color tuple for the specified leds.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies all <see cref="ColorCorrections"/>.
|
||||
/// if no <see cref="Led.CustomData"/> ist specified the <see cref="Led.Id"/> is used.
|
||||
/// </remarks>
|
||||
/// <param name="leds">The enumerable of leds to convert.</param>
|
||||
/// <returns>The enumerable of custom data and color tuples for the specified leds.</returns>
|
||||
protected virtual IEnumerable<(object key, Color color)> GetUpdateData(IEnumerable<Led> leds)
|
||||
{
|
||||
if (ColorCorrections.Count > 0)
|
||||
@ -145,13 +168,7 @@ namespace RGB.NET.Core
|
||||
protected virtual void DeviceUpdate()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> with the specified id.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The <see cref="LedId"/> to initialize.</param>
|
||||
/// <param name="location">The location of the <see cref="Led"/> to initialize.</param>
|
||||
/// <param name="size">The size of the <see cref="Led"/> to initialize.</param>
|
||||
/// <returns>The initialized led.</returns>
|
||||
/// <inheritdoc />
|
||||
public virtual Led? AddLed(LedId ledId, in Point location, in Size size, object? customData = null)
|
||||
{
|
||||
if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null;
|
||||
@ -161,6 +178,7 @@ namespace RGB.NET.Core
|
||||
return led;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Led? RemoveLed(LedId ledId)
|
||||
{
|
||||
if (ledId == LedId.Invalid) return null;
|
||||
@ -170,8 +188,19 @@ namespace RGB.NET.Core
|
||||
return led;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the custom data associated with the specified LED.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The id of the led.</param>
|
||||
/// <returns>The custom data for the specified LED.</returns>
|
||||
protected virtual object? GetLedCustomData(LedId ledId) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the device is attached to a surface.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When overriden base should be called to validate boundries.
|
||||
/// </remarks>
|
||||
protected virtual void OnAttached()
|
||||
{
|
||||
if (Location == Point.Invalid) Location = new Point(0, 0);
|
||||
@ -182,6 +211,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the device is detached from a surface.
|
||||
/// </summary>
|
||||
protected virtual void OnDetached() { }
|
||||
|
||||
#region Enumerator
|
||||
|
||||
@ -5,31 +5,48 @@ using System.Linq;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the abstract base implementation for a <see cref="IRGBDeviceProvider"/>.
|
||||
/// </summary>
|
||||
public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly double _defaultUpdateRateHardLimit;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsInitialized { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ThrowsExceptions { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<IRGBDevice> Devices { get; protected set; } = Enumerable.Empty<IRGBDevice>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dictionary containing the registered update triggers.
|
||||
/// Normally <see cref="UpdateTriggers"/> should be used to access them.
|
||||
/// </summary>
|
||||
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<ExceptionEventArgs>? Exception;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractRGBDeviceProvider" /> class.
|
||||
/// </summary>
|
||||
/// <param name="defaultUpdateRateHardLimit">The update rate hard limit all update triggers for this device provider are initialized with.</param>
|
||||
protected AbstractRGBDeviceProvider(double defaultUpdateRateHardLimit = 0)
|
||||
{
|
||||
this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit;
|
||||
@ -39,6 +56,7 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
|
||||
{
|
||||
ThrowsExceptions = throwExceptions;
|
||||
@ -71,6 +89,14 @@ namespace RGB.NET.Core
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads devices and returns a filtered list of them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The underlying loading of the devices happens in <see cref="LoadDevices"/>.
|
||||
/// </remarks>
|
||||
/// <param name="loadFilter"><see cref="RGBDeviceType"/>-flags to filter the device with.</param>
|
||||
/// <returns>The filtered collection of loaded devices.</returns>
|
||||
protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
|
||||
{
|
||||
List<IRGBDevice> devices = new();
|
||||
@ -92,10 +118,29 @@ namespace RGB.NET.Core
|
||||
return devices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the underlying SDK.
|
||||
/// </summary>
|
||||
protected abstract void InitializeSDK();
|
||||
|
||||
/// <summary>
|
||||
/// Loads all devices this device provider is capable of loading.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Filtering happens in <see cref="GetLoadedDevices"/>.
|
||||
/// </remarks>
|
||||
/// <returns>A collection of loaded devices.</returns>
|
||||
protected abstract IEnumerable<IRGBDevice> LoadDevices();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IDeviceUpdateTrigger"/> mapped to the specified id or a new one if the id wasn't requested before.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The creation of the update trigger happens in <see cref="CreateUpdateTrigger"/>.
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the update trigger.</param>
|
||||
/// <param name="updateRateHardLimit">The update rate hard limit to be set in the update trigger.</param>
|
||||
/// <returns>The update trigger mapped to the specified id.</returns>
|
||||
protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null)
|
||||
{
|
||||
if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger))
|
||||
@ -104,8 +149,18 @@ namespace RGB.NET.Core
|
||||
return updaeTrigger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a update trigger with the specified id and the specified update rate hard limit.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the update trigger.</param>
|
||||
/// <param name="updateRateHardLimit">The update rate hard limit tobe set in the update trigger.</param>
|
||||
/// <returns>The newly created update trigger.</returns>
|
||||
protected virtual IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resets the device provider and disposes all devices and update triggers.
|
||||
/// </summary>
|
||||
protected virtual void Reset()
|
||||
{
|
||||
foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values)
|
||||
@ -115,9 +170,15 @@ namespace RGB.NET.Core
|
||||
device.Dispose();
|
||||
|
||||
Devices = Enumerable.Empty<IRGBDevice>();
|
||||
UpdateTriggerMapping.Clear();
|
||||
IsInitialized = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the <see cref="Exception"/>-event and throws the specified exception if <see cref="ThrowsExceptions"/> is true and it is not overriden in the event.
|
||||
/// </summary>
|
||||
/// <param name="ex">The exception to throw.</param>
|
||||
/// <param name="isCritical">Indicates if the exception is critical for device provider to work correctly.</param>
|
||||
protected virtual void Throw(Exception ex, bool isCritical = false)
|
||||
{
|
||||
ExceptionEventArgs args = new(ex, isCritical, ThrowsExceptions);
|
||||
@ -127,9 +188,19 @@ namespace RGB.NET.Core
|
||||
throw new DeviceProviderException(ex, isCritical);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws the <see cref="Exception"/> event.
|
||||
/// </summary>
|
||||
/// <param name="args">The parameters passed to the event.</param>
|
||||
protected virtual void OnException(ExceptionEventArgs args) => Exception?.Invoke(this, args);
|
||||
|
||||
public virtual void Dispose() => Reset();
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
{
|
||||
Reset();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc cref="IEnumerable{T}" />
|
||||
/// <inheritdoc cref="IEnumerable{Led}" />
|
||||
/// <inheritdoc cref="IBindable" />
|
||||
/// <inheritdoc cref="IDisposable" />
|
||||
/// <summary>
|
||||
@ -13,6 +13,9 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the surface this device is attached to.
|
||||
/// </summary>
|
||||
RGBSurface? Surface { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
@ -20,6 +23,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
IRGBDeviceInfo DeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of color corrections applied to this device.
|
||||
/// </summary>
|
||||
IList<IColorCorrection> ColorCorrections { get; }
|
||||
|
||||
#endregion
|
||||
@ -34,18 +40,18 @@ namespace RGB.NET.Core
|
||||
Led? this[LedId ledId] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Led" /> at the given physical location.
|
||||
/// Gets the <see cref="Led" /> at the specified physical location.
|
||||
/// </summary>
|
||||
/// <param name="location">The <see cref="Point"/> to get the location from.</param>
|
||||
/// <returns>The <see cref="Led"/> at the given <see cref="Point"/> or null if no location is found.</returns>
|
||||
/// <returns>The <see cref="Led"/> at the specified <see cref="Point"/> or null if no location is found.</returns>
|
||||
Led? this[Point location] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="Led" /> inside the given <see cref="Rectangle"/>.
|
||||
/// Gets a list of <see cref="Led" /> inside the specified <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="referenceRect">The <see cref="Rectangle"/> to check.</param>
|
||||
/// <param name="minOverlayPercentage">The minimal percentage overlay a <see cref="Led"/> must have with the <see cref="Rectangle" /> to be taken into the list.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>A enumerable of leds inside the specified rectangle.</returns>
|
||||
IEnumerable<Led> this[Rectangle referenceRect, double minOverlayPercentage = 0.5] { get; }
|
||||
|
||||
#endregion
|
||||
@ -58,8 +64,21 @@ namespace RGB.NET.Core
|
||||
/// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param>
|
||||
void Update(bool flushLeds = false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a led to the device.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The id of the led.</param>
|
||||
/// <param name="location">The location of the led on the device.</param>
|
||||
/// <param name="size">The size of the led.</param>
|
||||
/// <param name="customData">Custom data saved on the led.</param>
|
||||
/// <returns>The newly added led or <c>null</c> if a led with this id is already added.</returns>
|
||||
Led? AddLed(LedId ledId, in Point location, in Size size, object? customData = null);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the led with the specified id from the device.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The id of the led to remove.</param>
|
||||
/// <returns>The removed led or <c>null</c> if there was no led with the specified id.</returns>
|
||||
Led? RemoveLed(LedId ledId);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -27,6 +27,9 @@
|
||||
/// </summary>
|
||||
string Model { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets custom metadata added to the layout.
|
||||
/// </summary>
|
||||
object? LayoutMetadata { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
// ReSharper disable EventNeverSubscribedTo.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
@ -17,10 +19,18 @@ namespace RGB.NET.Core
|
||||
bool IsInitialized { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IRGBDevice"/> loaded by this <see cref="IRGBDeviceProvider"/>.
|
||||
/// Indicates if exceptions in the device provider are thrown or silently ignored.
|
||||
/// </summary>
|
||||
bool ThrowsExceptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IRGBDevice"/> loaded by this <see cref="IRGBDeviceProvider"/>.
|
||||
/// </summary>
|
||||
IEnumerable<IRGBDevice> Devices { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection <see cref="IDeviceUpdateTrigger"/> registered to this device provider.
|
||||
/// </summary>
|
||||
ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
|
||||
|
||||
#endregion
|
||||
@ -28,7 +38,7 @@ namespace RGB.NET.Core
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when an exception is thrown in the device provider
|
||||
/// Occurs when an exception is thrown in the device provider.
|
||||
/// </summary>
|
||||
event EventHandler<ExceptionEventArgs>? Exception;
|
||||
|
||||
@ -36,6 +46,12 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the device provider and loads available devices.
|
||||
/// </summary>
|
||||
/// <param name="loadFilter"><see cref="RGBDeviceType"/>-flags to filter the devices to load.</param>
|
||||
/// <param name="throwExceptions">Specifies if exceptions should be thrown or silently be ignored.</param>
|
||||
/// <returns><c>true</c> if the initialization was successful; <c>false</c> otherwise.</returns>
|
||||
bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a list of available keyboard layout types.
|
||||
/// </summary>
|
||||
public enum KeyboardLayoutType
|
||||
{
|
||||
Unknown = 0,
|
||||
|
||||
@ -1,15 +1,24 @@
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a keyboard-device
|
||||
/// Represents a generic keyboard-device.
|
||||
/// </summary>
|
||||
public interface IKeyboard : IRGBDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the device information assiciated with this device.
|
||||
/// </summary>
|
||||
new IKeyboardDeviceInfo DeviceInfo { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic keyboard device information.
|
||||
/// </summary>
|
||||
public interface IKeyboardDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="KeyboardLayoutType"/> of the keyboard.
|
||||
/// </summary>
|
||||
KeyboardLayoutType Layout { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,8 +18,14 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a bool indicating if the exception is critical for the thrower.
|
||||
/// </summary>
|
||||
public bool IsCritical { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the exception should be thrown after the event is handled.
|
||||
/// </summary>
|
||||
public bool Throw { get; set; }
|
||||
|
||||
#endregion
|
||||
@ -31,6 +37,8 @@ namespace RGB.NET.Core
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.ExceptionEventArgs" /> class.
|
||||
/// </summary>
|
||||
/// <param name="exception">The <see cref="T:System.Exception" /> which is responsible for the event-call.</param>
|
||||
/// <param name="isCritical">Indicates if the exception is critical for the thrower.</param>
|
||||
/// <param name="throw">Indicates if the exception should be thrown after the event is handled.</param>
|
||||
public ExceptionEventArgs(Exception exception, bool isCritical = false, bool @throw = false)
|
||||
{
|
||||
this.Exception = exception;
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
public class ResolvePathEventArgs : EventArgs
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filename used to resolve the path.
|
||||
/// Also check <see cref="RelativePath "/> before use.
|
||||
/// </summary>
|
||||
public string? RelativePart { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filename used to resolve the path.
|
||||
/// Also check <see cref="RelativePath "/> before use.
|
||||
/// </summary>
|
||||
public string? FileName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the relative path used to resolve the path.
|
||||
/// If this is set <see cref="RelativePart" /> and <see cref="FileName" /> are unused.
|
||||
/// </summary>
|
||||
public string? RelativePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the resolved path.
|
||||
/// </summary>
|
||||
public string FinalPath { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Corer.ResolvePathEventArgs" /> class.
|
||||
/// </summary>
|
||||
/// <param name="relativePart">The filename used to resolve the path.</param>
|
||||
/// <param name="fileName">The filename used to resolve the path.</param>
|
||||
/// <param name="finalPath">The relative part used to resolve the path.</param>
|
||||
public ResolvePathEventArgs(string relativePart, string fileName, string finalPath)
|
||||
{
|
||||
this.RelativePart = relativePart;
|
||||
this.FileName = fileName;
|
||||
this.FinalPath = finalPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Corer.ResolvePathEventArgs" /> class.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The relative path used to resolve the path.</param>
|
||||
/// <param name="finalPath">The relative part used to resolve the path.</param>
|
||||
public ResolvePathEventArgs(string relativePath, string finalPath)
|
||||
{
|
||||
this.RelativePath = relativePath;
|
||||
this.FinalPath = finalPath;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,8 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="devices">The <see cref="T:RGB.NET.Core.IRGBDevice" /> that caused the change.</param>
|
||||
/// <param name="deviceAdded">A value indicating if the event is caused by the addition of a new <see cref="T:RGB.NET.Core.IRGBDevice" /> to the <see cref="T:RGB.NET.Core.RGBSurface" />.</param>
|
||||
/// <param name="deviceLocationChanged">A value indicating if the event is caused by a changed location of one of the devices on the <see cref="T:RGB.NET.Core.RGBSurface" />.</param>
|
||||
/// <param name="deviceRemoved">A value indicating if the event is caused by the removal of a <see cref="T:RGB.NET.Core.IRGBDevice" /> from the <see cref="T:RGB.NET.Core.RGBSurface" />.</param>
|
||||
/// <param name="deviceChanged">A value indicating if the event is caused by a change to a <see cref="T:RGB.NET.Core.IRGBDevice" /> on the <see cref="T:RGB.NET.Core.RGBSurface" />.</param>
|
||||
private SurfaceLayoutChangedEventArgs(IRGBDevice? devices, bool deviceAdded, bool deviceRemoved, bool deviceChanged)
|
||||
{
|
||||
this.Devices = devices;
|
||||
|
||||
@ -2,16 +2,28 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents an exception thrown by a <see cref="IRGBDeviceProvider" />.
|
||||
/// </summary>
|
||||
public class DeviceProviderException : ApplicationException
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private bool IsCritical { get; }
|
||||
/// <summary>
|
||||
/// Gets a bool indicating if the exception is critical and shouldn't be ingored.
|
||||
/// </summary>
|
||||
public bool IsCritical { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeviceProviderException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="innerException">The exception that is the casue of the current exception or null if this exception was thrown on purpose.</param>
|
||||
/// <param name="isCritical">A value indicating if the exception is critical and shouldn't be ignored.</param>
|
||||
public DeviceProviderException(Exception? innerException, bool isCritical)
|
||||
: base(innerException?.Message, innerException)
|
||||
{
|
||||
|
||||
@ -2,17 +2,20 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for <see cref="Color"/> related things.
|
||||
/// </summary>
|
||||
public static class ColorExtensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance between the two given colors using the redmean algorithm.
|
||||
/// Calculates the distance between the two specified colors using the redmean algorithm.
|
||||
/// For more infos check https://www.compuphase.com/cmetric.htm
|
||||
/// </summary>
|
||||
/// <param name="color1">The start color of the distance calculation.</param>
|
||||
/// <param name="color2">The end color fot the distance calculation.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>The redmean distance between the two specified colors.</returns>
|
||||
public static double DistanceTo(this in Color color1, in Color color2)
|
||||
{
|
||||
(_, byte r1, byte g1, byte b1) = color1.GetRGBBytes();
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for the work with floats
|
||||
/// Offers some extensions and helper-methods for the work with floats.
|
||||
/// </summary>
|
||||
public static class FloatExtensions
|
||||
{
|
||||
@ -83,18 +83,28 @@ namespace RGB.NET.Core
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a normalized float value in the range [0..1] to a byte [0..255].
|
||||
/// </summary>
|
||||
/// <param name="percentage">The normalized float value to convert.</param>
|
||||
/// <returns>The byte value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static byte GetByteValueFromPercentage(this float percentage)
|
||||
{
|
||||
if (float.IsNaN(percentage)) return 0;
|
||||
|
||||
percentage = percentage.Clamp(0, 1.0f);
|
||||
return (byte)(percentage >= 1.0 ? 255 : percentage * 256.0);
|
||||
return (byte)(percentage >= 1.0f ? 255 : percentage * 256.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte value [0..255] to a normalized float value in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="value">The byte value to convert.</param>
|
||||
/// <returns>The normalized float value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float GetPercentageFromByteValue(this byte value)
|
||||
=> ((float)value) / byte.MaxValue;
|
||||
=> value == 255 ? 1.0f : (value / 256.0f);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for <see cref="Point"/> related things.
|
||||
/// </summary>
|
||||
public static class PointExtensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Point"/> by the given amount.
|
||||
/// Moves the specified <see cref="Point"/> by the specified amount.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> to move.</param>
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
@ -16,7 +19,7 @@ namespace RGB.NET.Core
|
||||
public static Point Translate(this in Point point, float x = 0, float y = 0) => new(point.X + x, point.Y + y);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified <see cref="Point"/> by the given amuont around the given origin.
|
||||
/// Rotates the specified <see cref="Point"/> by the specified amuont around the specified origin.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> to rotate.</param>
|
||||
/// <param name="rotation">The rotation.</param>
|
||||
@ -33,7 +36,7 @@ namespace RGB.NET.Core
|
||||
x = (x * cos) - (y * sin);
|
||||
y = (x * sin) + (y * cos);
|
||||
|
||||
return new Point(x + origin.X, y + origin.Y); ;
|
||||
return new Point(x + origin.X, y + origin.Y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for the work with rectangles.
|
||||
/// </summary>
|
||||
public static class RectangleExtensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Rectangle.Location"/> of the given rectangle.
|
||||
/// Sets the <see cref="Rectangle.Location"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="location">The new location of the rectangle.</param>
|
||||
@ -15,7 +18,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle SetLocation(this in Rectangle rect, in Point location) => new(location, rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Point.X"/> of the <see cref="Rectangle.Location"/> of the given rectangle.
|
||||
/// Sets the <see cref="Point.X"/> of the <see cref="Rectangle.Location"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="x">The new x-location of the rectangle.</param>
|
||||
@ -23,7 +26,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle SetX(this in Rectangle rect, float x) => new(new Point(x, rect.Location.Y), rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Point.Y"/> of the <see cref="Rectangle.Location"/> of the given rectangle.
|
||||
/// Sets the <see cref="Point.Y"/> of the <see cref="Rectangle.Location"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="y">The new y-location of the rectangle.</param>
|
||||
@ -31,7 +34,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle SetY(this in Rectangle rect, float y) => new(new Point(rect.Location.X, y), rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Rectangle.Size"/> of the given rectangle.
|
||||
/// Sets the <see cref="Rectangle.Size"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="size">The new size of the rectangle.</param>
|
||||
@ -39,7 +42,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle SetSize(this in Rectangle rect, in Size size) => new(rect.Location, size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Size.Width"/> of the <see cref="Rectangle.Size"/> of the given rectangle.
|
||||
/// Sets the <see cref="Size.Width"/> of the <see cref="Rectangle.Size"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="width">The new width of the rectangle.</param>
|
||||
@ -47,7 +50,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle SetWidth(this in Rectangle rect, float width) => new(rect.Location, new Size(width, rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="Size.Height"/> of the <see cref="Rectangle.Size"/> of the given rectangle.
|
||||
/// Sets the <see cref="Size.Height"/> of the <see cref="Rectangle.Size"/> of the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to modify.</param>
|
||||
/// <param name="height">The new height of the rectangle.</param>
|
||||
@ -57,6 +60,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Calculates the percentage of intersection of a rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to calculate the intersection for.</param>
|
||||
/// <param name="intersectingRect">The intersecting rectangle.</param>
|
||||
/// <returns>The percentage of intersection.</returns>
|
||||
public static float CalculateIntersectPercentage(this in Rectangle rect, in Rectangle intersectingRect)
|
||||
@ -70,7 +74,8 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Calculates the <see cref="Rectangle"/> representing the intersection of this <see cref="Rectangle"/> and the one provided as parameter.
|
||||
/// </summary>
|
||||
/// <param name="intersectingRectangle">The intersecting <see cref="Rectangle"/></param>
|
||||
/// <param name="rect">The rectangle to calculate the intersection for.</param>
|
||||
/// <param name="intersectingRectangle">The intersecting <see cref="Rectangle"/>.</param>
|
||||
/// <returns>A new <see cref="Rectangle"/> representing the intersection this <see cref="Rectangle"/> and the one provided as parameter.</returns>
|
||||
public static Rectangle CalculateIntersection(this in Rectangle rect, in Rectangle intersectingRectangle)
|
||||
{
|
||||
@ -89,29 +94,32 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Determines if the specified <see cref="Point"/> is contained within this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The containing rectangle.</param>
|
||||
/// <param name="point">The <see cref="Point"/> to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the given point; otherwise <c>false</c>.</returns>
|
||||
/// <returns><c>true</c> if the rectangle contains the specified point; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, in Point point) => rect.Contains(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the specified location is contained within this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The containing rectangle.</param>
|
||||
/// <param name="x">The X-location to test.</param>
|
||||
/// <param name="y">The Y-location to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the given coordinates; otherwise <c>false</c>.</returns>
|
||||
/// <returns><c>true</c> if the rectangle contains the specified coordinates; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, float x, float y) => (rect.Location.X <= x) && (x < (rect.Location.X + rect.Size.Width))
|
||||
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height));
|
||||
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the specified <see cref="Rectangle"/> is contained within this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the given rect; otherwise <c>false</c>.</returns>
|
||||
/// <param name="rect">The containing rectangle.</param>
|
||||
/// <param name="rect2">The <see cref="Rectangle"/> to test.</param>
|
||||
/// <returns><c>true</c> if the rectangle contains the specified rect; otherwise <c>false</c>.</returns>
|
||||
public static bool Contains(this in Rectangle rect, in Rectangle rect2) => (rect.Location.X <= rect2.Location.X) && ((rect2.Location.X + rect2.Size.Width) <= (rect.Location.X + rect.Size.Width))
|
||||
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
|
||||
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Rectangle"/> by the given amount.
|
||||
/// Moves the specified <see cref="Rectangle"/> by the specified amount.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
|
||||
/// <param name="point">The amount to move.</param>
|
||||
@ -119,7 +127,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle Translate(this in Rectangle rect, in Point point) => rect.Translate(point.X, point.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Moves the specified <see cref="Rectangle"/> by the given amount.
|
||||
/// Moves the specified <see cref="Rectangle"/> by the specified amount.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
|
||||
/// <param name="x">The x-ammount to move.</param>
|
||||
@ -128,7 +136,7 @@ namespace RGB.NET.Core
|
||||
public static Rectangle Translate(this in Rectangle rect, float x = 0, float y = 0) => new(rect.Location.Translate(x, y), rect.Size);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified <see cref="Rectangle"/> by the given amuont around the given origin.
|
||||
/// Rotates the specified <see cref="Rectangle"/> by the specified amuont around the specified origin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The returned array of <see cref="Point"/> is filled with the new locations of the rectangle clockwise starting from the top left:
|
||||
|
||||
@ -5,10 +5,20 @@ using System.Linq;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for the work with the surface.
|
||||
/// </summary>
|
||||
public static class SurfaceExtensions
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the specifiec device provider and attaches all devices.
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface to attach the devices to.</param>
|
||||
/// <param name="deviceProvider">The device provider to load.</param>
|
||||
/// <param name="loadFilter"><see cref="RGBDeviceType"/>-flags to filter the devices to load.</param>
|
||||
/// <param name="throwExceptions">Specifies if exceptions should be thrown or silently be ignored.</param>
|
||||
public static void Load(this RGBSurface surface, IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
|
||||
{
|
||||
if (!deviceProvider.IsInitialized)
|
||||
@ -17,13 +27,22 @@ namespace RGB.NET.Core
|
||||
surface.Attach(deviceProvider.Devices);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the specified devices to the surface.
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface the devices are attached to.</param>
|
||||
/// <param name="devices">The devices to attach.</param>
|
||||
public static void Attach(this RGBSurface surface, IEnumerable<IRGBDevice> devices)
|
||||
{
|
||||
foreach (IRGBDevice device in devices)
|
||||
surface.Attach(device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the specified devices from the surface.
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface the devices are detached from.</param>
|
||||
/// <param name="devices">The devices to detach.</param>
|
||||
public static void Detach(this RGBSurface surface, IEnumerable<IRGBDevice> devices)
|
||||
{
|
||||
foreach (IRGBDevice device in devices)
|
||||
@ -42,6 +61,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets all devices of the specified <see cref="RGBDeviceType"/>.
|
||||
/// </summary>
|
||||
/// <param name="surface">The surface to get the devices from.</param>
|
||||
/// <param name="deviceType">The <see cref="RGBDeviceType"/> of the devices to get.</param>
|
||||
/// <returns>A collection of devices matching the specified <see cref="RGBDeviceType"/>.</returns>
|
||||
public static IEnumerable<IRGBDevice> GetDevices(this RGBSurface surface, RGBDeviceType deviceType)
|
||||
|
||||
@ -13,6 +13,8 @@ namespace RGB.NET.Core
|
||||
#region Properties & Fields
|
||||
|
||||
RGBSurface? ILedGroup.Surface { get; set; }
|
||||
|
||||
/// <inheritdoc cref="ILedGroup.Surface" />
|
||||
public RGBSurface? Surface => ((ILedGroup)this).Surface;
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -37,6 +39,10 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a enumerable containing all leds in this group.
|
||||
/// </summary>
|
||||
/// <returns>A enumerable containing all leds of this group.</returns>
|
||||
protected abstract IEnumerable<Led> GetLeds();
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -10,8 +10,14 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public interface ILedGroup : IDecoratable<ILedGroupDecorator>, IEnumerable<Led>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the surface this group is attached to or <c>null</c> if it is not attached to any surface.
|
||||
/// </summary>
|
||||
RGBSurface? Surface { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a bool indicating if the group is attached to a surface.
|
||||
/// </summary>
|
||||
bool IsAttached => Surface != null;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -9,7 +9,7 @@ namespace RGB.NET.Core
|
||||
public static class LedGroupExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the given <see cref="ILedGroup" /> to a <see cref="ListLedGroup" />.
|
||||
/// Converts the specified <see cref="ILedGroup" /> to a <see cref="ListLedGroup" />.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup" /> to convert.</param>
|
||||
/// <returns>The converted <see cref="ListLedGroup" />.</returns>
|
||||
@ -26,7 +26,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="ListLedGroup" /> which contains all <see cref="Led"/> from the given <see cref="ILedGroup"/> excluding the specified ones.
|
||||
/// Returns a new <see cref="ListLedGroup" /> which contains all <see cref="Led"/> from the specified <see cref="ILedGroup"/> excluding the specified ones.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The base <see cref="ILedGroup"/>.</param>
|
||||
/// <param name="ledIds">The <see cref="Led"/> to exclude.</param>
|
||||
@ -41,14 +41,15 @@ namespace RGB.NET.Core
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
/// <summary>
|
||||
/// Attaches the given <see cref="ILedGroup"/> to the <see cref="RGBSurface"/>.
|
||||
/// Attaches the specified <see cref="ILedGroup"/> to the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to attach.</param>
|
||||
/// <param name="surface">The <see cref="RGBSurface"/> to attach this group to.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be attached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Attach(this ILedGroup ledGroup, RGBSurface surface) => surface.Attach(ledGroup);
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the given <see cref="ILedGroup"/> from the <see cref="RGBSurface"/>.
|
||||
/// Detaches the specified <see cref="ILedGroup"/> from the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to attach.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be detached; otherwise, <c>false</c>.</returns>
|
||||
|
||||
@ -26,7 +26,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
/// <param name="surface">Specifies the surface to attach this group to or <c>null</c> if the group should not be attached on creation.</param>
|
||||
public ListLedGroup(RGBSurface? surface)
|
||||
: base(surface)
|
||||
{ }
|
||||
@ -35,7 +35,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
/// <param name="surface">Specifies the surface to attach this group to or <c>null</c> if the group should not be attached on creation.</param>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(RGBSurface? surface, IEnumerable<Led> leds)
|
||||
: base(surface)
|
||||
@ -47,7 +47,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
/// <param name="surface">Specifies the surface to attach this group to or <c>null</c> if the group should not be attached on creation.</param>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(RGBSurface? surface, params Led[] leds)
|
||||
: base(surface)
|
||||
@ -60,43 +60,42 @@ namespace RGB.NET.Core
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given LED(s) to this <see cref="ListLedGroup"/>.
|
||||
/// Adds the specified LED(s) to this <see cref="ListLedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="leds">The LED(s) to add.</param>
|
||||
public void AddLed(params Led[] leds) => AddLeds(leds);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given <see cref="Led"/> to this <see cref="ListLedGroup"/>.
|
||||
/// Adds the specified <see cref="Led"/> to this <see cref="ListLedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="leds">The <see cref="Led"/> to add.</param>
|
||||
public void AddLeds(IEnumerable<Led> leds)
|
||||
{
|
||||
lock (GroupLeds)
|
||||
foreach (Led led in leds)
|
||||
if ((led != null) && !ContainsLed(led))
|
||||
if (!ContainsLed(led))
|
||||
GroupLeds.Add(led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given LED(s) from this <see cref="ListLedGroup"/>.
|
||||
/// Removes the specified LED(s) from this <see cref="ListLedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="leds">The LED(s) to remove.</param>
|
||||
public void RemoveLed(params Led[] leds) => RemoveLeds(leds);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given <see cref="Led"/> from this <see cref="ListLedGroup"/>.
|
||||
/// Removes the specified <see cref="Led"/> from this <see cref="ListLedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="leds">The <see cref="Led"/> to remove.</param>
|
||||
public void RemoveLeds(IEnumerable<Led> leds)
|
||||
{
|
||||
lock (GroupLeds)
|
||||
foreach (Led led in leds)
|
||||
if (led != null)
|
||||
GroupLeds.Remove(led);
|
||||
GroupLeds.Remove(led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given LED is contained by this ledgroup.
|
||||
/// Checks if a specified LED is contained by this ledgroup.
|
||||
/// </summary>
|
||||
/// <param name="led">The LED which should be checked.</param>
|
||||
/// <returns><c>true</c> if the LED is contained by this ledgroup; otherwise, <c>false</c>.</returns>
|
||||
@ -107,7 +106,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the <see cref="Led"/> from the given ledgroup in this ledgroup.
|
||||
/// Merges the <see cref="Led"/> from the specified ledgroup in this ledgroup.
|
||||
/// </summary>
|
||||
/// <param name="groupToMerge">The ledgroup to merge.</param>
|
||||
public void MergeLeds(ILedGroup groupToMerge)
|
||||
|
||||
@ -3,10 +3,22 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offsers some helper methods for device creation.
|
||||
/// </summary>
|
||||
public static class DeviceHelper
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a unique device name from a manufacturer and model name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The id is made unique based on the assembly calling this method.
|
||||
/// </remarks>
|
||||
/// <param name="manufacturer">The manufacturer of the device.</param>
|
||||
/// <param name="model">The model of the device.</param>
|
||||
/// <returns>The unique identifier for this device.</returns>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static string CreateDeviceName(string manufacturer, string model) => IdGenerator.MakeUnique(Assembly.GetCallingAssembly(), $"{manufacturer} {model}");
|
||||
|
||||
|
||||
@ -4,6 +4,9 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some methods to create and handle unique identifiers.
|
||||
/// </summary>
|
||||
public static class IdGenerator
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -18,6 +21,11 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Makes the specified id unique based on the calling assembly by adding a counter if needed.
|
||||
/// </summary>
|
||||
/// <param name="id">The id to make unique.</param>
|
||||
/// <returns>The unique id.</returns>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static string MakeUnique(string id) => MakeUnique(Assembly.GetCallingAssembly(), id);
|
||||
|
||||
@ -49,6 +57,10 @@ namespace RGB.NET.Core
|
||||
return counter <= 1 ? mappedId : $"{mappedId} ({counter})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the counter used to create unique ids.
|
||||
/// All previous generated ids are not garantueed to stay unique if this is called!
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void ResetCounter() => ResetCounter(Assembly.GetCallingAssembly());
|
||||
|
||||
|
||||
@ -96,6 +96,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public object? CustomData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets some custom metadata of this led.
|
||||
/// </summary>
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
#endregion
|
||||
@ -124,6 +127,7 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateActualPlaceableData()
|
||||
{
|
||||
base.UpdateActualPlaceableData();
|
||||
|
||||
@ -4,6 +4,10 @@ using System.Linq;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a mapping from <see cref="LedId"/> to a custom identifier.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The identifier the <see cref="LedId"/> is mapped to.</typeparam>
|
||||
public class LedMapping<T> : IEnumerable<(LedId ledId, T mapping)>
|
||||
where T : notnull
|
||||
{
|
||||
@ -12,15 +16,30 @@ namespace RGB.NET.Core
|
||||
private readonly Dictionary<LedId, T> _mapping = new();
|
||||
private readonly Dictionary<T, LedId> _reverseMapping = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of entries in this mapping.
|
||||
/// </summary>
|
||||
public int Count => _mapping.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of all mapped ledids.
|
||||
/// </summary>
|
||||
public ICollection<LedId> LedIds => _mapping.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of all mapped custom identifiers.
|
||||
/// </summary>
|
||||
public ICollection<T> Mappings => _reverseMapping.Keys;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <summary>
|
||||
/// Gets the custom identifier mapped to the specified <see cref="LedId"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The led id to get the mapped identifier.</param>
|
||||
/// <returns>The mapped ifentifier.</returns>
|
||||
public T this[LedId ledId]
|
||||
{
|
||||
get => _mapping[ledId];
|
||||
@ -31,6 +50,11 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="LedId"/> mapped to the specified custom identifier.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The custom identifier to get the mapped led id.</param>
|
||||
/// <returns>The led id.</returns>
|
||||
public LedId this[T mapping]
|
||||
{
|
||||
get => _reverseMapping[mapping];
|
||||
@ -41,18 +65,52 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new entry to the mapping.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The <see cref="LedId"/> to map.</param>
|
||||
/// <param name="mapping">The custom identifier to map.</param>
|
||||
public void Add(LedId ledId, T mapping)
|
||||
{
|
||||
_mapping.Add(ledId, mapping);
|
||||
_reverseMapping.Add(mapping, ledId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified <see cref="LedId"/> is mapped.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The led id to check.</param>
|
||||
/// <returns><c>true</c> if the led id is mapped; otherwise <c>false</c>.</returns>
|
||||
public bool Contains(LedId ledId) => _mapping.ContainsKey(ledId);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified custom identifier is mapped.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The custom identifier to check.</param>
|
||||
/// <returns><c>true</c> if the led id is mapped; otherwise <c>false</c>.</returns>
|
||||
public bool Contains(T mapping) => _reverseMapping.ContainsKey(mapping);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the custom identifier mapped to the specified led id.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The led id to get the custom identifier for.</param>
|
||||
/// <param name="mapping">Contains the mapped custom identifier or null if there is no mapping for the specified led id.</param>
|
||||
/// <returns><c>true</c> if there was a custom identifier for the specified led id; otherwise <c>false</c>.</returns>
|
||||
public bool TryGetValue(LedId ledId, out T? mapping) => _mapping.TryGetValue(ledId, out mapping);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the led id mapped to the specified custom identifier.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The custom identifier to get the led id for.</param>
|
||||
/// <param name="ledId">Contains the mapped led id or null if there is no mapping for the specified led id.</param>
|
||||
/// <returns><c>true</c> if there was a led id for the specified custom identifier; otherwise <c>false</c>.</returns>
|
||||
public bool TryGetValue(T mapping, out LedId ledId) => _reverseMapping.TryGetValue(mapping, out ledId);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified led id and the mapped custom identifier.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The led id to remove.</param>
|
||||
/// <returns><c>true</c> if there was a mapping for the led id to remove; otherwise <c>false</c>.</returns>
|
||||
public bool Remove(LedId ledId)
|
||||
{
|
||||
if (_mapping.TryGetValue(ledId, out T? mapping))
|
||||
@ -60,6 +118,11 @@ namespace RGB.NET.Core
|
||||
return _mapping.Remove(ledId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified custom identifier and the mapped led id.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The custom identifier to remove.</param>
|
||||
/// <returns><c>true</c> if there was a mapping for the custom identifier to remove; otherwise <c>false</c>.</returns>
|
||||
public bool Remove(T mapping)
|
||||
{
|
||||
if (_reverseMapping.TryGetValue(mapping, out LedId ledId))
|
||||
@ -67,6 +130,9 @@ namespace RGB.NET.Core
|
||||
return _reverseMapping.Remove(mapping);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all registered mappings.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_mapping.Clear();
|
||||
@ -74,6 +140,8 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<(LedId ledId, T mapping)> GetEnumerator() => _mapping.Select(x => (x.Key, x.Value)).GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -21,12 +21,12 @@ namespace RGB.NET.Core
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the property already matches the desirec value or needs to be updated.
|
||||
/// Checks if the property already matches the desired value or needs to be updated.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the property.</typeparam>
|
||||
/// <param name="storage">Reference to the backing-filed.</param>
|
||||
/// <param name="value">Value to apply.</param>
|
||||
/// <returns></returns>
|
||||
/// <returns><c>true</c> if the value needs to be updated; otherweise <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected virtual bool RequiresUpdate<T>(ref T storage, T value) => !Equals(storage, value);
|
||||
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
using System;
|
||||
// ReSharper disable EventNeverSubscribedTo.Global
|
||||
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a generic placeable element.
|
||||
/// </summary>
|
||||
public interface IPlaceable
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -48,12 +53,39 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Location"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> LocationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Size"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> SizeChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Scale"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> ScaleChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Rotation"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> RotationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="ActualLocation"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> ActualLocationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="ActualSize"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> ActualSizeChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Boundary"/> property was changed.
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> BoundaryChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -2,10 +2,16 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a placeable element.
|
||||
/// </summary>
|
||||
public class Placeable : AbstractBindable, IPlaceable
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent this placeable is placed in.
|
||||
/// </summary>
|
||||
protected IPlaceable? Parent { get; }
|
||||
|
||||
private Point _location = Point.Invalid;
|
||||
@ -96,20 +102,40 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Events
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? LocationChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? SizeChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? ScaleChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? RotationChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? ActualLocationChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? ActualSizeChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? BoundaryChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Placeable" /> class.
|
||||
/// </summary>
|
||||
public Placeable() { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Placeable" /> class.
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent this placeable is placed in.</param>
|
||||
public Placeable(IPlaceable parent)
|
||||
{
|
||||
this.Parent = parent;
|
||||
@ -117,12 +143,23 @@ namespace RGB.NET.Core
|
||||
Parent.BoundaryChanged += (_, _) => UpdateActualPlaceableData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Placeable" /> class.
|
||||
/// </summary>
|
||||
/// <param name="location">The location of this placeable.</param>
|
||||
/// <param name="size">The size of this placeable.</param>
|
||||
public Placeable(Point location, Size size)
|
||||
{
|
||||
this.Location = location;
|
||||
this.Size = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Placeable" /> class.
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent placeable this placeable is placed in.</param>
|
||||
/// <param name="location">The location of this placeable.</param>
|
||||
/// <param name="size">The size of this placeable.</param>
|
||||
public Placeable(IPlaceable parent, Point location, Size size)
|
||||
{
|
||||
this.Parent = parent;
|
||||
@ -136,6 +173,9 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="ActualSize"/>, <see cref="ActualLocation"/> and <see cref="Boundary"/> based on the <see cref="Size"/>, <see cref="Scale"/> and <see cref="Rotation"/>.
|
||||
/// </summary>
|
||||
protected virtual void UpdateActualPlaceableData()
|
||||
{
|
||||
if (Parent != null)
|
||||
@ -166,32 +206,55 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="Location"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnLocationChanged()
|
||||
{
|
||||
LocationChanged?.Invoke(this, new EventArgs());
|
||||
UpdateActualPlaceableData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="Size"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnSizeChanged()
|
||||
{
|
||||
SizeChanged?.Invoke(this, new EventArgs());
|
||||
UpdateActualPlaceableData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="Scale"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnScaleChanged()
|
||||
{
|
||||
ScaleChanged?.Invoke(this, new EventArgs());
|
||||
UpdateActualPlaceableData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="Rotation"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnRotationChanged()
|
||||
{
|
||||
RotationChanged?.Invoke(this, new EventArgs());
|
||||
UpdateActualPlaceableData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="ActualLocation"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnActualLocationChanged() => ActualLocationChanged?.Invoke(this, new EventArgs());
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="ActualLocation"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnActualSizeChanged() => ActualSizeChanged?.Invoke(this, new EventArgs());
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="Boundary"/> property was changed.
|
||||
/// </summary>
|
||||
protected virtual void OnBoundaryChanged() => BoundaryChanged?.Invoke(this, new EventArgs());
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
@ -65,9 +66,8 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Point" /> equivalent to this <see cref="Point" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (!(obj is Point)) return false;
|
||||
if (obj is not Point comparePoint) return false;
|
||||
|
||||
Point comparePoint = (Point)obj;
|
||||
return ((float.IsNaN(X) && float.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X))
|
||||
&& ((float.IsNaN(Y) && float.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y));
|
||||
}
|
||||
@ -76,15 +76,7 @@ namespace RGB.NET.Core
|
||||
/// Returns a hash code for this <see cref="Point" />.
|
||||
/// </summary>
|
||||
/// <returns>An integer value that specifies the hash code for this <see cref="Point" />.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = X.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Y.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
public override int GetHashCode() => HashCode.Combine(X, Y);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -54,14 +54,14 @@ namespace RGB.NET.Core
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the <see cref="Location"/>(0,0) and the given <see cref="Core.Size"/>.
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the <see cref="Location"/>(0,0) and the specified <see cref="Core.Size"/>.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
|
||||
public Rectangle(Size size) : this(new Point(), size)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the given <see cref="Point"/> and <see cref="Core.Size"/>.
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the specified <see cref="Point"/> and <see cref="Core.Size"/>.
|
||||
/// </summary>
|
||||
/// <param name="location">The location of this of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
|
||||
/// <param name="size">The size of of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
|
||||
@ -75,19 +75,19 @@ namespace RGB.NET.Core
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the given array of <see cref="T:RGB.NET.Core.Rectangle" />.
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the specified array of <see cref="T:RGB.NET.Core.Rectangle" />.
|
||||
/// The <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /> is calculated to completely contain all rectangles provided as parameters.
|
||||
/// </summary>
|
||||
/// <param name="rectangles">The array of <see cref="T:RGB.NET.Core.Rectangle" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /></param>
|
||||
/// <param name="rectangles">The array of <see cref="T:RGB.NET.Core.Rectangle" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" />.</param>
|
||||
public Rectangle(params Rectangle[] rectangles)
|
||||
: this(rectangles.AsEnumerable())
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the given list of <see cref="Rectangle"/>.
|
||||
/// Initializes a new instance of the <see cref="Rectangle"/> class using the specified list of <see cref="Rectangle"/>.
|
||||
/// The <see cref="Location"/> and <see cref="Size"/> is calculated to completely contain all rectangles provided as parameters.
|
||||
/// </summary>
|
||||
/// <param name="rectangles">The list of <see cref="Rectangle"/> used to calculate the <see cref="Location"/> and <see cref="Size"/></param>
|
||||
/// <param name="rectangles">The list of <see cref="Rectangle"/> used to calculate the <see cref="Location"/> and <see cref="Size"/>.</param>
|
||||
public Rectangle(IEnumerable<Rectangle> rectangles)
|
||||
{
|
||||
bool hasPoint = false;
|
||||
@ -113,20 +113,20 @@ namespace RGB.NET.Core
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the given array of <see cref="T:RGB.NET.Core.Point" />.
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the specified array of <see cref="T:RGB.NET.Core.Point" />.
|
||||
/// The <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /> is calculated to contain all points provided as parameters.
|
||||
/// </summary>
|
||||
/// <param name="points">The array of <see cref="T:RGB.NET.Core.Point" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /></param>
|
||||
/// <param name="points">The array of <see cref="T:RGB.NET.Core.Point" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" />.</param>
|
||||
public Rectangle(params Point[] points)
|
||||
: this(points.AsEnumerable())
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the given list of <see cref="T:RGB.NET.Core.Point" />.
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the specified list of <see cref="T:RGB.NET.Core.Point" />.
|
||||
/// The <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /> is calculated to contain all points provided as parameters.
|
||||
/// </summary>
|
||||
/// <param name="points">The list of <see cref="T:RGB.NET.Core.Point" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" /></param>
|
||||
/// <param name="points">The list of <see cref="T:RGB.NET.Core.Point" /> used to calculate the <see cref="P:RGB.NET.Core.Rectangle.Location" /> and <see cref="P:RGB.NET.Core.Rectangle.Size" />.</param>
|
||||
public Rectangle(IEnumerable<Point> points)
|
||||
: this()
|
||||
{
|
||||
@ -223,6 +223,12 @@ namespace RGB.NET.Core
|
||||
public static bool operator !=(in Rectangle rectangle1, in Rectangle rectangle2) => !(rectangle1 == rectangle2);
|
||||
|
||||
// DarthAffe 20.02.2021: Used for normalization
|
||||
/// <summary>
|
||||
/// Returns a <see cref="Rectangle"/> normalized to the specified reference.
|
||||
/// </summary>
|
||||
/// <param name="rectangle1">The rectangle to nromalize.</param>
|
||||
/// <param name="rectangle2">The reference used for normalization.</param>
|
||||
/// <returns>A normalized rectangle.</returns>
|
||||
public static Rectangle operator /(in Rectangle rectangle1, in Rectangle rectangle2)
|
||||
{
|
||||
float x = rectangle1.Location.X / (rectangle2.Size.Width - rectangle2.Location.X);
|
||||
|
||||
@ -44,7 +44,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rotation"/> class using the provided values.
|
||||
/// </summary>
|
||||
/// <param name="scale">The rotation in degrees.</param>
|
||||
/// <param name="degrees">The rotation in degrees.</param>
|
||||
public Rotation(float degrees)
|
||||
: this(degrees, degrees * DEGREES_RADIANS_CONVERSION)
|
||||
{ }
|
||||
@ -60,16 +60,16 @@ namespace RGB.NET.Core
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Rotation out of the given degree-angle.
|
||||
/// Creates a new Rotation out of the specified degree-angle.
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in degrees.</param>
|
||||
/// <returns>The new rotation.</returns>
|
||||
public static Rotation FromDegrees(float degrees) => new(degrees);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Rotation out of the given radian-angle.
|
||||
/// Creates a new Rotation out of the specified radian-angle.
|
||||
/// </summary>
|
||||
/// <param name="degrees">The angle in radians.</param>
|
||||
/// <param name="radians">The angle in radians.</param>
|
||||
/// <returns>The new rotation.</returns>
|
||||
public static Rotation FromRadians(float radians) => new(radians * RADIANS_DEGREES_CONVERSION, radians);
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Size" /> equivalent to this <see cref="Size" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (!(obj is Size size)) return false;
|
||||
if (obj is not Size size) return false;
|
||||
|
||||
(float width, float height) = size;
|
||||
return ((float.IsNaN(Width) && float.IsNaN(width)) || Width.EqualsInTolerance(width))
|
||||
@ -185,11 +185,11 @@ namespace RGB.NET.Core
|
||||
public static Size operator /(in Size size, float factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the specified <see cref="Scale"/>.
|
||||
/// </summary>
|
||||
/// <param name="size">The <see cref="Size"/> to scale.</param>
|
||||
/// <param name="scale">The scaling factor.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.</returns>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the specified <see cref="Scale"/>.</returns>
|
||||
public static Size operator *(in Size size, in Scale scale) => new(size.Width * scale.Horizontal, size.Height * scale.Vertical);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
<RootNamespace>RGB.NET.Core</RootNamespace>
|
||||
<Description>Core-Module of RGB.NET</Description>
|
||||
<Summary>Core-Module of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2020</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2020</PackageCopyright>
|
||||
<PackageIconUrl>http://lib.arge.be/icon.png</PackageIconUrl>
|
||||
<Copyright>Copyright © Darth Affe 2021</Copyright>
|
||||
<Icon>icon.png</Icon>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</PackageLicenseUrl>
|
||||
<License>LGPL-2.1-only</License>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
@ -34,19 +33,24 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -24,4 +24,5 @@
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=rendering_005Ctextures_005Csampler/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=surfaces/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=update/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=update_005Cdevices/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=update_005Cdevices/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@ -18,11 +18,11 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Stopwatch _deltaTimeCounter;
|
||||
private readonly Stopwatch _deltaTimeCounter;
|
||||
|
||||
private readonly IList<IRGBDevice> _devices = new List<IRGBDevice>();
|
||||
private readonly IList<IUpdateTrigger> _updateTriggers = new List<IUpdateTrigger>();
|
||||
private readonly List<ILedGroup> _ledGroups = new List<ILedGroup>();
|
||||
private readonly List<ILedGroup> _ledGroups = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>.
|
||||
@ -83,7 +83,7 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Represents the event-handler of the <see cref="SurfaceLayoutChanged"/>-event.
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="args">The arguments provided by the event.</param>
|
||||
public delegate void SurfaceLayoutChangedEventHandler(SurfaceLayoutChangedEventArgs args);
|
||||
|
||||
#endregion
|
||||
@ -225,7 +225,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the given <see cref="ILedGroup"/>.
|
||||
/// Attaches the specified <see cref="ILedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to attach.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be attached; otherwise, <c>false</c>.</returns>
|
||||
@ -245,10 +245,10 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the given <see cref="ILedGroup"/>.
|
||||
/// Detaches the specified <see cref="ILedGroup"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to detached.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be detached; otherwise, <c>false</c>.</returns>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to detache.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be detached; <c>false</c> otherwise.</returns>
|
||||
public bool Detach(ILedGroup ledGroup)
|
||||
{
|
||||
lock (_ledGroups)
|
||||
@ -261,6 +261,10 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the specified <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="IRGBDevice"/> to attach.</param>
|
||||
public void Attach(IRGBDevice device)
|
||||
{
|
||||
lock (_devices)
|
||||
@ -276,6 +280,11 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the specified <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="IRGBDevice"/> to detache.</param>
|
||||
/// <returns><c>true</c> if the <see cref="IRGBDevice"/> could be detached; <c>false</c> otherwise.</returns>
|
||||
public void Detach(IRGBDevice device)
|
||||
{
|
||||
lock (_devices)
|
||||
|
||||
@ -46,6 +46,12 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Renders the brush to the specified list of <see cref="RenderTarget"/>.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The bounding box the brush is rendered in.</param>
|
||||
/// <param name="renderTargets">The targets to render to.</param>
|
||||
/// <returns>A enumerable containing the rendered <see cref="Color"/> for each <see cref="RenderTarget"/>.</returns>
|
||||
public virtual IEnumerable<(RenderTarget renderTarget, Color color)> Render(Rectangle rectangle, IEnumerable<RenderTarget> renderTargets)
|
||||
{
|
||||
foreach (RenderTarget renderTarget in renderTargets)
|
||||
@ -74,7 +80,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color at an specific point assuming the brush is drawn into the given rectangle.
|
||||
/// Gets the color at an specific point assuming the brush is drawn into the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
||||
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||
|
||||
@ -24,8 +24,7 @@ namespace RGB.NET.Core
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.SolidColorBrush" /> class.
|
||||
/// </summary>
|
||||
|
||||
@ -1,10 +1,17 @@
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a brush drawing a texture.
|
||||
/// </summary>
|
||||
public class TextureBrush : AbstractBrush
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private ITexture _texture = ITexture.Empty;
|
||||
/// <summary>
|
||||
/// Gets or sets the texture drawn by this brush.
|
||||
/// </summary>
|
||||
public ITexture Texture
|
||||
{
|
||||
get => _texture;
|
||||
@ -15,6 +22,10 @@
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TextureBrush" /> class.
|
||||
/// </summary>
|
||||
/// <param name="texture">The texture drawn by this brush.</param>
|
||||
public TextureBrush(ITexture texture)
|
||||
{
|
||||
this.Texture = texture;
|
||||
@ -24,6 +35,7 @@
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColorAtPoint(in Rectangle rectangle, in RenderTarget renderTarget)
|
||||
{
|
||||
Rectangle normalizedRect = renderTarget.Rectangle / rectangle;
|
||||
|
||||
@ -1,12 +1,32 @@
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a generic texture.
|
||||
/// </summary>
|
||||
public interface ITexture
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a empty texture.
|
||||
/// </summary>
|
||||
static ITexture Empty => new EmptyTexture();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the texture
|
||||
/// </summary>
|
||||
Size Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color at the specified location.
|
||||
/// </summary>
|
||||
/// <param name="point">The location to get the color from.</param>
|
||||
/// <returns>The color at the specified location.</returns>
|
||||
Color this[in Point point] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sampled color inside the specified rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to get the color from.</param>
|
||||
/// <returns>The sampled color.</returns>
|
||||
Color this[in Rectangle rectangle] { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,11 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a texture made of pixels (like a common image).
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the pixels.</typeparam>
|
||||
public abstract class PixelTexture<T> : ITexture
|
||||
where T : unmanaged
|
||||
{
|
||||
@ -18,11 +23,20 @@ namespace RGB.NET.Core
|
||||
private readonly int _dataPerPixel;
|
||||
private readonly int _stride;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sampler used to get the color of a region.
|
||||
/// </summary>
|
||||
public ISampler<T> Sampler { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Size Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying pixel data.
|
||||
/// </summary>
|
||||
protected abstract ReadOnlySpan<T> Data { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Color this[in Point point]
|
||||
{
|
||||
get
|
||||
@ -35,6 +49,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Color this[in Rectangle rectangle]
|
||||
{
|
||||
get
|
||||
@ -50,6 +65,14 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sampled color inside the specified region.
|
||||
/// </summary>
|
||||
/// <param name="x">The x-location of the region.</param>
|
||||
/// <param name="y">The y-location of the region.</param>
|
||||
/// <param name="width">The with of the region.</param>
|
||||
/// <param name="height">The height of the region.</param>
|
||||
/// <returns>The sampled color.</returns>
|
||||
public virtual Color this[int x, int y, int width, int height]
|
||||
{
|
||||
get
|
||||
@ -66,7 +89,7 @@ namespace RGB.NET.Core
|
||||
GetRegionData(x, y, width, height, buffer);
|
||||
|
||||
Span<T> pixelData = stackalloc T[_dataPerPixel];
|
||||
Sampler.SampleColor(new SamplerInfo<T>(width, height, buffer), pixelData);
|
||||
Sampler.Sample(new SamplerInfo<T>(width, height, buffer), pixelData);
|
||||
|
||||
return GetColor(pixelData);
|
||||
}
|
||||
@ -74,11 +97,11 @@ namespace RGB.NET.Core
|
||||
{
|
||||
T[] rent = ArrayPool<T>.Shared.Rent(bufferSize);
|
||||
|
||||
Span<T> buffer = new Span<T>(rent).Slice(0, bufferSize);
|
||||
Span<T> buffer = new Span<T>(rent)[..bufferSize];
|
||||
GetRegionData(x, y, width, height, buffer);
|
||||
|
||||
Span<T> pixelData = stackalloc T[_dataPerPixel];
|
||||
Sampler.SampleColor(new SamplerInfo<T>(width, height, buffer), pixelData);
|
||||
Sampler.Sample(new SamplerInfo<T>(width, height, buffer), pixelData);
|
||||
|
||||
ArrayPool<T>.Shared.Return(rent);
|
||||
|
||||
@ -91,6 +114,14 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PixelTexture{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="dataPerPixel">The amount of data-entries per pixel.</param>
|
||||
/// <param name="sampler">The sampler used to get the color of a region.</param>
|
||||
/// <param name="stride">The stride of the data or -1 if the width should be used.</param>
|
||||
public PixelTexture(int with, int height, int dataPerPixel, ISampler<T> sampler, int stride = -1)
|
||||
{
|
||||
this._stride = stride == -1 ? with : stride;
|
||||
@ -104,11 +135,30 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Converts the pixel-data to a color.
|
||||
/// </summary>
|
||||
/// <param name="pixel">The pixel-data to convert.</param>
|
||||
/// <returns>The color represented by the specified pixel-data.</returns>
|
||||
protected abstract Color GetColor(in ReadOnlySpan<T> pixel);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pixel-data at the specified location.
|
||||
/// </summary>
|
||||
/// <param name="x">The x-location.</param>
|
||||
/// <param name="y">The y-location.</param>
|
||||
/// <returns>The pixel-data on the specified location.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected virtual ReadOnlySpan<T> GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the pixel-data of the specified region to the passed buffer.
|
||||
/// </summary>
|
||||
/// <param name="x">The x-location of the region to get the data for.</param>
|
||||
/// <param name="y">The y-location of the region to get the data for.</param>
|
||||
/// <param name="width">The width of the region to get the data for.</param>
|
||||
/// <param name="height">The height of the region to get the data for.</param>
|
||||
/// <param name="buffer">The buffer to write the data to.</param>
|
||||
protected virtual void GetRegionData(int x, int y, int width, int height, in Span<T> buffer)
|
||||
{
|
||||
int dataWidth = width * _dataPerPixel;
|
||||
@ -124,34 +174,54 @@ namespace RGB.NET.Core
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a texture made of color-pixels.
|
||||
/// </summary>
|
||||
public sealed class PixelTexture : PixelTexture<Color>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly Color[] _data;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ReadOnlySpan<Color> Data => _data;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PixelTexture" /> class.
|
||||
/// A <see cref="AverageColorSampler"/> is used.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
public PixelTexture(int with, int height, Color[] data)
|
||||
: this(with, height, data, new AverageColorSampler())
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PixelTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
/// <param name="sampler">The sampler used to get the color of a region.</param>
|
||||
public PixelTexture(int with, int height, Color[] data, ISampler<Color> sampler)
|
||||
: base(with, height, 1, sampler)
|
||||
{
|
||||
this._data = data;
|
||||
|
||||
if (Data.Length != (with * height)) throw new ArgumentException($"Data-Length {Data.Length} differs from the given size {with}x{height} ({with * height}).");
|
||||
if (Data.Length != (with * height)) throw new ArgumentException($"Data-Length {Data.Length} differs from the specified size {with}x{height} ({with * height}).");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in ReadOnlySpan<Color> pixel) => pixel[0];
|
||||
|
||||
#endregion
|
||||
|
||||
@ -2,11 +2,18 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a sampled that averages multiple color to a single color.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Averages all components (A, R, G, B) of the colors separately which isn't ideal in cases where multiple different colors are combined.
|
||||
/// </remarks>
|
||||
public class AverageColorSampler : ISampler<Color>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public void SampleColor(in SamplerInfo<Color> info, in Span<Color> pixelData)
|
||||
/// <inheritdoc />
|
||||
public void Sample(in SamplerInfo<Color> info, in Span<Color> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
@ -2,8 +2,17 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a generic sampler to combine multipel data entries to a single one.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to sample.</typeparam>
|
||||
public interface ISampler<T>
|
||||
{
|
||||
void SampleColor(in SamplerInfo<T> info, in Span<T> pixelData);
|
||||
/// <summary>
|
||||
/// Samples the specified data to a single pixel-buffer.
|
||||
/// </summary>
|
||||
/// <param name="info">The information containing the data to sample.</param>
|
||||
/// <param name="pixelData">The buffer used to write the resulting pixel to.</param>
|
||||
void Sample(in SamplerInfo<T> info, in Span<T> pixelData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,18 +2,39 @@
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the information used to sample data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to sample.</typeparam>
|
||||
public readonly ref struct SamplerInfo<T>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the region the data comes from.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of region the data comes from.
|
||||
/// </summary>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data to sample.
|
||||
/// </summary>
|
||||
public ReadOnlySpan<T> Data { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SamplerInfo{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="width">The width of the region the data comes from.</param>
|
||||
/// <param name="height">The height of region the data comes from.</param>
|
||||
/// <param name="data">The data to sample.</param>
|
||||
public SamplerInfo(int width, int height, ReadOnlySpan<T> data)
|
||||
{
|
||||
this.Width = width;
|
||||
|
||||
@ -9,6 +9,7 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract double LastUpdateTime { get; protected set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -19,7 +19,7 @@ namespace RGB.NET.Core
|
||||
/// Gets or sets the value for a specific key.
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the value.</param>
|
||||
/// <returns>The value represented by the given key.</returns>
|
||||
/// <returns>The value represented by the specified key.</returns>
|
||||
public object? this[string key]
|
||||
{
|
||||
get => _data.TryGetValue(key.ToUpperInvariant(), out object? data) ? data : default;
|
||||
|
||||
@ -53,13 +53,32 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double LastUpdateTime { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the event to trigger when new data is available (<see cref="TriggerHasData"/>).
|
||||
/// </summary>
|
||||
protected AutoResetEvent HasDataEvent { get; set; } = new(false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a bool indicating if the trigger is currently updating.
|
||||
/// </summary>
|
||||
protected bool IsRunning { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the update loop of this trigger.
|
||||
/// </summary>
|
||||
protected Task? UpdateTask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cancellation token source used to create the cancellation token checked by the <see cref="UpdateTask"/>.
|
||||
/// </summary>
|
||||
protected CancellationTokenSource? UpdateTokenSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cancellation token checked by the <see cref="UpdateTask"/>.
|
||||
/// </summary>
|
||||
protected CancellationToken UpdateToken { get; set; }
|
||||
|
||||
#endregion
|
||||
@ -116,6 +135,9 @@ namespace RGB.NET.Core
|
||||
UpdateTask = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The update loop called by the <see cref="UpdateTask"/>.
|
||||
/// </summary>
|
||||
protected virtual void UpdateLoop()
|
||||
{
|
||||
OnStartup();
|
||||
|
||||
@ -3,6 +3,11 @@ using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a generic update queue.
|
||||
/// </summary>
|
||||
/// <typeparam name="TIdentifier">The identifier used to identify the data processed by this queue.</typeparam>
|
||||
/// <typeparam name="TData">The type of the data processed by this queue.</typeparam>
|
||||
public interface IUpdateQueue<TIdentifier, TData> : IDisposable
|
||||
where TIdentifier : notnull
|
||||
{
|
||||
@ -19,6 +24,9 @@ namespace RGB.NET.Core
|
||||
void Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic update queue processing <see cref="Color"/>-data using <see cref="object"/>-identifiers.
|
||||
/// </summary>
|
||||
public interface IUpdateQueue : IUpdateQueue<object, Color>
|
||||
{ }
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ namespace RGB.NET.Core
|
||||
if (_currentDataSet.Count == 0) return;
|
||||
|
||||
dataSet = ArrayPool<(TIdentifier, TData)>.Shared.Rent(_currentDataSet.Count);
|
||||
data = new Span<(TIdentifier, TData)>(dataSet).Slice(0, _currentDataSet.Count);
|
||||
data = new Span<(TIdentifier, TData)>(dataSet)[.._currentDataSet.Count];
|
||||
|
||||
int i = 0;
|
||||
foreach ((TIdentifier key, TData value) in _currentDataSet)
|
||||
@ -115,6 +115,8 @@ namespace RGB.NET.Core
|
||||
_updateTrigger.Update -= OnUpdate;
|
||||
|
||||
Reset();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -7,6 +7,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public interface IUpdateTrigger : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the time spent for the last update.
|
||||
/// </summary>
|
||||
double LastUpdateTime { get; }
|
||||
|
||||
/// <summary>
|
||||
@ -19,6 +22,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
event EventHandler<CustomUpdateData>? Update;
|
||||
|
||||
/// <summary>
|
||||
/// Starts the update trigger.
|
||||
/// </summary>
|
||||
void Start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,13 +8,13 @@ namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents an <see cref="T:RGB.NET.Core.IUpdateTrigger" />
|
||||
/// Represents an update trigger that is manully triggered by calling <see cref="TriggerUpdate"/>.
|
||||
/// </summary>
|
||||
public sealed class ManualUpdateTrigger : AbstractUpdateTrigger
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private AutoResetEvent _mutex = new(false);
|
||||
private readonly AutoResetEvent _mutex = new(false);
|
||||
private Task? UpdateTask { get; set; }
|
||||
private CancellationTokenSource? UpdateTokenSource { get; set; }
|
||||
private CancellationToken UpdateToken { get; set; }
|
||||
@ -31,7 +31,6 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManualUpdateTrigger"/> class.
|
||||
/// </summary>
|
||||
/// <param name="autostart">A value indicating if the trigger should automatically <see cref="Start"/> right after construction.</param>
|
||||
public ManualUpdateTrigger()
|
||||
{
|
||||
Start();
|
||||
@ -69,6 +68,9 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers an update.
|
||||
/// </summary>
|
||||
public void TriggerUpdate() => _mutex.Set();
|
||||
|
||||
private void UpdateLoop()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,16 +9,27 @@ namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents an <see cref="T:RGB.NET.Core.IUpdateTrigger" />
|
||||
/// Represents an update trigger that triggers in a set interval.
|
||||
/// </summary>
|
||||
public class TimerUpdateTrigger : AbstractUpdateTrigger
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private object _lock = new();
|
||||
private readonly object _lock = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the update loop of this trigger.
|
||||
/// </summary>
|
||||
protected Task? UpdateTask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cancellation token source used to create the cancellation token checked by the <see cref="UpdateTask"/>.
|
||||
/// </summary>
|
||||
protected CancellationTokenSource? UpdateTokenSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cancellation token checked by the <see cref="UpdateTask"/>.
|
||||
/// </summary>
|
||||
protected CancellationToken UpdateToken { get; set; }
|
||||
|
||||
private double _updateFrequency = 1.0 / 30.0;
|
||||
@ -46,6 +58,7 @@ namespace RGB.NET.Core
|
||||
public TimerUpdateTrigger(bool autostart = true)
|
||||
{
|
||||
if (autostart)
|
||||
// ReSharper disable once VirtualMemberCallInConstructor - HACK DarthAffe 01.06.2021: I've no idea how to correctly handle that case, for now just disable it
|
||||
Start();
|
||||
}
|
||||
|
||||
@ -109,7 +122,11 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose() => Stop();
|
||||
public override void Dispose()
|
||||
{
|
||||
Stop();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeSDK()
|
||||
{
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
@ -50,6 +51,7 @@ namespace RGB.NET.Devices.Asus
|
||||
_sdk.SwitchMode();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
if (_sdk == null) yield break;
|
||||
@ -84,6 +86,8 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
_devices = null;
|
||||
_sdk = null;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusDramRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the DRAM.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusDramRGBDevice(AsusRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace RGB.NET.Devices.Asus
|
||||
{
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="AsusRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by Asus for the device.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
protected AsusRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, new AsusUpdateQueue(updateTrigger, info.Device))
|
||||
{ }
|
||||
|
||||
@ -23,8 +23,12 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SDK-aura-device this device represents.
|
||||
/// </summary>
|
||||
public IAuraSyncDevice Device { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -21,6 +21,8 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusHeadsetRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the headset.</param>
|
||||
/// <param name="baseLedId">The ledId of the first led of this device. All other leds are created by incrementing this base-id by 1.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusUnspecifiedRGBDevice(AsusRGBDeviceInfo info, LedId baseLedId, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -25,6 +25,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="AsusUpdateQueue"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateTrigger">The update trigger used by this queue.</param>
|
||||
/// <param name="device">The SDK-aura-device this device represents.</param>
|
||||
public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice device)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusGraphicsCardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the graphics card.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusGraphicsCardRGBDevice(AsusRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusHeadsetRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the headset.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusHeadsetRGBDevice(AsusRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -2,188 +2,191 @@
|
||||
|
||||
namespace RGB.NET.Devices.Asus
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains mappings for <see cref="LedId"/> to <see cref="AsusLedId"/>.
|
||||
/// </summary>
|
||||
public static class LedMappings
|
||||
{
|
||||
/// <summary>
|
||||
/// A LED mapping containing ASUS keyboard LED IDs
|
||||
/// </summary>
|
||||
public static readonly LedMapping<AsusLedId> KeyboardMapping =
|
||||
new()
|
||||
{
|
||||
{LedId.Keyboard_Escape, AsusLedId.KEY_ESCAPE},
|
||||
{LedId.Keyboard_F1, AsusLedId.KEY_F1},
|
||||
{LedId.Keyboard_F2, AsusLedId.KEY_F2},
|
||||
{LedId.Keyboard_F3, AsusLedId.KEY_F3},
|
||||
{LedId.Keyboard_F4, AsusLedId.KEY_F4},
|
||||
{LedId.Keyboard_F5, AsusLedId.KEY_F5},
|
||||
{LedId.Keyboard_F6, AsusLedId.KEY_F6},
|
||||
{LedId.Keyboard_F7, AsusLedId.KEY_F7},
|
||||
{LedId.Keyboard_F8, AsusLedId.KEY_F8},
|
||||
{LedId.Keyboard_F9, AsusLedId.KEY_F9},
|
||||
{LedId.Keyboard_F10, AsusLedId.KEY_F10},
|
||||
{LedId.Keyboard_F11, AsusLedId.KEY_F11},
|
||||
{LedId.Keyboard_F12, AsusLedId.KEY_F12},
|
||||
{LedId.Keyboard_1, AsusLedId.KEY_1},
|
||||
{LedId.Keyboard_2, AsusLedId.KEY_2},
|
||||
{LedId.Keyboard_3, AsusLedId.KEY_3},
|
||||
{LedId.Keyboard_4, AsusLedId.KEY_4},
|
||||
{LedId.Keyboard_5, AsusLedId.KEY_5},
|
||||
{LedId.Keyboard_6, AsusLedId.KEY_6},
|
||||
{LedId.Keyboard_7, AsusLedId.KEY_7},
|
||||
{LedId.Keyboard_8, AsusLedId.KEY_8},
|
||||
{LedId.Keyboard_9, AsusLedId.KEY_9},
|
||||
{LedId.Keyboard_0, AsusLedId.KEY_0},
|
||||
{LedId.Keyboard_MinusAndUnderscore, AsusLedId.KEY_MINUS},
|
||||
{LedId.Keyboard_EqualsAndPlus, AsusLedId.KEY_EQUALS},
|
||||
{LedId.Keyboard_Backspace, AsusLedId.KEY_BACK},
|
||||
{LedId.Keyboard_Tab, AsusLedId.KEY_TAB},
|
||||
{LedId.Keyboard_Q, AsusLedId.KEY_Q},
|
||||
{LedId.Keyboard_W, AsusLedId.KEY_W},
|
||||
{LedId.Keyboard_E, AsusLedId.KEY_E},
|
||||
{LedId.Keyboard_R, AsusLedId.KEY_R},
|
||||
{LedId.Keyboard_T, AsusLedId.KEY_T},
|
||||
{LedId.Keyboard_Y, AsusLedId.KEY_Y},
|
||||
{LedId.Keyboard_U, AsusLedId.KEY_U},
|
||||
{LedId.Keyboard_I, AsusLedId.KEY_I},
|
||||
{LedId.Keyboard_O, AsusLedId.KEY_O},
|
||||
{LedId.Keyboard_P, AsusLedId.KEY_P},
|
||||
{LedId.Keyboard_BracketLeft, AsusLedId.KEY_LBRACKET},
|
||||
{LedId.Keyboard_BracketRight, AsusLedId.KEY_RBRACKET},
|
||||
{LedId.Keyboard_Enter, AsusLedId.KEY_RETURN},
|
||||
{LedId.Keyboard_CapsLock, AsusLedId.KEY_CAPITAL},
|
||||
{LedId.Keyboard_A, AsusLedId.KEY_A},
|
||||
{LedId.Keyboard_S, AsusLedId.KEY_S},
|
||||
{LedId.Keyboard_D, AsusLedId.KEY_D},
|
||||
{LedId.Keyboard_F, AsusLedId.KEY_F},
|
||||
{LedId.Keyboard_G, AsusLedId.KEY_G},
|
||||
{LedId.Keyboard_H, AsusLedId.KEY_H},
|
||||
{LedId.Keyboard_J, AsusLedId.KEY_J},
|
||||
{LedId.Keyboard_K, AsusLedId.KEY_K},
|
||||
{LedId.Keyboard_L, AsusLedId.KEY_L},
|
||||
{LedId.Keyboard_SemicolonAndColon, AsusLedId.KEY_SEMICOLON},
|
||||
{LedId.Keyboard_ApostropheAndDoubleQuote, AsusLedId.KEY_APOSTROPHE},
|
||||
{LedId.Keyboard_GraveAccentAndTilde, AsusLedId.KEY_GRAVE},
|
||||
{LedId.Keyboard_LeftShift, AsusLedId.KEY_LSHIFT},
|
||||
{LedId.Keyboard_Backslash, AsusLedId.KEY_BACKSLASH},
|
||||
{LedId.Keyboard_Z, AsusLedId.KEY_Z},
|
||||
{LedId.Keyboard_X, AsusLedId.KEY_X},
|
||||
{LedId.Keyboard_C, AsusLedId.KEY_C},
|
||||
{LedId.Keyboard_V, AsusLedId.KEY_V},
|
||||
{LedId.Keyboard_B, AsusLedId.KEY_B},
|
||||
{LedId.Keyboard_N, AsusLedId.KEY_N},
|
||||
{LedId.Keyboard_M, AsusLedId.KEY_M},
|
||||
{LedId.Keyboard_CommaAndLessThan, AsusLedId.KEY_COMMA},
|
||||
{LedId.Keyboard_PeriodAndBiggerThan, AsusLedId.KEY_PERIOD},
|
||||
{LedId.Keyboard_SlashAndQuestionMark, AsusLedId.KEY_SLASH},
|
||||
{LedId.Keyboard_RightShift, AsusLedId.KEY_RSHIFT},
|
||||
{LedId.Keyboard_LeftCtrl, AsusLedId.KEY_LCONTROL},
|
||||
{LedId.Keyboard_LeftGui, AsusLedId.KEY_LWIN},
|
||||
{LedId.Keyboard_LeftAlt, AsusLedId.KEY_LMENU},
|
||||
{LedId.Keyboard_Space, AsusLedId.KEY_SPACE},
|
||||
{LedId.Keyboard_RightAlt, AsusLedId.KEY_RMENU},
|
||||
{LedId.Keyboard_RightGui, AsusLedId.KEY_RWIN},
|
||||
{LedId.Keyboard_Application, AsusLedId.KEY_APPS},
|
||||
{LedId.Keyboard_RightCtrl, AsusLedId.KEY_RCONTROL},
|
||||
{LedId.Keyboard_PrintScreen, AsusLedId.KEY_SYSRQ},
|
||||
{LedId.Keyboard_ScrollLock, AsusLedId.KEY_SCROLL},
|
||||
{LedId.Keyboard_PauseBreak, AsusLedId.KEY_PAUSE},
|
||||
{LedId.Keyboard_Insert, AsusLedId.KEY_INSERT},
|
||||
{LedId.Keyboard_Home, AsusLedId.KEY_HOME},
|
||||
{LedId.Keyboard_PageUp, AsusLedId.KEY_PRIOR},
|
||||
{LedId.Keyboard_Delete, AsusLedId.KEY_DELETE},
|
||||
{LedId.Keyboard_End, AsusLedId.KEY_END},
|
||||
{LedId.Keyboard_PageDown, AsusLedId.KEY_NEXT},
|
||||
{LedId.Keyboard_ArrowUp, AsusLedId.KEY_UP},
|
||||
{LedId.Keyboard_ArrowLeft, AsusLedId.KEY_LEFT},
|
||||
{LedId.Keyboard_ArrowDown, AsusLedId.KEY_DOWN},
|
||||
{LedId.Keyboard_ArrowRight, AsusLedId.KEY_RIGHT},
|
||||
{LedId.Keyboard_NumLock, AsusLedId.KEY_NUMLOCK},
|
||||
{LedId.Keyboard_NumSlash, AsusLedId.KEY_DIVIDE},
|
||||
{LedId.Keyboard_NumAsterisk, AsusLedId.KEY_MULTIPLY},
|
||||
{LedId.Keyboard_NumMinus, AsusLedId.KEY_SUBTRACT},
|
||||
{LedId.Keyboard_Num7, AsusLedId.KEY_NUMPAD7},
|
||||
{LedId.Keyboard_Num8, AsusLedId.KEY_NUMPAD8},
|
||||
{LedId.Keyboard_Num9, AsusLedId.KEY_NUMPAD9},
|
||||
{LedId.Keyboard_NumPeriodAndDelete, AsusLedId.KEY_DECIMAL},
|
||||
{LedId.Keyboard_NumPlus, AsusLedId.KEY_ADD},
|
||||
{LedId.Keyboard_Num4, AsusLedId.KEY_NUMPAD4},
|
||||
{LedId.Keyboard_Num5, AsusLedId.KEY_NUMPAD5},
|
||||
{LedId.Keyboard_Num6, AsusLedId.KEY_NUMPAD6},
|
||||
{LedId.Keyboard_Num1, AsusLedId.KEY_NUMPAD1},
|
||||
{LedId.Keyboard_Num2, AsusLedId.KEY_NUMPAD2},
|
||||
{LedId.Keyboard_Num3, AsusLedId.KEY_NUMPAD3},
|
||||
{LedId.Keyboard_Num0, AsusLedId.KEY_NUMPAD0},
|
||||
{LedId.Keyboard_NumEnter, AsusLedId.KEY_NUMPADENTER},
|
||||
{LedId.Keyboard_NonUsBackslash, AsusLedId.UNDOCUMENTED_1},
|
||||
{LedId.Keyboard_NonUsTilde, AsusLedId.UNDOCUMENTED_2},
|
||||
{LedId.Keyboard_NumComma, AsusLedId.KEY_NUMPADCOMMA},
|
||||
{LedId.Logo, AsusLedId.UNDOCUMENTED_3},
|
||||
{LedId.Keyboard_Function, AsusLedId.KEY_FN},
|
||||
{LedId.Keyboard_MediaMute, AsusLedId.KEY_MUTE},
|
||||
{LedId.Keyboard_MediaPlay, AsusLedId.KEY_PLAYPAUSE},
|
||||
{LedId.Keyboard_MediaStop, AsusLedId.KEY_MEDIASTOP},
|
||||
{LedId.Keyboard_MediaVolumeDown, AsusLedId.KEY_VOLUMEDOWN},
|
||||
{LedId.Keyboard_MediaVolumeUp, AsusLedId.KEY_VOLUMEUP},
|
||||
{LedId.Keyboard_Custom1, AsusLedId.KEY_F13},
|
||||
{LedId.Keyboard_Custom2, AsusLedId.KEY_F14},
|
||||
{LedId.Keyboard_Custom3, AsusLedId.KEY_F15},
|
||||
{LedId.Keyboard_Custom4, AsusLedId.KEY_KANA},
|
||||
{LedId.Keyboard_Custom5, AsusLedId.KEY_ABNT_C1},
|
||||
{LedId.Keyboard_Custom6, AsusLedId.KEY_CONVERT},
|
||||
{LedId.Keyboard_Custom7, AsusLedId.KEY_NOCONVERT},
|
||||
{LedId.Keyboard_Custom8, AsusLedId.KEY_YEN},
|
||||
{LedId.Keyboard_Custom9, AsusLedId.KEY_ABNT_C2},
|
||||
{LedId.Keyboard_Custom10, AsusLedId.KEY_NUMPADEQUALS},
|
||||
{LedId.Keyboard_Custom11, AsusLedId.KEY_CIRCUMFLEX},
|
||||
{LedId.Keyboard_Custom12, AsusLedId.KEY_AT},
|
||||
{LedId.Keyboard_Custom13, AsusLedId.KEY_COLON},
|
||||
{LedId.Keyboard_Custom14, AsusLedId.KEY_UNDERLINE},
|
||||
{LedId.Keyboard_Custom15, AsusLedId.KEY_KANJI},
|
||||
{LedId.Keyboard_Custom16, AsusLedId.KEY_STOP},
|
||||
{LedId.Keyboard_Custom17, AsusLedId.KEY_AX},
|
||||
{LedId.Keyboard_Custom18, AsusLedId.KEY_UNLABELED},
|
||||
{LedId.Keyboard_Custom19, AsusLedId.KEY_NEXTTRACK},
|
||||
{LedId.Keyboard_Custom20, AsusLedId.KEY_CALCULATOR},
|
||||
{LedId.Keyboard_Custom21, AsusLedId.KEY_POWER},
|
||||
{LedId.Keyboard_Custom22, AsusLedId.KEY_SLEEP},
|
||||
{LedId.Keyboard_Custom23, AsusLedId.KEY_WAKE},
|
||||
{LedId.Keyboard_Custom24, AsusLedId.KEY_WEBSEARCH},
|
||||
{LedId.Keyboard_Custom25, AsusLedId.KEY_WEBFAVORITES},
|
||||
{LedId.Keyboard_Custom26, AsusLedId.KEY_WEBREFRESH},
|
||||
{LedId.Keyboard_Custom27, AsusLedId.KEY_WEBSTOP},
|
||||
{LedId.Keyboard_Custom28, AsusLedId.KEY_WEBFORWARD},
|
||||
{LedId.Keyboard_Custom29, AsusLedId.KEY_WEBHOME},
|
||||
{LedId.Keyboard_Custom30, AsusLedId.KEY_WEBBACK},
|
||||
{LedId.Keyboard_Custom31, AsusLedId.KEY_MYCOMPUTER},
|
||||
{LedId.Keyboard_Custom32, AsusLedId.KEY_MAIL},
|
||||
{LedId.Keyboard_Custom33, AsusLedId.KEY_MEDIASELECT},
|
||||
{LedId.Keyboard_Custom34, AsusLedId.UNDOCUMENTED_4},
|
||||
{LedId.Keyboard_Custom35, AsusLedId.UNDOCUMENTED_5},
|
||||
{LedId.Keyboard_Custom36, AsusLedId.UNDOCUMENTED_6}
|
||||
};
|
||||
public static LedMapping<AsusLedId> KeyboardMapping { get; } = new()
|
||||
{
|
||||
{ LedId.Keyboard_Escape, AsusLedId.KEY_ESCAPE },
|
||||
{ LedId.Keyboard_F1, AsusLedId.KEY_F1 },
|
||||
{ LedId.Keyboard_F2, AsusLedId.KEY_F2 },
|
||||
{ LedId.Keyboard_F3, AsusLedId.KEY_F3 },
|
||||
{ LedId.Keyboard_F4, AsusLedId.KEY_F4 },
|
||||
{ LedId.Keyboard_F5, AsusLedId.KEY_F5 },
|
||||
{ LedId.Keyboard_F6, AsusLedId.KEY_F6 },
|
||||
{ LedId.Keyboard_F7, AsusLedId.KEY_F7 },
|
||||
{ LedId.Keyboard_F8, AsusLedId.KEY_F8 },
|
||||
{ LedId.Keyboard_F9, AsusLedId.KEY_F9 },
|
||||
{ LedId.Keyboard_F10, AsusLedId.KEY_F10 },
|
||||
{ LedId.Keyboard_F11, AsusLedId.KEY_F11 },
|
||||
{ LedId.Keyboard_F12, AsusLedId.KEY_F12 },
|
||||
{ LedId.Keyboard_1, AsusLedId.KEY_1 },
|
||||
{ LedId.Keyboard_2, AsusLedId.KEY_2 },
|
||||
{ LedId.Keyboard_3, AsusLedId.KEY_3 },
|
||||
{ LedId.Keyboard_4, AsusLedId.KEY_4 },
|
||||
{ LedId.Keyboard_5, AsusLedId.KEY_5 },
|
||||
{ LedId.Keyboard_6, AsusLedId.KEY_6 },
|
||||
{ LedId.Keyboard_7, AsusLedId.KEY_7 },
|
||||
{ LedId.Keyboard_8, AsusLedId.KEY_8 },
|
||||
{ LedId.Keyboard_9, AsusLedId.KEY_9 },
|
||||
{ LedId.Keyboard_0, AsusLedId.KEY_0 },
|
||||
{ LedId.Keyboard_MinusAndUnderscore, AsusLedId.KEY_MINUS },
|
||||
{ LedId.Keyboard_EqualsAndPlus, AsusLedId.KEY_EQUALS },
|
||||
{ LedId.Keyboard_Backspace, AsusLedId.KEY_BACK },
|
||||
{ LedId.Keyboard_Tab, AsusLedId.KEY_TAB },
|
||||
{ LedId.Keyboard_Q, AsusLedId.KEY_Q },
|
||||
{ LedId.Keyboard_W, AsusLedId.KEY_W },
|
||||
{ LedId.Keyboard_E, AsusLedId.KEY_E },
|
||||
{ LedId.Keyboard_R, AsusLedId.KEY_R },
|
||||
{ LedId.Keyboard_T, AsusLedId.KEY_T },
|
||||
{ LedId.Keyboard_Y, AsusLedId.KEY_Y },
|
||||
{ LedId.Keyboard_U, AsusLedId.KEY_U },
|
||||
{ LedId.Keyboard_I, AsusLedId.KEY_I },
|
||||
{ LedId.Keyboard_O, AsusLedId.KEY_O },
|
||||
{ LedId.Keyboard_P, AsusLedId.KEY_P },
|
||||
{ LedId.Keyboard_BracketLeft, AsusLedId.KEY_LBRACKET },
|
||||
{ LedId.Keyboard_BracketRight, AsusLedId.KEY_RBRACKET },
|
||||
{ LedId.Keyboard_Enter, AsusLedId.KEY_RETURN },
|
||||
{ LedId.Keyboard_CapsLock, AsusLedId.KEY_CAPITAL },
|
||||
{ LedId.Keyboard_A, AsusLedId.KEY_A },
|
||||
{ LedId.Keyboard_S, AsusLedId.KEY_S },
|
||||
{ LedId.Keyboard_D, AsusLedId.KEY_D },
|
||||
{ LedId.Keyboard_F, AsusLedId.KEY_F },
|
||||
{ LedId.Keyboard_G, AsusLedId.KEY_G },
|
||||
{ LedId.Keyboard_H, AsusLedId.KEY_H },
|
||||
{ LedId.Keyboard_J, AsusLedId.KEY_J },
|
||||
{ LedId.Keyboard_K, AsusLedId.KEY_K },
|
||||
{ LedId.Keyboard_L, AsusLedId.KEY_L },
|
||||
{ LedId.Keyboard_SemicolonAndColon, AsusLedId.KEY_SEMICOLON },
|
||||
{ LedId.Keyboard_ApostropheAndDoubleQuote, AsusLedId.KEY_APOSTROPHE },
|
||||
{ LedId.Keyboard_GraveAccentAndTilde, AsusLedId.KEY_GRAVE },
|
||||
{ LedId.Keyboard_LeftShift, AsusLedId.KEY_LSHIFT },
|
||||
{ LedId.Keyboard_Backslash, AsusLedId.KEY_BACKSLASH },
|
||||
{ LedId.Keyboard_Z, AsusLedId.KEY_Z },
|
||||
{ LedId.Keyboard_X, AsusLedId.KEY_X },
|
||||
{ LedId.Keyboard_C, AsusLedId.KEY_C },
|
||||
{ LedId.Keyboard_V, AsusLedId.KEY_V },
|
||||
{ LedId.Keyboard_B, AsusLedId.KEY_B },
|
||||
{ LedId.Keyboard_N, AsusLedId.KEY_N },
|
||||
{ LedId.Keyboard_M, AsusLedId.KEY_M },
|
||||
{ LedId.Keyboard_CommaAndLessThan, AsusLedId.KEY_COMMA },
|
||||
{ LedId.Keyboard_PeriodAndBiggerThan, AsusLedId.KEY_PERIOD },
|
||||
{ LedId.Keyboard_SlashAndQuestionMark, AsusLedId.KEY_SLASH },
|
||||
{ LedId.Keyboard_RightShift, AsusLedId.KEY_RSHIFT },
|
||||
{ LedId.Keyboard_LeftCtrl, AsusLedId.KEY_LCONTROL },
|
||||
{ LedId.Keyboard_LeftGui, AsusLedId.KEY_LWIN },
|
||||
{ LedId.Keyboard_LeftAlt, AsusLedId.KEY_LMENU },
|
||||
{ LedId.Keyboard_Space, AsusLedId.KEY_SPACE },
|
||||
{ LedId.Keyboard_RightAlt, AsusLedId.KEY_RMENU },
|
||||
{ LedId.Keyboard_RightGui, AsusLedId.KEY_RWIN },
|
||||
{ LedId.Keyboard_Application, AsusLedId.KEY_APPS },
|
||||
{ LedId.Keyboard_RightCtrl, AsusLedId.KEY_RCONTROL },
|
||||
{ LedId.Keyboard_PrintScreen, AsusLedId.KEY_SYSRQ },
|
||||
{ LedId.Keyboard_ScrollLock, AsusLedId.KEY_SCROLL },
|
||||
{ LedId.Keyboard_PauseBreak, AsusLedId.KEY_PAUSE },
|
||||
{ LedId.Keyboard_Insert, AsusLedId.KEY_INSERT },
|
||||
{ LedId.Keyboard_Home, AsusLedId.KEY_HOME },
|
||||
{ LedId.Keyboard_PageUp, AsusLedId.KEY_PRIOR },
|
||||
{ LedId.Keyboard_Delete, AsusLedId.KEY_DELETE },
|
||||
{ LedId.Keyboard_End, AsusLedId.KEY_END },
|
||||
{ LedId.Keyboard_PageDown, AsusLedId.KEY_NEXT },
|
||||
{ LedId.Keyboard_ArrowUp, AsusLedId.KEY_UP },
|
||||
{ LedId.Keyboard_ArrowLeft, AsusLedId.KEY_LEFT },
|
||||
{ LedId.Keyboard_ArrowDown, AsusLedId.KEY_DOWN },
|
||||
{ LedId.Keyboard_ArrowRight, AsusLedId.KEY_RIGHT },
|
||||
{ LedId.Keyboard_NumLock, AsusLedId.KEY_NUMLOCK },
|
||||
{ LedId.Keyboard_NumSlash, AsusLedId.KEY_DIVIDE },
|
||||
{ LedId.Keyboard_NumAsterisk, AsusLedId.KEY_MULTIPLY },
|
||||
{ LedId.Keyboard_NumMinus, AsusLedId.KEY_SUBTRACT },
|
||||
{ LedId.Keyboard_Num7, AsusLedId.KEY_NUMPAD7 },
|
||||
{ LedId.Keyboard_Num8, AsusLedId.KEY_NUMPAD8 },
|
||||
{ LedId.Keyboard_Num9, AsusLedId.KEY_NUMPAD9 },
|
||||
{ LedId.Keyboard_NumPeriodAndDelete, AsusLedId.KEY_DECIMAL },
|
||||
{ LedId.Keyboard_NumPlus, AsusLedId.KEY_ADD },
|
||||
{ LedId.Keyboard_Num4, AsusLedId.KEY_NUMPAD4 },
|
||||
{ LedId.Keyboard_Num5, AsusLedId.KEY_NUMPAD5 },
|
||||
{ LedId.Keyboard_Num6, AsusLedId.KEY_NUMPAD6 },
|
||||
{ LedId.Keyboard_Num1, AsusLedId.KEY_NUMPAD1 },
|
||||
{ LedId.Keyboard_Num2, AsusLedId.KEY_NUMPAD2 },
|
||||
{ LedId.Keyboard_Num3, AsusLedId.KEY_NUMPAD3 },
|
||||
{ LedId.Keyboard_Num0, AsusLedId.KEY_NUMPAD0 },
|
||||
{ LedId.Keyboard_NumEnter, AsusLedId.KEY_NUMPADENTER },
|
||||
{ LedId.Keyboard_NonUsBackslash, AsusLedId.UNDOCUMENTED_1 },
|
||||
{ LedId.Keyboard_NonUsTilde, AsusLedId.UNDOCUMENTED_2 },
|
||||
{ LedId.Keyboard_NumComma, AsusLedId.KEY_NUMPADCOMMA },
|
||||
{ LedId.Logo, AsusLedId.UNDOCUMENTED_3 },
|
||||
{ LedId.Keyboard_Function, AsusLedId.KEY_FN },
|
||||
{ LedId.Keyboard_MediaMute, AsusLedId.KEY_MUTE },
|
||||
{ LedId.Keyboard_MediaPlay, AsusLedId.KEY_PLAYPAUSE },
|
||||
{ LedId.Keyboard_MediaStop, AsusLedId.KEY_MEDIASTOP },
|
||||
{ LedId.Keyboard_MediaVolumeDown, AsusLedId.KEY_VOLUMEDOWN },
|
||||
{ LedId.Keyboard_MediaVolumeUp, AsusLedId.KEY_VOLUMEUP },
|
||||
{ LedId.Keyboard_Custom1, AsusLedId.KEY_F13 },
|
||||
{ LedId.Keyboard_Custom2, AsusLedId.KEY_F14 },
|
||||
{ LedId.Keyboard_Custom3, AsusLedId.KEY_F15 },
|
||||
{ LedId.Keyboard_Custom4, AsusLedId.KEY_KANA },
|
||||
{ LedId.Keyboard_Custom5, AsusLedId.KEY_ABNT_C1 },
|
||||
{ LedId.Keyboard_Custom6, AsusLedId.KEY_CONVERT },
|
||||
{ LedId.Keyboard_Custom7, AsusLedId.KEY_NOCONVERT },
|
||||
{ LedId.Keyboard_Custom8, AsusLedId.KEY_YEN },
|
||||
{ LedId.Keyboard_Custom9, AsusLedId.KEY_ABNT_C2 },
|
||||
{ LedId.Keyboard_Custom10, AsusLedId.KEY_NUMPADEQUALS },
|
||||
{ LedId.Keyboard_Custom11, AsusLedId.KEY_CIRCUMFLEX },
|
||||
{ LedId.Keyboard_Custom12, AsusLedId.KEY_AT },
|
||||
{ LedId.Keyboard_Custom13, AsusLedId.KEY_COLON },
|
||||
{ LedId.Keyboard_Custom14, AsusLedId.KEY_UNDERLINE },
|
||||
{ LedId.Keyboard_Custom15, AsusLedId.KEY_KANJI },
|
||||
{ LedId.Keyboard_Custom16, AsusLedId.KEY_STOP },
|
||||
{ LedId.Keyboard_Custom17, AsusLedId.KEY_AX },
|
||||
{ LedId.Keyboard_Custom18, AsusLedId.KEY_UNLABELED },
|
||||
{ LedId.Keyboard_Custom19, AsusLedId.KEY_NEXTTRACK },
|
||||
{ LedId.Keyboard_Custom20, AsusLedId.KEY_CALCULATOR },
|
||||
{ LedId.Keyboard_Custom21, AsusLedId.KEY_POWER },
|
||||
{ LedId.Keyboard_Custom22, AsusLedId.KEY_SLEEP },
|
||||
{ LedId.Keyboard_Custom23, AsusLedId.KEY_WAKE },
|
||||
{ LedId.Keyboard_Custom24, AsusLedId.KEY_WEBSEARCH },
|
||||
{ LedId.Keyboard_Custom25, AsusLedId.KEY_WEBFAVORITES },
|
||||
{ LedId.Keyboard_Custom26, AsusLedId.KEY_WEBREFRESH },
|
||||
{ LedId.Keyboard_Custom27, AsusLedId.KEY_WEBSTOP },
|
||||
{ LedId.Keyboard_Custom28, AsusLedId.KEY_WEBFORWARD },
|
||||
{ LedId.Keyboard_Custom29, AsusLedId.KEY_WEBHOME },
|
||||
{ LedId.Keyboard_Custom30, AsusLedId.KEY_WEBBACK },
|
||||
{ LedId.Keyboard_Custom31, AsusLedId.KEY_MYCOMPUTER },
|
||||
{ LedId.Keyboard_Custom32, AsusLedId.KEY_MAIL },
|
||||
{ LedId.Keyboard_Custom33, AsusLedId.KEY_MEDIASELECT },
|
||||
{ LedId.Keyboard_Custom34, AsusLedId.UNDOCUMENTED_4 },
|
||||
{ LedId.Keyboard_Custom35, AsusLedId.UNDOCUMENTED_5 },
|
||||
{ LedId.Keyboard_Custom36, AsusLedId.UNDOCUMENTED_6 }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A LED mapping containing extra lights for the ROG Zephyrus Duo 15
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// ASUS notebooks have extra lights under wide keys like space and backspace, these do not appear as keys on the device.
|
||||
/// Instead they only appear in the Lights enumerable, this mapping maps LED IDs to the index of these lights.
|
||||
/// </para>
|
||||
/// <para>You may add more of these by further populating <see cref="AsusKeyboardRGBDevice.ExtraLedMappings"/>.</para>
|
||||
/// </summary>
|
||||
public static readonly LedMapping<int> ROGZephyrusDuo15 =
|
||||
new()
|
||||
{
|
||||
{LedId.Keyboard_Custom50, 39}, // Mapping starts at Custom50 to avoid possible conflicts with KeyboardMapping above
|
||||
{LedId.Keyboard_Custom51, 40},
|
||||
{LedId.Keyboard_Custom52, 55},
|
||||
{LedId.Keyboard_Custom53, 57},
|
||||
{LedId.Keyboard_Custom54, 97},
|
||||
{LedId.Keyboard_Custom55, 99},
|
||||
{LedId.Keyboard_Custom56, 118},
|
||||
{LedId.Keyboard_Custom57, 120},
|
||||
{LedId.Keyboard_Custom58, 130},
|
||||
{LedId.Keyboard_Custom59, 131},
|
||||
{LedId.Keyboard_Custom60, 133},
|
||||
};
|
||||
/// </remarks>
|
||||
public static LedMapping<int> ROGZephyrusDuo15 { get; } = new()
|
||||
{
|
||||
{ LedId.Keyboard_Custom50, 39 }, // Mapping starts at Custom50 to avoid possible conflicts with KeyboardMapping above
|
||||
{ LedId.Keyboard_Custom51, 40 },
|
||||
{ LedId.Keyboard_Custom52, 55 },
|
||||
{ LedId.Keyboard_Custom53, 57 },
|
||||
{ LedId.Keyboard_Custom54, 97 },
|
||||
{ LedId.Keyboard_Custom55, 99 },
|
||||
{ LedId.Keyboard_Custom56, 118 },
|
||||
{ LedId.Keyboard_Custom57, 120 },
|
||||
{ LedId.Keyboard_Custom58, 130 },
|
||||
{ LedId.Keyboard_Custom59, 131 },
|
||||
{ LedId.Keyboard_Custom60, 133 },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,20 +25,20 @@ namespace RGB.NET.Devices.Asus
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly LedMapping<AsusLedId>? _ledMapping;
|
||||
private Dictionary<LedId, AsusLedId> _ledAsusLed = new();
|
||||
private Dictionary<LedId, int> _ledAsusLights = new();
|
||||
private readonly Dictionary<LedId, AsusLedId> _ledAsusLed = new();
|
||||
private readonly Dictionary<LedId, int> _ledAsusLights = new();
|
||||
|
||||
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of extra LED mappings to apply to modes that match the provided regex
|
||||
/// <para>Note: These LED mappings should be based on light indexes</para>
|
||||
/// Gets or sets a list of extra LED mappings to apply to modes that match the provided regex.
|
||||
/// <para>Note: These LED mappings should be based on light indexes.</para>
|
||||
/// </summary>
|
||||
public static List<AsusKeyboardExtraMapping> ExtraLedMappings =
|
||||
new()
|
||||
{
|
||||
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15)
|
||||
};
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings = new()
|
||||
{
|
||||
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15)
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
@ -49,6 +49,8 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the keyboard.</param>
|
||||
/// <param name="ledMapping">A mapping of leds this device is initialized with.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusKeyboardRGBDevice(AsusKeyboardRGBDeviceInfo info, LedMapping<AsusLedId>? ledMapping, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -15,7 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// The ASUS SDK returns useless names for notebook keyboards, possibly for others as well.
|
||||
/// Keep a list of those and rely on <see cref="WMIHelper.GetSystemModelInfo()"/> to get the real model
|
||||
/// </summary>
|
||||
private static List<string> GenericDeviceNames = new() {"NotebookKeyboard"};
|
||||
private static readonly List<string> GENERIC_DEVICE_NAMES = new() { "NotebookKeyboard" };
|
||||
|
||||
/// <inheritdoc />
|
||||
public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;
|
||||
@ -37,10 +37,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Methods
|
||||
|
||||
private static string? GetKeyboardModel(string deviceName)
|
||||
{
|
||||
return GenericDeviceNames.Contains(deviceName) ? WMIHelper.GetSystemModelInfo() : deviceName;
|
||||
}
|
||||
private static string? GetKeyboardModel(string deviceName) => GENERIC_DEVICE_NAMES.Contains(deviceName) ? WMIHelper.GetSystemModelInfo() : deviceName;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusMainboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the mainboard.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusMainboardRGBDevice(AsusRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -15,6 +15,7 @@ namespace RGB.NET.Devices.Asus
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Asus.AsusMouseRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the mouse.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal AsusMouseRGBDevice(AsusRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
<RootNamespace>RGB.NET.Devices.Asus</RootNamespace>
|
||||
<Description>Asus-Device-Implementations of RGB.NET</Description>
|
||||
<Summary>Asus-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2020</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2020</PackageCopyright>
|
||||
<PackageIconUrl>http://lib.arge.be/icon.png</PackageIconUrl>
|
||||
<Copyright>Copyright © Darth Affe 2021</Copyright>
|
||||
<Icon>icon.png</Icon>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</PackageLicenseUrl>
|
||||
<License>LGPL-2.1-only</License>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
@ -34,22 +33,26 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<DebugType>portable</DebugType>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Management" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -8,4 +8,5 @@
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mainboard/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@ -53,12 +53,14 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeSDK()
|
||||
{
|
||||
_CoolerMasterSDK.Reload();
|
||||
if (_CoolerMasterSDK.GetSDKVersion() <= 0) Throw(new RGBDeviceException("Failed to initialize CoolerMaster-SDK"), true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
|
||||
@ -17,6 +17,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by CoolerMaster for the device.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
protected CoolerMasterRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, new CoolerMasterUpdateQueue(updateTrigger, info.DeviceIndex))
|
||||
{ }
|
||||
|
||||
@ -23,6 +23,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -44,7 +45,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
this.DeviceType = deviceType;
|
||||
this.DeviceIndex = deviceIndex;
|
||||
|
||||
Model = deviceIndex.GetDescription() ?? "Unknown";
|
||||
Model = deviceIndex.GetDescription();
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private CoolerMasterDevicesIndexes _deviceIndex;
|
||||
private readonly CoolerMasterDevicesIndexes _deviceIndex;
|
||||
private readonly _CoolerMasterColorMatrix _deviceMatrix;
|
||||
|
||||
#endregion
|
||||
@ -29,8 +29,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
this._deviceIndex = deviceIndex;
|
||||
|
||||
_deviceMatrix = new _CoolerMasterColorMatrix();
|
||||
_deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS];
|
||||
_deviceMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -15,7 +15,7 @@ namespace RGB.NET.Devices.CoolerMaster.Helper
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string? GetDescription(this Enum source)
|
||||
internal static string GetDescription(this Enum source)
|
||||
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -22,6 +22,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the keyboard</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterKeyboardRGBDevice(CoolerMasterKeyboardRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
|
||||
@ -10,15 +10,18 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice<CoolerMasterMouseRGBDeviceInfo>, IMouse
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the mouse</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterMouseRGBDevice(CoolerMasterMouseRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{ }
|
||||
{
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
// ReSharper disable UnusedMethodReturnValue.Global
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
// ReSharper disable UnusedMethodReturnValue.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
@ -53,13 +54,10 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
_setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer));
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr LoadLibrary(string dllToLoad);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern bool FreeLibrary(IntPtr dllHandle);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
<RootNamespace>RGB.NET.Devices.CoolerMaster</RootNamespace>
|
||||
<Description>Cooler Master-Device-Implementations of RGB.NET</Description>
|
||||
<Summary>Cooler Master-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2020</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2020</PackageCopyright>
|
||||
<PackageIconUrl>http://lib.arge.be/icon.png</PackageIconUrl>
|
||||
<Copyright>Copyright © Darth Affe 2021</Copyright>
|
||||
<Icon>icon.png</Icon>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</PackageLicenseUrl>
|
||||
<License>LGPL-2.1-only</License>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
@ -34,22 +33,26 @@
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<DebugType>portable</DebugType>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -3,4 +3,5 @@
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=keyboard/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mouse/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@ -43,7 +43,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <summary>
|
||||
/// Gets the last error documented by CUE.
|
||||
/// </summary>
|
||||
public CorsairError LastError => _CUESDK.CorsairGetLastError();
|
||||
public static CorsairError LastError => _CUESDK.CorsairGetLastError();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -63,6 +63,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeSDK()
|
||||
{
|
||||
_CUESDK.Reload();
|
||||
@ -80,7 +81,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
// DarthAffe 02.02.2021: 127 is iCUE
|
||||
if (!_CUESDK.CorsairSetLayerPriority(128))
|
||||
Throw(new CUEException(LastError), false);
|
||||
Throw(new CUEException(LastError));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -193,6 +194,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Reset()
|
||||
{
|
||||
ProtocolDetails = null;
|
||||
@ -207,6 +209,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
try { _CUESDK.UnloadCUESDK(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -21,6 +21,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairCustomRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the custom-device.</param>
|
||||
/// <param name="updateQueue">The queue used to update this device.</param>
|
||||
internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
|
||||
: base(info, new LedMapping<CorsairLedId>(), updateQueue)
|
||||
{ }
|
||||
|
||||
@ -17,8 +17,19 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the corsair-id of the first LED of this device.
|
||||
/// </summary>
|
||||
public CorsairLedId ReferenceCorsairLed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of LEDs this device contains.
|
||||
/// </summary>
|
||||
public int LedCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the offset used to access the LEDs of this device.
|
||||
/// </summary>
|
||||
internal int LedOffset { get; }
|
||||
|
||||
#endregion
|
||||
@ -33,7 +44,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair._CorsairChannelDeviceInfo" />.</param>
|
||||
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
|
||||
/// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param>
|
||||
/// <param name="referenceCorsairLed">The id of the first led of this device.</param>
|
||||
/// <param name="referenceCorsairLed">The id of the first LED of this device.</param>
|
||||
/// <param name="ledOffset">The offset used to find the LEDs of this device.</param>
|
||||
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed, int ledOffset)
|
||||
: base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo,
|
||||
GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo))
|
||||
@ -49,32 +61,21 @@ namespace RGB.NET.Devices.Corsair
|
||||
#region Methods
|
||||
|
||||
private static RGBDeviceType GetDeviceType(CorsairChannelDeviceType deviceType)
|
||||
{
|
||||
switch (deviceType)
|
||||
=> deviceType switch
|
||||
{
|
||||
case CorsairChannelDeviceType.Invalid:
|
||||
return RGBDeviceType.Unknown;
|
||||
|
||||
case CorsairChannelDeviceType.FanHD:
|
||||
case CorsairChannelDeviceType.FanSP:
|
||||
case CorsairChannelDeviceType.FanLL:
|
||||
case CorsairChannelDeviceType.FanML:
|
||||
case CorsairChannelDeviceType.DAP:
|
||||
case CorsairChannelDeviceType.FanQL:
|
||||
case CorsairChannelDeviceType.FanSPPRO:
|
||||
return RGBDeviceType.Fan;
|
||||
|
||||
case CorsairChannelDeviceType.Strip:
|
||||
return RGBDeviceType.LedStripe;
|
||||
|
||||
case CorsairChannelDeviceType.Pump:
|
||||
case CorsairChannelDeviceType.WaterBlock:
|
||||
return RGBDeviceType.Cooler;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
|
||||
}
|
||||
}
|
||||
CorsairChannelDeviceType.Invalid => RGBDeviceType.Unknown,
|
||||
CorsairChannelDeviceType.FanHD => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanSP => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanLL => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanML => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.DAP => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanQL => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanSPPRO => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.Strip => RGBDeviceType.LedStripe,
|
||||
CorsairChannelDeviceType.Pump => RGBDeviceType.Cooler,
|
||||
CorsairChannelDeviceType.WaterBlock => RGBDeviceType.Cooler,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null)
|
||||
};
|
||||
|
||||
private static string GetModelName(string model, _CorsairChannelDeviceInfo channelDeviceInfo)
|
||||
{
|
||||
@ -126,7 +127,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
return "Pump";
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(channelDeviceInfo.type), channelDeviceInfo.type, null);
|
||||
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
|
||||
throw new ArgumentOutOfRangeException($"{nameof(channelDeviceInfo)}.{nameof(channelDeviceInfo.type)}", channelDeviceInfo.type, null);
|
||||
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available SDK access modes.
|
||||
/// Represents an SDK access mode.
|
||||
/// </summary>
|
||||
public enum CorsairAccessMode
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available corsair channel device types.
|
||||
/// Contains a list of available corsair channel device types.
|
||||
/// </summary>
|
||||
public enum CorsairChannelDeviceType
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@ using System;
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of corsair device capabilities.
|
||||
/// Contains a list of corsair device capabilities.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum CorsairDeviceCaps
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available corsair device types.
|
||||
/// Contains a list of available corsair device types.
|
||||
/// </summary>
|
||||
public enum CorsairDeviceType
|
||||
{
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
// ReSharper disable UnusedMember.Global
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of all LEDs available for all corsair devices.
|
||||
/// Contains a list of all LEDs available for all corsair devices.
|
||||
/// </summary>
|
||||
public enum CorsairLedId
|
||||
{
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available logical layouts for corsair keyboards.
|
||||
/// Contains a list of available logical layouts for corsair keyboards.
|
||||
/// </summary>
|
||||
public enum CorsairLogicalKeyboardLayout
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available physical layouts for corsair keyboards.
|
||||
/// Contains a list of available physical layouts for corsair keyboards.
|
||||
/// </summary>
|
||||
public enum CorsairPhysicalKeyboardLayout
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available physical layouts for mice.
|
||||
/// Contains a list of available physical layouts for mice.
|
||||
/// </summary>
|
||||
public enum CorsairPhysicalMouseLayout
|
||||
{
|
||||
|
||||
@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping of <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.
|
||||
/// </summary>
|
||||
protected LedMapping<CorsairLedId> Mapping { get; }
|
||||
|
||||
#endregion
|
||||
@ -24,6 +27,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// Initializes a new instance of the <see cref="CorsairRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by CUE for the device.</param>
|
||||
/// <param name="mapping">The mapping <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.</param>
|
||||
/// <param name="updateQueue">The queue used to update this device.</param>
|
||||
protected CorsairRGBDevice(TDeviceInfo info, LedMapping<CorsairLedId> mapping, CorsairDeviceUpdateQueue updateQueue)
|
||||
: base(info, updateQueue)
|
||||
{
|
||||
@ -35,7 +40,10 @@ namespace RGB.NET.Devices.Corsair
|
||||
#region Methods
|
||||
|
||||
void ICorsairRGBDevice.Initialize() => InitializeLayout();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the LEDs of the device based on the data provided by the SDK.
|
||||
/// </summary>
|
||||
protected virtual void InitializeLayout()
|
||||
{
|
||||
_CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains mappings for <see cref="LedId"/> to <see cref="CorsairLedId"/>.
|
||||
/// </summary>
|
||||
public static class LedMappings
|
||||
{
|
||||
static LedMappings()
|
||||
@ -28,19 +31,44 @@ namespace RGB.NET.Devices.Corsair
|
||||
Keyboard.Add(LedId.Custom101 + i, CorsairLedId.OemLed101 + i);
|
||||
}
|
||||
|
||||
public static LedMapping<CorsairLedId> GraphicsCard = new();
|
||||
public static LedMapping<CorsairLedId> HeadsetStand = new();
|
||||
public static LedMapping<CorsairLedId> Mainboard = new();
|
||||
public static LedMapping<CorsairLedId> Memory = new();
|
||||
public static LedMapping<CorsairLedId> Mousepad = new();
|
||||
/// <summary>
|
||||
/// Gets the mapping for graphics cards.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> GraphicsCard { get; } = new();
|
||||
|
||||
public static LedMapping<CorsairLedId> Headset = new()
|
||||
/// <summary>
|
||||
/// Gets the mapping for headsets.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> HeadsetStand { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping for mainboards.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Mainboard { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping for memory.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Memory { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping for mousepads.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Mousepad { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapping for headsets.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Headset { get; } = new()
|
||||
{
|
||||
{ LedId.Headset1, CorsairLedId.LeftLogo },
|
||||
{ LedId.Headset2, CorsairLedId.RightLogo },
|
||||
};
|
||||
|
||||
public static LedMapping<CorsairLedId> Mouse = new()
|
||||
/// <summary>
|
||||
/// Gets the mapping for mice.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Mouse { get; } = new()
|
||||
{
|
||||
{ LedId.Mouse1, CorsairLedId.B1 },
|
||||
{ LedId.Mouse2, CorsairLedId.B2 },
|
||||
@ -64,7 +92,10 @@ namespace RGB.NET.Devices.Corsair
|
||||
{ LedId.Mouse20, CorsairLedId.B20 },
|
||||
};
|
||||
|
||||
public static LedMapping<CorsairLedId> Keyboard = new()
|
||||
/// <summary>
|
||||
/// Gets the mapping for keyboards.
|
||||
/// </summary>
|
||||
public static LedMapping<CorsairLedId> Keyboard { get; } = new()
|
||||
{
|
||||
{ LedId.Invalid, CorsairLedId.Invalid },
|
||||
{ LedId.Logo, CorsairLedId.Logo },
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user