public unsafe static void CreateConsole(int height, int width, string appName)
        {
            //set console
            ScreenHeight = height;
            ScreenWidth  = width;
            buf          = new CharInfo[ScreenHeight * ScreenWidth];
            rect         = new SmallRect()
            {
                Left = 0, Top = 0, Right = (short)ScreenWidth, Bottom = (short)ScreenHeight
            };
            AppName = appName;

            /*string font = "Consolas";
             *
             * FontInfo before = new FontInfo
             * {
             *  cbSize = Marshal.SizeOf<FontInfo>()
             * };
             *
             * FontInfo set = new FontInfo
             * {
             *  cbSize = Marshal.SizeOf<FontInfo>(),
             *  Font = 0,
             *  FontSize = new Coord(10, 10), //fontSize > 0 ? fontSize : before.FontSize
             *  FontFamily = FF_DONTCARE,
             *  FontWeight = TMPF_TRUETYPE,
             *  FontName = font,
             * };
             *
             * SetCurrentConsoleFontEx(Consoleh, false, ref set);*/
        }
Example #2
0
 static extern bool WriteConsoleOutput(
     IntPtr hConsoleOutput,
     CharInfo [] lpBuffer,
     Coord dwBufferSize,
     Coord dwBufferCoord,
     ref SmallRect lpWriteRegion
     );
Example #3
0
    public void print()
    {
        Console.WindowHeight = Console.LargestWindowHeight;
        Console.WindowWidth  = Console.LargestWindowWidth;
        SafeFileHandle h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

        if (!h.IsInvalid)
        {
            CharInfo[] buf  = new CharInfo[width * height];
            SmallRect  rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = width, Bottom = height
            };
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    buf[x + y * width].Attributes       = (short)(0 | ((int)framedata[x, y] << 4));
                    buf[x + y * width].Char.UnicodeChar = ' ';
                }
            }

            WriteConsoleOutput(h, buf,
                               new Coord()
            {
                X = width, Y = height
            },
                               new Coord()
            {
                X = 0, Y = 0
            },
                               ref rect);
        }
    }
Example #4
0
        public void Render()
        {
            var consoleRect = new SmallRect(0, 0, (short)Width, (short)Height);

            WriteConsoleOutput(consoleHandle, frameBuffer, new Coord((short)Width, (short)Height), new Coord(0, 0),
                               ref consoleRect);
        }
Example #5
0
 private static extern bool WriteConsoleOutput(
     SafeFileHandle hConsoleOutput,
     CharInfo[] lpBuffer,
     Coord dwBufferSize,
     Coord dwBufferCoord,
     ref SmallRect lpWriteRegion
     );
Example #6
0
    public static void Write(string line, CharacterAttribute attribute, short xLoc, short yLoc)
    {
        SafeFileHandle h           = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
        short          writeHeight = 1;
        short          writeWidth  = (short)line.Length;

        if (!h.IsInvalid)
        {
            CharInfo[] buf  = new CharInfo[writeWidth * writeHeight];
            SmallRect  rect = new SmallRect()
            {
                Left = xLoc, Top = yLoc, Right = (short)(writeWidth + xLoc), Bottom = (short)(writeHeight + yLoc)
            };
            for (int i = 0; i < writeWidth; i++)
            {
                buf[i].Attributes       = (ushort)attribute;
                buf[i].Char.UnicodeChar = line[i];
            }
            bool b = WriteConsoleOutput(h, buf, new Coord()
            {
                X = writeWidth, Y = writeHeight
            }, new Coord()
            {
                X = 0, Y = 0
            }, ref rect);
        }
    }
Example #7
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);
            }
        }
