Example #1
0
        public CorsairColor getColor()
        {
            CorsairColor green  = new CorsairColor(0, 255, 0);
            CorsairColor blue   = new CorsairColor(0, 0, 255);
            CorsairColor red    = new CorsairColor(255, 0, 0);
            CorsairColor yellow = new CorsairColor(255, 255, 0);
            CorsairColor orange = new CorsairColor(255, 165, 0);

            switch (type)
            {
            case 0:
                return(green);

            case 1:
                return(orange);

            case 2:
                return(yellow);

            case 3:
                return(blue);

            default:
                break;
            }

            return(orange);
        }
Example #2
0
        public override void NotifyActiveWindowChanged(Process process)
        {
            CorsairColor CalculatorColor = FromArgb(0xFF77FFFF);
            CorsairColor NormalColor     = FromArgb(0xFFFF7700);

            if ((process.ProcessName == "SpeedCrunch" && !SpeedCrunchActive) ||
                (process.ProcessName != "SpeedCrunch" && SpeedCrunchActive))
            {
                SpeedCrunchActive = !SpeedCrunchActive;
                NumpadGroup.Brush = new SolidColorBrush(SpeedCrunchActive ? NormalColor : CalculatorColor);
                PointF NumlockWithinNumpad = new PointF(0.08695652f, 0.07142857f);
                NumpadGroup2.Brush = new RadialGradientBrush(NumlockWithinNumpad, new LinearGradient(new GradientStop[] {
                    GradStop(0x00FFFFFF, 0f),
                    GradStop(SpeedCrunchActive ? CalculatorColor : NormalColor, -0.1f),
                }));
                NumpadGroup2.Brush.AddEffect(new MoveLinearGradientEffect(4));
                //AllButNumpad.Brush = new RadialGradientBrush(new LinearGradient(new GradientStop[] {
                //	GradStop(SpeedCrunchActive ? (uint)0x00000000 : 0x77000000, -0.2f),
                //	GradStop(SpeedCrunchActive ? (uint)0x77000000 : 0x00000000, 0),
                //}));
                //AllButNumpad.Brush.AddEffect(new MoveLinearGradientEffect(3, false));
            }
            else
            {
                NumpadGroup.Brush = new SolidColorBrush(SpeedCrunchActive ? CalculatorColor : NormalColor);
                //AllButNumpad.Brush = new SolidColorBrush(FromArgb(SpeedCrunchActive ? (uint)0x77000000 : 0x00000000));
            }
        }
Example #3
0
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            CorsairColor color;
            int          ID;

            if (renderTarget.LedId == CorsairLedId.F12)
            {
                ID = (int)CorsairLedId.F12 - 61;
            }
            else
            {
                ID = (int)renderTarget.LedId - 1;
            }

            if (ID < BarProgress)
            {
                color = Color;
            }
            else if (ID == BarProgress)
            {
                float factor = (ManaP - (BarProgress - 1) * 10) / 10f;
                color = new CorsairColor(255,
                                         (byte)(Color.R * factor),
                                         (byte)(Color.G * factor),
                                         (byte)(Color.B * factor));
            }
            else
            {
                color = new CorsairColor(255, 0, 0, 0);
            }

            return(color);
        }
Example #4
0
        // 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;

            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);
        }
        protected override void OnEffectTick(PatternRow playPattern)
        {
            if (_keyboard == null)
            {
                return; //something probably went wrong during initialization, ignore this device effect playback
            }
            var columnSize       = _keyboard.DeviceRectangle.Width / playPattern.TotalColumns;
            var columnStartIndex = 0;

            for (var patternColumn = 0; patternColumn < playPattern.TotalColumns; patternColumn++)
            {
                var columnEndIndex = columnStartIndex + (int)Math.Round(columnSize);
                var maxWidth       = (int)Math.Round(_keyboard.DeviceRectangle.Width);

                if (IsLastPatternColumn(playPattern, patternColumn))
                {
                    columnEndIndex = maxWidth + 100;
                }

                var drawArea     = new RectangleF(columnStartIndex, 0, columnEndIndex, _keyboard.DeviceRectangle.Height + 100);
                var columnColor  = GetPlaybackColumnColor(playPattern, patternColumn);
                var corsairColor = new CorsairColor(columnColor.R, columnColor.G, columnColor.B);

                foreach (var led in _keyboard[drawArea])
                {
                    led.Color = corsairColor;
                }

                columnStartIndex = columnEndIndex;
            }
        }
