StdPaint.ConsoleBuffer.DrawBuffer C# (CSharp) Method

DrawBuffer() public method

Draws the contents of another buffer onto this buffer at the specified location.
public DrawBuffer ( ConsoleBuffer buffer, int x, int y, BufferDrawMode drawMode ) : void
buffer ConsoleBuffer The buffer to draw.
x int The X position to begin drawing at.
y int The Y position to begin drawing at.
drawMode BufferDrawMode Specified how the buffer should be drawn.
return void
        public void DrawBuffer(ConsoleBuffer buffer, int x, int y, BufferDrawMode drawMode)
        {
            var b = _buffer;
            var b2 = buffer.Buffer;
            int offx = 0;
            int offy = 0;
            int w = buffer._width;
            int h = buffer._height;
            if (x + w < 0 || y + h == 0 || y >= _height || x >= _width)
            {
                return;
            }
            if (w + x > _width)
            {
                w -= w + x - _width;
            }
            if (x < 0)
            {
                offx = -x;
            }
            if (h + y > _height)
            {
                h -= h + y - _height;
            }
            if (y < 0)
            {
                offy = -y;
            }

            switch (drawMode)
            {
                case BufferDrawMode.Additive:
                    {
                        for (int i = w - 1; i >= offx; i--)
                        for (int j = h - 1; j >= offy; j--)
                        {
                            b[j + y + offy, i + x + offx]._attrs |= b2[j, i]._attrs;
                            b[j + y + offy, i + x + offx].CharData = b2[j, i].CharData;
                        }
                    }
                    break;
                case BufferDrawMode.DrawOver:
                    {
                        for (int i = w - 1; i >= offx; i--)
                        for (int j = h - 1; j >= offy; j--)
                        {
                            b[j + y + offy, i + x + offx]._attrs = b2[j, i]._attrs;
                            b[j + y + offy, i + x + offx].CharData = b2[j, i].CharData;
                        }
                    }
                    break;
                case BufferDrawMode.IgnoreBlack:
                    {
                        for (int i = w - 1; i >= offx; i--)
                        for (int j = h - 1; j >= offy; j--)
                        {
                            if (b2[j, i].BackColor != BufferColor.Black)
                            {
                                b[j + y + offy, i + x + offx]._attrs = b2[j, i]._attrs;
                            }
                            b[j + y + offy, i + x + offx].CharData = b2[j, i].CharData;
                        }
                    }
                    break;
            }
        }