Example #8
0
 public static void Update(ref SmallRect rect, short col, short row)
 {
     if (rect.Left == -1)
     {
         //System.Diagnostics.Debugger.Log (0, "debug", $"damager From Empty {col},{row}\n");
         rect.Left   = rect.Right = col;
         rect.Bottom = rect.Top = row;
         return;
     }
     if (col >= rect.Left && col <= rect.Right && row >= rect.Top && row <= rect.Bottom)
     {
         return;
     }
     if (col < rect.Left)
     {
         rect.Left = col;
     }
     if (col > rect.Right)
     {
         rect.Right = col;
     }
     if (row < rect.Top)
     {
         rect.Top = row;
     }
     if (row > rect.Bottom)
     {
         rect.Bottom = row;
     }
     //System.Diagnostics.Debugger.Log (0, "debug", $"Expanding {rect.ToString ()}\n");
 }
Example #9
0
        static bool CompareBuffers(out SmallRect rect)
        {
            bool refresh = false;

            rect = new SmallRect {
                Left = short.MaxValue, Top = short.MaxValue, Right = short.MinValue, Bottom = short.MinValue
            };

            for (short y = 0; y < maxSizeY; y++)
            {
                for (short x = 0; x < maxSizeX; x++)
                {
                    int i = x + y * SIZEX;
                    if (!buf[i].Equals(previousBuf[i]))
                    {
                        refresh     = true;
                        rect.Left   = Math.Min(rect.Left, x);
                        rect.Top    = Math.Min(rect.Top, y);
                        rect.Right  = Math.Max(rect.Right, x);
                        rect.Bottom = Math.Max(rect.Bottom, y);
                    }
                }
            }

            return(refresh);
        }
        /// <summary>
        /// Initilises the Virtual screen.
        /// </summary>
        /// <param name="w">width of the screen</param>
        /// <param name="h">height of the screen</param>
        public CompactGraphics(int w, int h)
        {
            // Initilisation=================================
            int[] wh = ScreenTest(w, h);
            Console.SetWindowSize(wh[0], wh[1]);
            Console.SetBufferSize(wh[0], wh[1]);
            Console.CursorVisible = false;
            //Console.OutputEncoding = System.Text.Encoding.ASCII;
            currentFrame = new TFrame(w, h);
            frameQueue   = new Queue <TFrame>();
            buf          = new CharInfo[w * h];
            rect         = new SmallRect()
            {
                Left = 0, Top = 0, Right = (short)w, Bottom = (short)h
            };
            this.f = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            FPS_FrameGet = new FrameTimeDelegate(FTFPS);

            Height         = h;
            Width          = w;
            maxQueueLength = 3;
            //thread creation================================
            ThreadStart fpsth = new ThreadStart(updateFps);

            updateFpsThread = new Thread(fpsth);
            updateFpsThread.IsBackground = true;
            updateFpsThread.Start();

            ThreadStart thref = new ThreadStart(FrameUpdater);

            updateThread = new Thread(thref);
            updateThread.IsBackground = true;
            updateThread.Start();
        }
Example #11
0
        public void TestOutput()
        {
            CharInfo[] buf  = new CharInfo[80 * 25];
            SmallRect  rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = 80, Bottom = 25
            };

            for (byte character = 65; character < 65 + 26; ++character)
            {
                for (int i = 0; i < buf.Length; ++i)
                {
                    buf[i].Attributes     = ColorToAttribute(new PInfo().SetBg(ConsoleColor.Red).SetFg(ConsoleColor.Yellow));
                    buf[i].Char.AsciiChar = CharToByte('a');
                }

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


                System.Threading.Thread.Sleep(100);
            }
        }
Example #12
0
        public static void Write(ConsoleBuffer buffer)
        {
            var handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            if (handle.IsInvalid)
            {
                throw new InvalidOperationException("Unable to create file handle for console output");
            }

            var buf  = new CharInfo[buffer.Size.Width * buffer.Size.Height];
            var rect = new SmallRect(0, 0, (short)buffer.Size.Width, (short)buffer.Size.Height);

            for (var y = 0; y < buffer.Size.Height; y++)
            {
                for (var x = 0; x < buffer.Size.Width; x++)
                {
                    if (!buffer[x, y].HasValue)
                    {
                        return;
                    }

                    buf[x + y * buffer.Size.Width].Char.UnicodeChar = buffer[x, y].Value.Value;
                    buf[x + y * buffer.Size.Width].Attributes       = (short)((int)buffer[x, y].Value.ForegroundColor | ((int)buffer[x, y].Value.BackgroundColor << 4));
                }
            }

            WriteConsoleOutput(handle, buf, new Coord((short)buffer.Size.Width, (short)buffer.Size.Height), new Coord(0, 0), ref rect);
        }