Example #6
0
        public static void clearSpace(CorsairKeyboard keyboard)
        {
            CorsairColor nothing = new CorsairColor(0, 0, 0);

            for (char c = 'A'; c <= 'Z'; c++)
            {
                keyboard[(CorsairLedId)System.Enum.Parse(typeof(CorsairLedId), c + "")].Color = nothing;
            }

            for (int i = 1; i <= 12; i++)
            {
                keyboard[(CorsairLedId)System.Enum.Parse(typeof(CorsairLedId), "F" + i)].Color = nothing;
            }

            keyboard[CorsairKeyboardLedId.D0].Color = nothing;
            keyboard[CorsairKeyboardLedId.D1].Color = nothing;
            keyboard[CorsairKeyboardLedId.D2].Color = nothing;
            keyboard[CorsairKeyboardLedId.D3].Color = nothing;
            keyboard[CorsairKeyboardLedId.D4].Color = nothing;
            keyboard[CorsairKeyboardLedId.D5].Color = nothing;
            keyboard[CorsairKeyboardLedId.D6].Color = nothing;
            keyboard[CorsairKeyboardLedId.D7].Color = nothing;
            keyboard[CorsairKeyboardLedId.D8].Color = nothing;
            keyboard[CorsairKeyboardLedId.D9].Color = nothing;

            keyboard[CorsairKeyboardLedId.CommaAndLessThan].Color     = nothing;
            keyboard[CorsairKeyboardLedId.PeriodAndBiggerThan].Color  = nothing;
            keyboard[CorsairKeyboardLedId.SlashAndQuestionMark].Color = nothing;
            keyboard[CorsairKeyboardLedId.SemicolonAndColon].Color    = nothing;
        }
Example #7
0
        public static void ResetBars()
        {
            var black = new CorsairColor(255, 0, 0, 0);

            ManaGroup.Brush   = (SolidColorBrush)black;
            HealthGroup.Brush = (SolidColorBrush)black;
            keyboard.Update();
        }
Example #8
0
 /// <summary>
 ///     Sets LEDs to selected color for preview.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ColorCanvas_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs <Color?> e)
 {
     if (CueSDK.IsInitialized)
     {
         CorsairColor color = new CorsairColor(colorCanvas.R, colorCanvas.G, colorCanvas.B);
         LedChanger.ChangeLeds(color);
     }
 }
Example #9
0
        /// <summary>
        /// Gets the saturation-value (HSV-color space) of the color.
        /// </summary>
        /// <param name="color">The color to take the saturation from.</param>
        /// <returns>The saturation-value (HSV-color space) of the color.</returns>
        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));

            // ReSharper disable RedundantCast - never trust this ...
            return((max == 0) ? 0 : 1f - ((float)min / (float)max));
            // ReSharper restore RedundantCast
        }
Example #10
0
        protected override CorsairColor FinalizeColor(CorsairColor color)
        {
            // Apply our gamma-correction
            ((GammaCorrection)Settings.Gamma).ApplyTo(color);

            float lightness = (float)Math.Max((Settings.MinLightness / 100.0), (color.GetHSVValue() * ((double)Brightness < 0.0 ? 0.0f : ((double)Brightness > 1.0 ? 1f : Brightness))));
            byte  alpha     = (byte)((double)color.A * ((double)Opacity < 0.0 ? 0.0 : ((double)Opacity > 1.0 ? 1.0 : (double)Opacity)));

            return(ColorHelper.ColorFromHSV(color.GetHSVHue(), color.GetHSVSaturation(), lightness, alpha));
        }
Example #11
0
        public static void SetColorToAllKeys(CorsairColor color)
        {
            var leds = Keyboard.GetLeds();

            foreach (var corsairLed in leds)
            {
                corsairLed.Color = color;
            }
            Keyboard.Update();
        }
Example #12
0
        /// <summary>
        /// Performas the render pass of the brush and calculates the raw colors for all requested points.
        /// </summary>
        /// <param name="rectangle">The rectangle in which the brush should be drawn.</param>
        /// <param name="renderTargets">The targets (keys/points) of which the color should be calculated.</param>
        public virtual void PerformRender(RectangleF rectangle, IEnumerable <BrushRenderTarget> renderTargets)
        {
            RenderedRectangle = rectangle;
            RenderedTargets.Clear();

            foreach (BrushRenderTarget point in renderTargets)
            {
                RenderedTargets[point] = new CorsairColor(GetColorAtPoint(rectangle, point)); // Clone the color, we don't want to have reference issues here and brushes might return the same color multiple times!
            }
        }
        private void AnimateVertical(PatternRow playPattern, int startIndex, int endIndex, int patternColumn)
        {
            var maxWidth     = (int)Math.Round(_mouse.DeviceRectangle.Width);
            var drawArea     = new RectangleF(0, startIndex, maxWidth, endIndex);
            var columnColor  = GetPlaybackColumnColor(playPattern, patternColumn);
            var corsairColor = new CorsairColor(columnColor.R, columnColor.G, columnColor.B);

            foreach (var led in _mouse[drawArea])
            {
                led.Color = corsairColor;
            }
        }
        private void AnimateHorizontal(PatternRow playPattern, int startIndex, int endIndex, int patternColumn)
        {
            var maxHeight    = (int)Math.Round(_mouse.DeviceRectangle.Height);
            var drawArea     = new RectangleF(startIndex, 0, endIndex, maxHeight);
            var columnColor  = GetPlaybackColumnColor(playPattern, patternColumn);
            var corsairColor = new CorsairColor(columnColor.R, columnColor.G, columnColor.B);

            foreach (var led in _mouse[drawArea])
            {
                led.Color = corsairColor;
            }
        }
        protected override void OnEffectStop()
        {
            if (_mouse == null)
            {
                return; //something probably went wrong during initialization, ignore this device effect playback
            }
            var standbyColor  = SettingsManager.Settings.ColorSettings.StandbyColor;
            var mouseLedColor = new CorsairColor(standbyColor.R, standbyColor.G, standbyColor.B);

            foreach (var mouseLed in _mouse.Leds)
            {
                mouseLed.Color = mouseLedColor;
            }
        }
