示例#1
0
        private void RenderVerticalLine(Point location, int width, char character = '-')
        {
            var str = new string(character, width);

            ConsoleAdapter.MoveCursor(location.Left, location.Top);
            ConsoleAdapter.Write(str);
        }
示例#2
0
        private void RenderTitle(Scoreboard scoreboard)
        {
            ConsoleColor previousForeground = ConsoleAdapter.ForegroundColor;
            ConsoleColor previousBackground = ConsoleAdapter.BackgroundColor;

            ConsoleAdapter.BackgroundColor = scoreboard.BackgroundColor;
            ConsoleAdapter.ForegroundColor = scoreboard.ForegroundColor;

            int titleLength = scoreboard.Title.Length;
            int left        = 0;

            switch (scoreboard.TitleAligment)
            {
            case TitleAligment.Left:
                left = scoreboard.Location.Left;
                ConsoleAdapter.MoveCursor(scoreboard.Location.Left, scoreboard.Location.Top);
                break;

            case TitleAligment.Center:
                left = (scoreboard.Size.Width / 2) - (titleLength / 2) + scoreboard.Location.Left;
                break;

            case TitleAligment.Right:
                left = scoreboard.Size.Width - titleLength + scoreboard.Location.Left;
                break;

            default:
                throw new ArgumentOutOfRangeException("aligment");
            }
            ConsoleAdapter.MoveCursor(left, scoreboard.Location.Top);
            ConsoleAdapter.Write(scoreboard.Title);
            ConsoleAdapter.ForegroundColor = previousForeground;
            ConsoleAdapter.BackgroundColor = previousBackground;
        }
示例#3
0
 private void RenderHorizontalLine(Point location, int height, char character = '-')
 {
     for (int i = 0; i < height; i++)
     {
         ConsoleAdapter.MoveCursor(location.Left, location.Top + i);
         ConsoleAdapter.Write(character);
     }
 }
示例#4
0
        private void RenderTextBox(TextBox textBox)
        {
            Point loc = textBox.AbsoluteLocation();

            ConsoleAdapter.Write(new string(' ', textBox.InputLength));
            ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
            ConsoleAdapter.Write(textBox.VisibleText);
        }
示例#5
0
 private void RenderPanel(Panel panel)
 {
     if (panel.DisplayText)
     {
         var loc = panel.AbsoluteLocation();
         ConsoleAdapter.MoveCursor(loc.Left + 1, loc.Top);
         ConsoleAdapter.Write(panel.VisibleText);
     }
 }
示例#6
0
 private void RenderPasswordBox(PasswordBox textBox)
 {
     ConsoleAdapter.Write(new string(' ', textBox.InputLength));
     ConsoleAdapter.MoveCursor(textBox.Location.Left, textBox.Location.Top);
     if (textBox.IsFocused && textBox.VisibleText.Length > 0)
     {
         ConsoleAdapter.Write(new String('*', textBox.VisibleText.Length - 1) + textBox.VisibleText[textBox.VisibleText.Length - 1]);
     }
     else
     {
         ConsoleAdapter.Write(new String('*', textBox.VisibleText.Length));
     }
 }
示例#7
0
        private void RenderBackgroundBox(Point point, Size size, ConsoleColor backgroundColor)
        {
            ConsoleColor previousBackground = ConsoleAdapter.BackgroundColor;

            ConsoleAdapter.BackgroundColor = backgroundColor;
            int lineLength = size.Width;

            var str = new string(' ', lineLength);

            for (int y = point.Top; y < point.Top + size.Height; y++)
            {
                ConsoleAdapter.MoveCursor(point.Left, y);
                ConsoleAdapter.Write(str);
            }
            ConsoleAdapter.MoveCursor(point.Left, point.Top);
            ConsoleAdapter.BackgroundColor = previousBackground;
        }