Example #13
0
        private static void CreateBuffer(short width, short height, out SafeFileHandle handle, out CharInfo[] buffer, out SmallRect rect)
        {
            handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
            buffer = new CharInfo[width * height];
            rect   = new SmallRect()
            {
                Left = 0, Top = 0, Right = width, Bottom = height
            };
            var rand = new Random();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var b = rand.Next(0, 100) > 90;
                    buffer[x + width * y] = new CharInfo
                    {
                        Attributes = (short)CharAttribute.FOREGROUND_GREEN,
                        Char       = new CharUnion
                        {
                            UnicodeChar = b ? 'I' : '_',
                        }
                    };
                }
            }
        }
Example #14
0
        public Display(int width, int height, int boardSize)
        {
            this.width     = width;
            this.height    = height;
            this.boardSize = boardSize;

            this.file = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
            this.rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = (short)width, Bottom = (short)height
            };
            this.c1 = new Coord()
            {
                X = (short)width, Y = (short)height
            };
            this.c2 = new Coord()
            {
                X = 0, Y = 0
            };

            this.playersBoardStart = new int[] { 10, 6 };
            this.botsBoardStart    = new int[] { 75, 6 };
            this.logs = new Queue <String>(10);
            for (int i = 0; i < 10; ++i)
            {
                logs.Enqueue("");
            }
            InitInterface(width, height);
        }
Example #15
0
        public Display(int width, int height)
        {
            this.width     = width;
            this.height    = height;
            this.boardSize = 0;

            this.file = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
            this.rect = new SmallRect()
            {
                Left   = 0,
                Top    = 0,
                Right  = (short)width,
                Bottom = (short)height
            };
            this.c1 = new Coord()
            {
                X = (short)width, Y = (short)height
            };
            this.c2 = new Coord()
            {
                X = 0, Y = 0
            };

            this.playersBoardStart = new int[] { 0, 0 };
            this.botsBoardStart    = new int[] { 0, 0 };
            this.logs = null;

            this.buf = new CharInfo[width * height];
            for (int i = 0; i < buf.Length; ++i)
            {
                buf[i].UnicodeChar = ' ';
                buf[i].Attributes  = 0;
            }
        }
Example #16
0
        private static void Render()                                                                                       //Метод рендера
        {
            int            fps         = 0;                                                                                //Текущий фпс
            int            currentStep = Environment.TickCount + 1000;                                                     //Время, через которое фпс обновится
            SafeFileHandle h           = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); //Штука нужна

            while (GameEngine.gameState != GameEngine.GameState.stop)                                                      //Пока рендер включён
            {
                if (!h.IsInvalid)                                                                                          //Если что-то корректно
                {
                    if (SceneManager.currentScene != null)                                                                 //Если сцена создана
                    {
                        int        size  = width * height;
                        CharInfo[] frame = new CharInfo[size]; //Получаем буффер символов размером с консоль
                        for (int i = 0; i < size; i++)
                        {
                            frame[i].Attributes = backColor;
                        }
                        SmallRect rect = new SmallRect()
                        {
                            Left = 0, Top = 0, Right = width, Bottom = height
                        };                                                                 //Рисовать будем во всей консоли
                        List <GameObject> objects = SceneManager.currentScene.gameObjects; //Получаем список объектов со сцены
                        for (int j = 0; j < objects.Count; j++)                            //Для каждого объекта
                        {
                            for (int i = 0; i < objects[j].components.Count; i++)          //Для каждого компонента
                            {
                                if (GameEngine.gameState != GameEngine.GameState.editorPause)
                                {
                                    objects[j].components[i].Update();                                     //Вызываем в нём Update()
                                }
                                if (objects[j].components[i] is IGraphicsComponent)                        //Если же этот компонент графический
                                {
                                    IGraphicsComponent c = objects[j].components[i] as IGraphicsComponent; //Получаем его интерфейс
                                    c.Draw(objects[j], ref frame);                                         //И вызываем метод отрисовки, отдавая в качестве аргументов
                                }                                                                          //объект, его вызываший и сам кадр
                            }
                        } //Рисуем это в консоли
                        bool b = WriteConsoleOutput(h, frame, new Coord()
                        {
                            X = rect.Right, Y = rect.Bottom
                        }, new Coord()
                        {
                            X = 0, Y = 0
                        }, ref rect);
                        fps++;                                                     //Добавляем фпс (кадр жи отрисовался)
                        if (Environment.TickCount > currentStep)                   //Если секунда с прошлого обновления прошла
                        {
                            currentStep = Environment.TickCount + 1000;            //То добавляем ещё секунду к следующему апдейту кадра
                            if (ConsoleEngine.Core.GameEngine.withEditor)          //Если у нас включён редактор
                            {
                                ConsoleEngine.Editor.GameEditorForm.gameFps = fps; //То ставим игровой фпс в нём на наш найденный фпс
                            }
                            fps = 0;                                               //И фпс становится 0
                        }
                    }
                    Thread.Sleep(5); //Засыпаем на 5 мс, обеспечивая не более 120 фпс и снимаем нагрузку на процессор
                }
            }
        }
