1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Fixed code issues

This commit is contained in:
Darth Affe 2021-07-31 16:59:51 +02:00
parent 7b0e9152fd
commit 59e11e5b82
120 changed files with 1348 additions and 342 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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>
///
/// </summary>
/// <param name="ledId"></param>
/// <returns></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

View File

@ -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
}

View File

@ -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,14 +40,14 @@ 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>
@ -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

View File

@ -27,6 +27,9 @@
/// </summary>
string Model { get; }
/// <summary>
/// Gets custom metadata added to the layout.
/// </summary>
object? LayoutMetadata { get; set; }
#endregion

View File

@ -19,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
@ -30,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;
@ -38,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

View File

@ -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,

View File

@ -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; }
}
}

View File

@ -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;

View File

@ -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
}
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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();

View File

@ -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
}

View File

@ -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>

View File

@ -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,6 +74,7 @@ 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="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:

View File

@ -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)

View File

@ -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></returns>
protected abstract IEnumerable<Led> GetLeds();
/// <inheritdoc />

View File

@ -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>

View File

@ -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>

View File

@ -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,13 +60,13 @@ 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)
@ -78,13 +78,13 @@ namespace RGB.NET.Core
}
/// <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)
@ -95,7 +95,7 @@ namespace RGB.NET.Core
}
/// <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>
@ -106,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)

View File

@ -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}");

View File

@ -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());

View File

@ -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();

View File

@ -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

View File

@ -4,6 +4,9 @@ using System;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic placeable element.
/// </summary>
public interface IPlaceable
{
#region Properties & Fields
@ -50,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

View File

@ -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

View File

@ -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,7 +75,7 @@ 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>
@ -84,7 +84,7 @@ namespace RGB.NET.Core
{ }
/// <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>
@ -113,7 +113,7 @@ 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>
@ -123,7 +123,7 @@ namespace RGB.NET.Core
/// <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>
@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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>

View File

@ -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>

View File

@ -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;

View File

@ -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; }
}
}

View File

@ -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);
}
@ -78,7 +101,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);
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

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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>
{ }
}

View File

@ -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();
}
}

View File

@ -8,7 +8,7 @@ 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
{
@ -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()

View File

@ -9,7 +9,7 @@ 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
{
@ -17,8 +17,19 @@ namespace RGB.NET.Core
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;

View File

@ -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

View File

@ -1,4 +1,5 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591
namespace RGB.NET.Devices.Asus
{

View File

@ -2,6 +2,9 @@
namespace RGB.NET.Devices.Asus
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="AsusLedId"/>.
/// </summary>
public static class LedMappings
{
/// <summary>
@ -163,12 +166,14 @@ namespace RGB.NET.Devices.Asus
/// <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>
/// </remarks>
public static LedMapping<int> ROGZephyrusDuo15 { get; } = new()
{
{ LedId.Keyboard_Custom50, 39 }, // Mapping starts at Custom50 to avoid possible conflicts with KeyboardMapping above

View File

@ -25,8 +25,8 @@ 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;
@ -34,11 +34,10 @@ namespace RGB.NET.Devices.Asus
/// 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)
};
public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings = new()
{
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15)
};
#endregion

View File

@ -23,6 +23,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>

View File

@ -10,12 +10,13 @@ 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)
{

View File

@ -57,7 +57,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion

View File

@ -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)
{ }

View File

@ -49,32 +49,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 +115,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
}
}

View File

@ -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
{

View File

@ -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
{

View File

@ -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

View File

@ -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
{

View File

@ -1,9 +1,11 @@
// ReSharper disable InconsistentNaming
// 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
{

View File

@ -1,10 +1,11 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
#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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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,18 +31,43 @@ namespace RGB.NET.Devices.Corsair
Keyboard.Add(LedId.Custom101 + i, CorsairLedId.OemLed101 + i);
}
/// <summary>
/// Gets the mapping for graphics cards.
/// </summary>
public static LedMapping<CorsairLedId> GraphicsCard { get; } = 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 },
};
/// <summary>
/// Gets the mapping for mice.
/// </summary>
public static LedMapping<CorsairLedId> Mouse { get; } = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
@ -64,6 +92,9 @@ namespace RGB.NET.Devices.Corsair
{ LedId.Mouse20, CorsairLedId.B20 },
};
/// <summary>
/// Gets the mapping for keyboards.
/// </summary>
public static LedMapping<CorsairLedId> Keyboard { get; } = new()
{
{ LedId.Invalid, CorsairLedId.Invalid },

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the graphics card.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairGraphicsCardRGBDevice(CorsairGraphicsCardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.GraphicsCard, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Headset, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetStandRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset stand</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.HeadsetStand, updateQueue)
{ }

View File

@ -24,6 +24,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the keyboard</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Keyboard, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMainboardRGBDevice(CorsairMainboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mainboard, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMemoryRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Memory, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mouse</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mouse, updateQueue)
{ }

View File

@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMousepadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mousepad</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mousepad, updateQueue)
{ }

