Added own color-type to have more control over and easier manipulation of collors

This commit is contained in:
DarthAffe committed 2016-09-11 10:40:01 +02:00
1 parent 5c6dba769b
commit 381ec55349
29 files changed
+271 -93

No files matched your search

+5 -4
View File
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Effects;
using CUE.NET.Helper;
@@ -41,7 +42,7 @@ namespace CUE.NET.Brushes
/// <summary>
/// Gets a dictionary containing all colors for points calculated in the last render pass.
/// </summary>
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
public Dictionary<BrushRenderTarget, CorsairColor> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, CorsairColor>();
/// <summary>
/// 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="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <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>
/// Finalizes the color by appliing the overall brightness and opacity.<br/>
@@ -105,14 +106,14 @@ namespace CUE.NET.Brushes
/// </summary>
/// <param name="color">The color to finalize.</param>
/// <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%
// 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!!!
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
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
+2 -1
View File
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Effects;
@@ -36,7 +37,7 @@ namespace CUE.NET.Brushes
/// <summary>
/// Gets a dictionary containing all colors for points calculated in the last render pass.
/// </summary>
Dictionary<BrushRenderTarget, Color> RenderedTargets { get; }
Dictionary<BrushRenderTarget, CorsairColor> RenderedTargets { get; }
/// <summary>
/// Performas the render pass of the brush and calculates the raw colors for all requested points.
+9
View File
@@ -0,0 +1,9 @@
using CUE.NET.Gradients;
namespace CUE.NET.Brushes
{
public interface IGradientBrush : IBrush
{
IGradient Gradient { get; }
}
}
+3 -2
View File
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using CUE.NET.Devices.Generic;
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="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <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)
return Color.Transparent;
return CorsairColor.Transparent;
//TODO DarthAffe 16.03.2016: Refactor to allow more scale-/interpolation-modes
float scaleX = Image.Width / rectangle.Width;
+5 -4
View File
@@ -6,6 +6,7 @@
// ReSharper disable UnusedMember.Global
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Gradients;
using CUE.NET.Helper;
@@ -14,10 +15,10 @@ namespace CUE.NET.Brushes
/// <summary>
/// Represents a brush drawing a linear gradient.
/// </summary>
public class LinearGradientBrush : AbstractBrush
public class LinearGradientBrush : AbstractBrush, IGradientBrush
{
#region Properties & Fields
/// <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)
/// </summary>
@@ -74,9 +75,9 @@ namespace CUE.NET.Brushes
/// <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>
/// <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 endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
+6 -6
View File
@@ -12,7 +12,7 @@ namespace CUE.NET.Brushes
{
#region Properties & Fields
private Dictionary<CorsairLedId, Color> _colors;
private Dictionary<CorsairLedId, CorsairColor> _colors;
#endregion
@@ -22,7 +22,7 @@ namespace CUE.NET.Brushes
/// Initializes a new instance of the <see cref="ProfileBrush"/> class.
/// </summary>
/// <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;
}
@@ -37,13 +37,13 @@ namespace CUE.NET.Brushes
/// <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>
/// <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];
if (led == null) return Color.Transparent;
if (led == null) return CorsairColor.Transparent;
Color color;
return !_colors.TryGetValue(led.Id, out color) ? Color.Transparent : color;
CorsairColor color;
return !_colors.TryGetValue(led.Id, out color) ? CorsairColor.Transparent : color;
}
#endregion
+4 -3
View File
@@ -4,6 +4,7 @@
using System;
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Gradients;
using CUE.NET.Helper;
@@ -12,7 +13,7 @@ namespace CUE.NET.Brushes
/// <summary>
/// Represents a brush drawing a radial gradient around a center point.
/// </summary>
public class RadialGradientBrush : AbstractBrush
public class RadialGradientBrush : AbstractBrush, IGradientBrush
{
#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="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <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);
+2 -1
View File
@@ -2,6 +2,7 @@
using System;
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Helper;
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="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <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);
}
+14 -3
View File
@@ -2,6 +2,7 @@
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System.Drawing;
using CUE.NET.Devices.Generic;
namespace CUE.NET.Brushes
{
@@ -15,7 +16,7 @@ namespace CUE.NET.Brushes
/// <summary>
/// Gets or sets the color drawn by the brush.
/// </summary>
public Color Color { get; set; }
public CorsairColor Color { get; set; }
#endregion
@@ -25,7 +26,7 @@ namespace CUE.NET.Brushes
/// Initializes a new instance of the <see cref="SolidColorBrush"/> class.
/// </summary>
/// <param name="color">The color drawn by the brush.</param>
public SolidColorBrush(Color color)
public SolidColorBrush(CorsairColor 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="renderTarget">The target (key/point) from which the color should be taken.</param>
/// <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;
}
@@ -59,6 +60,16 @@ namespace CUE.NET.Brushes
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
}
}