Example #17
0
        /// <summary>
        /// Initilises the Virtual screen.
        /// </summary>
        /// <param name="w">width of the screen</param>
        /// <param name="h">height of the screen</param>
        public Graphics(int w, int h)
        {
            // Initilisation=================================
            Console.SetWindowSize(w, h);
            Console.CursorVisible = false;
            currentFrame          = new TFrame(w, h);
            frameQueue            = new Queue <TFrame>();
            buf  = new CharInfo[w * h];
            rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = (short)w, Bottom = (short)h
            };
            this.f = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            Height         = h;
            Width          = w;
            maxQueueLength = 3;
            //thread creation================================
            ThreadStart fpsth = new ThreadStart(updateFps);

            updateFpsThread = new Thread(fpsth);
            updateFpsThread.IsBackground = true;
            updateFpsThread.Start();

            ThreadStart thref = new ThreadStart(FrameUpdater);

            updateThread = new Thread(thref);
            updateThread.IsBackground = true;
            updateThread.Start();
        }
Example #18
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);
        }
Example #19
0
        public void Render()
        {
            if (Root == null)
            {
                throw new ApplicationException("Root UI element must be set.");
            }

            short h = (short)Console.WindowHeight;
            short w = (short)Console.WindowWidth;

            var buf = new CharInfo[w * h];

            SmallRect rect = new SmallRect {
                Left = 0, Top = 0, Right = w, Bottom = h
            };

            Root.Render(new RenderContext(w, h, buf));

            WriteConsoleOutput(pending, buf,
                               new Coord {
                X = w, Y = h
            },
                               new Coord {
                X = 0, Y = 0
            },
                               ref rect);

            SetConsoleActiveScreenBuffer(pending.DangerousGetHandle());

            var tmp = pending;

            pending = visible;
            visible = tmp;
        }
