DrawString() public méthode

public DrawString ( ConsoleString str, int x, int y, bool vert = false ) : void
str ConsoleString
x int
y int
vert bool
Résultat void
Exemple #1
0
        /// <summary>
        /// paints the text box
        /// </summary>
        /// <param name="context"></param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var toPaint = textState.CurrentValue;

            var offset = 0;

            if (toPaint.Length >= Width && textState.CursorPosition > Width - 1)
            {
                offset  = (textState.CursorPosition + 1) - Width;
                toPaint = toPaint.Substring(offset);
            }

            var bgTransformed = new List <ConsoleCharacter>();

            foreach (var c in toPaint)
            {
                if (c.BackgroundColor == ConsoleString.DefaultBackgroundColor && Background != ConsoleString.DefaultBackgroundColor)
                {
                    bgTransformed.Add(new ConsoleCharacter(c.Value, Foreground, Background));
                }
                else
                {
                    bgTransformed.Add(c);
                }
            }

            context.DrawString(new ConsoleString(bgTransformed), 0, 0);

            if (blinkState && BlinkEnabled)
            {
                char blinkChar = textState.CursorPosition >= toPaint.Length ? ' ' : toPaint[textState.CursorPosition].Value;
                var  pen       = new ConsoleCharacter(blinkChar, DefaultColors.FocusContrastColor, DefaultColors.FocusColor);
                context.DrawPoint(pen, textState.CursorPosition - offset, 0);
            }
        }
Exemple #2
0
        /// <summary>
        /// paints the text box
        /// </summary>
        /// <param name="context"></param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var toPaint       = textState.CurrentValue;
            var bgTransformed = new List <ConsoleCharacter>();

            foreach (var c in toPaint)
            {
                if (c.BackgroundColor == ConsoleString.DefaultBackgroundColor && Background != ConsoleString.DefaultBackgroundColor)
                {
                    bgTransformed.Add(new ConsoleCharacter(c.Value, Foreground, Background));
                }
                else
                {
                    bgTransformed.Add(c);
                }
            }

            context.DrawString(new ConsoleString(bgTransformed), 0, 0);

            if (blinkState)
            {
                char blinkChar = textState.CursorPosition >= toPaint.Length ? ' ' : toPaint[textState.CursorPosition].Value;
                context.Pen = new ConsoleCharacter(blinkChar, Application.Theme.FocusContrastColor, Application.Theme.FocusColor);
                context.DrawPoint(textState.CursorPosition, 0);
            }
        }
Exemple #3
0
        private void RenderTitle(ConsoleBitmap context)
        {
            int yOffset = 0;

            foreach (var series in ViewModel.DataSeriesCollection)
            {
                var title = new ConsoleString(series.Title, series.PlotColor, Background);

                if (HasFocus && ViewModel.FocusedDataPointIndex >= 0 && ViewModel.FocusedDataPointIndex < series.DataPoints.Count && ViewModel.FocusedDataSeries == series)
                {
                    var xValue = XAxisValueFormatter(series.DataPoints[ViewModel.FocusedDataPointIndex].X);
                    var yValue = YAxisValueFormatter(series.DataPoints[ViewModel.FocusedDataPointIndex].Y);
                    title += new ConsoleString(" ( " + xValue + ", " + yValue + " )", Application.Theme.FocusColor);
                }

                if (title.Length > MaxTitleLength)
                {
                    title = title.Substring(0, MaxTitleLength) + ("_");
                }

                var titleLeft = XAxisLeft + ((XAxisWidth / 2) - (title.Length / 2));
                context.DrawString(title, titleLeft, YAxisTop + 1 + yOffset);
                yOffset++;
            }
        }
Exemple #4
0
        internal override void OnPaint(ConsoleBitmap context)
        {
            base.OnPaint(context);

            int y = 0;
            foreach(var item in ViewModel.Items)
            {
                var displayString = this.HasFocus && y == ViewModel.SelectedIndex && ViewModel.IsSelectionEnabled ? new ConsoleString(item.DisplayText, this.FocusForeground.ForegroundColor) : item.RichDisplayText;
                context.DrawString(displayString, 0, y++);
            }
        }
Exemple #5
0
        internal override void OnPaint(ConsoleBitmap context)
        {
            base.OnPaint(context);

            int y = 0;

            foreach (var item in ViewModel.Items)
            {
                var displayString = this.HasFocus && y == ViewModel.SelectedIndex && ViewModel.IsSelectionEnabled ? new ConsoleString(item.DisplayText, this.FocusForeground.ForegroundColor) : item.RichDisplayText;
                context.DrawString(displayString, 0, y++);
            }
        }
