Exemplo n.º 1
0
 private static Native.COORD ConsPosToCOORDS(ConsolePos pos)
 {
     return(new Native.COORD()
     {
         x = pos.x, y = pos.y
     });
 }
Exemplo n.º 2
0
        public static void SetColor(int length, ConsolePos pos, ConsoleColor textColor, ConsoleColor backgroundColor)
        {
            int written = -1;

            Native.wAttribute attr = ColorsToWAttribute(textColor, backgroundColor);
            Native.FillConsoleOutputAttribute(outputHandle, attr, length, ConsPosToCOORDS(pos), ref written);
        }
Exemplo n.º 3
0
        public static ConsolePos GetBufferSize()
        {
            Native.CONSOLE_SCREEN_BUFFER_INFO info = new Native.CONSOLE_SCREEN_BUFFER_INFO();
            Native.GetConsoleScreenBufferInfo(outputHandle, ref info);
            ConsolePos size = new ConsolePos()
            {
                x = info.bufferSize.x,
                y = info.bufferSize.y
            };

            return(size);
        }
Exemplo n.º 4
0
        public static ConsolePos GetWindowSize()
        {
            Native.CONSOLE_SCREEN_BUFFER_INFO info = new Native.CONSOLE_SCREEN_BUFFER_INFO();
            Native.GetConsoleScreenBufferInfo(outputHandle, ref info);
            ConsolePos size = new ConsolePos()
            {
                x = (short)(info.visibleSegment.Right - info.visibleSegment.Left),
                y = (short)(info.visibleSegment.Bottom - info.visibleSegment.Top)
            };

            return(size);
        }
Exemplo n.º 5
0
        public static ConsolePos GetWindowPosition()
        {
            Native.CONSOLE_SCREEN_BUFFER_INFO info = new Native.CONSOLE_SCREEN_BUFFER_INFO();
            Native.GetConsoleScreenBufferInfo(outputHandle, ref info);
            ConsolePos pos = new ConsolePos()
            {
                x = info.visibleSegment.Left,
                y = info.visibleSegment.Top
            };

            return(pos);
        }
Exemplo n.º 6
0
        public static void CopyArrayToScreen(ConsChar[,] buffer, ConsolePos destPos)
        {
            short width  = (short)buffer.GetLength(0);
            short height = (short)buffer.GetLength(1);

            Native.SMALL_RECT rect = new Native.SMALL_RECT()
            {
                Top    = destPos.y,
                Left   = destPos.x,
                Right  = (short)(destPos.x + width - 1),
                Bottom = (short)(destPos.y + height - 1)
            };

            Native.CHAR_INFO[] outBuffer = new Native.CHAR_INFO[buffer.Length];
            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    Native.wAttribute attribute = ColorsToWAttribute(buffer[i, j].TextColor, buffer[i, j].BgColor);

                    Native.CHAR_INFO info = new Native.CHAR_INFO()
                    {
                        c    = (short)buffer[i, j].Character,
                        attr = attribute
                    };
                    outBuffer[i + buffer.GetLength(0) * j] = info;
                }
            }

            Native.COORD outBufferDim = new Native.COORD()
            {
                x = width, y = height
            };

            Native.WriteConsoleOutputW(outputHandle, outBuffer, outBufferDim, new Native.COORD()
            {
                x = 0, y = 0
            }, ref rect);
        }
Exemplo n.º 7
0
 public static void Write(string text, ConsolePos pos, ConsoleColor textColor, ConsoleColor backgroundColor)
 {
     Write(text, pos);
     SetColor(text.Length, pos, textColor, backgroundColor);
 }
Exemplo n.º 8
0
        public static void Write(string text, ConsolePos pos)
        {
            int written = -1;

            Native.WriteConsoleOutputCharacter(outputHandle, text, text.Length, ConsPosToCOORDS(pos), ref written);
        }