home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / ppm / ppmdraw.h < prev    next >
C/C++ Source or Header  |  1993-10-04  |  5KB  |  104 lines

  1. /* ppmdraw.h - header file for simple drawing routines in libppm
  2. **
  3. ** Simple, yes, and also fairly slow if the truth be told; but also very
  4. ** flexible and powerful.
  5. **
  6. ** The two basic concepts are the drawproc and clientdata.  All the drawing
  7. ** routines take a drawproc that does the actual drawing.  A drawproc draws
  8. ** a single point, and it looks like this:
  9. */
  10. void ppmd_point_drawproc ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata ));
  11. /*
  12. ** So, you call a drawing routine, e.g. ppmd_line(), and pass it a drawproc;
  13. ** it calls the drawproc for each point it wants to draw.  Why so complicated?
  14. ** Because you can define your own drawprocs to do more interesting things than
  15. ** simply draw the point.  For example, you could make one that calls back into
  16. ** another drawing routine, say ppmd_circle() to draw a circle at each point
  17. ** of a line.
  18. **
  19. ** Slow?  Well sure, we're talking results here, not realtime.  You can do
  20. ** tricks with this arrangement that you couldn't even think of before.
  21. ** Still, to speed things up for the 90% case you can use this:
  22. */
  23. #if __STDC__
  24. #define PPMD_NULLDRAWPROC (void (*)(pixel**, int, int, pixval, int, int, char*)) 0
  25. #else /*__STDC__*/
  26. #define PPMD_NULLDRAWPROC (void (*)()) 0
  27. #endif /*__STDC__*/
  28. /*
  29. ** Just like ppmd_point_drawproc() it simply draws the point, but it's done
  30. ** inline, and clipping is assumed to be handled at a higher level.
  31. **
  32. ** Now, what about clientdata.  Well, it's an arbitrary pointer, and can
  33. ** mean something different to each different drawproc.  For the above two
  34. ** drawprocs, clientdata should be a pointer to a pixel holding the color
  35. ** to be drawn.  Other drawprocs can use it to point to something else,
  36. ** e.g. some structure to be modified, or they can ignore it.
  37. */
  38.  
  39.  
  40. /* Outline drawing routines.  Lines, splines, circles, etc. */
  41.  
  42. int ppmd_setlinetype ARGS(( int type ));
  43. #define PPMD_LINETYPE_NORMAL 0
  44. #define PPMD_LINETYPE_NODIAGS 1
  45. /* If you set NODIAGS, all pixels drawn by ppmd_line() will be 4-connected
  46. ** instead of 8-connected; in other words, no diagonals.  This is useful
  47. ** for some applications, for example when you draw many parallel lines
  48. ** and you want them to fit together without gaps.
  49. */
  50.  
  51. int ppmd_setlineclip ARGS(( int clip ));
  52. #define ppmd_setlineclipping(x)     ppmd_setlineclip(x)
  53. /* Normally, ppmd_line() clips to the edges of the pixmap.  You can use this
  54. ** routine to disable the clipping, for example if you are using a drawproc
  55. ** that wants to do its own clipping.
  56. */
  57.  
  58. void ppmd_line ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  59. /* Draws a line from (x0, y0) to (x1, y1).
  60. */
  61.  
  62. void ppmd_spline3 ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int x1, int y1, int x2, int y2, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  63. /* Draws a three-point spline from (x0, y0) to (x2, y2), with (x1, y1) as
  64. ** the control point.  All drawing is done via ppmd_line(), so the routines
  65. ** that control it control ppmd_spline3() as well.
  66. */
  67.  
  68. void ppmd_polyspline ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x0, int y0, int nc, int* xc, int* yc, int x1, int y1, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  69. /* Draws a bunch of splines end to end.  (x0, y0) and (x1, y1) are the initial
  70. ** and final points, and the xc and yc are the intermediate control points.
  71. ** nc is the number of these control points.
  72. */
  73.  
  74. void ppmd_circle ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int cx, int cy, int radius, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  75. /* Draws a circle centered at (cx, cy) with the specified radius.
  76. */
  77.  
  78.  
  79. /* Simple filling routines.  Ok, so there's only one. */
  80.  
  81. void ppmd_filledrectangle ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, int width, int height, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  82. /* Fills in the rectangle [x, y, width, height].
  83. */
  84.  
  85.  
  86. /* Arbitrary filling routines.  With these you can fill any outline that
  87. ** you can draw with the outline routines.
  88. */
  89.  
  90. char* ppmd_fill_init ARGS(( void ));
  91. /* Returns a blank fillhandle.
  92. */
  93.  
  94. void ppmd_fill_drawproc ARGS(( pixel** pixels, int cols, int rows, pixval maxval, int x, int y, char* clientdata ));
  95. /* Use this drawproc to trace the outline you want filled.  Be sure to use
  96. ** the fillhandle as the clientdata.
  97. */
  98.  
  99. void ppmd_fill ARGS(( pixel** pixels, int cols, int rows, pixval maxval, char* fillhandle, void (*drawprocP)(pixel**, int, int, pixval, int, int, char*), char* clientdata ));
  100. /* Once you've traced the outline, give the fillhandle to this routine to
  101. ** do the actual drawing.  As usual, it takes a drawproc and clientdata;
  102. ** you could define drawprocs to do stipple fills and such.
  103. */
  104.