mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Added own color-type to have more control over and easier manipulation of collors
This commit is contained in:
parent
5c6dba769b
commit
381ec55349
@ -5,6 +5,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Keyboard.Enums;
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
using CUE.NET.Effects;
|
using CUE.NET.Effects;
|
||||||
using CUE.NET.Helper;
|
using CUE.NET.Helper;
|
||||||
@ -41,7 +42,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary containing all colors for points calculated in the last render pass.
|
/// Gets a dictionary containing all colors for points calculated in the last render pass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
|
public Dictionary<BrushRenderTarget, CorsairColor> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, CorsairColor>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the strongly-typed target used for the effect.
|
/// Gets the strongly-typed target used for the effect.
|
||||||
@ -97,7 +98,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected abstract Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget);
|
protected abstract CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finalizes the color by appliing the overall brightness and opacity.<br/>
|
/// Finalizes the color by appliing the overall brightness and opacity.<br/>
|
||||||
@ -105,14 +106,14 @@ namespace CUE.NET.Brushes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to finalize.</param>
|
/// <param name="color">The color to finalize.</param>
|
||||||
/// <returns>The finalized color.</returns>
|
/// <returns>The finalized color.</returns>
|
||||||
protected virtual Color FinalizeColor(Color color)
|
protected virtual CorsairColor FinalizeColor(CorsairColor color)
|
||||||
{
|
{
|
||||||
// Since we use HSV to calculate there is no way to make a color 'brighter' than 100%
|
// Since we use HSV to calculate there is no way to make a color 'brighter' than 100%
|
||||||
// Be carefull with the naming: Since we use HSV the correct term is 'value' but outside we call it 'brightness'
|
// Be carefull with the naming: Since we use HSV the correct term is 'value' but outside we call it 'brightness'
|
||||||
// THIS IS NOT A HSB CALCULATION!!!
|
// THIS IS NOT A HSB CALCULATION!!!
|
||||||
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
|
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
|
||||||
byte finalAlpha = (byte)(color.A * (Opacity < 0 ? 0 : (Opacity > 1f ? 1f : Opacity)));
|
byte finalAlpha = (byte)(color.A * (Opacity < 0 ? 0 : (Opacity > 1f ? 1f : Opacity)));
|
||||||
return ColorHelper.ColorFromHSV(color.GetHue(), color.GetHSVSaturation(), finalBrightness, finalAlpha);
|
return ColorHelper.ColorFromHSV(color.GetHSVHue(), color.GetHSVSaturation(), finalBrightness, finalAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Keyboard.Enums;
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
using CUE.NET.Effects;
|
using CUE.NET.Effects;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary containing all colors for points calculated in the last render pass.
|
/// Gets a dictionary containing all colors for points calculated in the last render pass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Dictionary<BrushRenderTarget, Color> RenderedTargets { get; }
|
Dictionary<BrushRenderTarget, CorsairColor> RenderedTargets { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performas the render pass of the brush and calculates the raw colors for all requested points.
|
/// Performas the render pass of the brush and calculates the raw colors for all requested points.
|
||||||
|
|||||||
9
Brushes/IGradientBRush.cs
Normal file
9
Brushes/IGradientBRush.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using CUE.NET.Gradients;
|
||||||
|
|
||||||
|
namespace CUE.NET.Brushes
|
||||||
|
{
|
||||||
|
public interface IGradientBrush : IBrush
|
||||||
|
{
|
||||||
|
IGradient Gradient { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Brushes
|
namespace CUE.NET.Brushes
|
||||||
{
|
{
|
||||||
@ -66,10 +67,10 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
if (Image == null || Image.Width == 0 || Image.Height == 0)
|
if (Image == null || Image.Width == 0 || Image.Height == 0)
|
||||||
return Color.Transparent;
|
return CorsairColor.Transparent;
|
||||||
|
|
||||||
//TODO DarthAffe 16.03.2016: Refactor to allow more scale-/interpolation-modes
|
//TODO DarthAffe 16.03.2016: Refactor to allow more scale-/interpolation-modes
|
||||||
float scaleX = Image.Width / rectangle.Width;
|
float scaleX = Image.Width / rectangle.Width;
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Gradients;
|
using CUE.NET.Gradients;
|
||||||
using CUE.NET.Helper;
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
@ -14,10 +15,10 @@ namespace CUE.NET.Brushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a brush drawing a linear gradient.
|
/// Represents a brush drawing a linear gradient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LinearGradientBrush : AbstractBrush
|
public class LinearGradientBrush : AbstractBrush, IGradientBrush
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the start point (as percentage in the range [0..1]) of the gradient drawn by the brush. (default: 0f, 0.5f)
|
/// Gets or sets the start point (as percentage in the range [0..1]) of the gradient drawn by the brush. (default: 0f, 0.5f)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -74,9 +75,9 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
if (Gradient == null) return Color.Transparent;
|
if (Gradient == null) return CorsairColor.Transparent;
|
||||||
|
|
||||||
PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
|
PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
|
||||||
PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
|
PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace CUE.NET.Brushes
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private Dictionary<CorsairLedId, Color> _colors;
|
private Dictionary<CorsairLedId, CorsairColor> _colors;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// Initializes a new instance of the <see cref="ProfileBrush"/> class.
|
/// Initializes a new instance of the <see cref="ProfileBrush"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyLights">The light settings of the CUE profile.</param>
|
/// <param name="keyLights">The light settings of the CUE profile.</param>
|
||||||
internal ProfileBrush(Dictionary<CorsairLedId, Color> keyLights)
|
internal ProfileBrush(Dictionary<CorsairLedId, CorsairColor> keyLights)
|
||||||
{
|
{
|
||||||
this._colors = keyLights;
|
this._colors = keyLights;
|
||||||
}
|
}
|
||||||
@ -37,13 +37,13 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
CorsairLed led = CueSDK.KeyboardSDK[renderTarget.LedId];
|
CorsairLed led = CueSDK.KeyboardSDK[renderTarget.LedId];
|
||||||
if (led == null) return Color.Transparent;
|
if (led == null) return CorsairColor.Transparent;
|
||||||
|
|
||||||
Color color;
|
CorsairColor color;
|
||||||
return !_colors.TryGetValue(led.Id, out color) ? Color.Transparent : color;
|
return !_colors.TryGetValue(led.Id, out color) ? CorsairColor.Transparent : color;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Gradients;
|
using CUE.NET.Gradients;
|
||||||
using CUE.NET.Helper;
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a brush drawing a radial gradient around a center point.
|
/// Represents a brush drawing a radial gradient around a center point.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RadialGradientBrush : AbstractBrush
|
public class RadialGradientBrush : AbstractBrush, IGradientBrush
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -66,9 +67,9 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
if(Gradient == null) return Color.Transparent;
|
if(Gradient == null) return CorsairColor.Transparent;
|
||||||
|
|
||||||
PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);
|
PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Helper;
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
namespace CUE.NET.Brushes
|
namespace CUE.NET.Brushes
|
||||||
@ -27,7 +28,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
return ColorHelper.ColorFromHSV((float)_random.NextDouble() * 360f, 1, 1);
|
return ColorHelper.ColorFromHSV((float)_random.NextDouble() * 360f, 1, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Brushes
|
namespace CUE.NET.Brushes
|
||||||
{
|
{
|
||||||
@ -15,7 +16,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the color drawn by the brush.
|
/// Gets or sets the color drawn by the brush.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color { get; set; }
|
public CorsairColor Color { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// Initializes a new instance of the <see cref="SolidColorBrush"/> class.
|
/// Initializes a new instance of the <see cref="SolidColorBrush"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color drawn by the brush.</param>
|
/// <param name="color">The color drawn by the brush.</param>
|
||||||
public SolidColorBrush(Color color)
|
public SolidColorBrush(CorsairColor color)
|
||||||
{
|
{
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
}
|
}
|
||||||
@ -40,7 +41,7 @@ namespace CUE.NET.Brushes
|
|||||||
/// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
|
/// <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>
|
/// <param name="renderTarget">The target (key/point) from which the color should be taken.</param>
|
||||||
/// <returns>The color at the specified point.</returns>
|
/// <returns>The color at the specified point.</returns>
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
return Color;
|
return Color;
|
||||||
}
|
}
|
||||||
@ -59,6 +60,16 @@ namespace CUE.NET.Brushes
|
|||||||
return brush.Color;
|
return brush.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static explicit operator SolidColorBrush(CorsairColor color)
|
||||||
|
{
|
||||||
|
return new SolidColorBrush(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator CorsairColor(SolidColorBrush brush)
|
||||||
|
{
|
||||||
|
return brush.Color;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,10 +45,12 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Brushes\IGradientBrush.cs" />
|
||||||
<Compile Include="Brushes\ImageBrush.cs" />
|
<Compile Include="Brushes\ImageBrush.cs" />
|
||||||
<Compile Include="Brushes\ProfileBrush.cs" />
|
<Compile Include="Brushes\ProfileBrush.cs" />
|
||||||
<Compile Include="Brushes\BrushRenderTarget.cs" />
|
<Compile Include="Brushes\BrushRenderTarget.cs" />
|
||||||
<Compile Include="CueSDKAutoUpdate.cs" />
|
<Compile Include="CueSDKAutoUpdate.cs" />
|
||||||
|
<Compile Include="Devices\Generic\CorsairColor.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
||||||
|
|||||||
@ -254,7 +254,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
brush.UpdateEffects();
|
brush.UpdateEffects();
|
||||||
brush.PerformFinalize();
|
brush.PerformFinalize();
|
||||||
|
|
||||||
foreach (KeyValuePair<BrushRenderTarget, Color> renders in brush.RenderedTargets)
|
foreach (KeyValuePair<BrushRenderTarget, CorsairColor> renders in brush.RenderedTargets)
|
||||||
this[renders.Key.LedId].Color = renders.Value;
|
this[renders.Key.LedId].Color = renders.Value;
|
||||||
}
|
}
|
||||||
// ReSharper disable once CatchAllClause
|
// ReSharper disable once CatchAllClause
|
||||||
@ -263,7 +263,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
|
|
||||||
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
||||||
{
|
{
|
||||||
updateRequests = updateRequests.Where(x => x.Color != Color.Transparent).ToList();
|
updateRequests = updateRequests.Where(x => x.Color != CorsairColor.Transparent).ToList();
|
||||||
|
|
||||||
OnLedsUpdating(updateRequests);
|
OnLedsUpdating(updateRequests);
|
||||||
|
|
||||||
|
|||||||
54
Devices/Generic/CorsairColor.cs
Normal file
54
Devices/Generic/CorsairColor.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Generic
|
||||||
|
{
|
||||||
|
public class CorsairColor
|
||||||
|
{
|
||||||
|
#region Constants
|
||||||
|
|
||||||
|
public static CorsairColor Transparent => Color.Transparent;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public byte A { get; set; }
|
||||||
|
public byte R { get; set; }
|
||||||
|
public byte G { get; set; }
|
||||||
|
public byte B { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public CorsairColor()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public CorsairColor(byte r, byte g, byte b) : this(255, r, g, b)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public CorsairColor(byte a, byte r, byte g, byte b)
|
||||||
|
{
|
||||||
|
this.A = a;
|
||||||
|
this.R = r;
|
||||||
|
this.G = g;
|
||||||
|
this.B = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Operators
|
||||||
|
|
||||||
|
public static implicit operator CorsairColor(Color color)
|
||||||
|
{
|
||||||
|
return new CorsairColor(color.A, color.R, color.G, color.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator Color(CorsairColor color)
|
||||||
|
{
|
||||||
|
return Color.FromArgb(color.A, color.R, color.G, color.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -33,13 +33,13 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Color the LED should be set to on the next update.
|
/// Gets the Color the LED should be set to on the next update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color RequestedColor { get; private set; } = Color.Transparent;
|
public CorsairColor RequestedColor { get; private set; } = CorsairColor.Transparent;
|
||||||
|
|
||||||
private Color _color = Color.Transparent;
|
private CorsairColor _color = CorsairColor.Transparent;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current color of the LED. Sets the <see cref="RequestedColor" /> for the next update. />.
|
/// Gets the current color of the LED. Sets the <see cref="RequestedColor" /> for the next update. />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color
|
public CorsairColor Color
|
||||||
{
|
{
|
||||||
get { return _color; }
|
get { return _color; }
|
||||||
set
|
set
|
||||||
@ -86,8 +86,8 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void Reset()
|
internal void Reset()
|
||||||
{
|
{
|
||||||
_color = Color.Transparent;
|
_color = CorsairColor.Transparent;
|
||||||
RequestedColor = Color.Transparent;
|
RequestedColor = CorsairColor.Transparent;
|
||||||
IsLocked = false;
|
IsLocked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
|
||||||
namespace CUE.NET.Devices.Generic
|
namespace CUE.NET.Devices.Generic
|
||||||
@ -21,7 +20,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the requested color of the led.
|
/// Gets the requested color of the led.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color { get; set; }
|
public CorsairColor Color { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ledId">The id of the led to update.</param>
|
/// <param name="ledId">The id of the led to update.</param>
|
||||||
/// <param name="color">The requested color of the led.</param>
|
/// <param name="color">The requested color of the led.</param>
|
||||||
public LedUpateRequest(CorsairLedId ledId, Color color)
|
public LedUpateRequest(CorsairLedId ledId, CorsairColor color)
|
||||||
{
|
{
|
||||||
this.LedId = ledId;
|
this.LedId = ledId;
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
|
|||||||
@ -7,7 +7,8 @@ namespace CUE.NET.Effects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a basic effect targeting an <see cref="IBrush"/>.
|
/// Represents a basic effect targeting an <see cref="IBrush"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractBrushEffect : IEffect<IBrush>
|
public abstract class AbstractBrushEffect<T> : IEffect<IBrush>
|
||||||
|
where T : IBrush
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="IBrush"/> this effect is targeting.
|
/// Gets the <see cref="IBrush"/> this effect is targeting.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IBrush Brush { get; set; }
|
protected T Brush { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <returns><c>true</c> if the effect can be attached; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if the effect can be attached; otherwise, <c>false</c>.</returns>
|
||||||
public virtual bool CanBeAppliedTo(IBrush target)
|
public virtual bool CanBeAppliedTo(IBrush target)
|
||||||
{
|
{
|
||||||
return true;
|
return target is T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -47,7 +48,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <param name="target">The <see cref="IBrush"/> this effect is attached to.</param>
|
/// <param name="target">The <see cref="IBrush"/> this effect is attached to.</param>
|
||||||
public virtual void OnAttach(IBrush target)
|
public virtual void OnAttach(IBrush target)
|
||||||
{
|
{
|
||||||
Brush = target;
|
Brush = (T)target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -56,9 +57,15 @@ namespace CUE.NET.Effects
|
|||||||
/// <param name="target">The <see cref="IBrush"/> this effect is detached from.</param>
|
/// <param name="target">The <see cref="IBrush"/> this effect is detached from.</param>
|
||||||
public virtual void OnDetach(IBrush target)
|
public virtual void OnDetach(IBrush target)
|
||||||
{
|
{
|
||||||
Brush = null;
|
Brush = default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a basic effect targeting an <see cref="IBrush"/>.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractBrushEffect : AbstractBrushEffect<IBrush>
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@ namespace CUE.NET.Effects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a basic effect targeting an <see cref="ILedGroup"/>.
|
/// Represents a basic effect targeting an <see cref="ILedGroup"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractLedGroupEffect : IEffect<ILedGroup>
|
public abstract class AbstractLedGroupEffect<T> : IEffect<ILedGroup>
|
||||||
|
where T : ILedGroup
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="ILedGroup"/> this effect is targeting.
|
/// Gets the <see cref="ILedGroup"/> this effect is targeting.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected ILedGroup LedGroup { get; set; }
|
protected T LedGroup { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <returns><c>true</c> if the effect can be attached; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if the effect can be attached; otherwise, <c>false</c>.</returns>
|
||||||
public virtual bool CanBeAppliedTo(ILedGroup target)
|
public virtual bool CanBeAppliedTo(ILedGroup target)
|
||||||
{
|
{
|
||||||
return true;
|
return target is T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -49,7 +50,7 @@ namespace CUE.NET.Effects
|
|||||||
/// <param name="target">The <see cref="ILedGroup"/> this effect is attached to.</param>
|
/// <param name="target">The <see cref="ILedGroup"/> this effect is attached to.</param>
|
||||||
public virtual void OnAttach(ILedGroup target)
|
public virtual void OnAttach(ILedGroup target)
|
||||||
{
|
{
|
||||||
LedGroup = target;
|
LedGroup = (T)target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,9 +59,15 @@ namespace CUE.NET.Effects
|
|||||||
/// <param name="target">The <see cref="ILedGroup"/> this effect is detached from.</param>
|
/// <param name="target">The <see cref="ILedGroup"/> this effect is detached from.</param>
|
||||||
public virtual void OnDetach(ILedGroup target)
|
public virtual void OnDetach(ILedGroup target)
|
||||||
{
|
{
|
||||||
LedGroup = null;
|
LedGroup = default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a basic effect targeting an <see cref="ILedGroup"/>.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractLedGroupEffect : AbstractLedGroupEffect<ILedGroup>
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using CUE.NET;
|
using CUE.NET;
|
||||||
using CUE.NET.Brushes;
|
using CUE.NET.Brushes;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
using CUE.NET.Devices.Keyboard;
|
using CUE.NET.Devices.Keyboard;
|
||||||
using CUE.NET.Exceptions;
|
using CUE.NET.Exceptions;
|
||||||
@ -65,10 +66,10 @@ namespace Example_AudioAnalyzer_full
|
|||||||
CueSDK.UpdateMode = UpdateMode.Continuous;
|
CueSDK.UpdateMode = UpdateMode.Continuous;
|
||||||
// Add a black background. We want this to be semi-transparent to add some sort of fade-effect - this will smooth everything out a bit
|
// Add a black background. We want this to be semi-transparent to add some sort of fade-effect - this will smooth everything out a bit
|
||||||
// Note that this isn't a 'real effect' since it's update-rate dependent. A real effect would do always the same thing not mather how fast the keyboard updates.
|
// Note that this isn't a 'real effect' since it's update-rate dependent. A real effect would do always the same thing not mather how fast the keyboard updates.
|
||||||
_keyboard.Brush = new SolidColorBrush(Color.FromArgb(96, 0, 0, 0));
|
_keyboard.Brush = new SolidColorBrush(new CorsairColor(96, 0, 0, 0));
|
||||||
// Add our song-beat-effect. Remember to uncomment the update in the spectrum effect if you want to remove this.
|
// Add our song-beat-effect. Remember to uncomment the update in the spectrum effect if you want to remove this.
|
||||||
ListLedGroup songBeatGroup = new ListLedGroup(_keyboard, _keyboard);
|
ListLedGroup songBeatGroup = new ListLedGroup(_keyboard, _keyboard);
|
||||||
songBeatGroup.Brush = new SolidColorBrush(Color.FromArgb(127, 164, 164, 164));
|
songBeatGroup.Brush = new SolidColorBrush(new CorsairColor(127, 164, 164, 164));
|
||||||
songBeatGroup.Brush.AddEffect(new SongBeatEffect(_soundDataProcessor));
|
songBeatGroup.Brush.AddEffect(new SongBeatEffect(_soundDataProcessor));
|
||||||
|
|
||||||
// Add our spectrum-effect using the soundDataProcessor and a rainbow from purple to red as gradient
|
// Add our spectrum-effect using the soundDataProcessor and a rainbow from purple to red as gradient
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using CUE.NET.Brushes;
|
using CUE.NET.Brushes;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Gradients;
|
using CUE.NET.Gradients;
|
||||||
using Example_AudioAnalyzer_full.TakeAsIs;
|
using Example_AudioAnalyzer_full.TakeAsIs;
|
||||||
|
|
||||||
@ -28,9 +29,9 @@ namespace Example_AudioAnalyzer_full
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
|
||||||
{
|
{
|
||||||
if (_soundDataProcessor?.BarValues == null) return Color.Transparent;
|
if (_soundDataProcessor?.BarValues == null) return CorsairColor.Transparent;
|
||||||
|
|
||||||
// This logic is also stolen from AterialDawn
|
// This logic is also stolen from AterialDawn
|
||||||
int barSampleIndex = (int)Math.Floor(_soundDataProcessor.BarValues.Length * (renderTarget.Point.X / (rectangle.X + rectangle.Width))); // Calculate bar sampling index
|
int barSampleIndex = (int)Math.Floor(_soundDataProcessor.BarValues.Length * (renderTarget.Point.X / (rectangle.X + rectangle.Width))); // Calculate bar sampling index
|
||||||
@ -38,7 +39,7 @@ namespace Example_AudioAnalyzer_full
|
|||||||
float verticalPos = (renderTarget.Point.Y / rectangle.Height);
|
float verticalPos = (renderTarget.Point.Y / rectangle.Height);
|
||||||
|
|
||||||
// If the barHeight is lower than the vertical pos currently calculated return the brush value. Otherwise do nothing by returning transparent.
|
// If the barHeight is lower than the vertical pos currently calculated return the brush value. Otherwise do nothing by returning transparent.
|
||||||
return curBarHeight <= verticalPos ? base.GetColorAtPoint(rectangle, renderTarget) : Color.Transparent;
|
return curBarHeight <= verticalPos ? base.GetColorAtPoint(rectangle, renderTarget) : CorsairColor.Transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
37
Examples/SimpleDevTest/MoveRainbowEffect.cs
Normal file
37
Examples/SimpleDevTest/MoveRainbowEffect.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using CUE.NET.Brushes;
|
||||||
|
using CUE.NET.Effects;
|
||||||
|
using CUE.NET.Gradients;
|
||||||
|
|
||||||
|
namespace SimpleDevTest
|
||||||
|
{
|
||||||
|
public class MoveRainbowEffect : AbstractBrushEffect<IGradientBrush>
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public float DegreePerSecond { get; set; } = 30f;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public override void Update(float deltaTime)
|
||||||
|
{
|
||||||
|
float value = DegreePerSecond * deltaTime;
|
||||||
|
|
||||||
|
//DarthAffe 11.09.2016: Only to test! This will overflow if run for a longer time!!!
|
||||||
|
((RainbowGradient)Brush.Gradient).StartHue += value;
|
||||||
|
((RainbowGradient)Brush.Gradient).EndHue += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanBeAppliedTo(IBrush target)
|
||||||
|
{
|
||||||
|
return (target as IGradientBrush)?.Gradient is RainbowGradient;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -39,17 +39,15 @@ namespace SimpleDevTest
|
|||||||
CueSDK.UpdateMode = UpdateMode.Continuous;
|
CueSDK.UpdateMode = UpdateMode.Continuous;
|
||||||
|
|
||||||
IBrush rainbowBrush = new LinearGradientBrush(new RainbowGradient());
|
IBrush rainbowBrush = new LinearGradientBrush(new RainbowGradient());
|
||||||
rainbowBrush.AddEffect(new FlashEffect());
|
rainbowBrush.AddEffect(new FlashEffect { Attack = 5f, Sustain = 1f, Decay = 0, Release = 5f, Interval = 1f });
|
||||||
|
rainbowBrush.AddEffect(new MoveRainbowEffect());
|
||||||
|
rainbowBrush.AddEffect(new RemoveRedEffect());
|
||||||
|
|
||||||
AddTestBrush(CueSDK.KeyboardSDK, rainbowBrush);
|
|
||||||
AddTestBrush(CueSDK.KeyboardSDK, rainbowBrush);
|
|
||||||
AddTestBrush(CueSDK.KeyboardSDK, rainbowBrush);
|
AddTestBrush(CueSDK.KeyboardSDK, rainbowBrush);
|
||||||
AddTestBrush(CueSDK.MouseSDK, rainbowBrush);
|
AddTestBrush(CueSDK.MouseSDK, rainbowBrush);
|
||||||
AddTestBrush(CueSDK.HeadsetSDK, rainbowBrush);
|
AddTestBrush(CueSDK.HeadsetSDK, rainbowBrush);
|
||||||
AddTestBrush(CueSDK.MousematSDK, rainbowBrush);
|
AddTestBrush(CueSDK.MousematSDK, rainbowBrush);
|
||||||
|
|
||||||
Wait(10);
|
|
||||||
|
|
||||||
//// Get connected keyboard or throw exception if there is no light controllable keyboard connected
|
//// Get connected keyboard or throw exception if there is no light controllable keyboard connected
|
||||||
//CorsairKeyboard keyboard = CueSDK.KeyboardSDK;
|
//CorsairKeyboard keyboard = CueSDK.KeyboardSDK;
|
||||||
//if (keyboard == null)
|
//if (keyboard == null)
|
||||||
|
|||||||
14
Examples/SimpleDevTest/RemoveRedEffect.cs
Normal file
14
Examples/SimpleDevTest/RemoveRedEffect.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
using CUE.NET.Effects;
|
||||||
|
|
||||||
|
namespace SimpleDevTest
|
||||||
|
{
|
||||||
|
public class RemoveRedEffect : AbstractBrushEffect
|
||||||
|
{
|
||||||
|
public override void Update(float deltaTime)
|
||||||
|
{
|
||||||
|
foreach (CorsairColor colors in Brush.RenderedTargets.Values)
|
||||||
|
colors.R = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -47,8 +47,10 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="MoveRainbowEffect.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RemoveRedEffect.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config">
|
<None Include="App.config">
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Gradients
|
namespace CUE.NET.Gradients
|
||||||
{
|
{
|
||||||
@ -65,7 +66,7 @@ namespace CUE.NET.Gradients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||||
/// <returns>The color at the specific offset.</returns>
|
/// <returns>The color at the specific offset.</returns>
|
||||||
public abstract Color GetColor(float offset);
|
public abstract CorsairColor GetColor(float offset);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Gradients
|
namespace CUE.NET.Gradients
|
||||||
{
|
{
|
||||||
@ -20,7 +21,7 @@ namespace CUE.NET.Gradients
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the color of the stop.
|
/// Gets or sets the color of the stop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color { get; set; }
|
public CorsairColor Color { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ namespace CUE.NET.Gradients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="offset">The percentage offset to place this stop.</param>
|
/// <param name="offset">The percentage offset to place this stop.</param>
|
||||||
/// <param name="color">The color of the stop.</param>
|
/// <param name="color">The color of the stop.</param>
|
||||||
public GradientStop(float offset, Color color)
|
public GradientStop(float offset, CorsairColor color)
|
||||||
{
|
{
|
||||||
this.Offset = offset;
|
this.Offset = offset;
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
using System.Drawing;
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Gradients
|
namespace CUE.NET.Gradients
|
||||||
{
|
{
|
||||||
@ -12,6 +12,6 @@ namespace CUE.NET.Gradients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||||
/// <returns>The color at the specific offset.</returns>
|
/// <returns>The color at the specific offset.</returns>
|
||||||
Color GetColor(float offset);
|
CorsairColor GetColor(float offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Gradients
|
namespace CUE.NET.Gradients
|
||||||
{
|
{
|
||||||
@ -35,9 +36,9 @@ namespace CUE.NET.Gradients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||||
/// <returns>The color at the specific offset.</returns>
|
/// <returns>The color at the specific offset.</returns>
|
||||||
public override Color GetColor(float offset)
|
public override CorsairColor GetColor(float offset)
|
||||||
{
|
{
|
||||||
if (!GradientStops.Any()) return Color.Transparent;
|
if (!GradientStops.Any()) return CorsairColor.Transparent;
|
||||||
if (GradientStops.Count == 1) return GradientStops.First().Color;
|
if (GradientStops.Count == 1) return GradientStops.First().Color;
|
||||||
|
|
||||||
offset = ClipOffset(offset);
|
offset = ClipOffset(offset);
|
||||||
@ -54,7 +55,7 @@ namespace CUE.NET.Gradients
|
|||||||
byte colG = (byte)((gsAfter.Color.G - gsBefore.Color.G) * blendFactor + gsBefore.Color.G);
|
byte colG = (byte)((gsAfter.Color.G - gsBefore.Color.G) * blendFactor + gsBefore.Color.G);
|
||||||
byte colB = (byte)((gsAfter.Color.B - gsBefore.Color.B) * blendFactor + gsBefore.Color.B);
|
byte colB = (byte)((gsAfter.Color.B - gsBefore.Color.B) * blendFactor + gsBefore.Color.B);
|
||||||
|
|
||||||
return Color.FromArgb(colA, colR, colG, colB);
|
return new CorsairColor(colA, colR, colG, colB);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||||
|
|
||||||
using System.Drawing;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Helper;
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
namespace CUE.NET.Gradients
|
namespace CUE.NET.Gradients
|
||||||
@ -50,7 +50,7 @@ namespace CUE.NET.Gradients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||||
/// <returns>The color at the specific offset.</returns>
|
/// <returns>The color at the specific offset.</returns>
|
||||||
public Color GetColor(float offset)
|
public CorsairColor GetColor(float offset)
|
||||||
{
|
{
|
||||||
float range = EndHue - StartHue;
|
float range = EndHue - StartHue;
|
||||||
float hue = (StartHue + (range * offset)) % 360f;
|
float hue = (StartHue + (range * offset)) % 360f;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using CUE.NET.Devices.Generic;
|
||||||
|
|
||||||
namespace CUE.NET.Helper
|
namespace CUE.NET.Helper
|
||||||
{
|
{
|
||||||
@ -13,57 +13,56 @@ namespace CUE.NET.Helper
|
|||||||
#region byte/float conversion
|
#region byte/float conversion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the alpha-value of the <see cref="Color"/> to an float value int the range [0..1].
|
/// Converts the alpha-value of the <see cref="CorsairColor"/> to an float value int the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the alpha-value from.</param>
|
/// <param name="color">The color to take the alpha-value from.</param>
|
||||||
/// <returns>The float-value in the range of [0..1]</returns>
|
/// <returns>The float-value in the range of [0..1]</returns>
|
||||||
public static float GetFloatA(this Color color)
|
public static float GetFloatA(this CorsairColor color)
|
||||||
{
|
{
|
||||||
return color.A / 255f;
|
return color.A / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the red-value of the <see cref="Color"/> to an float value int the range [0..1].
|
/// Converts the red-value of the <see cref="CorsairColor"/> to an float value int the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the red-value from.</param>
|
/// <param name="color">The color to take the red-value from.</param>
|
||||||
/// <returns>The float-value in the range of [0..1]</returns>
|
/// <returns>The float-value in the range of [0..1]</returns>
|
||||||
public static float GetFloatR(this Color color)
|
public static float GetFloatR(this CorsairColor color)
|
||||||
{
|
{
|
||||||
return color.R / 255f;
|
return color.R / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the green-value of the <see cref="Color"/> to an float value int the range [0..1].
|
/// Converts the green-value of the <see cref="CorsairColor"/> to an float value int the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the green-value from.</param>
|
/// <param name="color">The color to take the green-value from.</param>
|
||||||
/// <returns>The float-value in the range of [0..1]</returns>
|
/// <returns>The float-value in the range of [0..1]</returns>
|
||||||
public static float GetFloatG(this Color color)
|
public static float GetFloatG(this CorsairColor color)
|
||||||
{
|
{
|
||||||
return color.G / 255f;
|
return color.G / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the blue-value of the <see cref="Color"/> to an float value int the range [0..1].
|
/// Converts the blue-value of the <see cref="CorsairColor"/> to an float value int the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the blue-value from.</param>
|
/// <param name="color">The color to take the blue-value from.</param>
|
||||||
/// <returns>The float-value in the range of [0..1]</returns>
|
/// <returns>The float-value in the range of [0..1]</returns>
|
||||||
public static float GetFloatB(this Color color)
|
public static float GetFloatB(this CorsairColor color)
|
||||||
{
|
{
|
||||||
return color.B / 255f;
|
return color.B / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="Color"/> object from the respective rgb-float-values in the range [0..1].
|
/// Creates a <see cref="CorsairColor"/> object from the respective rgb-float-values in the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="a">The alpha-value in the range [0..1].</param>
|
/// <param name="a">The alpha-value in the range [0..1].</param>
|
||||||
/// <param name="r">The red-value in the range [0..1].</param>
|
/// <param name="r">The red-value in the range [0..1].</param>
|
||||||
/// <param name="g">The green-value in the range [0..1].</param>
|
/// <param name="g">The green-value in the range [0..1].</param>
|
||||||
/// <param name="b">The blue-value in the range [0..1].</param>
|
/// <param name="b">The blue-value in the range [0..1].</param>
|
||||||
/// <returns>The color-object created representing the given values.</returns>
|
/// <returns>The color-object created representing the given values.</returns>
|
||||||
public static Color CreateColorFromFloat(float a, float r, float g, float b)
|
public static CorsairColor CreateColorFromFloat(float a, float r, float g, float b)
|
||||||
{
|
{
|
||||||
// ReSharper disable once ExceptionNotDocumentedOptional
|
return new CorsairColor(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b));
|
||||||
return Color.FromArgb(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte GetIntColorFromFloat(float f)
|
private static byte GetIntColorFromFloat(float f)
|
||||||
@ -83,7 +82,7 @@ namespace CUE.NET.Helper
|
|||||||
/// <param name="bg">The background-color.</param>
|
/// <param name="bg">The background-color.</param>
|
||||||
/// <param name="fg">The foreground-color</param>
|
/// <param name="fg">The foreground-color</param>
|
||||||
/// <returns>The resulting color.</returns>
|
/// <returns>The resulting color.</returns>
|
||||||
public static Color Blend(this Color bg, Color fg)
|
public static CorsairColor Blend(this CorsairColor bg, CorsairColor fg)
|
||||||
{
|
{
|
||||||
if (fg.A == 255)
|
if (fg.A == 255)
|
||||||
return fg;
|
return fg;
|
||||||
@ -103,12 +102,39 @@ namespace CUE.NET.Helper
|
|||||||
#region RGB/HSV conversion
|
#region RGB/HSV conversion
|
||||||
// https://en.wikipedia.org/wiki/HSL_and_HSV
|
// https://en.wikipedia.org/wiki/HSL_and_HSV
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the hue-value (HSV-color space) of the color.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The color to take the hue from.</param>
|
||||||
|
/// <returns>The hue-value (HSV-color space) of the color.</returns>
|
||||||
|
public static float GetHSVHue(this CorsairColor color)
|
||||||
|
{
|
||||||
|
if (color.R == color.G && color.G == color.B) return 0.0f;
|
||||||
|
|
||||||
|
float min = Math.Min(Math.Min(color.R, color.G), color.B);
|
||||||
|
float max = Math.Max(Math.Max(color.R, color.G), color.B);
|
||||||
|
|
||||||
|
float hue = 0f;
|
||||||
|
if (Math.Abs(max - color.R) < float.Epsilon) // r is max
|
||||||
|
hue = (color.G - color.B) / (max - min);
|
||||||
|
else if (Math.Abs(max - color.G) < float.Epsilon) // g is max
|
||||||
|
hue = 2f + (color.B - color.R) / (max - min);
|
||||||
|
else // b is max
|
||||||
|
hue = 4f + (color.R - color.G) / (max - min);
|
||||||
|
|
||||||
|
hue = hue * 60f;
|
||||||
|
if (hue < 0f)
|
||||||
|
hue += 360f;
|
||||||
|
|
||||||
|
return hue;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the saturation-value (HSV-color space) of the color.
|
/// Gets the saturation-value (HSV-color space) of the color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the saturation from.</param>
|
/// <param name="color">The color to take the saturation from.</param>
|
||||||
/// <returns>The saturation-value (HSV-color space) of the color.</returns>
|
/// <returns>The saturation-value (HSV-color space) of the color.</returns>
|
||||||
public static float GetHSVSaturation(this Color color)
|
public static float GetHSVSaturation(this CorsairColor color)
|
||||||
{
|
{
|
||||||
int max = Math.Max(color.R, Math.Max(color.G, color.B));
|
int max = Math.Max(color.R, Math.Max(color.G, color.B));
|
||||||
int min = Math.Min(color.R, Math.Min(color.G, color.B));
|
int min = Math.Min(color.R, Math.Min(color.G, color.B));
|
||||||
@ -123,26 +149,26 @@ namespace CUE.NET.Helper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The color to take the value from.</param>
|
/// <param name="color">The color to take the value from.</param>
|
||||||
/// <returns>The value-value (HSV-color space) of the color.</returns>
|
/// <returns>The value-value (HSV-color space) of the color.</returns>
|
||||||
public static float GetHSVValue(this Color color)
|
public static float GetHSVValue(this CorsairColor color)
|
||||||
{
|
{
|
||||||
return Math.Max(color.R, Math.Max(color.G, color.B)) / 255f;
|
return Math.Max(color.R, Math.Max(color.G, color.B)) / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both/6930407#6930407 as of 27.09.2015
|
// Based on http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both/6930407#6930407 as of 27.09.2015
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="Color"/> object from the respective hsv-float-values in the range [0..1].
|
/// Creates a <see cref="CorsairColor"/> object from the respective hsv-float-values in the range [0..1].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hue">The hue of the color.</param>
|
/// <param name="hue">The hue of the color.</param>
|
||||||
/// <param name="saturation">The saturation of the color.</param>
|
/// <param name="saturation">The saturation of the color.</param>
|
||||||
/// <param name="value">The value of the color.</param>
|
/// <param name="value">The value of the color.</param>
|
||||||
/// <param name="alpha">The alpha of the color.</param>
|
/// <param name="alpha">The alpha of the color.</param>
|
||||||
/// <returns>The color-object created representing the given values.</returns>
|
/// <returns>The color-object created representing the given values.</returns>
|
||||||
public static Color ColorFromHSV(float hue, float saturation, float value, byte alpha = 255)
|
public static CorsairColor ColorFromHSV(float hue, float saturation, float value, byte alpha = 255)
|
||||||
{
|
{
|
||||||
if (saturation <= 0.0)
|
if (saturation <= 0.0)
|
||||||
{
|
{
|
||||||
int val = GetIntColorFromFloat(value);
|
byte val = GetIntColorFromFloat(value);
|
||||||
return Color.FromArgb(alpha, val, val, val);
|
return new CorsairColor(alpha, val, val, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
float hh = (hue % 360f) / 60f;
|
float hh = (hue % 360f) / 60f;
|
||||||
@ -155,17 +181,17 @@ namespace CUE.NET.Helper
|
|||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(t), GetIntColorFromFloat(p));
|
return new CorsairColor(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(t), GetIntColorFromFloat(p));
|
||||||
case 1:
|
case 1:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(q), GetIntColorFromFloat(value), GetIntColorFromFloat(p));
|
return new CorsairColor(alpha, GetIntColorFromFloat(q), GetIntColorFromFloat(value), GetIntColorFromFloat(p));
|
||||||
case 2:
|
case 2:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(value), GetIntColorFromFloat(t));
|
return new CorsairColor(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(value), GetIntColorFromFloat(t));
|
||||||
case 3:
|
case 3:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(q), GetIntColorFromFloat(value));
|
return new CorsairColor(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(q), GetIntColorFromFloat(value));
|
||||||
case 4:
|
case 4:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(t), GetIntColorFromFloat(p), GetIntColorFromFloat(value));
|
return new CorsairColor(alpha, GetIntColorFromFloat(t), GetIntColorFromFloat(p), GetIntColorFromFloat(value));
|
||||||
default:
|
default:
|
||||||
return Color.FromArgb(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(p), GetIntColorFromFloat(q));
|
return new CorsairColor(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(p), GetIntColorFromFloat(q));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using CUE.NET.Brushes;
|
using CUE.NET.Brushes;
|
||||||
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
|
||||||
namespace CUE.NET.Profiles
|
namespace CUE.NET.Profiles
|
||||||
@ -20,7 +21,7 @@ namespace CUE.NET.Profiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal string Name { get; }
|
internal string Name { get; }
|
||||||
|
|
||||||
private Dictionary<CorsairLedId, Color> _colors;
|
private Dictionary<CorsairLedId, CorsairColor> _colors;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ namespace CUE.NET.Profiles
|
|||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
key = (CorsairLedId)Enum.Parse(typeof(CorsairLedId), name),
|
key = (CorsairLedId)Enum.Parse(typeof(CorsairLedId), name),
|
||||||
color = ColorTranslator.FromHtml(x.Attribute("color").Value)
|
color = (CorsairColor)ColorTranslator.FromHtml(x.Attribute("color").Value)
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.ToDictionary(x => x.key, x => x.color)
|
.ToDictionary(x => x.key, x => x.color)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user