コード例 #1
0
        /// <summary>
        /// Write highlighted text
        /// </summary>
        /// <param name="text">Text</param>
        /// <param name="textAlignment">Text alignment</param>
        /// <param name="foregroundColor">Foreground color</param>
        /// <param name="backgroundColor">Background color</param>
        /// <param name="highlightForegroundColor">Highlight foreground color</param>
        /// <param name="highlightBackgroundColor">Highlight background color</param>
        /// <param name="startHighlight">Start highlight</param>
        /// <param name="highlightSize">Highlight size</param>
        /// <param name="allowTransparency">Allow transparency</param>
        /// <param name="buffer">Buffer</param>
        /// <param name="rectangle">Rectangle</param>
        internal static void WriteHighlightedText(string text, ETextAlignment textAlignment, ConsoleColor foregroundColor, ConsoleColor backgroundColor, ConsoleColor highlightForegroundColor, ConsoleColor highlightBackgroundColor, uint startHighlight, uint highlightSize, bool allowTransparency, BufferCell[,] buffer, RectInt rectangle)
        {
            BufferCell empty_cell             = new BufferCell(BufferCell.empty.Character, foregroundColor, backgroundColor);
            BufferCell highlighted_empty_cell = new BufferCell(BufferCell.empty.Character, highlightForegroundColor, highlightBackgroundColor);

            For(new Vector2Int(buffer.GetLength(0), buffer.GetLength(1)), new RectInt(rectangle.X, rectangle.Y, rectangle.Width, Math.Min(rectangle.Height, 1)), (x, y) =>
            {
                bool show      = true;
                int index      = x;
                bool highlight = ((x >= startHighlight) && (x < (startHighlight + highlightSize)));
                switch (textAlignment)
                {
                case ETextAlignment.TopCenter:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == 0);
                    break;

                case ETextAlignment.TopRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == 0);
                    break;

                case ETextAlignment.CenterLeft:
                    show = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.Center:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.CenterRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.BottomLeft:
                    show = (y == (rectangle.Height - 1));
                    break;

                case ETextAlignment.BottomCenter:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == (rectangle.Height - 1));
                    break;

                case ETextAlignment.BottomRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == (rectangle.Height - 1));
                    break;
                }
                BufferCell cell = (show ? (((index < 0) || (index >= text.Length)) ? (highlight ? highlighted_empty_cell : empty_cell) : new BufferCell(text[index], highlight ? highlightForegroundColor : foregroundColor, highlight ? highlightBackgroundColor : backgroundColor)) : empty_cell);
                if ((cell.Character != BufferCell.empty.Character) || (!allowTransparency))
                {
                    buffer[rectangle.X + x, rectangle.Y + y] = cell;
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Write text
        /// </summary>
        /// <param name="text">Text</param>
        /// <param name="textAlignment">Text alignment</param>
        /// <param name="foregroundColor">Foreground color</param>
        /// <param name="backgroundColor">Background color</param>
        /// <param name="allowTransparency">Allow transparency</param>
        /// <param name="buffer">Buffer</param>
        /// <param name="rectangle">Rectangle</param>
        internal static void WriteText(string text, ETextAlignment textAlignment, ConsoleColor foregroundColor, ConsoleColor backgroundColor, bool allowTransparency, BufferCell[,] buffer, RectInt rectangle)
        {
            BufferCell empty_cell = new BufferCell(BufferCell.empty.Character, foregroundColor, backgroundColor);

            For(new Vector2Int(buffer.GetLength(0), buffer.GetLength(1)), rectangle, (x, y) =>
            {
                bool show = true;
                int index = x;
                switch (textAlignment)
                {
                case ETextAlignment.TopCenter:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == 0);
                    break;

                case ETextAlignment.TopRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == 0);
                    break;

                case ETextAlignment.CenterLeft:
                    show = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.Center:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.CenterRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == (rectangle.Height / 2));
                    break;

                case ETextAlignment.BottomLeft:
                    show = (y == (rectangle.Height - 1));
                    break;

                case ETextAlignment.BottomCenter:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    show  = (y == (rectangle.Height - 1));
                    break;

                case ETextAlignment.BottomRight:
                    index = x - (rectangle.Width - text.Length);
                    show  = (y == (rectangle.Height - 1));
                    break;
                }
                BufferCell cell = (show ? (((index < 0) || (index >= text.Length)) ? empty_cell : new BufferCell(text[index], foregroundColor, backgroundColor)) : empty_cell);
                if ((cell.Character != BufferCell.empty.Character) || (!allowTransparency))
                {
                    buffer[rectangle.X + x, rectangle.Y + y] = cell;
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// Write text lines
        /// </summary>
        /// <param name="textLines">Text lines</param>
        /// <param name="textAlignment">Text alignment</param>
        /// <param name="foregroundColor">Foreground color</param>
        /// <param name="backgroundColor">Background color</param>
        /// <param name="allowTransparency">Allow transparency</param>
        /// <param name="buffer">Buffer</param>
        /// <param name="rectangle">Rectangle</param>
        internal static void WriteTextLines(IReadOnlyList <string> textLines, ETextAlignment textAlignment, ConsoleColor foregroundColor, ConsoleColor backgroundColor, bool allowTransparency, BufferCell[,] buffer, RectInt rectangle)
        {
            BufferCell empty_cell = new BufferCell(BufferCell.empty.Character, foregroundColor, backgroundColor);

            For(new Vector2Int(buffer.GetLength(0), buffer.GetLength(1)), rectangle, (x, y) =>
            {
                int row     = y;
                int index   = x;
                string text = string.Empty;
                switch (textAlignment)
                {
                case ETextAlignment.TopLeft:
                case ETextAlignment.TopCenter:
                case ETextAlignment.TopRight:
                    text = (((row < 0) || (row >= textLines.Count)) ? string.Empty : ((textLines[row] == null) ? string.Empty : textLines[row]));
                    break;

                case ETextAlignment.CenterLeft:
                case ETextAlignment.Center:
                case ETextAlignment.CenterRight:
                    row  = y - ((rectangle.Height - textLines.Count) / 2);
                    text = (((row < 0) || (row >= textLines.Count)) ? string.Empty : ((textLines[row] == null) ? string.Empty : textLines[row]));
                    break;

                case ETextAlignment.BottomLeft:
                case ETextAlignment.BottomCenter:
                case ETextAlignment.BottomRight:
                    row  = y - (rectangle.Height - textLines.Count);
                    text = (((row < 0) || (row >= textLines.Count)) ? string.Empty : ((textLines[row] == null) ? string.Empty : textLines[row]));
                    break;
                }
                switch (textAlignment)
                {
                case ETextAlignment.TopCenter:
                case ETextAlignment.Center:
                case ETextAlignment.BottomCenter:
                    index = x - ((rectangle.Width - text.Length) / 2);
                    break;

                case ETextAlignment.TopRight:
                case ETextAlignment.CenterRight:
                case ETextAlignment.BottomRight:
                    index = x - (rectangle.Width - text.Length);
                    break;
                }
                BufferCell cell = (((index < 0) || (index >= text.Length)) ? empty_cell : new BufferCell(text[index], foregroundColor, backgroundColor));
                if ((cell.Character != BufferCell.empty.Character) || (!allowTransparency))
                {
                    buffer[rectangle.X + x, rectangle.Y + y] = cell;
                }
            });
        }
コード例 #4
0
            public static string Alignment(ETextAlignment alignment, string data, int length, char alignWith = SpaceChar)
            {
                switch (alignment)
                {
                case ETextAlignment.Left:
                    return(Left(data, length, alignWith));

                case ETextAlignment.Center:
                    return(Center(data, length, alignWith));

                case ETextAlignment.Right:
                    return(Right(data, length, alignWith));

                default:
                    throw new ArgumentOutOfRangeException(nameof(alignment));
                }
            }