示例#8
0
        private void RenderVerticalScroll(Point point, int height, int rollerSize = 1, int rollerOffset = 0)
        {
            RenderHorizontalLine(new Point()
            {
                Left = point.Left, Top = point.Top + 1
            }, height - 2, '░');
            ConsoleAdapter.BackgroundColor = ConsoleColor.DarkGray;
            ConsoleAdapter.MoveCursor(point.Left, point.Top);
            ConsoleAdapter.Write('▲');
            ConsoleAdapter.MoveCursor(point.Left, point.Top + height - 1);
            ConsoleAdapter.Write('▼');

            RenderHorizontalLine(new Point()
            {
                Left = point.Left, Top = point.Top + 1 + rollerOffset
            }, rollerSize, '█');
        }
示例#9
0
        private void RenderLabel(Label label)
        {
            Point loc = label.AbsoluteLocation();

            ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
            if (label.Text.Contains('\n'))
            {
                var textLines = label.Text.Split('\n').Select(t => t.Replace('\r', ' ')).ToArray();

                if (textLines.Length > 6)
                {
                    var textsList = textLines.Take(6).ToList();
                    textsList.Add("...");
                    textLines = textsList.ToArray();
                }
                else
                {
                    textLines = textLines;
                }

                var startTop = loc.Top;
                foreach (var text in textLines)
                {
                    var currentText = text;
                    if (label.ParentScoreboard != null)
                    {
                        var supposedTextLength = label.ParentScoreboard.Size.Width - label.Location.Left -
                                                 (label.ParentScoreboard.IsBorderVisible ? 4 : 2);
                        if (text.Length > supposedTextLength)
                        {
                            currentText = text.Substring(0, supposedTextLength) + "...";
                        }
                    }

                    ConsoleAdapter.MoveCursor(loc.Left, startTop);
                    ConsoleAdapter.Write(currentText);
                    startTop++;
                }
            }
            else
            {
                ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
                ConsoleAdapter.Write(label.Text);
            }
        }
示例#10
0
        private void RenderImage(Image image)
        {
            Point loc = image.AbsoluteLocation();

            RenderBackgroundBox(
                loc,
                image.Size,
                image.BackgroundColor
                );
            if (image.UseColors)
            {
                ConsoleColor previousColor = image.UseInvertedColors ? ConsoleAdapter.BackgroundColor : ConsoleAdapter.BackgroundColor;
                for (int y = 0; y < image.Size.Height; ++y)
                {
                    for (int x = 0; x < image.Size.Width; x++)
                    {
                        ConsoleAdapter.MoveCursor(x + loc.Left, y + loc.Top);
                        if (image.UseInvertedColors)
                        {
                            ConsoleAdapter.BackgroundColor = image.ImageArray[y, x].Color;
                            ConsoleAdapter.ForegroundColor = image.ForegroundColor;
                        }
                        else
                        {
                            ConsoleAdapter.ForegroundColor = image.ImageArray[y, x].Color;
                        }
                        ConsoleAdapter.Write(image.ImageArray[y, x].Char);
                    }
                }
                ConsoleAdapter.ForegroundColor = previousColor;
            }
            else
            {
                for (int y = 0; y < image.Size.Height; ++y)
                {
                    for (int x = 0; x < image.Size.Width; x++)
                    {
                        ConsoleAdapter.MoveCursor(x + loc.Left, y + loc.Top);
                        ConsoleAdapter.Write(image.ImageArray[y, x].Char);
                    }
                }
            }
        }
示例#11
0
        private void RenderButton(Button button)
        {
            int lineLength = button.Width;

            var   str = new string(' ', lineLength);
            Point loc = button.AbsoluteLocation();

            ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
            ConsoleAdapter.Write(str);

            if (button.DisplayText)
            {
                int titleLength = button.VisibleText.Length;
                int left        = 0;
                switch (button.TextAligment)
                {
                case TitleAligment.Left:
                    left = button.Location.Left;
                    ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
                    break;

                case TitleAligment.Center:
                    left = (button.Width / 2) - (titleLength / 2) + loc.Left;
                    break;

                case TitleAligment.Right:
                    left = button.Width - titleLength + loc.Left;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("aligment");
                }
                ConsoleAdapter.MoveCursor(left, loc.Top);
                ConsoleAdapter.Write(button.VisibleText);
            }
        }
