int InvertColor(int color)
    {
        int red   = 255 - (color & 0xFF);
        int green = 255 - ((color >> 8) & 0xFF);
        int blue  = 255 - ((color >> 16) & 0xFF);

        return(ChromaAnimationAPI.GetRGB(red, green, blue));
    }
예제 #2
0
        private void SendHeadsetData(LEDData data)
        {
            byte[] colorArray = data.Mousepad.ToByteArray();

            for (int i = 0; i < 2; i++)
            {
                int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                ChromaAnimationAPI.Set1DColor(baseHeadsetAnim, 0, i, color);
            }
            ChromaAnimationAPI.PreviewFrame(baseHeadsetAnim, 0);
        }
예제 #3
0
        private void SendGeneralData(LEDData data)
        {
            byte[] colorArray = data.General.ToByteArray();

            for (int i = 0; i < 5; i++)
            {
                int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                ChromaAnimationAPI.Set1DColor(baseGeneralAnim, 0, i, color);
            }
            ChromaAnimationAPI.PreviewFrame(baseGeneralAnim, 0);
        }
예제 #4
0
        private void SendMousepadData(LEDData data)
        {
            byte[] colorArray = data.Mousepad.ToByteArray();

            for (int i = 0; i < 16; i++)
            {
                int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                ChromaAnimationAPI.Set1DColor(baseMousepadAnim, 0, 16 - i, color); // inverted order
            }
            ChromaAnimationAPI.PreviewFrame(baseMousepadAnim, 0);
        }
예제 #5
0
        private void SendKeypadData(LEDData data)
        {
            byte[] colorArray = data.Keypad.ToByteArray();

            for (int col = 0; col < 4; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    int index = col * 5 + row;
                    int color = ChromaAnimationAPI.GetRGB(colorArray[index * 3], colorArray[index * 3 + 1], colorArray[index * 3 + 2]);
                    ChromaAnimationAPI.Set2DColor(baseKeypadAnim, 0, col, row, color);
                }
            }
            ChromaAnimationAPI.PreviewFrame(baseKeypadAnim, 0);
        }
    int MinColor(int color1, int color2)
    {
        int redColor1   = color1 & 0xFF;
        int greenColor1 = (color1 >> 8) & 0xFF;
        int blueColor1  = (color1 >> 16) & 0xFF;

        int redColor2   = color2 & 0xFF;
        int greenColor2 = (color2 >> 8) & 0xFF;
        int blueColor2  = (color2 >> 16) & 0xFF;

        int red   = Mathf.Min(redColor1, redColor2) & 0xFF;
        int green = Mathf.Min(greenColor1, greenColor2) & 0xFF;
        int blue  = Mathf.Min(blueColor1, blueColor2) & 0xFF;

        return(ChromaAnimationAPI.GetRGB(red, green, blue));
    }
    int SubtractColor(int color1, int color2)
    {
        int redColor1   = color1 & 0xFF;
        int greenColor1 = (color1 >> 8) & 0xFF;
        int blueColor1  = (color1 >> 16) & 0xFF;

        int redColor2   = color2 & 0xFF;
        int greenColor2 = (color2 >> 8) & 0xFF;
        int blueColor2  = (color2 >> 16) & 0xFF;

        int red   = Mathf.Max(redColor1 - redColor2, 0) & 0xFF;
        int green = Mathf.Max(greenColor1 - greenColor2, 0) & 0xFF;
        int blue  = Mathf.Max(blueColor1 - blueColor2, 0) & 0xFF;

        return(ChromaAnimationAPI.GetRGB(red, green, blue));
    }
    int MultiplyColor(int color1, int color2)
    {
        int redColor1   = color1 & 0xFF;
        int greenColor1 = (color1 >> 8) & 0xFF;
        int blueColor1  = (color1 >> 16) & 0xFF;

        int redColor2   = color2 & 0xFF;
        int greenColor2 = (color2 >> 8) & 0xFF;
        int blueColor2  = (color2 >> 16) & 0xFF;

        int red   = (int)Mathf.Floor(255 * ((redColor1 / 255.0f) * (redColor2 / 255.0f)));
        int green = (int)Mathf.Floor(255 * ((greenColor1 / 255.0f) * (greenColor2 / 255.0f)));
        int blue  = (int)Mathf.Floor(255 * ((blueColor1 / 255.0f) * (blueColor2 / 255.0f)));

        return(ChromaAnimationAPI.GetRGB(red, green, blue));
    }
