Ejemplo n.º 1
0
        protected void ApplyColorToBinding(CustomKeyboardEffect grid, string bindingName, Color color)
        {
            if (!Game.BindingPreset.Bindings.TryGetValue(bindingName, out var binding))
            {
                return;
            }

            foreach (var bps in new[] { binding.Primary, binding.Secondary })
            {
                if (bps.Device != Device.Keyboard)
                {
                    continue;
                }

                if (!KeyMappings.TryGetKey(bps.Key, Game.BindingPreset.KeyboardLayout, Game.ForceEnUSKeyboardLayout, out var key, NativeMethods))
                {
                    continue;
                }

                if (key == 0)
                {
                    continue;
                }

                if (!bps.Modifiers.Equals(Game.PressedModifiers))
                {
                    continue;
                }

                grid[key] = color;

                color = color.Transform(Colors.SecondaryBindingBrightness);
            }
        }
Ejemplo n.º 2
0
        public void ShouldGetWithKeyIndexer()
        {
            var grid = CustomKeyboardEffect.Create();

            grid[Key.Escape] = Color.Red;
            Assert.AreEqual(Color.Red, grid[Key.Escape]);
        }
Ejemplo n.º 3
0
        public void ShouldClearToBlack()
        {
            var grid = new CustomKeyboardEffect(Color.Pink);

            grid.Clear();

            Assert.That(grid, Is.EqualTo(CustomKeyboardEffect.Create()));
        }
Ejemplo n.º 4
0
        public void ShouldNotEqualNull()
        {
            var grid = CustomKeyboardEffect.Create();

            Assert.False(grid == null);
            Assert.True(grid != null);
            Assert.AreNotEqual(grid, null);
        }
Ejemplo n.º 5
0
        public void ShouldSetWithIndexIndexer()
        {
            var grid = CustomKeyboardEffect.Create();

            grid[5] = Color.Red;

            Assert.AreEqual(Color.Red, grid[5]);
        }
Ejemplo n.º 6
0
        public void ShouldSetNewColors()
        {
            var grid = CustomKeyboardEffect.Create();

            grid[0, 5] = Color.Red;

            Assert.That(grid[0, 5], Is.EqualTo(Color.Red));
        }
Ejemplo n.º 7
0
        public static CustomKeyboardEffect MaxAt(this CustomKeyboardEffect keyboard, int row, int column, Color c)
        {
            var key = GetKeyAt(row, column);

            keyboard[key] = keyboard[key].Max(c);

            return(keyboard);
        }
            private void Render(CustomKeyboardEffect keyboard, Color c, double lastZ)
            {
                // Particles are drawn as stretched lines, simulating movement.
                // Lines are antialiased at both ends.
                //         x0      x1
                //        ┌───┐   ┌───┐
                //  ┌───┬───┬───┬───┬───┬───┐
                //  │   │▒▒▒│███│███│▒▒▒│   │
                //  └───┴───┴───┴───┴───┴───┘
                //   -1   0   1   2   3   4
                const double xScale  = KeyboardConstants.MaxColumns / 2.0;
                const double xCenter = (KeyboardConstants.MaxColumns - 1) / 2.0;

                Debug.Assert(lastZ >= Z, "Z always decreases");
                var xPrev = (lastZ > 0 ? Math.Min(1 / lastZ, 2) : 2) * xScale;
                var xCurr = (Z > 0 ? Math.Min(1 / Z, 2) : 2) * xScale;

                double x0, x1;

                if (_angle >= 180)
                {
                    x0 = xCenter + xPrev;
                    x1 = xCenter + xCurr;
                }
                else
                {
                    x1 = xCenter - xPrev;
                    x0 = xCenter - xCurr;
                }

                var y = _angle % KeyboardConstants.MaxRows;

                // First pixel
                var xi = (int)Math.Floor(x0);

                if (xi >= 0 && xi < KeyboardConstants.MaxColumns)
                {
                    var caa = c.Transform(1 - (x0 - xi));
                    keyboard[y, xi] = keyboard[y, xi].Max(caa);
                }

                // Last pixel
                var xj = (int)Math.Ceiling(x1);

                if (xj >= 0 && xj < KeyboardConstants.MaxColumns)
                {
                    var caa = c.Transform(1 - (xj - x1));
                    keyboard[y, xj] = keyboard[y, xj].Max(caa);
                }

                // Middle pixels
                xi = Math.Max(0, xi + 1);
                xj = Math.Min(xj, KeyboardConstants.MaxColumns);
                for (; xi < xj; xi++)
                {
                    keyboard[y, xi] = keyboard[y, xi].Max(c);
                }
            }
