Example #1
0
        /// <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);
        }