Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ MoveBufferArea()

static unsafe void System.ConsolePal.MoveBufferArea ( int sourceLeft,
int sourceTop,
int sourceWidth,
int sourceHeight,
int targetLeft,
int targetTop,
char sourceChar,
ConsoleColor sourceForeColor,
ConsoleColor sourceBackColor )
inlinestatic

Definition at line 716 of file ConsolePal.cs.

717 {
718 if (sourceForeColor < ConsoleColor.Black || sourceForeColor > ConsoleColor.White)
719 {
720 throw new ArgumentException(System.SR.Arg_InvalidConsoleColor, "sourceForeColor");
721 }
722 if (sourceBackColor < ConsoleColor.Black || sourceBackColor > ConsoleColor.White)
723 {
724 throw new ArgumentException(System.SR.Arg_InvalidConsoleColor, "sourceBackColor");
725 }
726 global::Interop.Kernel32.COORD dwSize = GetBufferInfo().dwSize;
727 if (sourceLeft < 0 || sourceLeft > dwSize.X)
728 {
729 throw new ArgumentOutOfRangeException("sourceLeft", sourceLeft, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
730 }
731 if (sourceTop < 0 || sourceTop > dwSize.Y)
732 {
733 throw new ArgumentOutOfRangeException("sourceTop", sourceTop, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
734 }
735 if (sourceWidth < 0 || sourceWidth > dwSize.X - sourceLeft)
736 {
737 throw new ArgumentOutOfRangeException("sourceWidth", sourceWidth, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
738 }
739 if (sourceHeight < 0 || sourceTop > dwSize.Y - sourceHeight)
740 {
741 throw new ArgumentOutOfRangeException("sourceHeight", sourceHeight, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
742 }
743 if (targetLeft < 0 || targetLeft > dwSize.X)
744 {
745 throw new ArgumentOutOfRangeException("targetLeft", targetLeft, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
746 }
747 if (targetTop < 0 || targetTop > dwSize.Y)
748 {
749 throw new ArgumentOutOfRangeException("targetTop", targetTop, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries);
750 }
751 if (sourceWidth == 0 || sourceHeight == 0)
752 {
753 return;
754 }
755 global::Interop.Kernel32.CHAR_INFO[] array = new global::Interop.Kernel32.CHAR_INFO[sourceWidth * sourceHeight];
756 dwSize.X = (short)sourceWidth;
757 dwSize.Y = (short)sourceHeight;
758 global::Interop.Kernel32.COORD bufferCoord = default(global::Interop.Kernel32.COORD);
759 global::Interop.Kernel32.SMALL_RECT readRegion = default(global::Interop.Kernel32.SMALL_RECT);
760 readRegion.Left = (short)sourceLeft;
761 readRegion.Right = (short)(sourceLeft + sourceWidth - 1);
762 readRegion.Top = (short)sourceTop;
763 readRegion.Bottom = (short)(sourceTop + sourceHeight - 1);
764 bool flag;
765 fixed (global::Interop.Kernel32.CHAR_INFO* pBuffer = array)
766 {
767 flag = global::Interop.Kernel32.ReadConsoleOutput(OutputHandle, pBuffer, dwSize, bufferCoord, ref readRegion);
768 }
769 if (!flag)
770 {
772 }
773 global::Interop.Kernel32.COORD cOORD = default(global::Interop.Kernel32.COORD);
774 cOORD.X = (short)sourceLeft;
775 global::Interop.Kernel32.Color color = ConsoleColorToColorAttribute(sourceBackColor, isBackground: true);
776 color |= ConsoleColorToColorAttribute(sourceForeColor, isBackground: false);
777 short wColorAttribute = (short)color;
778 for (int i = sourceTop; i < sourceTop + sourceHeight; i++)
779 {
780 cOORD.Y = (short)i;
781 if (!global::Interop.Kernel32.FillConsoleOutputCharacter(OutputHandle, sourceChar, sourceWidth, cOORD, out var pNumCharsWritten))
782 {
784 }
785 if (!global::Interop.Kernel32.FillConsoleOutputAttribute(OutputHandle, wColorAttribute, sourceWidth, cOORD, out pNumCharsWritten))
786 {
788 }
789 }
790 global::Interop.Kernel32.SMALL_RECT writeRegion = default(global::Interop.Kernel32.SMALL_RECT);
791 writeRegion.Left = (short)targetLeft;
792 writeRegion.Right = (short)(targetLeft + sourceWidth);
793 writeRegion.Top = (short)targetTop;
794 writeRegion.Bottom = (short)(targetTop + sourceHeight);
795 fixed (global::Interop.Kernel32.CHAR_INFO* buffer = array)
796 {
797 global::Interop.Kernel32.WriteConsoleOutput(OutputHandle, buffer, dwSize, bufferCoord, ref writeRegion);
798 }
799 }
static global::Interop.Kernel32.Color ConsoleColorToColorAttribute(ConsoleColor color, bool isBackground)
static IntPtr OutputHandle
static global::Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO GetBufferInfo()
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string ArgumentOutOfRange_ConsoleBufferBoundaries
Definition SR.cs:64
static string Arg_InvalidConsoleColor
Definition SR.cs:56
Definition SR.cs:7

References System.SR.Arg_InvalidConsoleColor, System.SR.ArgumentOutOfRange_ConsoleBufferBoundaries, System.array, System.buffer, System.ConsolePal.ConsoleColorToColorAttribute(), System.ConsolePal.GetBufferInfo(), System.IO.Win32Marshal.GetExceptionForWin32Error(), System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), and System.ConsolePal.OutputHandle.

Referenced by System.Console.MoveBufferArea(), and System.Console.MoveBufferArea().