StdPaint.ConsoleBuffer.FloodFill C# (CSharp) Method

FloodFill() public method

Flood fills a closed region containing the specified coordinates with a brush.
public FloodFill ( int x, int y, BufferBrush brush ) : void
x int The X coordinate to begin filling at.
y int The Y coordinate to begin filling at.
brush BufferBrush The brush to fill the region with.
return void
        public void FloodFill(int x, int y, BufferBrush brush)
        {
            if (!InBounds(x, y)) return;
            var initColor = _buffer[y, x].BackColor;
            if (brush.GetColor(x,y) == initColor) return;
            List<Point> queue = new List<Point>(32);
            queue.Add(new Point(x, y));
            Point p;
            int w, e, j;
            for (int i = 0; i < queue.Count; i++)
            {
                p = queue[i];
                w = e = p.X;
                while (w - 1 >= 0)
                {
                    if (_buffer[p.Y, w - 1].BackColor == initColor)
                    {
                        w--;
                    }
                    else
                    {
                        break;
                    }
                }
                while (e + 1 < _width)
                {
                    if (_buffer[p.Y, e + 1].BackColor == initColor)
                    {
                        e++;
                    }
                    else
                    {
                        break;
                    }
                }
                for (j = w; j <= e; j++)
                {
                    _buffer[p.Y, j].BackColor = brush.GetColor(j, p.Y);
                    if (p.Y + 1 < _height)
                    {
                        if (_buffer[p.Y + 1, j].BackColor == initColor)
                        {
                            queue.Add(new Point(j, p.Y + 1));
                        }
                    }
                    if (p.Y - 1 >= 0)
                    {
                        if (_buffer[p.Y - 1, j].BackColor == initColor)
                        {
                            queue.Add(new Point(j, p.Y - 1));
                        }
                    }
                }
            }
        }

Same methods

ConsoleBuffer::FloodFill ( int x, int y, BufferColor color ) : void