예제 #9
0
        private void SendKeyboardData(LEDData data)
        {
            byte[] colorArray = data.Keyboard.ToByteArray();

            int black = ChromaAnimationAPI.GetRGB(0, 0, 0);

            foreach (Keyboard.RZKEY key in numPadKeys)
            {
                ChromaAnimationAPI.SetKeyColor(baseKeyboardAnim, 0, (int)key, black);
            }
            for (int i = 0; i < 88; i++) // TODO: NUMPAD
            {
                int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                ChromaAnimationAPI.SetKeyColor(baseKeyboardAnim, 0, (int)indexKeyMap[i], color);
            }
            ChromaAnimationAPI.PreviewFrame(baseKeyboardAnim, 0);
        }
예제 #10
0
        private void SendMouseData(LEDData data)
        {
            byte[] colorArray = data.Mouse.ToByteArray();

            for (int i = 0; i < 16; i++)
            {
                int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);

                ushort number;
                byte   upper;
                byte   lower;
                if (i == 0) // logo and bottom leds
                {
                    foreach (RZLED2 led in MOUSE_BOTTOM_LEDS)
                    {
                        number = Convert.ToUInt16(RZLED2.RZLED2_LOGO);
                        upper  = (byte)(number >> 8);
                        lower  = (byte)(number & 0xff);
                        ChromaAnimationAPI.Set2DColor(baseMouseAnim, 0, upper, lower, color);
                    }
                }
                else if (i == 1) // scrollwheel and backlight
                {
                    number = Convert.ToUInt16(RZLED2.RZLED2_SCROLLWHEEL);
                    upper  = (byte)(number >> 8);
                    lower  = (byte)(number & 0xff);
                    ChromaAnimationAPI.Set2DColor(baseMouseAnim, 0, upper, lower, color);

                    number = Convert.ToUInt16(RZLED2.RZLED2_BACKLIGHT);
                    upper  = (byte)(number >> 8);
                    lower  = (byte)(number & 0xff);
                    ChromaAnimationAPI.Set2DColor(baseMouseAnim, 0, upper, lower, color);
                }
                else
                {
                    number = Convert.ToUInt16(MOUSE_LEDS[i]);
                    upper  = (byte)(number >> 8);
                    lower  = (byte)(number & 0xff);
                    ChromaAnimationAPI.Set2DColor(baseMouseAnim, 0, upper, lower, color);
                }
            }
            ChromaAnimationAPI.PreviewFrame(baseMouseAnim, 0);
        }
 void SetKeyColorRGB(int[] colors, int rzkey, int red, int green, int blue)
 {
     SetKeyColor(colors, rzkey, ChromaAnimationAPI.GetRGB(red, green, blue));
 }
    public void GameLoop()
    {
        int sizeChromaLink = GetColorArraySize1D(Device1D.ChromaLink);
        int sizeHeadset    = GetColorArraySize1D(Device1D.Headset);
        int sizeKeyboard   = GetColorArraySize2D(Device2D.Keyboard);
        int sizeKeypad     = GetColorArraySize2D(Device2D.Keypad);
        int sizeMouse      = GetColorArraySize2D(Device2D.Mouse);
        int sizeMousepad   = GetColorArraySize1D(Device1D.Mousepad);

        int[] colorsChromaLink = new int[sizeChromaLink];
        int[] colorsHeadset    = new int[sizeHeadset];
        int[] colorsKeyboard   = new int[sizeKeyboard];
        int[] colorsKeypad     = new int[sizeKeypad];
        int[] colorsMouse      = new int[sizeMouse];
        int[] colorsMousepad   = new int[sizeMousepad];

        int[] tempColorsChromaLink = new int[sizeChromaLink];
        int[] tempColorsHeadset    = new int[sizeHeadset];
        int[] tempColorsKeyboard   = new int[sizeKeyboard];
        int[] tempColorsKeypad     = new int[sizeKeypad];
        int[] tempColorsMouse      = new int[sizeMouse];
        int[] tempColorsMousepad   = new int[sizeMousepad];

        while (_mWaitForExit)
        {
            // start with a blank frame
            Array.Clear(colorsChromaLink, 0, sizeChromaLink);
            Array.Clear(colorsHeadset, 0, sizeHeadset);
            Array.Clear(colorsKeyboard, 0, sizeKeyboard);
            Array.Clear(colorsKeypad, 0, sizeKeypad);
            Array.Clear(colorsMouse, 0, sizeMouse);
            Array.Clear(colorsMousepad, 0, sizeMousepad);

#if !USE_ARRAY_EFFECTS
            SetupAnimation1D(ANIMATION_FINAL_CHROMA_LINK, Device1D.ChromaLink);
            SetupAnimation1D(ANIMATION_FINAL_HEADSET, Device1D.Headset);
            SetupAnimation2D(ANIMATION_FINAL_KEYBOARD, Device2D.Keyboard);
            SetupAnimation2D(ANIMATION_FINAL_KEYPAD, Device2D.Keypad);
            SetupAnimation2D(ANIMATION_FINAL_MOUSE, Device2D.Mouse);
            SetupAnimation1D(ANIMATION_FINAL_MOUSEPAD, Device1D.Mousepad);
#endif

            BlendAnimations(_mScene,
                            colorsChromaLink, tempColorsChromaLink,
                            colorsHeadset, tempColorsHeadset,
                            colorsKeyboard, tempColorsKeyboard,
                            colorsKeypad, tempColorsKeypad,
                            colorsMouse, tempColorsMouse,
                            colorsMousepad, tempColorsMousepad);

            if (_mAmmo)
            {
                // SHow health animation
                {
                    int[] keys =
                    {
                        (int)Keyboard.RZKEY.RZKEY_F1,
                        (int)Keyboard.RZKEY.RZKEY_F2,
                        (int)Keyboard.RZKEY.RZKEY_F3,
                        (int)Keyboard.RZKEY.RZKEY_F4,
                        (int)Keyboard.RZKEY.RZKEY_F5,
                        (int)Keyboard.RZKEY.RZKEY_F6,
                    };
                    int keysLength = keys.Length;

                    float t  = _mTimeMS * 0.002f;
                    float hp = (float)Math.Abs(Math.Cos(Math.PI / 2.0f + t));
                    for (int i = 0; i < keysLength; ++i)
                    {
                        int color;
                        if (((i + 1) / ((float)keysLength + 1)) < hp)
                        {
                            color = ChromaAnimationAPI.GetRGB(0, 255, 0);
                        }
                        else
                        {
                            color = ChromaAnimationAPI.GetRGB(0, 100, 0);
                        }
                        int key = keys[i];
                        SetKeyColor(colorsKeyboard, key, color);
                    }
                }

                // Show ammo animation
                {
                    int[] keys =
                    {
                        (int)Keyboard.RZKEY.RZKEY_F7,
                        (int)Keyboard.RZKEY.RZKEY_F8,
                        (int)Keyboard.RZKEY.RZKEY_F9,
                        (int)Keyboard.RZKEY.RZKEY_F10,
                        (int)Keyboard.RZKEY.RZKEY_F11,
                        (int)Keyboard.RZKEY.RZKEY_F12,
                    };
                    int keysLength = keys.Length;

                    float t  = _mTimeMS * 0.001f;
                    float hp = (float)Math.Abs(Math.Cos(Math.PI / 2.0f + t));
                    for (int i = 0; i < keysLength; ++i)
                    {
                        int color;
                        if (((i + 1) / ((float)keysLength + 1)) < hp)
                        {
                            color = ChromaAnimationAPI.GetRGB(255, 255, 0);
                        }
                        else
                        {
                            color = ChromaAnimationAPI.GetRGB(100, 100, 0);
                        }
                        int key = keys[i];
                        SetKeyColor(colorsKeyboard, key, color);
                    }
                }
            }

            if (_mHotkeys)
            {
                // Show hotkeys
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_ESC, 255, 255, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_W, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_A, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_S, 255, 0, 0);
                SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_D, 255, 0, 0);

                if (_mAmmo)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_A, 0, 255, 0);
                }

                // Highlight R if rainbow is active
                if (_mScene._mEffects[_mIndexRainbow]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_R, 0, 255, 0);
                }

                // Highlight S if spiral is active
                if (_mScene._mEffects[_mIndexSpiral]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_S, 0, 255, 0);
                }

                // Highlight L if landscape is active
                if (_mScene._mEffects[_mIndexLandscape]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_L, 0, 255, 0);
                }

                // Highlight L if landscape is active
                if (_mScene._mEffects[_mIndexFire]._mState)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_F, 0, 255, 0);
                }

                if (_mHotkeys)
                {
                    SetKeyColorRGB(colorsKeyboard, (int)Keyboard.RZKEY.RZKEY_H, 0, 255, 0);
                }
            }

