예제 #1
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);
        }
예제 #2
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);
        }