Example #20
0
 static void ClearArea(short left, short top, short width, short height, CharInfo charAttr)
 {
     using (SafeFileHandle h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero))
     {
         if (!h.IsInvalid)
         {
             CharInfo[] buf = new CharInfo[width * height];
             for (int i = 0; i < buf.Length; ++i)
             {
                 buf[i] = charAttr;
             }
             SmallRect rect = new SmallRect()
             {
                 Left = left, Top = top, Right = (short)(left + width), Bottom = (short)(top + height)
             };
             WriteConsoleOutput(h, buf,
                                new Coord()
             {
                 X = width, Y = height
             },
                                new Coord()
             {
                 X = 0, Y = 0
             },
                                ref rect);
         }
     }
 }
        public static void WriteCharArray(char[,] array)
        {
            SafeFileHandle h = CreateFile("CONOUT$", 0x4000_0000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            if (!h.IsInvalid)
            {
                short      rows = (short)array.GetLength(0);
                short      cols = (short)array.GetLength(1);
                CharInfo[] buf  = new CharInfo[rows * cols];
                SmallRect  rect = new SmallRect()
                {
                    Left = 0, Top = 0, Bottom = rows, Right = cols
                };

                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        buf[i * cols + j].Attributes     = (short)colorScheme[array[i, j]];
                        buf[i * cols + j].Char.AsciiChar = (byte)array[i, j];
                    }
                }

                bool b = WriteConsoleOutput(h, buf,
                                            new Coord()
                {
                    X = cols, Y = rows
                },
                                            new Coord()
                {
                    X = 0, Y = 0
                },
                                            ref rect);
            }
        }
Example #22
0
 static extern bool ReadConsoleOutput(
     IntPtr hConsoleOutput,
     [Out] CharInfo [] lpBuffer,
     Coord dwBufferSize,
     Coord dwBufferCoord,
     ref SmallRect lpReadRegion
     );
Example #23
0
    public static bool WriteBuffer(CharInfo[,] buffer)       // returns true of success
    {
        SafeFileHandle h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

        if (!h.IsInvalid)
        {
            short      BufferWidth  = (short)buffer.GetLength(0);
            short      BufferHeight = (short)buffer.GetLength(1);
            CharInfo[] buf          = new CharInfo[BufferWidth * BufferHeight];
            SmallRect  rect         = new SmallRect()
            {
                Left = 0, Top = 0, Right = BufferWidth, Bottom = BufferHeight
            };
            for (int y = 0; y < BufferHeight; y++)
            {
                for (int x = 0; x < BufferWidth; x++)
                {
                    buf[y * BufferWidth + x] = buffer[x, y];
                }
            }
            return(WriteConsoleOutput(h, buf, new Coord()
            {
                X = BufferWidth, Y = BufferHeight
            }, new Coord()
            {
                X = 0, Y = 0
            }, ref rect));
        }
        return(false);
    }
Example #24
0
        public override void Repaint(bool force)
        {
            var arr = new SmallRect[_invalidatedAreas.Count];

            _invalidatedAreas.CopyTo(arr, 0);
            base.Repaint(force);
            var s = new SmallRect(0, 0, Width, Height);

            if (arr.Length > 0)
            {
                s = arr[0];
                for (int i = 1; i < arr.Length; i++)
                {
                    if (arr[i].Left < s.Left)
                    {
                        s.Left = arr[i].Left;
                    }
                    if (arr[i].Top < s.Top)
                    {
                        s.Top = arr[i].Top;
                    }

                    if (arr[i].Right > s.Right)
                    {
                        s.Right = arr[i].Right;
                    }
                    if (arr[i].Bottom > s.Bottom)
                    {
                        s.Bottom = arr[i].Bottom;
                    }
                }
            }
            EConsole.UpdateRegion(Buffer, new Coord(s.Left, s.Top), new Coord(Width, Height), ref s);
        }
Example #25
0
        public void Render(ScreenZone zone)
        {
            var consoleRect = new SmallRect((short)zone.Left, (short)zone.Top, (short)(zone.Width + zone.Left - 1),
                                            (short)(zone.Height + zone.Top - 1));

            WriteConsoleOutput(consoleHandle, frameBuffer, new Coord((short)Width, (short)Height),
                               new Coord((short)zone.Left, (short)zone.Top), ref consoleRect);
        }
Example #26
0
    internal static extern bool WriteConsoleOutput(IntPtr hConsoleOutput,

                                                   /* This pointer is treated as the origin of a two-dimensional array of CHAR_INFO structures
                                                    * whose size is specified by the dwBufferSize parameter.*/
                                                   [MarshalAs(UnmanagedType.LPArray), In] 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);
        }
