home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / GR_FILL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  1.7 KB  |  92 lines

  1. /*********************
  2.  *
  3.  *  gr_fill.c - Graphics general pupose fill.
  4.  *
  5.  *  Purpose: This file contains the graphics boundary fill function
  6.  *           and its supporting functions.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include "blackstr.h"
  14. #include "gr_head.h"
  15.  
  16. extern gr_gpt_(int x, int y);
  17.  
  18.  
  19. /********
  20.  *
  21.  *   gr_fill(seedx,seedy) - general boundary fill function
  22.  *
  23.  **/
  24.  
  25. void gr_fill(int seedx, int seedy)
  26. {
  27.     int x1,x2;
  28.  
  29.     ut_push(-1); ut_push(-1);       /* save end on stack */
  30.     while(seedx != -1) {
  31.     x1 = gr_fnb(seedx,seedy) + 1;
  32.     x2 = gr_fpb(seedx,seedy) - 1;
  33.     gr_line(x1,seedy,x2 ,seedy);
  34.     gr_fseed(x1,x2,seedy);       /* find more seeds */
  35.     seedy = ut_pop();            /* get next seed */
  36.     seedx = ut_pop();
  37.     }
  38. }
  39.  
  40.  
  41. /********
  42.  *
  43.  *   gr_fseed(x1,x2,y1) - find new seed point
  44.  *
  45.  **/
  46.  
  47. void gr_fseed(int x1, int x2, int y1)
  48. {
  49.     int x,y;
  50.  
  51.     for(y=y1-1; y<y1+2; y+=2) {
  52.     x = x2;
  53.     while(x >=x1) {          /* while not interior bound */
  54.         if(gr_gpt_(x,y)!=grfcol_) {      /* start of run  */
  55.         ut_push(x);             /* save point on stack */
  56.         ut_push(y);
  57.         x = gr_fnb(x,y);        /* go to left boundary */
  58.         } else
  59.         --x;                     /* still in boundary */
  60.     }
  61.     }
  62. }
  63.  
  64.  
  65. /********
  66.  *
  67.  *   gr_fnb(x,y) - find negative boundary
  68.  *
  69.  **/
  70.  
  71. int gr_fnb(int x, int y)
  72. {
  73.     while((gr_gpt_(x,y) != grfcol_) && (x > gr_minx_))
  74.     --x;
  75.     return(x);
  76. }
  77.  
  78.  
  79. /********
  80.  *
  81.  *   gr_fpb(x,y) - find positive boundary
  82.  *
  83.  **/
  84.  
  85. int gr_fpb(int x, int y)
  86. {
  87.     while((gr_gpt_(x,y) != grfcol_) && (x < gr_maxx_))
  88.     ++x;
  89.     return(x);
  90. }
  91.  
  92.