diff --git a/Brushes/AbstractBrush.cs b/Brushes/AbstractBrush.cs index 0851b10..3e9626d 100644 --- a/Brushes/AbstractBrush.cs +++ b/Brushes/AbstractBrush.cs @@ -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 /// /// Gets a dictionary containing all colors for points calculated in the last render pass. /// - public Dictionary RenderedTargets { get; } = new Dictionary(); + public Dictionary RenderedTargets { get; } = new Dictionary(); /// /// Gets the strongly-typed target used for the effect. @@ -97,7 +98,7 @@ namespace CUE.NET.Brushes /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - protected abstract Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget); + protected abstract CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget); /// /// Finalizes the color by appliing the overall brightness and opacity.
@@ -105,14 +106,14 @@ namespace CUE.NET.Brushes ///
/// The color to finalize. /// The finalized color. - 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 diff --git a/Brushes/IBrush.cs b/Brushes/IBrush.cs index 559d186..b831614 100644 --- a/Brushes/IBrush.cs +++ b/Brushes/IBrush.cs @@ -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 /// /// Gets a dictionary containing all colors for points calculated in the last render pass. /// - Dictionary RenderedTargets { get; } + Dictionary RenderedTargets { get; } /// /// Performas the render pass of the brush and calculates the raw colors for all requested points. diff --git a/Brushes/IGradientBRush.cs b/Brushes/IGradientBRush.cs new file mode 100644 index 0000000..e2839b7 --- /dev/null +++ b/Brushes/IGradientBRush.cs @@ -0,0 +1,9 @@ +using CUE.NET.Gradients; + +namespace CUE.NET.Brushes +{ + public interface IGradientBrush : IBrush + { + IGradient Gradient { get; } + } +} diff --git a/Brushes/ImageBrush.cs b/Brushes/ImageBrush.cs index 332c648..222f474 100644 --- a/Brushes/ImageBrush.cs +++ b/Brushes/ImageBrush.cs @@ -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 /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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; diff --git a/Brushes/LinearGradientBrush.cs b/Brushes/LinearGradientBrush.cs index 95ae138..82e8a18 100644 --- a/Brushes/LinearGradientBrush.cs +++ b/Brushes/LinearGradientBrush.cs @@ -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 /// /// Represents a brush drawing a linear gradient. /// - public class LinearGradientBrush : AbstractBrush + public class LinearGradientBrush : AbstractBrush, IGradientBrush { #region Properties & Fields - + /// /// Gets or sets the start point (as percentage in the range [0..1]) of the gradient drawn by the brush. (default: 0f, 0.5f) /// @@ -74,9 +75,9 @@ namespace CUE.NET.Brushes /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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); diff --git a/Brushes/ProfileBrush.cs b/Brushes/ProfileBrush.cs index 0a9049f..64701c5 100644 --- a/Brushes/ProfileBrush.cs +++ b/Brushes/ProfileBrush.cs @@ -12,7 +12,7 @@ namespace CUE.NET.Brushes { #region Properties & Fields - private Dictionary _colors; + private Dictionary _colors; #endregion @@ -22,7 +22,7 @@ namespace CUE.NET.Brushes /// Initializes a new instance of the class. /// /// The light settings of the CUE profile. - internal ProfileBrush(Dictionary keyLights) + internal ProfileBrush(Dictionary keyLights) { this._colors = keyLights; } @@ -37,13 +37,13 @@ namespace CUE.NET.Brushes /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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 diff --git a/Brushes/RadialGradientBrush.cs b/Brushes/RadialGradientBrush.cs index c4212bc..617a1eb 100644 --- a/Brushes/RadialGradientBrush.cs +++ b/Brushes/RadialGradientBrush.cs @@ -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 /// /// Represents a brush drawing a radial gradient around a center point. /// - public class RadialGradientBrush : AbstractBrush + public class RadialGradientBrush : AbstractBrush, IGradientBrush { #region Properties & Fields @@ -66,9 +67,9 @@ namespace CUE.NET.Brushes /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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); diff --git a/Brushes/RandomColorBrush.cs b/Brushes/RandomColorBrush.cs index 8143f13..da4f090 100644 --- a/Brushes/RandomColorBrush.cs +++ b/Brushes/RandomColorBrush.cs @@ -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 /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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); } diff --git a/Brushes/SolidColorBrush.cs b/Brushes/SolidColorBrush.cs index 6d20a81..2881477 100644 --- a/Brushes/SolidColorBrush.cs +++ b/Brushes/SolidColorBrush.cs @@ -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 /// /// Gets or sets the color drawn by the brush. /// - 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 class. ///
/// The color drawn by the brush. - public SolidColorBrush(Color color) + public SolidColorBrush(CorsairColor color) { this.Color = color; } @@ -40,7 +41,7 @@ namespace CUE.NET.Brushes /// The rectangle in which the brush should be drawn. /// The target (key/point) from which the color should be taken. /// The color at the specified point. - 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 } } \ No newline at end of file diff --git a/CUE.NET.csproj b/CUE.NET.csproj index 4f0102f..9685bbc 100644 --- a/CUE.NET.csproj +++ b/CUE.NET.csproj @@ -45,10 +45,12 @@ + + diff --git a/Devices/Generic/AbstractCueDevice.cs b/Devices/Generic/AbstractCueDevice.cs index aa69a43..1232144 100644 --- a/Devices/Generic/AbstractCueDevice.cs +++ b/Devices/Generic/AbstractCueDevice.cs @@ -254,7 +254,7 @@ namespace CUE.NET.Devices.Generic brush.UpdateEffects(); brush.PerformFinalize(); - foreach (KeyValuePair renders in brush.RenderedTargets) + foreach (KeyValuePair renders in brush.RenderedTargets) this[renders.Key.LedId].Color = renders.Value; } // ReSharper disable once CatchAllClause @@ -263,7 +263,7 @@ namespace CUE.NET.Devices.Generic private void UpdateLeds(ICollection updateRequests) { - updateRequests = updateRequests.Where(x => x.Color != Color.Transparent).ToList(); + updateRequests = updateRequests.Where(x => x.Color != CorsairColor.Transparent).ToList(); OnLedsUpdating(updateRequests); diff --git a/Devices/Generic/CorsairColor.cs b/Devices/Generic/CorsairColor.cs new file mode 100644 index 0000000..41d275f --- /dev/null +++ b/Devices/Generic/CorsairColor.cs @@ -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 + } +} diff --git a/Devices/Generic/CorsairLed.cs b/Devices/Generic/CorsairLed.cs index 0bfe302..29a9630 100644 --- a/Devices/Generic/CorsairLed.cs +++ b/Devices/Generic/CorsairLed.cs @@ -33,13 +33,13 @@ namespace CUE.NET.Devices.Generic /// /// Gets the Color the LED should be set to on the next update. /// - 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; /// /// Gets the current color of the LED. Sets the for the next update. />. /// - public Color Color + public CorsairColor Color { get { return _color; } set @@ -86,8 +86,8 @@ namespace CUE.NET.Devices.Generic /// internal void Reset() { - _color = Color.Transparent; - RequestedColor = Color.Transparent; + _color = CorsairColor.Transparent; + RequestedColor = CorsairColor.Transparent; IsLocked = false; } diff --git a/Devices/Generic/LedUpateRequest.cs b/Devices/Generic/LedUpateRequest.cs index e5fac1a..d41d695 100644 --- a/Devices/Generic/LedUpateRequest.cs +++ b/Devices/Generic/LedUpateRequest.cs @@ -1,7 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global -using System.Drawing; using CUE.NET.Devices.Generic.Enums; namespace CUE.NET.Devices.Generic @@ -21,7 +20,7 @@ namespace CUE.NET.Devices.Generic /// /// Gets the requested color of the led. /// - public Color Color { get; set; } + public CorsairColor Color { get; set; } #endregion @@ -32,7 +31,7 @@ namespace CUE.NET.Devices.Generic /// /// The id of the led to update. /// The requested color of the led. - public LedUpateRequest(CorsairLedId ledId, Color color) + public LedUpateRequest(CorsairLedId ledId, CorsairColor color) { this.LedId = ledId; this.Color = color; diff --git a/Effects/AbstractBrushEffect.cs b/Effects/AbstractBrushEffect.cs index fe523bc..f27b7a4 100644 --- a/Effects/AbstractBrushEffect.cs +++ b/Effects/AbstractBrushEffect.cs @@ -7,7 +7,8 @@ namespace CUE.NET.Effects /// /// Represents a basic effect targeting an . /// - public abstract class AbstractBrushEffect : IEffect + public abstract class AbstractBrushEffect : IEffect + where T : IBrush { #region Properties & Fields @@ -19,7 +20,7 @@ namespace CUE.NET.Effects /// /// Gets the this effect is targeting. /// - protected IBrush Brush { get; set; } + protected T Brush { get; set; } #endregion @@ -38,7 +39,7 @@ namespace CUE.NET.Effects /// true if the effect can be attached; otherwise, false. public virtual bool CanBeAppliedTo(IBrush target) { - return true; + return target is T; } /// @@ -47,7 +48,7 @@ namespace CUE.NET.Effects /// The this effect is attached to. public virtual void OnAttach(IBrush target) { - Brush = target; + Brush = (T)target; } /// @@ -56,9 +57,15 @@ namespace CUE.NET.Effects /// The this effect is detached from. public virtual void OnDetach(IBrush target) { - Brush = null; + Brush = default(T); } #endregion } + + /// + /// Represents a basic effect targeting an . + /// + public abstract class AbstractBrushEffect : AbstractBrushEffect + { } } diff --git a/Effects/AbstractLedGroupEffect.cs b/Effects/AbstractLedGroupEffect.cs index 61f3ce3..6248cd3 100644 --- a/Effects/AbstractLedGroupEffect.cs +++ b/Effects/AbstractLedGroupEffect.cs @@ -9,7 +9,8 @@ namespace CUE.NET.Effects /// /// Represents a basic effect targeting an . /// - public abstract class AbstractLedGroupEffect : IEffect + public abstract class AbstractLedGroupEffect : IEffect + where T : ILedGroup { #region Properties & Fields @@ -21,7 +22,7 @@ namespace CUE.NET.Effects /// /// Gets the this effect is targeting. /// - protected ILedGroup LedGroup { get; set; } + protected T LedGroup { get; set; } #endregion @@ -40,7 +41,7 @@ namespace CUE.NET.Effects /// true if the effect can be attached; otherwise, false. public virtual bool CanBeAppliedTo(ILedGroup target) { - return true; + return target is T; } /// @@ -49,7 +50,7 @@ namespace CUE.NET.Effects /// The this effect is attached to. public virtual void OnAttach(ILedGroup target) { - LedGroup = target; + LedGroup = (T)target; } /// @@ -58,9 +59,15 @@ namespace CUE.NET.Effects /// The this effect is detached from. public virtual void OnDetach(ILedGroup target) { - LedGroup = null; + LedGroup = default(T); } #endregion } + + /// + /// Represents a basic effect targeting an . + /// + public abstract class AbstractLedGroupEffect : AbstractLedGroupEffect + { } } diff --git a/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioAnalyzerExample.cs b/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioAnalyzerExample.cs index 16980ee..d81ef5d 100644 --- a/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioAnalyzerExample.cs +++ b/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioAnalyzerExample.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using CUE.NET; using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Keyboard; using CUE.NET.Exceptions; @@ -65,10 +66,10 @@ namespace Example_AudioAnalyzer_full 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 // 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. 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)); // Add our spectrum-effect using the soundDataProcessor and a rainbow from purple to red as gradient diff --git a/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioSpectrumBrush.cs b/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioSpectrumBrush.cs index 9811d86..a0411c6 100644 --- a/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioSpectrumBrush.cs +++ b/Examples/AudioAnalyzer/Example_AudioAnalyzer_full/AudioSpectrumBrush.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; using CUE.NET.Gradients; using Example_AudioAnalyzer_full.TakeAsIs; @@ -28,9 +29,9 @@ namespace Example_AudioAnalyzer_full #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 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); // 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 diff --git a/Examples/SimpleDevTest/MoveRainbowEffect.cs b/Examples/SimpleDevTest/MoveRainbowEffect.cs new file mode 100644 index 0000000..87bdd91 --- /dev/null +++ b/Examples/SimpleDevTest/MoveRainbowEffect.cs @@ -0,0 +1,37 @@ +using CUE.NET.Brushes; +using CUE.NET.Effects; +using CUE.NET.Gradients; + +namespace SimpleDevTest +{ + public class MoveRainbowEffect : AbstractBrushEffect + { + #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 + } +} diff --git a/Examples/SimpleDevTest/Program.cs b/Examples/SimpleDevTest/Program.cs index 80f5383..d37d1c9 100644 --- a/Examples/SimpleDevTest/Program.cs +++ b/Examples/SimpleDevTest/Program.cs @@ -39,17 +39,15 @@ namespace SimpleDevTest CueSDK.UpdateMode = UpdateMode.Continuous; 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.MouseSDK, rainbowBrush); AddTestBrush(CueSDK.HeadsetSDK, rainbowBrush); AddTestBrush(CueSDK.MousematSDK, rainbowBrush); - - Wait(10); - + //// Get connected keyboard or throw exception if there is no light controllable keyboard connected //CorsairKeyboard keyboard = CueSDK.KeyboardSDK; //if (keyboard == null) diff --git a/Examples/SimpleDevTest/RemoveRedEffect.cs b/Examples/SimpleDevTest/RemoveRedEffect.cs new file mode 100644 index 0000000..1b110c7 --- /dev/null +++ b/Examples/SimpleDevTest/RemoveRedEffect.cs @@ -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; + } + } +} diff --git a/Examples/SimpleDevTest/SimpleDevTest.csproj b/Examples/SimpleDevTest/SimpleDevTest.csproj index d1def2d..61889c2 100644 --- a/Examples/SimpleDevTest/SimpleDevTest.csproj +++ b/Examples/SimpleDevTest/SimpleDevTest.csproj @@ -47,8 +47,10 @@ + + diff --git a/Gradients/AbstractGradient.cs b/Gradients/AbstractGradient.cs index 7a48ad2..f027594 100644 --- a/Gradients/AbstractGradient.cs +++ b/Gradients/AbstractGradient.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using CUE.NET.Devices.Generic; namespace CUE.NET.Gradients { @@ -65,7 +66,7 @@ namespace CUE.NET.Gradients /// /// The percentage offset to take the color from. /// The color at the specific offset. - public abstract Color GetColor(float offset); + public abstract CorsairColor GetColor(float offset); #endregion } diff --git a/Gradients/GradientStop.cs b/Gradients/GradientStop.cs index ae2c92a..5c1197f 100644 --- a/Gradients/GradientStop.cs +++ b/Gradients/GradientStop.cs @@ -2,6 +2,7 @@ // ReSharper disable MemberCanBePrivate.Global using System.Drawing; +using CUE.NET.Devices.Generic; namespace CUE.NET.Gradients { @@ -20,7 +21,7 @@ namespace CUE.NET.Gradients /// /// Gets or sets the color of the stop. /// - public Color Color { get; set; } + public CorsairColor Color { get; set; } #endregion @@ -31,7 +32,7 @@ namespace CUE.NET.Gradients /// /// The percentage offset to place this stop. /// The color of the stop. - public GradientStop(float offset, Color color) + public GradientStop(float offset, CorsairColor color) { this.Offset = offset; this.Color = color; diff --git a/Gradients/IGradient.cs b/Gradients/IGradient.cs index 275d9af..20feedd 100644 --- a/Gradients/IGradient.cs +++ b/Gradients/IGradient.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using CUE.NET.Devices.Generic; namespace CUE.NET.Gradients { @@ -12,6 +12,6 @@ namespace CUE.NET.Gradients /// /// The percentage offset to take the color from. /// The color at the specific offset. - Color GetColor(float offset); + CorsairColor GetColor(float offset); } } diff --git a/Gradients/LinearGradient.cs b/Gradients/LinearGradient.cs index 5ac8b21..bec3f0f 100644 --- a/Gradients/LinearGradient.cs +++ b/Gradients/LinearGradient.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Linq; +using CUE.NET.Devices.Generic; namespace CUE.NET.Gradients { @@ -35,9 +36,9 @@ namespace CUE.NET.Gradients /// /// The percentage offset to take the color from. /// The color at the specific offset. - 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; 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 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 diff --git a/Gradients/RainbowGradient.cs b/Gradients/RainbowGradient.cs index 5270fde..740908c 100644 --- a/Gradients/RainbowGradient.cs +++ b/Gradients/RainbowGradient.cs @@ -1,7 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global -using System.Drawing; +using CUE.NET.Devices.Generic; using CUE.NET.Helper; namespace CUE.NET.Gradients @@ -50,7 +50,7 @@ namespace CUE.NET.Gradients /// /// The percentage offset to take the color from. /// The color at the specific offset. - public Color GetColor(float offset) + public CorsairColor GetColor(float offset) { float range = EndHue - StartHue; float hue = (StartHue + (range * offset)) % 360f; diff --git a/Helper/ColorHelper.cs b/Helper/ColorHelper.cs index 3825ca3..d03e20b 100644 --- a/Helper/ColorHelper.cs +++ b/Helper/ColorHelper.cs @@ -1,7 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global using System; -using System.Drawing; +using CUE.NET.Devices.Generic; namespace CUE.NET.Helper { @@ -13,57 +13,56 @@ namespace CUE.NET.Helper #region byte/float conversion /// - /// Converts the alpha-value of the to an float value int the range [0..1]. + /// Converts the alpha-value of the to an float value int the range [0..1]. /// /// The color to take the alpha-value from. /// The float-value in the range of [0..1] - public static float GetFloatA(this Color color) + public static float GetFloatA(this CorsairColor color) { return color.A / 255f; } /// - /// Converts the red-value of the to an float value int the range [0..1]. + /// Converts the red-value of the to an float value int the range [0..1]. /// /// The color to take the red-value from. /// The float-value in the range of [0..1] - public static float GetFloatR(this Color color) + public static float GetFloatR(this CorsairColor color) { return color.R / 255f; } /// - /// Converts the green-value of the to an float value int the range [0..1]. + /// Converts the green-value of the to an float value int the range [0..1]. /// /// The color to take the green-value from. /// The float-value in the range of [0..1] - public static float GetFloatG(this Color color) + public static float GetFloatG(this CorsairColor color) { return color.G / 255f; } /// - /// Converts the blue-value of the to an float value int the range [0..1]. + /// Converts the blue-value of the to an float value int the range [0..1]. /// /// The color to take the blue-value from. /// The float-value in the range of [0..1] - public static float GetFloatB(this Color color) + public static float GetFloatB(this CorsairColor color) { return color.B / 255f; } /// - /// Creates a object from the respective rgb-float-values in the range [0..1]. + /// Creates a object from the respective rgb-float-values in the range [0..1]. /// /// The alpha-value in the range [0..1]. /// The red-value in the range [0..1]. /// The green-value in the range [0..1]. /// The blue-value in the range [0..1]. /// The color-object created representing the given values. - 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 Color.FromArgb(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b)); + return new CorsairColor(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b)); } private static byte GetIntColorFromFloat(float f) @@ -83,7 +82,7 @@ namespace CUE.NET.Helper /// The background-color. /// The foreground-color /// The resulting color. - public static Color Blend(this Color bg, Color fg) + public static CorsairColor Blend(this CorsairColor bg, CorsairColor fg) { if (fg.A == 255) return fg; @@ -103,12 +102,39 @@ namespace CUE.NET.Helper #region RGB/HSV conversion // https://en.wikipedia.org/wiki/HSL_and_HSV + /// + /// Gets the hue-value (HSV-color space) of the color. + /// + /// The color to take the hue from. + /// The hue-value (HSV-color space) of the color. + 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; + } + /// /// Gets the saturation-value (HSV-color space) of the color. /// /// The color to take the saturation from. /// The saturation-value (HSV-color space) of the color. - 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 min = Math.Min(color.R, Math.Min(color.G, color.B)); @@ -123,26 +149,26 @@ namespace CUE.NET.Helper /// /// The color to take the value from. /// The value-value (HSV-color space) of the color. - 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; } // 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 /// - /// Creates a object from the respective hsv-float-values in the range [0..1]. + /// Creates a object from the respective hsv-float-values in the range [0..1]. /// /// The hue of the color. /// The saturation of the color. /// The value of the color. /// The alpha of the color. /// The color-object created representing the given values. - 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) { - int val = GetIntColorFromFloat(value); - return Color.FromArgb(alpha, val, val, val); + byte val = GetIntColorFromFloat(value); + return new CorsairColor(alpha, val, val, val); } float hh = (hue % 360f) / 60f; @@ -155,17 +181,17 @@ namespace CUE.NET.Helper switch (i) { case 0: - return Color.FromArgb(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(t), GetIntColorFromFloat(p)); + return new CorsairColor(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(t), GetIntColorFromFloat(p)); case 1: - return Color.FromArgb(alpha, GetIntColorFromFloat(q), GetIntColorFromFloat(value), GetIntColorFromFloat(p)); + return new CorsairColor(alpha, GetIntColorFromFloat(q), GetIntColorFromFloat(value), GetIntColorFromFloat(p)); case 2: - return Color.FromArgb(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(value), GetIntColorFromFloat(t)); + return new CorsairColor(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(value), GetIntColorFromFloat(t)); case 3: - return Color.FromArgb(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(q), GetIntColorFromFloat(value)); + return new CorsairColor(alpha, GetIntColorFromFloat(p), GetIntColorFromFloat(q), GetIntColorFromFloat(value)); case 4: - return Color.FromArgb(alpha, GetIntColorFromFloat(t), GetIntColorFromFloat(p), GetIntColorFromFloat(value)); + return new CorsairColor(alpha, GetIntColorFromFloat(t), GetIntColorFromFloat(p), GetIntColorFromFloat(value)); default: - return Color.FromArgb(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(p), GetIntColorFromFloat(q)); + return new CorsairColor(alpha, GetIntColorFromFloat(value), GetIntColorFromFloat(p), GetIntColorFromFloat(q)); } } diff --git a/Profiles/CueProfileMode.cs b/Profiles/CueProfileMode.cs index b764d73..c2aa7bb 100644 --- a/Profiles/CueProfileMode.cs +++ b/Profiles/CueProfileMode.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.Linq; using System.Xml.Linq; using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; using CUE.NET.Devices.Generic.Enums; namespace CUE.NET.Profiles @@ -20,7 +21,7 @@ namespace CUE.NET.Profiles /// internal string Name { get; } - private Dictionary _colors; + private Dictionary _colors; #endregion @@ -72,7 +73,7 @@ namespace CUE.NET.Profiles return new { 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)