home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / contrib / bcc2grx / src / bccgrx13.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-03  |  2.3 KB  |  92 lines

  1. /*
  2.  *  BCC2GRX  -  Interfacing Borland based graphics programs to LIBGRX
  3.  *  Copyright (C) 1993  Hartmut Schirmer
  4.  *
  5.  *  see bccgrx.c for details
  6.  */
  7.  
  8.  
  9. #include "bccgrx00.h"
  10.  
  11. /*
  12.    - Take care : Borland C defines polypoints as int * but
  13.    -             assumes struct pointtype *  .
  14.    -             GRX requires int points[][2] !
  15.    - The good news are : Both definitions are compatible !
  16. */
  17.  
  18. /* ----------------------------------------------------------------- */
  19. void __gr_drawpoly(int numpoints, void *polypoints, int close)
  20. {
  21.   int *pp, x, y, sx, sy, nx, ny, fast;
  22.  
  23.   _DO_INIT_CHECK;
  24.   LNE.lno_color = COL|WR;
  25.   fast = (__gr_lstyle == SOLID_LINE) && (LNE.lno_width == 1);
  26.   pp = (int *)polypoints;
  27.   while (numpoints > 0) {
  28.     x = sx = *(pp++)+VL;
  29.     y = sy = *(pp++)+VT;
  30.     --numpoints;
  31.     while (numpoints > 0)  {
  32.       nx = *(pp++) + VL;
  33.       ny = *(pp++) + VT;
  34.       if (fast)
  35.     GrLine( x, y, nx, ny, LNE.lno_color);
  36.       else
  37.     GrCustomLine( x, y, nx, ny, &LNE);
  38.       x = nx; y = ny;
  39.       --numpoints;
  40.       if ( x==sx && y==sy)
  41.     break;
  42.     }
  43.     if ( close && (x != sx || y != sy))
  44.       if (fast)
  45.     GrLine( x, y, sx, sy, LNE.lno_color);
  46.       else
  47.     GrCustomLine( x, y, sx, sy, &LNE);
  48.   }
  49. }
  50.  
  51. /* ----------------------------------------------------------------- */
  52. void fillpoly(int numpoints, void *polypoints)
  53. {
  54.   void *cpp;
  55.  
  56.   _DO_INIT_CHECK;
  57.   if (VL != 0 || VT != 0) {
  58.     int i, *ppd, *pps;
  59.  
  60.     pps = polypoints;
  61.     ppd = cpp = alloca( sizeof(int) * 2 * numpoints);
  62.     if (cpp==NULL) {
  63.       ERR = grNoScanMem;
  64.       return;
  65.     }
  66.     for (i=0; i < numpoints; ++i) {
  67.       *(ppd++) = *(pps++) + VL;
  68.       *(ppd++) = *(pps++) + VT;
  69.     }
  70.   } else
  71.     cpp = polypoints;
  72.  
  73.   switch (FPATT) {
  74.     case SOLID_FILL :
  75.       GrFilledPolygon(numpoints, cpp, FILL);
  76.       if (COL != FILL)
  77.     __gr_drawpoly(numpoints, polypoints, TRUE);
  78.       break;
  79.     case EMPTY_FILL :
  80.       GrFilledPolygon(numpoints, cpp, COLBG);
  81.       if (COL != COLBG)
  82.     __gr_drawpoly(numpoints, polypoints, TRUE);
  83.       break;
  84.     default :
  85.       FILLP.gp_bmp_fgcolor = FILL;
  86.       FILLP.gp_bmp_bgcolor = COLBG;
  87.       GrPatternFilledPolygon( numpoints, cpp, &FILLP);
  88.       __gr_drawpoly( numpoints, polypoints, TRUE);
  89.       break;
  90.   }
  91. }
  92.