INF: _ellipse() Floodfills Until Border Color Is Reached

ID Number: Q75242

5.00 5.10 6.00 6.00a 6.00ax

MS-DOS

Summary:

Using the _ellipse() function with _GFILLINTERIOR, which is part of

the graphics library shipped with the Microsoft C Compiler versions

5.0, 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.00, and Microsoft

QuickC versions 2.0, 2.01, 2.5, and 2.51, will create an ellipse that

is filled with the current color. First the border is drawn, then the

ellipse is floodfilled (meaning the fill begins at one point and

continues in all directions until the boundary color is reached).

More Information:

If the ellipse being filled contains pixels with the boundary color,

the ellipse will not be completely filled. This is expected because

the method used to fill the ellipse is a floodfill.

In the first example, two ellipses are floodfilled. The ellipses

overlap, so the filling of the second ellipse is not complete. This

will happen if any shape intersects the ellipse. The portion of the

ellipse filled is determined by the points of intersection and the

point at which floodfilling is begun. This point was chosen to be the

center of the ellipse and there is no way to override that choice.

In the second example, an ellipse is floodfilled and text is written

within it. The program attempts to erase the writing by repeating

the exact same ellipse. The ellipse is already filled with the color,

so floodfilling ceases immediately without erasing the text.

There are several ways to avoid these and similar situations:

- Use _polygon() or _rectangle() instead of _ellipse(), because they

use a different method to fill the region.

-or-

- Use a different color when drawing the ellipse, so that the color

of the existing shapes or text will not cause the floodfill to

cease. The ellipse can be left that color or can then be

subsequently filled with the color of existing shapes or text

(that is, in the first example, draw the first ellipse, change the

color, draw the second ellipse, restore the color, redraw the

second ellipse; in the second example, draw a blue ellipse, write

white text in it, draw an ellipse in anything but blue or white,

then draw the blue ellipse.)

-or-

- Use _remappalette() so that two different color indices map to the

same color. Filling with these colors is visually identical,

but they will be considered two different colors in a floodfill.

This workaround is used in the same way as the second workaround,

but will avoid the flicker that comes from using a visually

different color. If you need to remap the palette to change the

duplicate index back into its original color, make sure that the

ellipse has been redrawn in the original index (rather than the

duplicate) before you do this, otherwise the ellipse will change

color when the palette is remapped.

Sample Code 1

-------------

/* Compile options needed: none

*/

#include <conio.h>

#include <graph.h>

void main()

{

_setvideomode( _ERESCOLOR );

_ellipse( _GFILLINTERIOR, 290, 0, 345, 349 );

_ellipse( _GFILLINTERIOR, 0, 155, 525, 195 );

while( !kbhit() );

_setvideomode( _DEFAULTMODE );

}

Sample Code 2

-------------

/* Compile options needed: none

*/

#include <graph.h>

#include <conio.h>

#include <stdlib.h>

char fondir[80]; /* String for user's font directory */

void main( )

{

/* Set the video mode for the maximum resolution */

_setvideomode( _MAXRESMODE );

/* Register a font 24 pixels high with _registerfonts and _setfont */

if( _registerfonts( "*.fon" ) <= 0 )

{

_settextposition( 5, 5 );

_outtext( "Enter directory where fonts are located: " );

gets( fondir );

_clearscreen( _GCLEARSCREEN );

strcat( fondir, "\\*.FON" );

if( _registerfonts( fondir ) <= 0 )

{

_outtext( "Exiting - can't register fonts.\n" );

while( !kbhit() );

_setvideomode(_DEFAULTMODE);

exit( 1 );

}

}

_setfont( "h24" );

/* Draw a blue ellipse */

_setcolor( 1 );

_ellipse( _GFILLINTERIOR, 100, 145, 500, 200 );

/* Draw white text inside the ellipse using _outgtext and wait */

_setcolor( 7 );

_moveto( 170, 160 );

_outgtext( "Press any key to erase...\n" );

_setcolor( 1 );

do

getch( );

while( kbhit() );

/* Draw a blue ellipse in the exact spot. The intent is to erase

the white text, but since the ellipse is already blue and _ellipse

uses a floodfill, the blue border is reached before the text is

erased.

*/

_ellipse( _GFILLINTERIOR, 100, 145, 500, 200 );

while( !kbhit() );

_setvideomode( _DEFAULTMODE );

}

Additional reference words: 1.00 1.01 2.00 2.01 2.50 2.51 5.00 5.10

6.00 6.00a 6.00ax 7.00