Example #28
0
 public virtual void Invalidate(SmallRect rect)
 {
     _invalidatedAreas.Push(rect);
     foreach (var containerElement in Children.OfType <ContainerElement>().Where(e => e.BoundingRect.Intersects(rect)))
     {
         containerElement.Invalidate(rect + Location);
     }
 }
Example #29
0
        public void Render()
        {
            var bufferSize  = new Coord((short)(_width), (short)(_height));
            var bufferPos   = new Coord(0, 0);
            var writeRegion = new SmallRect(0, 0, (short)(_width - 1), (short)(_height - 1));

            WriteConsoleOutput(_handle, _buff, bufferSize, bufferPos, writeRegion);
            Clear();
        }
Example #30
0
 public void Draw()
 {
     var rect = new SmallRect()
     {
         Left = _left, Top = _top, Right = (short)(_left + _width), Bottom = (short)(_top + _height)
     };
     bool b = WriteConsoleOutput(_safeFileHandle, _buffer,
                                 new Coord(_width, _height),
                                 new Coord(0, 0), ref rect);
 }
Example #31
0
        public static CharInfo[] ReadOutput(Point startPoint, Size sizeOf)
        {
            if (IsAttached == true && m_consoleOutputHandle != IntPtr.Zero)
            {
                CharInfo[] buffer = new CharInfo[sizeOf.Width * sizeOf.Height];
                Coord bufferSize = new Coord((short)sizeOf.Width, (short)sizeOf.Height);
                Coord bufferCoord = new Coord((short)startPoint.X, (short)startPoint.Y);
                SmallRect readReg = new SmallRect((short)startPoint.X, (short)startPoint.Y,
                    (short)(startPoint.X + sizeOf.Width), (short)(startPoint.Y + sizeOf.Height));

                Win32.ReadConsoleOutput(m_consoleOutputHandle, buffer, bufferSize, bufferCoord, ref readReg);

                return buffer;
            }
            throw new Exception("Error: No console attached to that process");
        }