#if USE_ARRAY_EFFECTS
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.ChromaLink, colorsChromaLink);
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.Headset, colorsHeadset);
            ChromaAnimationAPI.SetEffectCustom1D((int)Device1D.Mousepad, colorsMousepad);

            ChromaAnimationAPI.SetCustomColorFlag2D((int)Device2D.Keyboard, colorsKeyboard);
            ChromaAnimationAPI.SetEffectKeyboardCustom2D((int)Device2D.Keyboard, colorsKeyboard);

            ChromaAnimationAPI.SetEffectCustom2D((int)Device2D.Keypad, colorsKeypad);
            ChromaAnimationAPI.SetEffectCustom2D((int)Device2D.Mouse, colorsMouse);
#else
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_CHROMA_LINK, 0, 0.1f, colorsChromaLink, sizeChromaLink);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_HEADSET, 0, 0.1f, colorsHeadset, sizeHeadset);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_KEYBOARD, 0, 0.1f, colorsKeyboard, sizeKeyboard);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_KEYPAD, 0, 0.1f, colorsKeypad, sizeKeypad);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_MOUSE, 0, 0.1f, colorsMouse, sizeMouse);
            ChromaAnimationAPI.UpdateFrameName(ANIMATION_FINAL_MOUSEPAD, 0, 0.1f, colorsMousepad, sizeMousepad);

            // display the change
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_CHROMA_LINK, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_HEADSET, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_KEYBOARD, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_KEYPAD, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_MOUSE, 0);
            ChromaAnimationAPI.PreviewFrameName(ANIMATION_FINAL_MOUSEPAD, 0);
