_ellipse() Floodfills Until Border Color Is Reached

ID: Q75242

5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50

MS-DOS                      | WINDOWS
kbprg

The information in this article applies to:

SUMMARY

Using the _ellipse() function with _GFILLINTERIOR, which is part of the graphics library shipped with the Microsoft C Compiler versions 5.0 an later 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:

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: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00 KBCategory: kbprg KBSubcategory: CLngIss GraphicsIss Keywords : kb16bitonly

Last Reviewed: July 18, 1997