Example #32
0
 /// <summary>
 /// Reads a rectangular block of character and attribute information from the screen buffer into the passed array.
 /// </summary>
 /// <param name="buff">The array into which character information is to be placed.</param>
 /// <param name="buffX">The column position in the array where the first character is to be placed.</param>
 /// <param name="buffY">The row position in the array where the first character is to be placed.</param>
 /// <param name="left">Column position of the top-left corner of the screen buffer area from which characters are to be read.</param>
 /// <param name="top">Row position of the top-left corner of the screen buffer area from which characters are to be read.</param>
 /// <param name="right">Column position of the bottom-right corner of the screen buffer area from which characters are to be read.</param>
 /// <param name="bottom">Row position of the bottom-right corner of the screen buffer area from which characters are to be read.</param>
 public void ReadBlock(ConsoleCharInfo[,] buff, int buffX, int buffY, int left, int top, int right, int bottom)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     // determine size of the buffer
     Coord bufferSize = new Coord ((short)buff.GetLength(1), (short)buff.GetLength(0));
     Coord bufferPos = new Coord((short)buffX, (short)buffY);
     SmallRect readRegion = new SmallRect((short)left, (short)top, (short)right, (short)bottom);
     if (!WinCon.ReadConsoleOutput(handle, buff, bufferSize, bufferPos, readRegion))
     {
         throw new IOException("Read error.", Marshal.GetLastWin32Error());
     }
 }
 private void SetWindowRect(SmallRect sr, bool bAbsolute)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     if (!WinCon.SetConsoleWindowInfo(_handle, bAbsolute, sr))
     {
         int err = Marshal.GetLastWin32Error();
         throw new ApplicationException(String.Format("Unable to set window rect: {0}", err));
     }
 }
 /// <summary>
 /// Writes character and attribute information to a rectangular portion of the screen buffer.
 /// </summary>
 /// <param name="buff">The array that contains characters and attributes to be written.</param>
 /// <param name="buffX">Column position of the first character to be written from the array.</param>
 /// <param name="buffY">Row position of the first character to be written from the array.</param>
 /// <param name="left">Column position of the top-left corner of the screen buffer area where characters are to be written.</param>
 /// <param name="top">Row position of the top-left corner of the screen buffer area where characters are to be written.</param>
 /// <param name="right">Column position of the bottom-right corner of the screen buffer area where characters are to be written.</param>
 /// <param name="bottom">Row position of the bottom-right corner of the screen buffer area where characters are to be written.</param>
 public void WriteBlock(ConsoleCharInfo[,] buff, int buffX, int buffY, int left, int top, int right, int bottom)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     Coord bufferSize = new Coord((short)buff.GetLength(1), (short)buff.GetLength(0));
     Coord bufferPos = new Coord((short)buffX, (short)buffY);
     SmallRect writeRegion = new SmallRect((short)left, (short)top, (short)right, (short)bottom);
     if (!WinCon.WriteConsoleOutput(_handle, buff, bufferSize, bufferPos, writeRegion))
     {
         throw new IOException("Write error.", Marshal.GetLastWin32Error());
     }
 }
 /// <summary>
 /// Copies a specified source area of the screen buffer to a specified destination area.
 /// Vacated character cells are filled with the specified character and color attributes.
 /// </summary>
 /// <param name="sourceLeft">Column position of the source area's top-left corner.</param>
 /// <param name="sourceTop">Row position of the source arean't top-left corner.</param>
 /// <param name="sourceWidth">Width, in character columns, of the source area.</param>
 /// <param name="sourceHeight">Height, in character rows, of the source area.</param>
 /// <param name="targetLeft">Column position of the target's top-left corner.</param>
 /// <param name="targetTop">Row position of the target's top-left corner.</param>
 /// <param name="sourceChar">Character with which to fill vacated character positions.</param>
 /// <param name="sourceForeColor">Foreground color to use for filling.</param>
 /// <param name="sourceBackColor">Background color to use for filling.</param>
 public void MoveBufferArea(
     int sourceLeft,
     int sourceTop,
     int sourceWidth,
     int sourceHeight,
     int targetLeft,
     int targetTop,
     char sourceChar,
     ConsoleColor sourceForeColor,
     ConsoleColor sourceBackColor
     )
 {
     SmallRect sourceRect = new SmallRect((short)sourceLeft, (short)sourceTop,
         (short)(sourceLeft + sourceWidth - 1), (short)(sourceTop + sourceHeight - 1));
     Coord dest = new Coord((short)targetLeft, (short)targetTop);
     ConsoleCharInfo cci = new ConsoleCharInfo(sourceChar, new ConsoleCharAttribute(sourceForeColor, sourceBackColor));
     if (!WinCon.ScrollConsoleScreenBuffer(_handle, sourceRect, null, dest, ref cci))
     {
         throw new IOException("Error scrolling screen buffer", Marshal.GetLastWin32Error());
     }
 }
Example #36
0
        public void RenderNextBuffer()
        {
            bufferindex = (bufferindex + 1) % numbuffers;

            SmallRect rect = new SmallRect(0, 0, Width, Height);
            WriteConsoleOutput(ConsoleHandle, drawers[bufferindex].Buffer, new Coord(Width, Height), Coord.Zero, ref rect);
        }
Example #37
0
 private static extern bool WriteConsoleOutput(
   SafeFileHandle hConsoleOutput,
   ConsoleChar[] lpBuffer,
   Coord dwBufferSize,
   Coord dwBufferCoord,
   ref SmallRect lpWriteRegion);
Example #38
0
 public static extern bool GetWindowRect(IntPtr hWnd, out SmallRect lpRect);
Example #39
0
 public static extern bool WriteConsoleOutputW(
   SafeFileHandle hConsoleOutput,
   CharInfo[] lpBuffer,
   Coord dwBufferSize,
   Coord dwBufferCoord,
   ref SmallRect lpWriteRegion);
Example #40
0
        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];
        }
Example #41
0
 public static extern Boolean ReadConsoleOutput(IntPtr hConsoleOutput, [Out] CharInfo[] lpBuffer,
     Coord dwBufferSize, Coord dwBufferCoord, ref SmallRect lpReadRegion);