示例#12
0
        private void RenderBorder(IBorderable control, Point location, Size size, BorderCharType borderCharType)
        {
            ConsoleColor previousBackground = ConsoleAdapter.BackgroundColor;

            ConsoleAdapter.BackgroundColor = control.BorderBackgroundColor;

            ConsoleColor previousForeground = ConsoleAdapter.ForegroundColor;

            ConsoleAdapter.ForegroundColor = control.BorderForegroundColor;
            RenderVerticalLine(
                new Point
            {
                Left = location.Left + 1,
                Top  = location.Top
            },
                size.Width - 2, borderCharType.HorizontalChar);
            RenderVerticalLine(
                new Point
            {
                Left = location.Left + 1,
                Top  = location.Top + size.Height - 1
            },
                size.Width - 2, borderCharType.HorizontalChar);
            RenderHorizontalLine(
                new Point
            {
                Left = location.Left,
                Top  = location.Top + 1
            },
                size.Height - 2, borderCharType.VerticalChar);
            RenderHorizontalLine(
                new Point
            {
                Left = location.Left + size.Width - 1,
                Top  = location.Top + 1
            },
                size.Height - 2, borderCharType.VerticalChar);

            ConsoleAdapter.MoveCursor(location.Left + size.Width - 1, location.Top + size.Height - 1);
            if (!(RenderOptions.WindowHeight == location.Left + size.Width && RenderOptions.WindowHeight == location.Top + size.Height))
            {
                ConsoleAdapter.Write(borderCharType.BottomRightChar);
            }
            else
            {
                ConsoleAdapter.MoveCursor(location.Left, location.Top);
                ConsoleAdapter.Write(borderCharType.BottomRightChar);
                ConsoleAdapter.MoveArea(location.Left, location.Top, 1, 1, location.Left + size.Width - 1, location.Top + size.Height - 1);
            }

            ConsoleAdapter.MoveCursor(location.Left, location.Top);
            ConsoleAdapter.Write(borderCharType.TopLeftChar);

            ConsoleAdapter.MoveCursor(location.Left, location.Top + size.Height - 1);
            ConsoleAdapter.Write(borderCharType.BottomLeftChar);

            ConsoleAdapter.MoveCursor(location.Left + size.Width - 1, location.Top);
            ConsoleAdapter.Write(borderCharType.TopRightChar);
            ConsoleAdapter.BackgroundColor = previousBackground;
            ConsoleAdapter.ForegroundColor = previousForeground;
        }
示例#13
0
        private void RenderProgressBar(ProgressBar progressBar)
        {
            var location = progressBar.AbsoluteLocation();

            ConsoleAdapter.MoveCursor(location.Left, location.Top);
            ConsoleAdapter.Write(new string(' ', progressBar.Width));

            int normalMax   = progressBar.Maximum - progressBar.Minimum;
            int normalValue = progressBar.Value - progressBar.Minimum;
            var size        = (int)((normalValue / (normalMax * 1.0)) * progressBar.Width);

            ConsoleAdapter.MoveCursor(location.Left, location.Top);
            ConsoleColor saveColor = ConsoleAdapter.BackgroundColor;

            ConsoleAdapter.BackgroundColor = progressBar.StripeColor;
            ConsoleAdapter.Write(new string(' ', size));
            ConsoleAdapter.BackgroundColor = saveColor;

            if (progressBar.DisplayText)
            {
                int titleLength = progressBar.VisibleText.Length;
                int left        = 0;
                int offset      = 0;
                switch (progressBar.TextAligment)
                {
                case TitleAligment.Left:
                    left   = location.Left;
                    offset = 0;
                    break;

                case TitleAligment.Center:
                    offset = (progressBar.Width / 2) - (titleLength / 2);
                    left   = offset + location.Left;
                    break;

                case TitleAligment.Right:
                    offset = progressBar.Width - titleLength;
                    left   = offset + location.Left;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("aligment");
                }
                ConsoleAdapter.MoveCursor(location.Left, location.Top);
                var intersection    = size - offset < 0 ? 0 : size - offset;
                var filledString    = progressBar.VisibleText.Substring(0, intersection > progressBar.VisibleText.Length ? progressBar.VisibleText.Length : intersection);
                var nonFilledString =
                    progressBar.VisibleText.Substring(intersection > progressBar.VisibleText.Length ? progressBar.VisibleText.Length : intersection);

                ConsoleAdapter.BackgroundColor = progressBar.StripeColor;
                ConsoleAdapter.ForegroundColor = progressBar.BackgroundColor;
                ConsoleAdapter.MoveCursor(left, location.Top);
                ConsoleAdapter.Write(filledString);

                if (!string.IsNullOrEmpty(nonFilledString))
                {
                    ConsoleAdapter.BackgroundColor = progressBar.BackgroundColor;
                    ConsoleAdapter.ForegroundColor = progressBar.StripeColor;
                    ConsoleAdapter.MoveCursor(left + filledString.Length, location.Top);
                    ConsoleAdapter.Write(nonFilledString);
                }
            }
        }
