Esempio n. 1
0
        public void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
                                   int targetLeft, int targetTop, Char sourceChar,
                                   ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
        {
            if (sourceForeColor < 0)
            {
                throw new ArgumentException("Cannot be less than 0.", "sourceForeColor");
            }

            if (sourceBackColor < 0)
            {
                throw new ArgumentException("Cannot be less than 0.", "sourceBackColor");
            }

            if (sourceWidth == 0 || sourceHeight == 0)
            {
                return;
            }

            ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();

            GetConsoleScreenBufferInfo(outputHandle, out info);
            CharInfo [] buffer = new CharInfo [sourceWidth * sourceHeight];
            Coord       bsize  = new Coord(sourceWidth, sourceHeight);
            Coord       bpos   = new Coord(0, 0);
            SmallRect   region = new SmallRect(sourceLeft, sourceTop, sourceLeft + sourceWidth - 1, sourceTop + sourceHeight - 1);

            fixed(void *ptr = &buffer[0])
            {
                if (!ReadConsoleOutput(outputHandle, ptr, bsize, bpos, ref region))
                {
                    throw new ArgumentException(String.Empty, "Cannot read from the specified coordinates.");
                }
            }

            int   written;
            short attr = GetAttrForeground(0, sourceForeColor);

            attr = GetAttrBackground(attr, sourceBackColor);
            bpos = new Coord(sourceLeft, sourceTop);
            for (int i = 0; i < sourceHeight; i++, bpos.Y++)
            {
                FillConsoleOutputCharacter(outputHandle, sourceChar, sourceWidth, bpos, out written);
                FillConsoleOutputAttribute(outputHandle, attr, sourceWidth, bpos, out written);
            }

            bpos   = new Coord(0, 0);
            region = new SmallRect(targetLeft, targetTop, targetLeft + sourceWidth - 1, targetTop + sourceHeight - 1);
            if (!WriteConsoleOutput(outputHandle, buffer, bsize, bpos, ref region))
            {
                throw new ArgumentException(String.Empty, "Cannot write to the specified coordinates.");
            }
        }
Esempio n. 2
0
        public void SetWindowSize(int width, int height)
        {
            ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();

            GetConsoleScreenBufferInfo(outputHandle, out info);
            SmallRect rect = info.Window;

            rect.Right  = (short)(rect.Left + width - 1);
            rect.Bottom = (short)(rect.Top + height - 1);
            if (!SetConsoleWindowInfo(outputHandle, true, ref rect))
            {
                throw new ArgumentOutOfRangeException("left/top", "Windows error " + Marshal.GetLastWin32Error());
            }
        }
Esempio n. 3
0
        public void SetWindowPosition(int left, int top)
        {
            ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();

            GetConsoleScreenBufferInfo(outputHandle, out info);
            SmallRect rect = info.Window;

            rect.Left = (short)left;
            rect.Top  = (short)top;
            if (!SetConsoleWindowInfo(outputHandle, true, ref rect))
            {
                throw new ArgumentOutOfRangeException("left/top", "Windows error " + Marshal.GetLastWin32Error());
            }
        }