Exemple #6
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var drawState = new ConsoleString();

            drawState = "[".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background = Background);
            if (Text != null)
            {
                ConsoleColor fg, bg;

                if (HasFocus)
                {
                    fg = Application.Theme.FocusContrastColor;
                    bg = Application.Theme.FocusColor;
                }
                else if (CanFocus)
                {
                    fg = Foreground;
                    bg = Background;
                }
                else
                {
                    fg = Application.Theme.DisabledColor;
                    bg = Background;
                }

                drawState += new ConsoleString(Text, fg, bg);

                if (Shortcut != null)
                {
                    if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Alt)
                    {
                        drawState += new ConsoleString($" (ALT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Shift)
                    {
                        drawState += new ConsoleString($" (SHIFT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Control)
                    {
                        drawState += new ConsoleString($" (CTL+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else
                    {
                        drawState += new ConsoleString($" ({Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                }
            }

            drawState += "]".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background);
            Width      = drawState.Length;
            context.DrawString(drawState, 0, 0);
        }
Exemple #7
0
        private void RenderThreshold(ConsoleBitmap context, DataSeries series)
        {
            if (series.Threshold == null) return;

            var yPixel = ConvertYValueToPixel(series.Threshold.Value);

            context.Pen = new ConsoleCharacter('-', series.Threshold.PlotColor, Background);
            context.DrawLine(XAxisLeft, yPixel, XAxisRight, yPixel);

            var title = series.Threshold.Title;

            if(title.Length > XAxisWidth-2)
            {
                title = series.Threshold.Title.Substring(0, XAxisWidth - 3) + "_";
            }

            context.DrawString(new ConsoleString(title, series.Threshold.PlotColor), XAxisLeft + 1, yPixel);
        }
Exemple #8
0
        private void RenderXAxisLabels(ConsoleBitmap context)
        {
            ConsoleString lastLabel = null;
            int y = XAxisYValue + 1;
            for(int x = XAxisLeft; x < XAxisRight; x+=MaxXAxisLabelLength+1)
            {
                var xConverted = ConvertXPixelToValue(x);
                var label = XAxisValueCompactFormatter(xConverted);

                if (label.Length > MaxXAxisLabelLength)
                {
                    label = label.Substring(0, MaxXAxisLabelLength - 1).AppendUsingCurrentFormat("_");
                }

                if (label != lastLabel)
                {
                    context.DrawString(label, x, y);
                    lastLabel = label;
                }
            }
        }
Exemple #9
0
        private void RenderYAxisLabels(ConsoleBitmap context)
        {
            ConsoleString lastLabel = null;
            for(int y = YAxisTop; y <= YAxisBottom; y+=2)
            {
                double yConverted = ConvertYPixelToValue(y);
                var label = YAxisValueCompactFormatter(yConverted);
                if(label.Length > MaxYAxisLabelLength)
                {
                    label = label.Substring(0, MaxYAxisLabelLength-1).AppendUsingCurrentFormat("_");
                }

                label = label.ToDifferentBackground(Background);

                var labelLeft = YAxisLeftOffset - 1 - label.Length;

                if (label != lastLabel)
                {
                    context.DrawString(label, labelLeft, y);
                    lastLabel = label;
                }
            }
        }
Exemple #10
0
        private void PaintInternal(ConsoleBitmap context)
        {
            if (this.Height < 5)
            {
                context.DrawString("Grid can't render in a space this small", 0, 0);
                return;
            }

            if (VisibleColumns.Count == 0)
            {
                context.DrawString(NoVisibleColumnsMessage.ToConsoleString(DefaultColors.H1Color), 0, 0);
                return;
            }

            List <ConsoleString>          headers           = new List <ConsoleString>();
            List <List <ConsoleString> >  rows              = new List <List <ConsoleString> >();
            List <ColumnOverflowBehavior> overflowBehaviors = new List <ColumnOverflowBehavior>();


            if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0)
            {
                foreach (var col in VisibleColumns)
                {
                    col.WidthPercentage = 1.0 / VisibleColumns.Count;
                }
            }

            foreach (var header in VisibleColumns)
            {
                headers.Add(header.ColumnDisplayName);
                var colWidth = (int)(header.WidthPercentage * this.Width);

                if (header.OverflowBehavior is SmartWrapOverflowBehavior)
                {
                    (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth;
                }
                else if (header.OverflowBehavior is TruncateOverflowBehavior)
                {
                    (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth == 0 ? colWidth : (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth;
                }

                overflowBehaviors.Add(header.OverflowBehavior);
            }

            int viewIndex = visibleRowOffset;

            foreach (var item in DataView.Items)
            {
                List <ConsoleString> row = new List <ConsoleString>();
                int columnIndex          = 0;
                foreach (var col in VisibleColumns)
                {
                    var value        = PropertyResolver(item, col.ColumnName.ToString());
                    var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString());

                    if (viewIndex == SelectedIndex && this.CanFocus)
                    {
                        if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex))
                        {
                            displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? DefaultColors.FocusColor : DefaultColors.SelectedUnfocusedColor);
                        }
                    }

                    row.Add(displayValue);
                    columnIndex++;
                }
                viewIndex++;
                rows.Add(row);
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            ConsoleString       table;

            table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter);


            if (FilterText != null)
            {
                table = table.Highlight(FilterText, DefaultColors.HighlightContrastColor, DefaultColors.HighlightColor, StringComparison.InvariantCultureIgnoreCase);
            }

            if (DataView.IsViewComplete == false)
            {
                table += "Loading more rows...".ToConsoleString(DefaultColors.H1Color);
            }
            else if (DataView.IsViewEndOfData && DataView.Items.Count == 0)
            {
                table += NoDataMessage.ToConsoleString(DefaultColors.H1Color);
            }
            else if (DataView.IsViewEndOfData)
            {
                if (ShowEndIfComplete)
                {
                    table += EndOfDataMessage.ToConsoleString(DefaultColors.H1Color);
                }
            }
            else
            {
                table += MoreDataMessage;
            }
            context.DrawString(table, 0, 0);


            if (FilteringEnabled)
            {
            }
        }
Exemple #11
0
 /// <summary>
 /// paints the button
 /// </summary>
 /// <param name="context">drawing context</param>
 protected override void OnPaint(ConsoleBitmap context) => context.DrawString(GetButtonDisplayString(), 0, 0);
Exemple #12
0
        /// <summary>
        /// paints the text box
        /// </summary>
        /// <param name="context"></param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var toPaint = textState.CurrentValue;
            var bgTransformed = new List<ConsoleCharacter>();

            foreach(var c in toPaint)
            {
                if(c.BackgroundColor == ConsoleString.DefaultBackgroundColor && Background != ConsoleString.DefaultBackgroundColor)
                {
                    bgTransformed.Add(new ConsoleCharacter(c.Value, Foreground, Background));
                }
                else
                {
                    bgTransformed.Add(c);
                }
            }

            context.DrawString(new ConsoleString(bgTransformed), 0, 0);

            if (blinkState)
            {
                char blinkChar = textState.CursorPosition >= toPaint.Length ? ' ' : toPaint[textState.CursorPosition].Value;
                context.Pen = new ConsoleCharacter(blinkChar, Application.Theme.FocusContrastColor, Application.Theme.FocusColor);
                context.DrawPoint(textState.CursorPosition, 0);
            }
        }
Exemple #13
0
 protected override void OnPaint(ConsoleBitmap context) => context.DrawString(_text, 0, 0);
Exemple #14
0
        /// <summary>
        /// paints the button
        /// </summary>
        /// <param name="context">drawing context</param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var drawState = new ConsoleString();

            drawState = "[".ToConsoleString(CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor, Background = Background);
            if (Text != null)
            {
                ConsoleColor fg, bg;

                var effectiveText = Text;
                if (effectiveText.IsUnstyled)
                {
                    if (HasFocus)
                    {
                        fg = DefaultColors.FocusContrastColor;
                        bg = DefaultColors.FocusColor;
                    }
                    else if (CanFocus)
                    {
                        fg = Foreground;
                        bg = Background;
                    }
                    else
                    {
                        fg = DefaultColors.DisabledColor;
                        bg = Background;
                    }
                    effectiveText = new ConsoleString(effectiveText.StringValue, fg, bg);
                }
                else if (HasFocus)
                {
                    effectiveText = effectiveText.ToDifferentBackground(DefaultColors.FocusColor);
                }

                drawState += effectiveText;

                if (Shortcut != null)
                {
                    if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Alt)
                    {
                        drawState += new ConsoleString($" (ALT+{Shortcut.Key})", CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Shift)
                    {
                        drawState += new ConsoleString($" (SHIFT+{Shortcut.Key})", CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Control)
                    {
                        drawState += new ConsoleString($" (CTL+{Shortcut.Key})", CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor);
                    }
                    else
                    {
                        drawState += new ConsoleString($" ({Shortcut.Key})", CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor);
                    }
                }
            }

            drawState += "]".ToConsoleString(CanFocus ? DefaultColors.H1Color : DefaultColors.DisabledColor, Background);
            Width      = drawState.Length;
            context.DrawString(drawState, 0, 0);
        }
Exemple #15
0
        private void PaintInternal(ConsoleBitmap context)
        {
            if (this.Height < 5)
            {
                context.DrawString("Grid can't render in a space this small", 0, 0);
                return;
            }

            if (VisibleColumns.Count == 0)
            {
                context.DrawString(NoVisibleColumnsMessage.ToConsoleString(Application.Theme.H1Color), 0, 0);
                return;
            }

            List<ConsoleString> headers = new List<ConsoleString>();
            List<List<ConsoleString>> rows = new List<List<ConsoleString>>();
            List<ColumnOverflowBehavior> overflowBehaviors = new List<ColumnOverflowBehavior>();

            if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0)
            {
                foreach (var col in VisibleColumns)
                {
                    col.WidthPercentage = 1.0 / VisibleColumns.Count;
                }
            }

            foreach (var header in VisibleColumns)
            {
                headers.Add(header.ColumnDisplayName);
                var colWidth = (int)(header.WidthPercentage * this.Width);

                if (header.OverflowBehavior is SmartWrapOverflowBehavior)
                {
                    (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth;
                }
                else if (header.OverflowBehavior is TruncateOverflowBehavior)
                {
                    (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = colWidth;
                }

                overflowBehaviors.Add(header.OverflowBehavior);
            }

            int viewIndex = visibleRowOffset;
            foreach (var item in DataView.Items)
            {
                List<ConsoleString> row = new List<ConsoleString>();
                int columnIndex = 0;
                foreach (var col in VisibleColumns)
                {
                    var value = PropertyResolver(item, col.ColumnName.ToString());
                    var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString());

                    if (viewIndex == SelectedIndex)
                    {
                        if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex))
                        {
                            displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? Application.Theme.FocusColor : Application.Theme.SelectedUnfocusedColor);
                        }
                    }

                    row.Add(displayValue);
                    columnIndex++;
                }
                viewIndex++;
                rows.Add(row);
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            ConsoleString table;
            #if PROFILING
            using (new TimeProfiler("Grid.FormatAsTable"))
            {
            #endif
                table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter);
            #if PROFILING
            }
            #endif

            if (FilterText != null)
            {
                table = table.Highlight(FilterText, Application.Theme.HighlightContrastColor, Application.Theme.HighlightColor, StringComparison.InvariantCultureIgnoreCase);
            }

            if (DataView.IsViewComplete == false)
            {
                table += "Loading more rows...".ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData && DataView.Items.Count == 0)
            {
                table += NoDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData)
            {
                table += EndOfDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else
            {
                table += "more data below".ToConsoleString(Application.Theme.H1Color);
            }
            context.DrawString(table, 0, 0);

            if (FilteringEnabled)
            {

            }
        }
Exemple #16
0
        /// <summary>
        /// paints the button
        /// </summary>
        /// <param name="context">drawing context</param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var drawState = new ConsoleString();

            drawState = "[".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background = Background);
            if (Text != null)
            {
                ConsoleColor fg, bg;

                if(HasFocus)
                {
                    fg = Application.Theme.FocusContrastColor;
                    bg = Application.Theme.FocusColor;
                }
                else if(CanFocus)
                {
                    fg = Foreground;
                    bg = Background;
                }
                else
                {
                    fg = Application.Theme.DisabledColor;
                    bg = Background;
                }

                drawState += new ConsoleString(Text, fg, bg);

                if(Shortcut != null)
                {
                    if(Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Alt)
                    {
                        drawState += new ConsoleString($" (ALT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Shift)
                    {
                        drawState += new ConsoleString($" (SHIFT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Control)
                    {
                        drawState += new ConsoleString($" (CTL+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else
                    {
                        drawState += new ConsoleString($" ({Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                }
            }

            drawState += "]".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background);
            Width = drawState.Length;
            context.DrawString(drawState, 0, 0);
        }