Ejemplo n.º 9
0
        public void ShouldNotEqual2DArrayWithInvalidRowCount()
        {
            var grid = CustomKeyboardEffect.Create();
            var arr  = new Color[2][];

            Assert.False(grid == arr);
            Assert.True(grid != arr);
            Assert.False(grid.Equals(arr));
            Assert.AreNotEqual(grid, arr);
        }
Ejemplo n.º 10
0
        public static CustomKeyboardEffect Combine(this CustomKeyboardEffect keyboard, Color c, double cPct = 0.5)
        {
            for (var i = 0; i < _allKeys.Length; i++)
            {
                var key = _allKeys[i];
                keyboard[key] = keyboard[key].Combine(c, cPct);
            }

            return(keyboard);
        }
Ejemplo n.º 11
0
        public void ShouldNotEqualArbitraryObject()
        {
            var grid = CustomKeyboardEffect.Create();
            var obj  = new object();

            Assert.False(grid == obj);
            Assert.True(grid != obj);
            Assert.False(grid.Equals(obj));
            Assert.AreNotEqual(grid, obj);
        }
Ejemplo n.º 12
0
        public static CustomKeyboardEffect Max(this CustomKeyboardEffect keyboard, Color c)
        {
            for (var i = 0; i < _allKeys.Length; i++)
            {
                var key = _allKeys[i];
                keyboard[key] = keyboard[key].Max(c);
            }

            return(keyboard);
        }
Ejemplo n.º 13
0
        public void ShouldNotEqualDifferentGrid()
        {
            var a = new CustomKeyboardEffect(Color.Red);
            var b = new CustomKeyboardEffect(Color.Pink);

            Assert.False(a == b);
            Assert.True(a != b);
            Assert.False(a.Equals(b));
            Assert.AreNotEqual(a, b);
        }
Ejemplo n.º 14
0
        public void ShouldEqualIdenticalGrid()
        {
            var a = new CustomKeyboardEffect(Color.Red);
            var b = new CustomKeyboardEffect(Color.Red);

            Assert.True(a == b);
            Assert.False(a != b);
            Assert.True(a.Equals(b));
            Assert.AreEqual(a, b);
        }
Ejemplo n.º 15
0
        protected void ApplyColorToBinding(CustomKeyboardEffect grid, IEnumerable <string> bindingNames, Color color)
        {
            if (bindingNames == null)
            {
                throw new ArgumentNullException(nameof(bindingNames));
            }

            foreach (var bindingName in bindingNames)
            {
                ApplyColorToBinding(grid, bindingName, color);
            }
        }
Ejemplo n.º 16
0
        public void ShouldSetAllColorsWithColorCtor()
        {
            var grid = new CustomKeyboardEffect(Color.Red);

            for (var row = 0; row < KeyboardConstants.MaxRows; row++)
            {
                for (var column = 0; column < KeyboardConstants.MaxColumns; column++)
                {
                    Assert.That(grid[row, column], Is.EqualTo(Color.Red));
                }
            }
        }