Esempio n. 4
0
 // Create and fill in a multideminsional list with blank spaces.
 /// <summary>
 /// Consctructor class for the buffer. Pass in the width and height you want the buffer to be.
 /// </summary>
 /// <param name="Width"></param>
 /// <param name="Height"></param>
 public ConsoleBuffer(int Width, int Height, int wWidth, int wHeight)
 {
     if (Width > wWidth || Height > wHeight)
     {
         throw new System.ArgumentException("The buffer width and height can not be greater than the window width and height.");
     }
     h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
     width = Width;
     height = Height;
     windowWidth = wWidth;
     windowHeight = wHeight;
     buf = new CharInfo[width * height];
     rect = new SmallRect();
     rect.setDrawCord(0, 0);
     rect.setWindowSize((short)windowWidth, (short)windowHeight);
     Clear();
 }
		extern static bool ReadConsoleOutput (IntPtr handle, void *buffer, Coord bsize, Coord bpos, ref SmallRect region);
		extern static bool SetConsoleWindowInfo (IntPtr handle, bool absolute, ref SmallRect rect);
		public void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
					int targetLeft, int targetTop, Char sourceChar,
					ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
		{
			if (sourceForeColor < 0)
				throw new ArgumentException ("Cannot be less than 0.", "sourceForeColor");

			if (sourceBackColor < 0)
				throw new ArgumentException ("Cannot be less than 0.", "sourceBackColor");

			if (sourceWidth == 0 || sourceHeight == 0)
				return;

			ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo ();
			GetConsoleScreenBufferInfo (outputHandle, out info);
			CharInfo [] buffer = new CharInfo [sourceWidth * sourceHeight];
			Coord bsize = new Coord (sourceWidth, sourceHeight);
			Coord bpos = new Coord (0, 0);
			SmallRect region = new SmallRect (sourceLeft, sourceTop, sourceLeft + sourceWidth - 1, sourceTop + sourceHeight - 1);
			fixed (void *ptr = &buffer [0]) {
				if (!ReadConsoleOutput (outputHandle, ptr, bsize, bpos, ref region))
					throw new ArgumentException (String.Empty, "Cannot read from the specified coordinates.");
			}

			int written;
			short attr  = GetAttrForeground (0, sourceForeColor);
			attr  = GetAttrBackground (attr, sourceBackColor);
			bpos = new Coord (sourceLeft, sourceTop);
			for (int i = 0; i < sourceHeight; i++, bpos.Y++) {
				FillConsoleOutputCharacter (outputHandle, sourceChar, sourceWidth, bpos, out written);
				FillConsoleOutputAttribute (outputHandle, attr, sourceWidth, bpos, out written);
			}

			bpos = new Coord (0, 0);
			region = new SmallRect (targetLeft, targetTop, targetLeft + sourceWidth - 1, targetTop + sourceHeight - 1);
			if (!WriteConsoleOutput (outputHandle, buffer, bsize, bpos, ref region))
				throw new ArgumentException (String.Empty, "Cannot write to the specified coordinates.");
		}
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.CursorVisible = false;

            bool isTimeToQuit = false;

            short xLoc = 43;
            short yLoc = 5;

            SafeFileHandle h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            CharInfo[] buf = new CharInfo[80 * 25];
            SmallRect rect = new SmallRect() { Left = 0, Top = 0, Right = 80, Bottom = 25 };

            ConsoleKeyInfo cki = new ConsoleKeyInfo();

            Random r = new Random();
            int dir = r.Next(1, 4);

            while (isTimeToQuit == false)
            {
                if (!h.IsInvalid)
                {
                    for (int i = 0; i < buf.Length; ++i)
                    {
                        buf[i].Attributes = 7;
                        buf[i].Char.AsciiChar = 46;
                        if (i == (yLoc*80)+xLoc)
                        {
                            buf[i].Attributes = 7;
                            buf[i].Char.AsciiChar = 64;
                        }
                    }
                    if (Console.KeyAvailable == true)
                    {
                        cki = Console.ReadKey(true);
                        switch (cki.Key)
                        {
                            case ConsoleKey.LeftArrow:
                                xLoc--;
                                if (xLoc <= 0)
                                    xLoc = 0;
                                break;
                            case ConsoleKey.RightArrow:
                                xLoc++;
                                if (xLoc >= 79)
                                    xLoc = 79;
                                break;
                            case ConsoleKey.UpArrow:
                                yLoc--;
                                if (yLoc <= 0)
                                    yLoc = 0;
                                break;
                            case ConsoleKey.DownArrow:
                                yLoc++;
                                if (yLoc >= 24)
                                    yLoc = 24;
                                break;
                            case ConsoleKey.Escape:
                                isTimeToQuit = true;
                                break;
                            default:
                                break;
                        }
                    }

                    bool b = WriteConsoleOutput(h, buf,
                        new Coord() { X = 80, Y = 25 },
                        new Coord() { X = 0, Y = 0 },
                        ref rect);

                }
            }
        }
Esempio n. 9
0
 public static extern bool WriteConsoleOutput(
   SafeFileHandle hConsoleOutput,
   CharInfo[] lpBuffer,
   Coord dwBufferSize,
   Coord dwBufferCoord,
   ref SmallRect lpWriteRegion);
Esempio n. 10
0
 extern static bool WriteConsoleOutput(IntPtr handle, CharInfo [] buffer, Coord bsize, Coord bpos, ref SmallRect region);
Esempio n. 11
0
        private void Refresh()
        {
            SmallRect rect = new SmallRect() { Left = 0, Top = 0, Right = width_, Bottom = height_ };

            for (;;)
            {
                lock(sync_)
                {
                    if (dirty_)
                    {
                        Invert();
                        WriteConsoleOutput(handle_, buffer_, new Coord() {X = width_, Y = height_},
                            new Coord() {X = 0, Y = 0}, ref rect);
                        Invert();
                        dirty_ = false;
                    }
                }
                Thread.Sleep(50);
            }
        }
Esempio n. 12
0
 static bool SetConsoleWindowInfo(IntPtr handle, bool absolute, ref SmallRect rect)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 13
0
 static bool WriteConsoleOutput(IntPtr handle, CharInfo [] buffer, Coord bsize, Coord bpos, ref SmallRect region)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 14
0
 static bool ReadConsoleOutput(IntPtr handle, void *buffer, Coord bsize, Coord bpos, ref SmallRect region)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 15
0
		internal static extern bool ReadConsoleOutput(
			IntPtr hConsoleOutput,
			[Out] CharInfo[] lpBuffer,
			Coord dwBufferSize,
			Coord dwBufferCoord,
			ref SmallRect lpReadRegion);
