Exemplo n.º 1
0
 public void Clear(char ch, ConsoleColor foreground, ConsoleColor background)
 {
     for (int i = 0; i < Width * Height; i++)
     {
         Buffer[i] = new ScreenBufferCharacter(ch, foreground, background, EnableUnderline);
     }
 }
Exemplo n.º 2
0
 public ScreenBuffer(ScreenBufferManager manager, int width, int height)
 {
     Manager = manager;
     Width   = width;
     Height  = height;
     Buffer  = new ScreenBufferCharacter[width * height];
     for (int i = 0; i < Buffer.Length; i++)
     {
         Buffer[i] = new ScreenBufferCharacter(' ', ConsoleColor.Gray, ConsoleColor.Black, EnableUnderline);
     }
 }
Exemplo n.º 3
0
        public void Clear(Rectangle rectangle)
        {
            Debug.Assert(
                rectangle.Left >= 0 &&
                rectangle.Top >= 0 &&
                rectangle.Right <= Width &&
                rectangle.Height <= Height);

            for (int y = rectangle.Top; y < rectangle.Bottom; y++)
            {
                for (int x = rectangle.Left; x < rectangle.Right; x++)
                {
                    Buffer[y * Width + x] = new ScreenBufferCharacter(' ', ConsoleColor.Gray, ConsoleColor.Black, EnableUnderline);
                }
            }
        }
Exemplo n.º 4
0
        public void Draw(int x, int y, string text, ConsoleColor foreground, ConsoleColor background)
        {
            int len = text.Length;

            if (x + len > Width)
            {
                len = Math.Max(0, Width - x);
            }

            Debug.Assert(x + len <= Width);
            Debug.Assert(y < Height);

            for (int i = 0; i < len; i++)
            {
                Buffer[y * Width + x + i] = new ScreenBufferCharacter(text[i], foreground, background, EnableUnderline);
            }
        }
Exemplo n.º 5
0
        public void Commit()
        {
            for (int y = 0; y < _display.Height; y++)
            {
                for (int x = 0; x < _display.Width; x++)
                {
                    var i = y * _display.Width + x;
                    ref ScreenBufferCharacter displayChar    = ref _display.Buffer[i];
                    ref ScreenBufferCharacter backbufferChar = ref Backbuffer.Buffer[i];

                    if (displayChar != backbufferChar)
                    {
                        displayChar = backbufferChar;

                        var ci = new Win32Console.CHAR_INFO();
                        ci.Character  = (byte)displayChar.Character;
                        ci.Attributes = GetAttributesFromColors(displayChar.Foreground, displayChar.Background);

                        if (displayChar.Underline)
                        {
                            ci.Attributes |= Win32Console.COMMON_LVB_UNDERSCORE;
                        }

                        var ci_array = new Win32Console.CHAR_INFO[1] {
                            ci
                        };

                        var rc = new Win32Console.SMALL_RECT((short)x, (short)y, (short)(x + 1), (short)(y + 1));
                        Debug.Assert(Win32Console.WriteConsoleOutput(
                                         _screenBuffer,
                                         ci_array,
                                         new Win32Console.COORD(1, 1), // dwBufferSize - width/height of the 2d ci_array
                                         new Win32Console.COORD(),     // dwBufferCoord
                                         ref rc));                     // lpWriteRegion - where to write to
                    }
                }
Exemplo n.º 6
0
 public void Draw(int x, int y, char ch, ConsoleColor foreground, ConsoleColor background)
 {
     Debug.Assert(x < Width);
     Debug.Assert(y < Height);
     Buffer[y * Width + x] = new ScreenBufferCharacter(ch, foreground, background, EnableUnderline);
 }