DeveloperConsole.DeveloperConsole.DrawConsole C# (CSharp) Method

DrawConsole() private method

Draws the console on screen
private DrawConsole ( ) : void
return void
        private void DrawConsole()
        {
            if (!_isHidden) {
                var offset = (UI.HEIGHT/3) - 20;

                var console = new UIContainer(new Point(0, 0), new Size(UI.WIDTH, UI.HEIGHT/3),
                    ConsoleSettings.DefaultBgColor);
                var consoleText = new UIContainer(new Point(0, 0), new Size(UI.WIDTH, offset));
                var consoleInput = new UIContainer(new Point(0, UI.HEIGHT/3), new Size(UI.WIDTH, 20));

                // Draw console log
                var height = (offset/ConsoleSettings.NumLines);

                var start = _lines.Count - ConsoleSettings.NumLines + _lineOffset;
                if (start < 0) start = 0;

                var amt = ConsoleSettings.NumLines;
                if (start + amt > _lines.Count) amt = _lines.Count - start;

                var drawLines = _lines.GetRange(start, amt);
                for (var i = 0; i < drawLines.Count; i++) {
                    foreach (
                        var uit in
                            GetLargeStringUIText(drawLines[i].Key,
                                new Point(5, (ConsoleSettings.NumLines*height) - (height*(drawLines.Count - i)) + 5),
                                ConsoleSettings.FontSize,
                                drawLines[i].Value, 0, false)) {
                        consoleText.Items.Add(uit);
                    }
                }

                // Draw scrollbar
                const int scrollBarWidth = 8;
                const int scrollBarPadding = 2;
                const int scrollBarVPadding = 6;

                var scrollMaxHeight = (offset - scrollBarVPadding);
                var scrollRatio = Convert.ToDouble(ConsoleSettings.NumLines)/Convert.ToDouble(_lines.Count);
                var relLineHeight = Convert.ToDouble(scrollMaxHeight)/Convert.ToDouble(_lines.Count);
                if (scrollRatio < 1) {
                    var scrollHeight = Convert.ToInt32(scrollRatio*scrollMaxHeight);
                    var yOffset = Convert.ToInt32(((_lines.Count + _lineOffset)*relLineHeight) - scrollHeight);
                    if (yOffset + scrollHeight > scrollMaxHeight) yOffset = scrollMaxHeight - scrollHeight;
                    console.Items.Add(
                        new UIRectangle(
                            new Point(UI.WIDTH - (scrollBarPadding + scrollBarWidth), yOffset + (scrollBarPadding/2)),
                            new Size(scrollBarWidth, scrollHeight), Color.FromArgb(100, 118, 91, 227)));
                }

                // Draw version string
                console.Items.Add(new UIText(ConsoleSettings.Version,
                    new Point(UI.WIDTH - 20 - scrollBarWidth - scrollBarPadding, (ConsoleSettings.NumLines*height) - 12),
                    ConsoleSettings.FontSize,
                    ConsoleSettings.DefaultTextColor, 0, false));

                // Draw Cursor and input
                consoleInput.Items.Add(new UIRectangle(new Point(0, -20), new Size(UI.WIDTH, 1),
                    Color.FromArgb(ConsoleSettings.Alpha, 255, 255, 255)));

                if (Game.GameTime - _lastBlinkTime > 600) {
                    _cursorChar = _cursorChar == "" ? ConsoleSettings.CursorCharacter : "";
                    _lastBlinkTime = Game.GameTime;
                }

                var displayString = Input.Insert(Input.Length - _inputOffset, _cursorChar);

                foreach (
                    var uit in
                        GetLargeStringUIText(ConsoleSettings.PreString + displayString, new Point(5, offset + 3),
                            ConsoleSettings.FontSize,
                            Color.FromArgb(ConsoleSettings.TextAlpha, 255, 255, 255), 0, false)) {
                    consoleText.Items.Add(uit);
                }

                console.Items.Add(consoleText);
                console.Items.Add(consoleInput);

                console.Draw();
            }
        }