Microsoft KB Archive/75242

{|
 * width="100%"|

_ellipse Floodfills Until Border Color Is Reached

 * }

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: - The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 -- 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: - 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 #include 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 #include #include 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( &quot;*.fon&quot; ) <= 0 ) { _settextposition( 5, 5 ); _outtext( &quot;Enter directory where fonts are located: &quot; ); gets( fondir ); _clearscreen( _GCLEARSCREEN ); strcat( fondir, &quot;\\*.FON&quot; ); if( _registerfonts( fondir ) <= 0 ) { _outtext( &quot;Exiting - can't register fonts.\n&quot; ); while( !kbhit ); _setvideomode(_DEFAULTMODE); exit( 1 ); } } _setfont( &quot;h24&quot; ); /* 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( &quot;Press any key to erase...\n&quot; ); _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

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT