Example #1
0
        public static void DrawRect(this IRenderFrame buffer, int xPos, int yPos, int width, int height, ConsoleColor forground, ConsoleColor background, RectPen p)
        {
            // Draw corners
            buffer[xPos, 0] = new ColoredKey(p.topLeft, forground, background);
            buffer[xPos, yPos + height - 1]             = new ColoredKey(p.bottomLeft, forground, background);
            buffer[xPos + width - 1, yPos]              = new ColoredKey(p.topRight, forground, background);
            buffer[xPos + width - 1, yPos + height - 1] = new ColoredKey(p.bottemRight, forground, background);

            //Draw top Line
            for (int x = xPos + 1; x < xPos + width - 1; x++)
            {
                buffer[x, yPos] = new ColoredKey(p.top, forground, background);
            }

            //Draw bottom Line
            for (int x = xPos + 1; x < xPos + width - 1; x++)
            {
                buffer[x, yPos + height - 1] = new ColoredKey(p.bottom, forground, background);
            }

            //Draw left Line
            for (int y = yPos + 1; y < yPos + height - 1; y++)
            {
                buffer[xPos, y] = new ColoredKey(p.left, forground, background);
            }

            //Draw right Line
            for (int y = yPos + 1; y < yPos + height - 1; y++)
            {
                buffer[xPos + width - 1, y] = new ColoredKey(p.right, forground, background);
            }
        }
Example #2
0
 public static void FillRect(this IRenderFrame buffer, int xPos, int yPos, int width, int height, ConsoleColor forground, ConsoleColor background, char c)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             buffer[x + xPos, y + yPos] = new ColoredKey((char)c, forground, background);
         }
     }
 }
Example #3
0
 private bool Equals(ColoredKey other)
 {
     return(other.Character == this.Character && other.forground == this.forground && other.background == this.background);
 }
Example #4
0
        private void RenderHorizontal(IRenderFrame frame)
        {
            int top, buttom;

            switch (VerticalAlignment)
            {
            case VerticalAlignment.Top:
                top    = 0;
                buttom = 0;
                break;

            case VerticalAlignment.Bottom:
                top    = frame.Height - 1;
                buttom = frame.Height - 1;
                break;

            case VerticalAlignment.Center:
                buttom = frame.Height / 2;
                top    = frame.Height / 2;
                break;

            case VerticalAlignment.Strech:
                top    = 0;
                buttom = frame.Height - 1;
                break;

            default:
                throw new NotSupportedException($"The value {HorizontalAlignment} is not expected in {typeof(HorizontalAlignment).FullName}");
            }
            for (var y = (int)MathEx.Max(top, frame.Clip.Top); y <= MathEx.Min(buttom, frame.Clip.Bottom); y++)
            {
                if (frame.Width == 1)
                {
                    frame[0, y] = new ColoredKey(Characters.Arrows.LEFT_RIGHT_ARROW, Foreground, Background);
                }
                else
                {
                    for (var x = (int)frame.Clip.Left; x < frame.Clip.Right; x++)
                    {
                        if (x == 0)
                        {
                            frame[0, y] = new ColoredKey(Characters.Arrows.LEFTWARDS_ARROW, Foreground, Background);
                        }
                        else if (x == frame.Width - 1)
                        {
                            frame[frame.Width - 1, y] = new ColoredKey(Characters.Arrows.RIGHTWARDS_ARROW, Foreground, Background);
                        }
                        else if (x == this.startPosition)
                        {
                            if (this.isBeginningFullBlock)
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                            }
                            else
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.LEFT_HALF_BLOCK, Foreground, Background);
                            }
                        }
                        else if (x == this.endPosition)
                        {
                            if (this.isEndingFullBlock)
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                            }
                            else
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.RIGHT_HALF_BLOCK, Foreground, Background);
                            }
                        }
                        else if (x > this.startPosition && x < this.endPosition && this.startPosition != -1 && this.endPosition != -1)
                        {
                            frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                        }
                        else
                        {
                            frame[x, y] = new ColoredKey(' ', Foreground, Background);
                        }
                    }
                }
            }
        }
Example #5
0
        private void RenderVertical(IRenderFrame frame)
        {
            int left, right;

            switch (HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                left  = 0;
                right = 0;
                break;

            case HorizontalAlignment.Right:
                left  = frame.Width - 1;
                right = frame.Width - 1;
                break;

            case HorizontalAlignment.Center:
                right = frame.Width / 2;
                left  = frame.Width / 2;
                break;

            case HorizontalAlignment.Strech:
                left  = 0;
                right = frame.Width - 1;
                break;

            default:
                throw new NotSupportedException($"The value {HorizontalAlignment} is not expected in {typeof(HorizontalAlignment).FullName}");
            }
            for (var x = (int)MathEx.Max(left, frame.Clip.Left); x <= MathEx.Min(right, frame.Clip.Right); x++)
            {
                if (frame.Height == 1)
                {
                    frame[x, 0] = new ColoredKey(Characters.Arrows.UP_DOWN_ARROW, Foreground, Background);
                }
                else
                {
                    for (var y = (int)frame.Clip.Top; y < frame.Clip.Bottom; y++)
                    {
                        if (y == 0)
                        {
                            frame[x, 0] = new ColoredKey(Characters.Arrows.UPWARDS_ARROW, Foreground, Background);
                        }
                        else if (y == frame.Height - 1)
                        {
                            frame[x, frame.Height - 1] = new ColoredKey(Characters.Arrows.DOWNWARDS_ARROW, Foreground, Background);
                        }
                        else if (y == this.startPosition)
                        {
                            if (this.isBeginningFullBlock)
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                            }
                            else
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.LOWER_HALF_BLOCK, Foreground, Background);
                            }
                        }
                        else if (y == this.endPosition)
                        {
                            if (this.isEndingFullBlock)
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                            }
                            else
                            {
                                frame[x, y] = new ColoredKey(Characters.Block.UPPER_HALF_BLOCK, Foreground, Background);
                            }
                        }
                        else if (y > this.startPosition && y < this.endPosition && this.startPosition != -1 && this.endPosition != -1)
                        {
                            frame[x, y] = new ColoredKey(Characters.Block.FULL_BLOCK, Foreground, Background);
                        }
                        else
                        {
                            frame[x, y] = new ColoredKey(' ', Foreground, Background);
                        }
                    }
                }
            }
        }