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); } }
public void ShouldGetWithKeyIndexer() { var grid = CustomKeyboardEffect.Create(); grid[Key.Escape] = Color.Red; Assert.AreEqual(Color.Red, grid[Key.Escape]); }
public void ShouldClearToBlack() { var grid = new CustomKeyboardEffect(Color.Pink); grid.Clear(); Assert.That(grid, Is.EqualTo(CustomKeyboardEffect.Create())); }
public void ShouldNotEqualNull() { var grid = CustomKeyboardEffect.Create(); Assert.False(grid == null); Assert.True(grid != null); Assert.AreNotEqual(grid, null); }
public void ShouldSetWithIndexIndexer() { var grid = CustomKeyboardEffect.Create(); grid[5] = Color.Red; Assert.AreEqual(Color.Red, grid[5]); }
public void ShouldSetNewColors() { var grid = CustomKeyboardEffect.Create(); grid[0, 5] = Color.Red; Assert.That(grid[0, 5], Is.EqualTo(Color.Red)); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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)); } } }
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)); } } }
/// <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(); }
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); }
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)); }
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)); }
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); }
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)); }
public void ShouldGetWithIndexIndexer() { var grid = new CustomKeyboardEffect(Color.Red); Assert.AreEqual(Color.Red, grid[3]); }