public void MoveBufferArea(int DataLeft, int DataTop, int DataWidth, int DataHeight, int DestX, int DestY, char FillChar, ConsoleColor FillForground, ConsoleColor FillBackground) { SmallRect Source = new SmallRect(DataLeft, DataTop, DataLeft + DataWidth - 1, DataTop + DataHeight - 1); Coord Destination = new Coord(DestX, DestY); CharInfo Fill = new CharInfo(FillChar, new CharacterAttribute(FillForground, FillBackground)); if (!WinAPI.ScrollConsoleScreenBuffer(BufferHandle, ref Source, IntPtr.Zero, Destination, ref Fill)) { throw new ConsoleExException("ConsoleEx: Unable to move data in screen buffer."); } }
public void SetWindowSize(int width, int height) { SmallRect NewWindow = ScreenBufferInfo.Window; NewWindow.Height = height; NewWindow.Width = width; if (!WinAPI.SetConsoleWindowInfo(BufferHandle, true, ref NewWindow)) { throw new ConsoleExException("ConsoleEx: Unable to set Console Window Info."); } }
public void MoveBufferArea(System.Drawing.Rectangle DataPos, System.Drawing.Rectangle ClippingPos, System.Drawing.Point DestinationLoc, char FillChar, ConsoleColor FillForground, ConsoleColor FillBackground) { SmallRect Source = new SmallRect(DataPos.Left, DataPos.Top, DataPos.Right, DataPos.Bottom); SmallRect Clipping = new SmallRect(ClippingPos.Left, ClippingPos.Top, ClippingPos.Right, ClippingPos.Bottom); Coord Destination = new Coord(DestinationLoc.X, DestinationLoc.Y); CharInfo Fill = new CharInfo(FillChar, new CharacterAttribute(FillForground, FillBackground)); if (!WinAPI.ScrollConsoleScreenBufferWithClipping(BufferHandle, ref Source, ref Clipping, Destination, ref Fill)) { throw new ConsoleExException("ConsoleEx: Unable to move data in screen buffer."); } }
public int ReadPos(CharInfo[,] Buffer, int BufferOffsetX, int BufferOffsetY, int PosLeft, int PosTop, int PosRight, int PosBottom) { Coord BufferSize = new Coord(Buffer.GetLength(1), Buffer.GetLength(0)); Coord BufferPos = new Coord(BufferOffsetX, BufferOffsetY); SmallRect Region = new SmallRect(PosLeft, PosTop, PosRight, PosBottom); if (!WinAPI.ReadConsoleOutput(BufferHandle, Buffer, BufferSize, BufferPos, ref Region)) { throw new ConsoleExException("ConsoleEx: Unable to read from screen buffer."); } return(Region.Height * Region.Width); }
public ScreenBuffer(ScreenBuffer CloneFrom, bool CopyContents = false) : this() { Mode = CloneFrom.Mode; ConsoleScreenBufferInfoEx TempBufferInfo = CloneFrom.ScreenBufferInfo; ScreenBufferInfo = TempBufferInfo; CursorSize = CloneFrom.CursorSize; CursorVisible = CloneFrom.CursorVisible; CursorLeft = CloneFrom.CursorLeft; CursorTop = CloneFrom.CursorTop; if (CopyContents) { // ReadConsoleOutput has a soft limited of 64K of data, but can go lower depending on heap usage. // Because of that we will limit ourselves to 32k per a copy, which works out to 8192 CharInfos. // So we will calculate the best size of buffer to fit into that. short BufferBlockWidth = TempBufferInfo.BufferSize.X; short BufferBlockHeight = (short)(0x2000 / TempBufferInfo.BufferSize.X); CharInfo[,] Buffer = new CharInfo[BufferBlockHeight, BufferBlockWidth]; Coord BufferSize = new Coord(BufferBlockWidth, BufferBlockHeight); Coord BufferPos = new Coord(0, 0); SmallRect Region = new SmallRect(0, 0, BufferSize.X - 1, BufferBlockHeight - 1); while (Region.Top <= TempBufferInfo.BufferSize.Y) { if (!WinAPI.ReadConsoleOutput(CloneFrom.BufferHandle, Buffer, BufferSize, BufferPos, ref Region)) { throw new ConsoleExException("ConsoleEx: Unable to read source screen buffer."); } if (!WinAPI.WriteConsoleOutput(BufferHandle, Buffer, BufferSize, BufferPos, ref Region)) { throw new ConsoleExException("ConsoleEx: Unable to write to screen buffer."); } Region.Top += BufferBlockHeight; Region.Bottom += BufferBlockHeight; } } OriginalAttributes = Attribute; }
public void SetWindowPosition(int left, int top) { SmallRect NewWindow = ScreenBufferInfo.Window; int OldWidth = NewWindow.Width; int OldHeight = NewWindow.Height; NewWindow.Left = (short)left; NewWindow.Top = (short)top; NewWindow.Width = OldWidth; NewWindow.Height = OldHeight; if (!WinAPI.SetConsoleWindowInfo(BufferHandle, true, ref NewWindow)) { throw new ConsoleExException("ConsoleEx: Unable to set Console Window Info."); } }
private static void Draw() { for (int y = 0; y < 25; y++) { for (int x = 0; x < 80; x++) { if (PreBuffer[x, y] == null) { Buffer[y * 80 + x] = Background.Value; } else { Buffer[y * 80 + x] = PreBuffer[x, y].Value; } } } SmallRect rect = new SmallRect() { Left = 0, Top = 0, Right = 80, Bottom = 25 }; //Create a rectangle for ConsoleWIndow bool b = WriteConsoleOutputW(h, Buffer, new Coord() { X = 80, Y = 25 }, new Coord() { X = 0, Y = 0 }, ref rect); //Reset prebuffer PreBuffer = new IDrawableUnit[80, 25]; }
static public extern bool ScrollConsoleScreenBufferWithClipping(Microsoft.Win32.SafeHandles.SafeFileHandle ConsoleOutput, ref SmallRect ScrollRectangle, ref SmallRect ClippingRectangle, Coord DestinationOrigin, ref CharInfo Fill);
static public extern bool ScrollConsoleScreenBuffer(Microsoft.Win32.SafeHandles.SafeFileHandle ConsoleOutput, ref SmallRect ScrollRectangle, IntPtr Reserved, Coord DestinationOrigin, ref CharInfo Fill);
static public extern bool WriteConsoleOutput(Microsoft.Win32.SafeHandles.SafeFileHandle ConsoleOutput, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] CharInfo[,] Buffer, Coord BufferSize, Coord BufferCoord, ref SmallRect WriteRegion);
static public extern bool SetConsoleWindowInfo(Microsoft.Win32.SafeHandles.SafeFileHandle ConsoleOutput, bool Absolute, ref SmallRect ConsoleWindow);
public static extern bool GetWindowRect(IntPtr hWnd, out SmallRect lpRect);
public static extern bool WriteConsoleOutputW( SafeFileHandle hConsoleOutput, CharInfo[] lpBuffer, Coord dwBufferSize, Coord dwBufferCoord, ref SmallRect lpWriteRegion);