Example #16
0
        /// <summary>
        /// Finalizes the color by appliing the overall brightness and opacity.<br/>
        /// This method should always be the last call of a <see cref="GetColorAtPoint" /> implementation.
        /// If you overwrite this method please make sure that you never return the same color-object twice to prevent reference-issues!
        /// </summary>
        /// <param name="color">The color to finalize.</param>
        /// <returns>The finalized color.</returns>
        protected virtual CorsairColor FinalizeColor(CorsairColor color)
        {
            foreach (IColorCorrection colorCorrection in ColorCorrections)
            {
                colorCorrection.ApplyTo(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.GetHSVHue(), color.GetHSVSaturation(), finalBrightness, finalAlpha));
        }
Example #17
0
 public void ShowRGB(RGBValue rgb)
 {
     if (_lastColor == null)
     {
         _lastColor     = new CorsairColor(rgb.R, rgb.G, rgb.B);
         _headset.Brush = new SolidColorBrush(_lastColor);
     }
     else
     {
         // Don't need to instantiate it again and again
         _lastColor.R = rgb.R;
         _lastColor.G = rgb.G;
         _lastColor.B = rgb.B;
     }
     _headset.Update();
 }
Example #18
0
        /// <summary>
        /// Applies the gamma-correction to the given color.
        /// </summary>
        /// <param name="color">The color to correct.</param>
        public void ApplyTo(CorsairColor color)
        {
            if (Math.Abs(R - 1f) > float.Epsilon)
            {
                color.R = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatR(), 1.0 / R));
            }

            if (Math.Abs(G - 1f) > float.Epsilon)
            {
                color.G = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatG(), 1.0 / G));
            }

            if (Math.Abs(B - 1f) > float.Epsilon)
            {
                color.B = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatB(), 1.0 / B));
            }
        }
Example #19
0
        protected void ShowStartScreen()
        {
            var backgroundColor = new CorsairColor(0, 0, 0);
            var textColor1      = new CorsairColor(255, 255, 0);
            var startKeyColor   = new CorsairColor(0, 255, 0);

            var startKey = CorsairLedId.Space;

            SetColorToAllKeys(backgroundColor);

            // Color the start key to its color
            Keyboard[startKey].Color       = startKeyColor;
            Keyboard[CorsairLedId.T].Color = startKeyColor;

            // Write out ssss...
            // -= S =-
            Keyboard[CorsairLedId.F2].Color             = textColor1;
            Keyboard[CorsairLedId.F1].Color             = textColor1;
            Keyboard[CorsairLedId.D1].Color             = textColor1;
            Keyboard[CorsairLedId.Q].Color              = textColor1;
            Keyboard[CorsairLedId.W].Color              = textColor1;
            Keyboard[CorsairLedId.S].Color              = textColor1;
            Keyboard[CorsairLedId.Z].Color              = textColor1;
            Keyboard[CorsairLedId.NonUsBackslash].Color = textColor1;

            // TODO Complete writing out S's

            Keyboard.Update();

            Console.WriteLine("Welcome to snake!");
            Console.WriteLine("[T]     - Test Keys");
            Console.WriteLine("[Space] - Start Game");

            var keyInfo = Console.ReadKey(true);

            Console.Clear();
            if (keyInfo.Key == ConsoleKey.T)
            {
                KeyboardLayout.TestGameBoard();
            }
            else if (keyInfo.Key == ConsoleKey.Spacebar)
            {
                StartGame();
            }
        }