Esempio n. 16
0
        /// <summary>
        /// Prepare the display for rendering.
        /// </summary>
        /// <param name="width">Desired horizontal size of the display in characters.</param>
        /// <param name="height">Desired vertical size of the display in characters.</param>
        protected override void OnInitialize(int width, int height)
        {
            var handle = GetConsoleWindow();

            if (handle == IntPtr.Zero) {
                AllocConsole();
            } else {
                ShowWindow(handle, SW_SHOW);
            }

            _handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            Console.SetWindowSize(Math.Min(width, Console.WindowWidth), Math.Min(height, Console.WindowHeight));

            Console.SetBufferSize(width, height);
            Console.SetWindowSize(width, height);

            Console.CursorVisible = false;

            _buffer = new CharInfo[width * height];
            _rect = new SmallRect { Left = 0, Top = 0, Right = (short) width, Bottom = (short) height };
        }
		extern static bool WriteConsoleOutput (IntPtr handle, CharInfo [] buffer, Coord bsize, Coord bpos, ref SmallRect region);
Esempio n. 18
0
 extern static bool SetConsoleWindowInfo(IntPtr handle, bool absolute, ref SmallRect rect);
		static bool SetConsoleWindowInfo (IntPtr handle, bool absolute, ref SmallRect rect)
		{
			throw new System.NotImplementedException();
		}
Esempio n. 20
0
        public static void Init(string title, int _w, int _h, int _frames)
        {
            w = _w;
            h = _h;
            frames = _frames;
            handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
            if (handle.IsInvalid)
                throw new Exception("Failed to init console.");
            buf = new CharInfo[w * h];
            rect = new SmallRect() { Left = 0, Top = 0, Right = (short)w, Bottom = (short)h };
            buf_size = new Coord((short)w, (short)h);
            buf_pos = new Coord(0, 0);

            long freql;
            if (!QueryPerformanceFrequency(out freql))
                throw new Exception("Failed to init timer.");
            freq = (double)freql;
            long timerl;
            QueryPerformanceCounter(out timerl);
            timer = (float)(timerl / freq);

            System.Console.CursorVisible = false;
            System.Console.SetWindowSize(w, h);
            System.Console.SetBufferSize(w, h);
            System.Console.Title = title;
        }
		static bool ReadConsoleOutput (IntPtr handle, void *buffer, Coord bsize, Coord bpos, ref SmallRect region)
		{
			throw new System.NotImplementedException();
		}
		static bool WriteConsoleOutput (IntPtr handle, CharInfo [] buffer, Coord bsize, Coord bpos, ref SmallRect region)
		{
			throw new System.NotImplementedException();
		}
Esempio n. 23
0
 extern static bool ReadConsoleOutput(IntPtr handle, void *buffer, Coord bsize, Coord bpos, ref SmallRect region);
Esempio n. 24
0
 static extern bool WriteConsoleOutput(
     IntPtr hConsoleOutput,
     CharInfo[] lpBuffer,
     Coord dwBufferSize,
     Coord dwBufferCoord,
     ref SmallRect lpWriteRegion);
		private void DrawBuffer(CharInfo[] buffer, short x, short y, short width, short height)
		{
			var rect = new SmallRect {Left = x, Top = y, Right = (short) (x + width - 1), Bottom = (short) (y + height - 1)};
			WriteConsoleOutput(_handle, buffer, new Coord(width, height), new Coord(0, 0), ref rect);
		}
Esempio n. 26
0
        public static void ChangeSize(int width, int height)
        {
            _dimensions.width = width;
            _dimensions.height = height;
            Console.WindowWidth = width;
            Console.BufferWidth = width;

            Console.WindowHeight = height;
            Console.BufferHeight = height;

            buffer = new CharInfo[Console.BufferHeight][];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = new CharInfo[Console.BufferWidth];
            }
            singleBuf = new CharInfo[buffer.Length * buffer[0].Length];
            rect = new SmallRect() { Left = 0, Top = 0, Right = (short)buffer[0].Length, Bottom = (short)buffer.Length };
            dwBufferSize = new Coord() { X = (short)Dimensions.width, Y = (short)Dimensions.height };
            dwBufferCoord = new Coord(0, 0);
        }
Esempio n. 27
0
        public void DrawBuffer()
        {
            if (!this.bufferHandle.IsInvalid)
            {
                SmallRect bufferRect = new SmallRect() { Left = 0, Top = 0, Right = this.bufferWidth, Bottom = this.bufferHeight };

                bool drawBuffer = WriteConsoleOutput(this.bufferHandle, this.buffer,
                    new Coord() { X = bufferWidth, Y = this.bufferHeight },
                    new Coord() { X = 0, Y = 0 },
                    ref bufferRect);
            }
        }
Esempio n. 28
0
 internal static extern bool SetConsoleWindowInfo(IntPtr hConsoleOutput, bool bAbsolute, ref SmallRect lpConsoleWindow);