示例#14
0
        private void RenderComboBox(ComboBox comboBox)
        {
            Point loc = comboBox.AbsoluteLocation();

            ConsoleAdapter.Write(new string(' ', comboBox.Width));
            ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
            ConsoleAdapter.Write(comboBox.VisibleText);
            ConsoleAdapter.MoveCursor(loc.Left + comboBox.Width - 1, loc.Top);
            ConsoleColor saveColor = ConsoleAdapter.BackgroundColor;

            ConsoleAdapter.BackgroundColor = comboBox.ExpanderBackground;

            var expanded = comboBox.DroppedDown;

            ConsoleAdapter.Write(expanded ? '▲' : '▼');
            ConsoleAdapter.BackgroundColor = saveColor;
            var initialCurosrTopPosition = loc.Top + 1;
            var itemLinesToDraw          = comboBox.Items.Count > comboBox.VisibleItemsCount
                                                        ? comboBox.VisibleItemsCount
                                                        : comboBox.Items.Count;

            var expanderLocation = new Point
            {
                Left = loc.Left + 1,
                Top  = initialCurosrTopPosition
            };

            var expanderSize = new Size {
                Width = comboBox.Width - 1, Height = itemLinesToDraw
            };

            if (expanded)
            {
                ConsoleAdapter.MoveCursor(loc.Left + comboBox.Width - 1, loc.Top);

                RenderBackgroundBox(
                    expanderLocation,
                    expanderSize,
                    comboBox.BackgroundColor
                    );
                ConsoleAdapter.ForegroundColor = comboBox.ForegroundColor;
                ConsoleAdapter.BackgroundColor = comboBox.BackgroundColor;

                var startItem = comboBox.SelectedIndex >= comboBox.VisibleItemsCount ? comboBox.SelectedIndex - comboBox.VisibleItemsCount + 1 : 0;
                for (int i = startItem; i < startItem + itemLinesToDraw; i++)
                {
                    ConsoleAdapter.MoveCursor(loc.Left + 1, initialCurosrTopPosition);
                    if (comboBox.Items[i] == comboBox.Items[comboBox.SelectedIndex])
                    {
                        ConsoleAdapter.BackgroundColor = RenderOptions.ColorScheme.FocusedBackgroundColor;
                        ConsoleAdapter.ForegroundColor = comboBox.SelectedColor;
                    }
                    ConsoleAdapter.Write(comboBox.Items[i].Text);
                    ConsoleAdapter.BackgroundColor = comboBox.BackgroundColor;
                    ConsoleAdapter.ForegroundColor = comboBox.ForegroundColor;
                    ++initialCurosrTopPosition;
                }

                if (comboBox.Items.Count > comboBox.VisibleItemsCount)
                {
                    var rollerSize   = (int)((comboBox.VisibleItemsCount / (float)comboBox.Items.Count) * (comboBox.VisibleItemsCount - 2));
                    var rollDiff     = comboBox.Items.Count - comboBox.VisibleItemsCount;
                    var rollerOffset = comboBox.SelectedIndex < comboBox.VisibleItemsCount ?
                                       0 :
                                       (int)(((comboBox.SelectedIndex - comboBox.VisibleItemsCount + 1) / (float)rollDiff) * (comboBox.VisibleItemsCount - 2 - rollerSize));
                    RenderVerticalScroll(
                        new Point()
                    {
                        Left = loc.Left + comboBox.Width - 1, Top = loc.Top + 1
                    },
                        comboBox.VisibleItemsCount,
                        rollerSize,
                        rollerOffset
                        );
                }
            }
            else
            {
                RenderBackgroundBox(
                    expanderLocation,
                    expanderSize,
                    ScoreboardContext.Navigation.Current.Scoreboard.BackgroundColor
                    );
                var overlapped = GetOverlappedControls(expanderLocation, new Point
                {
                    Left = expanderLocation.Left + expanderSize.Width,
                    Top  = expanderLocation.Top + expanderSize.Height
                }).Where(_ => _ != comboBox);

                RenderOverridedExcept(overlapped, comboBox);
            }
        }