Ejemplo n.º 17
0
        public void ShouldSetToBlackWithCreate()
        {
            var grid = CustomKeyboardEffect.Create();

            for (var row = 0; row < KeyboardConstants.MaxRows; row++)
            {
                for (var column = 0; column < KeyboardConstants.MaxColumns; column++)
                {
                    Assert.That(grid[row, column], Is.EqualTo(Color.Black));
                }
            }
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyboardImplementation" /> class.
        /// </summary>
        public KeyboardImplementation(IChromaApi api)
            : base(api)
        {
            Log.Info("Keyboard initializing...");

            CurrentEffectId = Guid.Empty;

            // We keep a local copy of a grid to speed up grid operations
            Log.Debug("Initializing private copy of Custom");
            _grid = CustomKeyboardEffect.Create();

            Log.Debug("Initializing private copy of Deathstalker grid");
            _deathstalkerGrid = DeathstalkerGridEffect.Create();
        }
Ejemplo n.º 19
0
        public async Task ApplyAsync(IVirtualLedGrid virtualGrid, CancellationToken cancellationToken = default)
        {
            var keyboardGrid   = CustomKeyboardEffect.Create();
            var mouseGrid      = CustomMouseEffect.Create();
            var mousepadGrid   = CustomMousepadEffect.Create();
            var headsetGrid    = CustomHeadsetEffect.Create();
            var chromaLinkGrid = CustomChromaLinkEffect.Create();

            foreach (var k in virtualGrid)
            {
                switch (k.Type)
                {
                case KeyType.Invalid:
                    break;

                case KeyType.Keyboard:
                    var kbVal = (Key)Enum.Parse(typeof(Key), k.FriendlyName);
                    keyboardGrid[kbVal] = ToColoreColor(k.Color);
                    break;

                case KeyType.Mouse:
                    var mouseVal = (GridLed)Enum.Parse(typeof(GridLed), k.FriendlyName);
                    mouseGrid[mouseVal] = ToColoreColor(k.Color);
                    break;

                case KeyType.Mousepad:
                    mousepadGrid[k.KeyCode] = ToColoreColor(k.Color);
                    break;

                case KeyType.Headset:
                    headsetGrid[k.KeyCode] = ToColoreColor(k.Color);
                    break;

                case KeyType.ChromaLink:
                    chromaLinkGrid[k.KeyCode] = ToColoreColor(k.Color);
                    break;
                }
            }

            await this._chromaInterface.Keyboard.SetCustomAsync(keyboardGrid);

            await this._chromaInterface.Mouse.SetGridAsync(mouseGrid);

            await this._chromaInterface.Mousepad.SetCustomAsync(mousepadGrid);

            await this._chromaInterface.Headset.SetCustomAsync(headsetGrid);

            await this._chromaInterface.ChromaLink.SetCustomAsync(chromaLinkGrid);
        }
Ejemplo n.º 20
0
        public override Task ApplyAsync(IVirtualLedGrid virtualGrid, CancellationToken cancellationToken = default)
        {
            if (!this.Initialized)
            {
                return(Task.CompletedTask);
            }

            var keyboardGrid = CustomKeyboardEffect.Create();

            for (var row = 0; row < virtualGrid.RowCount; row++)
            {
                for (var col = 0; col < virtualGrid.ColumnCount; col++)
                {
                    keyboardGrid[row, col] = ToColoreColor(virtualGrid[col, row]);
                }
            }

            return(this.ChromaInterface !.Keyboard.SetCustomAsync(keyboardGrid));
        }
Ejemplo n.º 21
0
        public void ShouldThrowWhenOutOfRange1DSet()
        {
            var grid = CustomKeyboardEffect.Create();

            Assert.That(
                () => grid[-1] = Color.Red,
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("index")
                .And.Property("ActualValue")
                .EqualTo(-1));

            Assert.That(
                () => grid[KeyboardConstants.MaxKeys] = Color.Red,
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("index")
                .And.Property("ActualValue")
                .EqualTo(KeyboardConstants.MaxKeys));
        }
Ejemplo n.º 22
0
        public void ShouldNotEqualDifferent2DArray()
        {
            var grid = new CustomKeyboardEffect(Color.Pink);
            var arr  = new Color[KeyboardConstants.MaxRows][];

            // Populate the 2D array
            for (var row = 0; row < KeyboardConstants.MaxRows; row++)
            {
                arr[row] = new Color[KeyboardConstants.MaxColumns];
                for (var col = 0; col < KeyboardConstants.MaxColumns; col++)
                {
                    arr[row][col] = Color.Red;
                }
            }

            Assert.False(grid == arr);
            Assert.True(grid != arr);
            Assert.False(grid.Equals(arr));
            Assert.AreNotEqual(grid, arr);
        }
Ejemplo n.º 23
0
        public void ShouldThrowWhenOutOfRange2DGet()
        {
            var grid = CustomKeyboardEffect.Create();

            // ReSharper disable once NotAccessedVariable
            Color dummy;

            Assert.That(
                () => dummy = grid[-1, 0],
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("row")
                .And.Property("ActualValue")
                .EqualTo(-1));

            Assert.That(
                () => dummy = grid[KeyboardConstants.MaxRows, 0],
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("row")
                .And.Property("ActualValue")
                .EqualTo(KeyboardConstants.MaxRows));

            Assert.That(
                () => dummy = grid[0, -1],
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("column")
                .And.Property("ActualValue")
                .EqualTo(-1));

            Assert.That(
                () => dummy = grid[0, KeyboardConstants.MaxColumns],
                Throws.InstanceOf <ArgumentOutOfRangeException>()
                .With.Property("ParamName")
                .EqualTo("column")
                .And.Property("ActualValue")
                .EqualTo(KeyboardConstants.MaxColumns));
        }
Ejemplo n.º 24
0
        public void ShouldGetWithIndexIndexer()
        {
            var grid = new CustomKeyboardEffect(Color.Red);

            Assert.AreEqual(Color.Red, grid[3]);
        }