#endif

            Thread.Sleep(33); //30 FPS
        }
    }
예제 #13
0
        public void SendData(int ledCount, byte[] colorArray, LightingMode mode)
        {
            if (!enabled)
            {
                return;
            }
            List <Point> points = new List <Point>();

            if (mode == LightingMode.Line)
            {
                for (int i = 0; i < ledCount; i++)
                {
                    Color c = Color.FromArgb(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                    int   x = (int)Utils.Scale(i, 0, ledCount, 0, 22);// TODO: Handle keyboards without numpads
                    points.Clear();
                    for (int j = 0; j < 6; j++)
                    {
                        points.Add(new Point(x, j));
                    }
                    try
                    {
                        foreach (var point in points)
                        {
                            ChromaAnimationAPI.Set2DColor(baseKeyboardAnim, 0, point.Y, point.X, ChromaAnimationAPI.GetRGB(c.R, c.G, c.B));
                        }
                        // keyboardFrame.SetKeys(points, c);
                    }
                    catch
                    {
                        Console.WriteLine("Error sending data to Chroma keyboard. Perhaps it doesn't have a keypad");
                    }
                }
            }
            else if (mode == LightingMode.Point)
            {
                for (int i = 0; i < KEYBOARD_LED_COUNT; i++)
                {
                    int col = ChromaAnimationAPI.GetRGB(colorArray[0], colorArray[1], colorArray[2]);
                    ChromaAnimationAPI.Set1DColor(baseKeyboardAnim, 0, i, col);
                }

                /*points.Clear();
                 * for (int i = 0; i < 22; i++)
                 * {
                 *  for (int j = 0; j < 6; j++)
                 *  {
                 *      points.Add(new Point(i, j));
                 *  }
                 * }
                 * try
                 * {
                 *  keyboardFrame.SetKeys(points, Color.FromArgb(colorArray[0], colorArray[1], colorArray[2]));
                 * } catch (Exception) // TODO: Handle keyboards without numpads
                 * {
                 *  Console.WriteLine("Error sending data to Chroma keyboard. Perhaps it doesn't have a keypad");
                 * }*/
            }
            else if (mode == LightingMode.Keyboard)
            {
                int black = ChromaAnimationAPI.GetRGB(0, 0, 0);
                foreach (Keyboard.RZKEY key in numPadKeys)
                {
                    ChromaAnimationAPI.SetKeyColor(baseKeyboardAnim, 0, (int)key, black);
                    //keyboardFrame.SetKey(key, Color.Black); // set numpad keys to black
                }
                for (int i = 0; i < 88; i++)
                {
                    //Color c = Color.FromArgb();
                    int color = ChromaAnimationAPI.GetRGB(colorArray[i * 3], colorArray[i * 3 + 1], colorArray[i * 3 + 2]);
                    ChromaAnimationAPI.SetKeyColor(baseKeyboardAnim, 0, (int)indexKeyMap[i], color);
                    //keyboardFrame.SetKey(indexKeyMap[i], c);
                }
            }
            else
            {
                Console.Error.WriteLine("RazerChroma: Invalid lighting mode");
                throw new ArgumentException("Invalid lighting mode");
            }

            // keyboardFrame.Update();
            ChromaAnimationAPI.PreviewFrame(baseKeyboardAnim, 0);
        }