View File

@ -68,7 +68,7 @@ namespace RGB.NET.Devices.Corsair.Native
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion

View File

@ -46,7 +46,7 @@ namespace RGB.NET.Devices.DMX
#region Methods
/// <summary>
/// Adds the given <see cref="IDMXDeviceDefinition" /> to this device-provider.
/// Adds the specified <see cref="IDMXDeviceDefinition" /> to this device-provider.
/// </summary>
/// <param name="deviceDefinition">The <see cref="IDMXDeviceDefinition"/> to add.</param>
public void AddDeviceDefinition(IDMXDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition);

View File

@ -1,5 +1,8 @@
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of available logitech device types.
/// </summary>
public enum LogitechDeviceType
{
Keyboard = 0x0,

View File

@ -1,4 +1,5 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591
namespace RGB.NET.Devices.Logitech
{

View File

@ -2,8 +2,14 @@
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="LogitechDeviceCaps"/>.
/// </summary>
public static class LedMappings
{
/// <summary>
/// Gets the mapping for per key devices.
/// </summary>
public static LedMapping<LogitechLedId> PerKey { get; } = new()
{
{ LedId.Keyboard_Escape, LogitechLedId.ESC },
@ -131,11 +137,17 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Keyboard_Custom1, LogitechLedId.G_BADGE },
};
/// <summary>
/// Gets the mapping for per device devices.
/// </summary>
public static LedMapping<int> Device { get; } = new()
{
{ LedId.Custom1, 0 }
};
/// <summary>
/// Gets the mapping for per zone keyboards.
/// </summary>
public static LedMapping<int> ZoneKeyboard { get; } = new()
{
{ LedId.Keyboard_Programmable1, 0 },
@ -172,6 +184,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Keyboard_Programmable32, 31 },
};
/// <summary>
/// Gets the mapping for per zone mice.
/// </summary>
public static LedMapping<int> ZoneMouse { get; } = new()
{
{ LedId.Mouse1, 0 },
@ -208,6 +223,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Mouse32, 31 },
};
/// <summary>
/// Gets the mapping for per zone headsets.
/// </summary>
public static LedMapping<int> ZoneHeadset { get; } = new()
{
{ LedId.Headset1, 0 },
@ -244,6 +262,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Headset32, 31 },
};
/// <summary>
/// Gets the mapping for per zone mousepads.
/// </summary>
public static LedMapping<int> ZoneMousepad { get; } = new()
{
{ LedId.Mousepad1, 0 },
@ -280,6 +301,9 @@ namespace RGB.NET.Devices.Logitech
{ LedId.Mousepad32, 31 },
};
/// <summary>
/// Gets the mapping for per zone speakers.
/// </summary>
public static LedMapping<int> ZoneSpeaker { get; } = new()
{
{ LedId.Speaker1, 0 },

View File

@ -69,7 +69,7 @@ namespace RGB.NET.Devices.Logitech.Native
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion

View File

@ -75,7 +75,7 @@ namespace RGB.NET.Devices.Msi.Native
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion

View File

@ -53,7 +53,7 @@ namespace RGB.NET.Devices.Novation
/// <summary>
/// Creates a update-message out of a given data set.
/// Creates a update-message out of a specified data set.
/// </summary>
/// <param name="data">The data set to create the message from.</param>
/// <returns>The message created out of the data set.</returns>

View File

@ -17,6 +17,7 @@ namespace RGB.NET.Devices.Novation
/// Initializes a new instance of the <see cref="NovationRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Novation for the device.</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
protected NovationRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
: base(info, GetUpdateQueue(updateTrigger, info))
{ }

View File

@ -2,10 +2,16 @@
namespace RGB.NET.Devices.PicoPi
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to the buffer-offset.
/// </summary>
public static class LedMappings
{
#region Properties & Fields
/// <summary>
/// Gets the defautlt offset-mapping.
/// </summary>
public static LedMapping<int> StripeMapping = new();
#endregion

View File

@ -13,7 +13,16 @@ namespace RGB.NET.Devices.PicoPi
{
#region Constants
/// <summary>
/// The vendor id used by the pico-pi firmware.
/// Registered at https://pid.codes/1209/2812/
/// </summary>
public const int VENDOR_ID = 0x1209;
/// <summary>
/// The product id used by the pico-pi firmware.
/// Registered at https://pid.codes/1209/2812/
/// </summary>
public const int HID_BULK_CONTROLLER_PID = 0x2812;
private const byte COMMAND_CHANNEL_COUNT = 0x01;

View File

@ -3,8 +3,14 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to the matrix location.
/// </summary>
public static class LedMappings
{
/// <summary>
/// Gets the mapping for keyboards.
/// </summary>
public static LedMapping<int> Keyboard { get; } = new()
{
//Row 0 is empty
@ -154,6 +160,9 @@ namespace RGB.NET.Devices.Razer
//Row 7 is also empty
};
/// <summary>
/// Gets the mapping for laptop keyboards.
/// </summary>
public static LedMapping<int> LaptopKeyboard { get; } = new()
{
//Row 0 is empty
@ -272,6 +281,9 @@ namespace RGB.NET.Devices.Razer
//Row 7 is also empty
};
/// <summary>
/// Gets the mapping for mice.
/// </summary>
public static LedMapping<int> Mouse { get; } = new()
{
//row 0 empty
@ -316,12 +328,24 @@ namespace RGB.NET.Devices.Razer
};
//TODO DarthAffe 27.04.2021: Are mappings for these possible?
/// <summary>
/// Gets the mapping for mousepads.
/// </summary>
public static LedMapping<int> Mousepad { get; } = new();
/// <summary>
/// Gets the mapping for headsets.
/// </summary>
public static LedMapping<int> Headset { get; } = new();
/// <summary>
/// Gets the mapping for keypads.
/// </summary>
public static LedMapping<int> Keypad { get; } = new();
/// <summary>
/// Gets the mapping for chroma link devices.
/// </summary>
public static LedMapping<int> ChromaLink { get; } = new();
}
}

View File

@ -17,6 +17,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerRGBDevice"/> class.
/// </summary>
/// <param name="info">The generic information provided by razer for the device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
protected RazerRGBDevice(RazerRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{

View File

@ -68,7 +68,7 @@ namespace RGB.NET.Devices.Razer.Native
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion

View File

@ -1,7 +1,11 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591
namespace RGB.NET.Devices.SteelSeries
{
/// <summary>
/// Contains a list of Steel Series LED IDs
/// </summary>
public enum SteelSeriesLedId
{
[APIName("one")]

View File

@ -2,8 +2,14 @@
namespace RGB.NET.Devices.SteelSeries
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="SteelSeriesLedId"/>.
/// </summary>
public static class LedMappings
{
/// <summary>
/// Gets the uk-mapping for keyboards.
/// </summary>
public static LedMapping<SteelSeriesLedId> KeyboardMappingUk { get; } = new()
{
{ LedId.Logo, SteelSeriesLedId.Logo },
@ -114,6 +120,9 @@ namespace RGB.NET.Devices.SteelSeries
{ LedId.Keyboard_NumPeriodAndDelete, SteelSeriesLedId.KeypadPeriod }
};
/// <summary>
/// Gets the uk-tkl-mapping for keyboards.
/// </summary>
public static LedMapping<SteelSeriesLedId> KeyboardTklMappingUk { get; } = new()
{
{ LedId.Logo, SteelSeriesLedId.Logo },
@ -207,17 +216,26 @@ namespace RGB.NET.Devices.SteelSeries
{ LedId.Keyboard_ArrowRight, SteelSeriesLedId.RightArrow }
};
/// <summary>
/// Gets the mapping for one-zone mice.
/// </summary>
public static LedMapping<SteelSeriesLedId> MouseOneZone { get; } = new()
{
{ LedId.Mouse1, SteelSeriesLedId.ZoneOne }
};
/// <summary>
/// Gets the mapping for two-zone mice.
/// </summary>
public static LedMapping<SteelSeriesLedId> MouseTwoZone { get; } = new()
{
{ LedId.Mouse1, SteelSeriesLedId.ZoneOne },
{ LedId.Mouse2, SteelSeriesLedId.ZoneTwo }
};
/// <summary>
/// Gets the mapping for three-zone mice.
/// </summary>
public static LedMapping<SteelSeriesLedId> MouseThreeZone { get; } = new()
{
{ LedId.Mouse1, SteelSeriesLedId.ZoneOne },
@ -225,6 +243,9 @@ namespace RGB.NET.Devices.SteelSeries
{ LedId.Mouse3, SteelSeriesLedId.ZoneThree }
};
/// <summary>
/// Gets the mapping for eight-zone mice.
/// </summary>
public static LedMapping<SteelSeriesLedId> MouseEightZone { get; } = new()
{
{ LedId.Mouse1, SteelSeriesLedId.ZoneOne },
@ -237,12 +258,18 @@ namespace RGB.NET.Devices.SteelSeries
{ LedId.Mouse8, SteelSeriesLedId.ZoneEight }
};
/// <summary>
/// Gets the mapping for two-zone headsets.
/// </summary>
public static LedMapping<SteelSeriesLedId> HeadsetTwoZone { get; } = new()
{
{ LedId.Headset1, SteelSeriesLedId.ZoneOne },
{ LedId.Headset2, SteelSeriesLedId.ZoneTwo }
};
/// <summary>
/// Gets the mapping for twelve-zone mousepads
/// </summary>
public static LedMapping<SteelSeriesLedId> MousepadTwelveZone { get; } = new()
{
{ LedId.Mousepad1, SteelSeriesLedId.ZoneOne },
@ -259,6 +286,9 @@ namespace RGB.NET.Devices.SteelSeries
{ LedId.Mousepad12, SteelSeriesLedId.ZoneTwelve },
};
/// <summary>
/// Gets the mapping for 103-zone led strip devices (monitor).
/// </summary>
public static LedMapping<SteelSeriesLedId> MonitorOnehundredandthreeZone { get; } = new()
{
{ LedId.LedStripe1, SteelSeriesLedId.ZoneOne },

View File

@ -11,6 +11,7 @@ namespace RGB.NET.Devices.WS281X
/// Represents a device provider responsible for WS2812B- and WS2811-Led-devices.
/// </summary>
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedType.Global
public class WS281XDeviceProvider : AbstractRGBDeviceProvider
{
#region Properties & Fields
@ -47,14 +48,16 @@ namespace RGB.NET.Devices.WS281X
#region Methods
/// <summary>
/// Adds the given <see cref="IWS281XDeviceDefinition" /> to this device-provider.
/// Adds the specified <see cref="IWS281XDeviceDefinition" /> to this device-provider.
/// </summary>
/// <param name="deviceDefinition">The <see cref="IWS281XDeviceDefinition"/> to add.</param>
// ReSharper disable once UnusedMember.Global
public void AddDeviceDefinition(IWS281XDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition);
/// <inheritdoc />
protected override void InitializeSDK() { }
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
int i = 0;

View File

@ -2,6 +2,9 @@
namespace RGB.NET.Devices.Wooting.Enum
{
/// <summary>
/// Represents the type of a wooting device
/// </summary>
public enum WootingDeviceType
{
/// 10 Keyless Keyboard. E.g. Wooting One

View File

@ -7,8 +7,18 @@ using RGB.NET.Core;
namespace RGB.NET.HID
{
/// <summary>
/// Represents the data used to define a HID-device.
/// </summary>
/// <typeparam name="TLed">The type of the identifier leds are mapped to.</typeparam>
/// <typeparam name="TData">The type of the custom data added to the HID-device.</typeparam>
public record HIDDeviceDefinition<TLed, TData>(int ProductId, RGBDeviceType DeviceType, string Name, LedMapping<TLed> LedMapping, TData CustomData) where TLed : notnull;
/// <summary>
/// Represents a loaded for HID-devices based on the specified definitions.
/// </summary>
/// <typeparam name="TLed">The type of the identifier leds are mapped to.</typeparam>
/// <typeparam name="TData">The type of the custom data added to the HID-device.</typeparam>
public class HIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<TLed, TData>>
where TLed : notnull
{
@ -16,14 +26,24 @@ namespace RGB.NET.HID
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
/// <summary>
/// Gets the vendor id used for this loader.
/// </summary>
public int VendorId { get; }
/// <summary>
/// Gets or sets the filter used to determine which devices should be loaded.
/// </summary>
public RGBDeviceType LoadFilter { get; set; } = RGBDeviceType.All;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="HIDLoader{TLed,TData}"/> class.
/// </summary>
/// <param name="vendorId">The vendor id used for this loader.</param>
public HIDLoader(int vendorId)
{
this.VendorId = vendorId;
@ -33,9 +53,21 @@ namespace RGB.NET.HID
#region Methods
/// <summary>
/// Adds a new <see cref="HIDDeviceDefinition{TLed,TData}"/> to this loader.
/// </summary>
/// <param name="productId">The product id of the HID-device.</param>
/// <param name="deviceType">The type of the device.</param>
/// <param name="name">The name of the device.</param>
/// <param name="ledMapping">The mapping of the leds of the device.</param>
/// <param name="customData">Some custom data to attach to the device.</param>
public void Add(int productId, RGBDeviceType deviceType, string name, LedMapping<TLed> ledMapping, TData customData)
=> _deviceDefinitions.Add(productId, new HIDDeviceDefinition<TLed, TData>(productId, deviceType, name, ledMapping, customData));
/// <summary>
/// Gets a enumerable containing all devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
/// </summary>
/// <returns>The enumerable containing the connected devices.</returns>
public IEnumerable<(HIDDeviceDefinition<TLed, TData> definition, HidDevice device)> GetConnectedDevices()
{
IEnumerable<HidDevice> devices = DeviceList.Local.GetHidDevices(VendorId);
@ -47,11 +79,20 @@ namespace RGB.NET.HID
}
}
/// <summary>
/// Gets a enumerable containing all the first device of each group of devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
/// The grouping is done by the specified function.
/// </summary>
/// <typeparam name="TKey">The type of the key used to group the devices.</typeparam>
/// <param name="groupBy">The function grouping the devices.</param>
/// <returns>The enumerable containing the selected devices.</returns>
public IEnumerable<(HIDDeviceDefinition<TLed, TData> definition, HidDevice device)> GetConnectedDevices<TKey>(Func<HIDDeviceDefinition<TLed, TData>, TKey> groupBy)
=> GetConnectedDevices().GroupBy(x => groupBy(x.definition))
.Select(group => group.First());
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
/// <inheritdoc />
public IEnumerator<HIDDeviceDefinition<TLed, TData>> GetEnumerator() => _deviceDefinitions.Values.GetEnumerator();
#endregion

View File

@ -87,6 +87,10 @@ namespace RGB.NET.Layout
[DefaultValue(19.0)]
public float LedUnitHeight { get; set; } = 19.0f;
/// <summary>
/// Gets or sets the internal list of led layouts.
/// Normally you should use <see cref="Leds"/> to access this data.
/// </summary>
[XmlArray("Leds")]
public List<LedLayout> InternalLeds { get; set; } = new();
@ -96,9 +100,14 @@ namespace RGB.NET.Layout
[XmlIgnore]
public IEnumerable<ILedLayout> Leds => InternalLeds;
/// <summary>
/// Gets or sets the internal custom data of this layout.
/// Normally you should use <see cref="CustomData"/> to access or set this data.
/// </summary>
[XmlElement("CustomData")]
public object? InternalCustomData { get; set; }
/// <inheritdoc />
[XmlIgnore]
public object? CustomData { get; set; }
@ -107,9 +116,11 @@ namespace RGB.NET.Layout
#region Methods
/// <summary>
/// Creates a new <see cref="DeviceLayout"/> from the given xml.
/// Creates a new <see cref="DeviceLayout"/> from the specified xml.
/// </summary>
/// <param name="path">The path to the xml file.</param>
/// <param name="customDeviceDataType">The type of the custom data.</param>
/// <param name="customLedDataType">The type of the custom data of the leds.</param>
/// <returns>The deserialized <see cref="DeviceLayout"/>.</returns>
public static DeviceLayout? Load(string path, Type? customDeviceDataType = null, Type? customLedDataType = null)
{
@ -144,6 +155,12 @@ namespace RGB.NET.Layout
}
}
/// <summary>
/// Gets the deserialized custom data.
/// </summary>
/// <param name="customData">The internal custom data node.</param>
/// <param name="type">The type of the custom data.</param>
/// <returns>The deserialized custom data object.</returns>
protected virtual object? GetCustomData(object? customData, Type? type)
{
XmlNode? node = (customData as XmlNode) ?? (customData as IEnumerable<XmlNode>)?.FirstOrDefault()?.ParentNode; //HACK DarthAffe 16.01.2021: This gives us the CustomData-Node

Some files were not shown because too many files have changed in this diff Show More