public static void Draw(ConsoleArea window, int x, int y, int width, int height)
        {
            if (width < 2 || height < 2)
            {
                return;
            }
            var left   = x - width / 2;
            var right  = left + width - 1;
            var top    = y - height / 2;
            var bottom = top + height - 1;

            window.Move(new Position(left, top));
            window.AddCharacter(BoxDrawing.ULCORNER);
            window.RepeatCharacter(BoxDrawing.HLINE, width - 2);
            window.AddCharacter(BoxDrawing.URCORNER);

            window.Move(new Position(left, top + 1));
            window.RepeatCharacterVertical(BoxDrawing.VLINE, height - 2);
            window.Move(new Position(right, top + 1));
            window.RepeatCharacterVertical(BoxDrawing.VLINE, height - 2);

            window.Move(new Position(left, bottom));
            window.AddCharacter(BoxDrawing.LLCORNER);
            window.RepeatCharacter(BoxDrawing.HLINE, width - 2);
            window.AddCharacter(BoxDrawing.LRCORNER);
        }
Exemple #2
0
        public static int Draw(ConsoleArea window, string text, int cursorX, int characterCount, TextAlign align)
        {
            var textToDisplay = TruncateString(text, align, characterCount);

            var spaces          = characterCount - textToDisplay.Length;
            var spacesBefore    = 0;
            var spacesAfter     = 0;
            var adjustedCursorX = cursorX;

            switch (align)
            {
            case TextAlign.Left:
                spacesAfter = spaces;
                break;

            case TextAlign.Center:
                spacesBefore     = spaces / 2;
                spacesAfter      = spaces - spacesBefore;
                adjustedCursorX += spacesBefore;
                break;

            case TextAlign.Right:
                spacesBefore    = spaces;
                adjustedCursorX = spacesBefore - cursorX;
                break;
            }
            window.ClearCharacters(spacesBefore);
            window.AddString(textToDisplay);
            window.ClearCharacters(spacesAfter);

            return(adjustedCursorX);
        }
Exemple #3
0
        public void Copy(ConsoleArea window, Position offset)
        {
            var minHeight = Math.Min(window.Size.Height, Size.Height - offset.Y);
            var minWidth  = Math.Min(window.Size.Width, Size.Width - offset.X);

            for (var y = 0; y < minHeight; ++y)
            {
                for (var x = 0; x < minWidth; ++x)
                {
                    var position    = new Position(x, y);
                    var sourceIndex = window.GetCharacterIndex(position);

                    if (sourceIndex < 0)
                    {
                        continue;
                    }
                    var targetIndex = GetCharacterIndex(position + offset);

                    if (targetIndex < 0)
                    {
                        continue;
                    }
                    characters [targetIndex] = window.characters [sourceIndex];
                }
            }
        }
        public void Update(ConsoleArea window)
        {
            Console.CursorVisible = false;
            int lastX        = -1;
            int lastY        = -1;
            var updateHeight = Math.Min(window.Size.Height, screenWindow.Size.Height);
            var updateWidth  = Math.Min(window.Size.Width, screenWindow.Size.Width);

            var chars = window.ConsoleCharacters;

            for (var y = 0; y < updateHeight; ++y)
            {
                for (var x = 0; x < updateWidth; ++x)
                {
                    var position    = new Position(x, y);
                    var sourceIndex = window.GetCharacterIndex(position);
                    var sourceChar  = window.ConsoleCharacters [sourceIndex];
                    var targetIndex = screenWindow.GetCharacterIndex(position);
                    var targetChar  = screenWindow.ConsoleCharacters [targetIndex];

                    if (!sourceChar.IsSame(targetChar))
                    {
                        if (x != lastX || y != lastY)
                        {
                            SetCursorPosition(x, y);
                        }
                        SetCharacterAndColor(sourceChar);
                        lastX = x + 1;
                        lastY = y;
                        screenWindow.ConsoleCharacters [targetIndex] = sourceChar;
                    }
                }
            }
            _driver.Move(window.CursorPosition);
            _driver.Refresh();
            // Console.CursorVisible = true;
        }
 public ConsoleWindow(ConsoleArea area)
 {
 }
Exemple #6
0
 public ConsoleScrollWindow(Size size)
 {
     window = new ConsoleArea(size);
 }
 public ConsoleUpdater(IDriver driver, Size size)
 {
     _driver      = driver;
     screenWindow = new ConsoleArea(size);
 }