示例#15
0
        private void RenderControl(ControlBase control)
        {
            if (!control.IsVisible)
            {
                return;
            }

            ConsoleColor previousForeground = ConsoleAdapter.ForegroundColor;
            ConsoleColor previousBackground = ConsoleAdapter.BackgroundColor;

            if (control.IsEnabled)
            {
                ConsoleAdapter.BackgroundColor = control.IsFocused ? RenderOptions.ColorScheme.FocusedBackgroundColor : control.BackgroundColor;
                ConsoleAdapter.ForegroundColor = control.IsFocused ? RenderOptions.ColorScheme.FocusedForegroundColor : control.ForegroundColor;
            }
            else
            {
                ConsoleAdapter.BackgroundColor = RenderOptions.ColorScheme.DisabledBackgroundColor;
                ConsoleAdapter.ForegroundColor = RenderOptions.ColorScheme.DisabledForegroundColor;
            }

            var sizeable = control as ISizable;

            if (control is IBorderable borderable && sizeable != null)
            {
                RenderBorder(borderable, control.Location, sizeable.Size, new BorderCharType
                {
                    TopLeftChar     = '┌',
                    BottomLeftChar  = '└',
                    BottomRightChar = '┘',
                    TopRightChar    = '┐',
                    HorizontalChar  = '─',
                    VerticalChar    = '│'
                });
            }

            Point loc = control.AbsoluteLocation();

            ConsoleAdapter.MoveCursor(loc.Left, loc.Top);
            if (control is Checkbox checkbox)
            {
                RenderCheckBox(checkbox);
            }

            if (control is RadioButton radioButton)
            {
                RenderRadioButton(radioButton);
            }

            if (control is Label label)
            {
                RenderLabel(label);
            }

            if (control is PasswordBox passwordBox)
            {
                RenderPasswordBox(passwordBox);
            }

            if (control is TextBox text && !(control is PasswordBox))
            {
                RenderTextBox(text);
            }

            if (control is Button button)
            {
                RenderButton(button);
            }

            if (control is ProgressBar progressBar)
            {
                RenderProgressBar(progressBar);
            }

            if (control is Image image)
            {
                RenderImage(image);
            }

            if (control is PlotChart plotChart)
            {
                RenderPlotChart(plotChart);
            }

            if (control is Panel panel)
            {
                RenderPanel(panel);
            }

            if (control is StatusStripItem stripItem)
            {
                RenderStripItem(stripItem);
            }

            if (control is MenuItem <object> menuItem)
            {
                RenderMenuItem(menuItem);
            }

            if (control is ComboBox comboBox)
            {
                RenderComboBox(comboBox);
            }

            if (control is IListView listView)
            {
                RenderListView(listView);
            }

            ConsoleAdapter.ForegroundColor = previousForeground;
            ConsoleAdapter.BackgroundColor = previousBackground;
        }