Region Fill

Fastgraph includes functions for filling arbitrary regions. The fg_flood() and fg_paint() functions fill a region with the current color value by specifying a screen space point in the region's interior. The fg_floodw() and fg_paintw() functions also fill a region, but they require the interior point to be expressed in world space. All region fill functions have two parameters that specify the (x,y) coordinates of the interior point. For fg_flood() and fg_paint(), the parameters are integer quantities. For fg_floodw() and fg_paintw(), they are floating point quantities. None of them change the graphics cursor position. The difference between the "flood" and "paint" versions of these functions is simple: fg_flood() and fg_floodw() will not extend the region fill beyond the clipping limits, while fg_paint() and fg_paintw() ignore the clipping limits. As a result, fg_paint() and fg_paintw() are significantly faster.

The region being filled must be a closed polygon whose boundary color is different from that of the specified interior point. The region may contain holes (interior areas that will not be filled). Fastgraph fills the region by changing every interior pixel whose color is the same as the specified interior point, to the current color. If the interior point is already the current color, the region fill functions do nothing. It is important to note fg_paint() and fg_paintw() do not treat the virtual buffer edges as polygon boundaries. Filling an open polygon will cause these functions to behave unpredictably. This is not the case with fg_flood() and fg_floodw() as long as the clipping limits are not beyond the virtual buffer edges.

The following code snippet illustrates a simple use of fg_paint() for a 256-color virtual buffer. It first draws a hollow rectangle in color 20 and a hollow diamond in color 19. The diamond is drawn in the middle of the rectangle, thus making it a hole with respect to the rectangle. We then use fg_paint() to fill that part of the rectangle outside the diamond with color 20, and again use fg_paint() to fill the interior of the diamond with color 25.

C/C++ and Delphi:


Visual Basic:

Call fg_setcolor(20)
Call fg_box(100, 220, 50, 150)
Call fg_setcolor(19)
Call fg_move(160, 80)
Call fg_drawrel(30, 20)
Call fg_drawrel(-30, 20)
Call fg_drawrel(-30, -20)
Call fg_drawrel(30, -20)
Call fg_setcolor(20)
Call fg_paint(160, 70)
Call fg_setcolor(25)
Call fg_paint(160, 100)

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.