/// <summary> /// Paints the keyboard on the screen. /// </summary> protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(GlobalSettings.CurrentStyle.BackgroundColor); if (GlobalSettings.CurrentDefinition == null || !this.backBrushes.Any()) { return; } // Fill the appropriate back brush. e.Graphics.FillRectangle( this.backBrushes[KeyboardState.ShiftDown][KeyboardState.CapsActive], new Rectangle(0, 0, GlobalSettings.CurrentDefinition.Width, GlobalSettings.CurrentDefinition.Height)); // Render all keys. KeyboardState.CheckKeyHolds(GlobalSettings.Settings.PressHold); var kbKeys = KeyboardState.PressedKeys; var diKeys = DirectInputState.PressedButtons; var diPad = DirectInputState.PressedDpads; var diAxis = DirectInputState.DirectInputAxis; var mouseKeys = MouseState.PressedKeys.Select(k => (int)k).ToList(); MouseState.CheckKeyHolds(GlobalSettings.Settings.PressHold); MouseState.CheckScrollAndMovement(); var scrollCounts = MouseState.ScrollCounts; var allDefs = GlobalSettings.CurrentDefinition.Elements; foreach (var def in allDefs) { this.Render(e.Graphics, def, allDefs, kbKeys, mouseKeys, diKeys, diPad, diAxis, scrollCounts, false); } // Draw the element being manipulated if (this.currentlyManipulating == null) { if (this.highlightedDefinition != this.selectedDefinition) { // Draw highlighted only if it is not also selected. this.highlightedDefinition?.RenderHighlight(e.Graphics); } if (this.selectedDefinition != null) { this.Render(e.Graphics, this.selectedDefinition, allDefs, kbKeys, mouseKeys, diKeys, diPad, diAxis, scrollCounts, true); this.selectedDefinition.RenderSelected(e.Graphics); } } else { this.currentlyManipulating.Value.definition.RenderEditing(e.Graphics); } base.OnPaint(e); }
/// <summary> /// Paints the keyboard on the screen. /// </summary> protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(GlobalSettings.CurrentStyle.BackgroundColor); if (GlobalSettings.CurrentDefinition == null || !this.backBrushes.Any()) { return; } // Fill the appropriate back brush. e.Graphics.FillRectangle( this.backBrushes[KeyboardState.ShiftDown][KeyboardState.CapsActive], new Rectangle(0, 0, GlobalSettings.CurrentDefinition.Width, GlobalSettings.CurrentDefinition.Height)); // Render all keys. var kbKeys = KeyboardState.PressedKeys; var mouseKeys = MouseState.PressedKeys.Select(k => (int)k).ToList(); MouseState.CheckScrollAndMovement(); var scrollCounts = MouseState.ScrollCounts; var allDefs = GlobalSettings.CurrentDefinition.Elements; foreach (var def in allDefs) { if (def is KeyboardKeyDefinition kkDef) { if (!kkDef.KeyCodes.Any() || !kkDef.KeyCodes.All(kbKeys.Contains)) { continue; } if (kkDef.KeyCodes.Count == 1 && allDefs.OfType <KeyboardKeyDefinition>() .Any(d => d.KeyCodes.Count > 1 && d.KeyCodes.All(kbKeys.Contains) && d.KeyCodes.ContainsAll(kkDef.KeyCodes))) { continue; } kkDef.Render(e.Graphics, true, KeyboardState.ShiftDown, KeyboardState.CapsActive); } if (def is MouseKeyDefinition mkDef) { if (mouseKeys.Contains(mkDef.KeyCodes.Single())) { mkDef.Render(e.Graphics, true, KeyboardState.ShiftDown, KeyboardState.CapsActive); } } if (def is MouseScrollDefinition msDef) { var scrollCount = scrollCounts[msDef.KeyCodes.Single()]; if (scrollCount > 0) { msDef.Render(e.Graphics, scrollCount); } } if (def is MouseSpeedIndicatorDefinition) { ((MouseSpeedIndicatorDefinition)def).Render(e.Graphics, MouseState.AverageSpeed); } } // Draw the element being manipulated if (this.currentlyManipulating == null) { if (this.highlightedDefinition != this.selectedDefinition) { // Draw highlighted only if it is not also selected. this.highlightedDefinition?.RenderHighlight(e.Graphics); } this.selectedDefinition?.RenderSelected(e.Graphics); } else { this.currentlyManipulating.Item2.RenderEditing(e.Graphics); } base.OnPaint(e); }
/// <summary> /// Paints the keyboard on the screen. /// </summary> protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(GlobalSettings.CurrentStyle.BackgroundColor); if (GlobalSettings.CurrentDefinition == null || !this.backBrushes.Any()) { return; } // Fill the appropriate back brush. e.Graphics.FillRectangle( this.backBrushes[KeyboardState.ShiftDown][KeyboardState.CapsActive], new Rectangle(0, 0, GlobalSettings.CurrentDefinition.Width, GlobalSettings.CurrentDefinition.Height)); // Render keyboard keys. var kbDefs = GlobalSettings.CurrentDefinition.Elements.OfType <KeyboardKeyDefinition>(); var kbKeys = KeyboardState.PressedKeys; var onlySingles = true; foreach (var def in kbDefs .Where(d => kbKeys.ContainsAll(d.KeyCodes)) .OrderByDescending(d => d.KeyCodes.Count) .TakeWhile( d => { if (d.KeyCodes.Count > 1) { onlySingles = false; } return(onlySingles || d.KeyCodes.Count > 1); })) { def.Render(e.Graphics, true, KeyboardState.ShiftDown, KeyboardState.CapsActive); } // Render mouse keys. onlySingles = true; var mouseKeys = MouseState.PressedKeys; foreach (var def in mouseKeys.SelectMany( keyCode => GlobalSettings.CurrentDefinition.Elements.OfType <MouseKeyDefinition>() .Where(x => x.KeyCodes.Contains((int)keyCode)))) { def.Render(e.Graphics, true, KeyboardState.ShiftDown, KeyboardState.CapsActive); } // Render mouse scrolls. onlySingles = true; MouseState.CheckScrollAndMovement(); var scrollCounts = MouseState.ScrollCounts; for (var i = 0; i < scrollCounts.Count; i++) { if (scrollCounts[i] == 0) { continue; } foreach (var def in GlobalSettings.CurrentDefinition.Elements.OfType <MouseScrollDefinition>() .Where(x => x.KeyCodes.Contains(i)) .ToList()) { def.Render(e.Graphics, scrollCounts[i]); } } // Render mouse speeds. foreach (var def in GlobalSettings.CurrentDefinition.Elements.OfType <MouseSpeedIndicatorDefinition>()) { def.Render(e.Graphics, MouseState.AverageSpeed); } base.OnPaint(e); }