Example #20
0
        static void Main(string[] args)
        {
            CueSDK.Initialize();
            CueSDK.UpdateMode      = CUE.NET.Devices.Generic.Enums.UpdateMode.Continuous;
            CueSDK.UpdateFrequency = 1f / 30f;

            CorsairKeyboard keyboard = CueSDK.KeyboardSDK;

            bool done = false;

            List <CorsairLedId> wasd = new List <CorsairLedId>();

            wasd = new List <CorsairLedId>();
            wasd.Add(CorsairLedId.W);
            wasd.Add(CorsairLedId.A);
            wasd.Add(CorsairLedId.S);
            wasd.Add(CorsairLedId.D);

            CorsairColor wasdColor  = new CorsairColor(255, 0, 0);
            CorsairColor mainColor  = new CorsairColor(0, 64, 255);
            CorsairColor otherColor = new CorsairColor(255, 255, 255);

            while (!done)
            {
                currentMultiplier -= 0.05f;
                if (currentMultiplier <= 0.0f)
                {
                    currentMultiplier = 0.0f;
                    done = true;
                }

                foreach (CorsairLedId led in wasd)
                {
                    keyboard[led].Color = new CorsairColor((byte)(currentMultiplier * wasdColor.R), (byte)(currentMultiplier * wasdColor.G), (byte)(currentMultiplier * wasdColor.B));
                }


                System.Threading.Thread.Sleep(64);
            }

            System.Threading.Thread.Sleep(5000);
        }
Example #21
0
        /// <summary>
        /// Blends two colors.
        /// </summary>
        /// <param name="bg">The background-color.</param>
        /// <param name="fg">The foreground-color</param>
        /// <returns>The resulting color.</returns>
        public static CorsairColor Blend(this CorsairColor bg, CorsairColor fg)
        {
            // ReSharper disable once ConvertIfStatementToSwitchStatement
            if (fg.A == 255)
            {
                return(fg);
            }

            if (fg.A == 0)
            {
                return(bg);
            }

            float resultA = (1f - (1f - fg.GetFloatA()) * (1f - bg.GetFloatA()));
            float resultR = (fg.GetFloatR() * fg.GetFloatA() / resultA + bg.GetFloatR() * bg.GetFloatA() * (1f - fg.GetFloatA()) / resultA);
            float resultG = (fg.GetFloatG() * fg.GetFloatA() / resultA + bg.GetFloatG() * bg.GetFloatA() * (1f - fg.GetFloatA()) / resultA);
            float resultB = (fg.GetFloatB() * fg.GetFloatA() / resultA + bg.GetFloatB() * bg.GetFloatA() * (1f - fg.GetFloatA()) / resultA);

            return(CreateColorFromFloat(resultA, resultR, resultG, resultB));
        }
Example #22
0
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            CorsairColor color;

            if (Damage >= DamageMax)
            {
                color = Color;
            }
            else if (IsCrit)
            {
                color = new CorsairColor(193, 5, 255);
            }
            else
            {
                float factor = (float)Math.Ceiling((float)(Damage / DamageMax) * 10) / 10f;
                color = new CorsairColor(255,
                                         (byte)(Color.R * factor),
                                         (byte)(Color.G * factor),
                                         (byte)(Color.B * factor));
            }

            return(color);
        }
Example #23
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="SolidColorBrush" /> class.
 /// </summary>
 /// <param name="color">The color drawn by the brush.</param>
 public SolidColorBrush(CorsairColor color) => Color = color;
 public HealthBrush(CorsairColor color)
 {
     Color = color;
 }
Example #25
0
 public static GradientStop GradStop(CorsairColor color, float offset)
 {
     return(new GradientStop(offset, color));
 }
Example #26
0
 /// <summary>
 /// Converts the blue-value of the <see cref="CorsairColor"/> to a float value in the range [0..1].
 /// </summary>
 /// <param name="color">The color to take the blue-value from.</param>
 /// <returns>The float-value in the range of [0..1]</returns>
 public static float GetFloatB(this CorsairColor color)
 {
     return(color.B / 255f);
 }
Example #27
0
 public ManaBrush(CorsairColor color)
 {
     Color = color;
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GradientStop"/> class.
 /// </summary>
 /// <param name="offset">The percentage offset to place this stop.</param>
 /// <param name="color">The color of the stop.</param>
 public GradientStop(float offset, CorsairColor color)
 {
     this.Offset = offset;
     this.Color  = color;
 }
Example #29
0
 public PositionDetectorBrush(CorsairLedId led, CorsairColor color) : base(color)
 {
     this.Led = led;
 }
Example #30
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="GradientStop" /> class.
 /// </summary>
 /// <param name="offset">The percentage offset to place this stop.</param>
 /// <param name="color">The color of the stop.</param>
 public GradientStop(float offset, CorsairColor color)
 {
     Offset = offset;
     Color  = color;
 }