inc/vGfx.h

Go to the documentation of this file.
00001 /* vGfx - interface to polymorphic graphic object
00002  * that currently can either be a memory buffer or
00003  * a postScript file. */
00004 
00005 #ifndef VGFX_H
00006 #define VGFX_H
00007 
00008 #ifndef MEMGFX_H
00009 #include "memgfx.h"
00010 #include "hash.h"
00011 #endif
00012 
00013 struct vGfx
00014 /* Virtual graphic object - mostly a bunch of function
00015  * pointers. */
00016     {
00017     struct vGfx *next;  /* Next in list. */
00018     void *data;         /* Type specific data. */
00019     boolean pixelBased; /* Real pixels, not PostScript or something. */
00020     int width, height;  /* Virtual pixel dimensions. */
00021 
00022     void (*close)(void **pV);
00023     /* Finish writing out and free structure. */
00024 
00025     void (*dot)(void *v, int x, int y, int colorIx);
00026     /* Draw a single pixel.  Try to work at a higher level
00027      * when possible! */
00028 
00029     int (*getDot)(void *v, int x, int y);
00030     /* Fetch a single pixel.  Please do not use this, this is special
00031      * for verticalText only. */
00032 
00033     void (*box)(void *v, int x, int y, 
00034             int width, int height, int colorIx);
00035     /* Draw a box. */
00036 
00037     void (*line)(void *v, 
00038             int x1, int y1, int x2, int y2, int colorIx);
00039     /* Draw a line from one point to another. */
00040 
00041     void (*text)(void *v, int x, int y, int colorIx, void *font, char *text);
00042     /* Draw a line of text with upper left corner x,y. */
00043 
00044     void (*textRight)(void *v, int x, int y, int width, int height,
00045         int colorIx, void *font, char *text);
00046     /* Draw a line of text with upper left corner x,y. */
00047 
00048     void (*textCentered)(void *v, int x, int y, int width, int height,
00049         int colorIx, void *font, char *text);
00050     /* Draw a line of text in middle of box. */
00051 
00052     int (*findColorIx)(void *v, int r, int g, int b);
00053     /* Find color in map if possible, otherwise create new color or
00054      * in a pinch a close color. */
00055 
00056     struct rgbColor (*colorIxToRgb)(void *v, int colorIx);
00057     /* Return rgb values for given color index. */
00058 
00059     void (*setClip)(void *v, int x, int y, int width, int height);
00060     /* Set clipping rectangle. */
00061 
00062     void (*unclip)(void *v);
00063     /* Set clipping rect cover full thing. */
00064 
00065     void (*verticalSmear)(void *v,
00066             int xOff, int yOff, int width, int height, 
00067             unsigned char *dots, boolean zeroClear);
00068     /* Put a series of one 'pixel' width vertical lines. */
00069 
00070     void (*fillUnder)(void *v, int x1, int y1, int x2, int y2, 
00071             int bottom, Color color);
00072     /* Draw a 4 sided filled figure that has line x1/y1 to x2/y2 at
00073      * it's top, a horizontal line at bottom at it's bottom,  and
00074      * vertical lines from the bottom to y1 on the left and bottom to
00075      * y2 on the right. */
00076 
00077     void (*drawPoly)(void *v, struct gfxPoly *poly, Color color, 
00078         boolean filled);
00079     /* Draw polygon, possibly filled in color. */
00080 
00081     void (*setHint)(void *v, char *hint, char *value);
00082     /* Set hint */
00083 
00084     char * (*getHint)(void *v, char *hint);
00085     /* Get hint */
00086 
00087     };
00088 
00089 struct vGfx *vgOpenGif(int width, int height, char *fileName);
00090 /* Open up something that we'll write out as a gif 
00091  * someday. */
00092 
00093 struct vGfx *vgOpenPostScript(int width, int height, char *fileName);
00094 /* Open up something that will someday be a PostScript file. */
00095 
00096 void vgClose(struct vGfx **pVg);
00097 /* Close down virtual graphics object, and finish writing it to file. */
00098 
00099 #define vgDot(v,x,y, color) v->dot(v->data,x,y,color)
00100 /* Draw a single pixel.  Try to work at a higher level
00101  * when possible! */
00102 
00103 #define vgGetDot(v,x,y) v->getDot(v->data,x,y)
00104 /* Fetch a single pixel.  Please do not use this, this is special for
00105  * verticalText only */
00106 
00107 #define vgBox(v,x,y,width,height,color) v->box(v->data,x,y,width,height,color)
00108 /* Draw a box. */
00109 
00110 #define vgLine(v,x1,y1,x2,y2,color) v->line(v->data,x1,y1,x2,y2,color)
00111 /* Draw a line from one point to another. */
00112 
00113 #define vgText(v,x,y,color,font,string) v->text(v->data,x,y,color,font,string)
00114 /* Draw a line of text with upper left corner x,y. */
00115 
00116 #define vgTextRight(v,x,y,width,height,color,font,string) \
00117         v->textRight(v->data,x,y,width,height,color,font,string)
00118 /* Draw a line of text with upper left corner x,y. */
00119 
00120 #define vgTextCentered(v,x,y,width,height,color,font,string) \
00121         v->textCentered(v->data,x,y,width,height,color,font,string)
00122 /* Draw a line of text in middle of box. */
00123 
00124 #define vgFindColorIx(v,r,g,b) v->findColorIx(v->data, r, g, b)
00125 /* Find index of RGB color.  */
00126 
00127 #define vgColorIxToRgb(v,colorIx) v->colorIxToRgb(v->data, colorIx)
00128 /* Return rgb values for given color index. */
00129 
00130 #define vgSetClip(v,x,y,width,height) \
00131         v->setClip(v->data, x, y, width, height)
00132 /* Set clipping rectangle. */
00133 
00134 #define vgUnclip(v) v->unclip(v->data);
00135 /* Get rid of clipping rectangle.  Note this is not completely
00136  * the same in PostScript and the memory images.  PostScript
00137  * demands that vgSetClip/vgUnclip come in pairs, and that
00138  * vgSetClip just further restrict a previous vgSetClip call.
00139  * The only portable way to do this is to strictly pair up
00140  * the setClip/unclip calls and not to nest them. */
00141 
00142 #define vgVerticalSmear(v,x,y,w,h,dots,zeroClear) \
00143         v->verticalSmear(v->data,x,y,w,h,dots,zeroClear)
00144 /* Take array of dots and smear them vertically. */
00145 
00146 #define vgFillUnder(v,x1,y1,x2,y2,bottom,color) \
00147         v->fillUnder(v->data,x1,y1,x2,y2,bottom,color)
00148     /* Draw a 4 sided filled figure that has line x1/y1 to x2/y2 at
00149      * it's top, a horizontal line at bottom at it's bottom,  and
00150      * vertical lines from the bottom to y1 on the left and bottom to
00151      * y2 on the right. */
00152 
00153 #define vgDrawPoly(v,poly,color,filled) \
00154         v->drawPoly(v->data,poly,color,filled)
00155     /* Draw a polygon in color, optionally filled. */
00156 
00157 #define vgSetHint(v,hint,value) \
00158         v->setHint(v->data,hint,value)
00159     /* Set hint */
00160 
00161 #define vgGetHint(v,hint) \
00162         v->getHint(v->data,hint)
00163     /* Get hint */
00164 
00165 
00166 
00167 int vgFindRgb(struct vGfx *vg, struct rgbColor *rgb);
00168 /* Find color index corresponding to rgb color. */
00169 
00170 Color vgContrastingColor(struct vGfx *vg, int backgroundIx);
00171 /* Return black or white whichever would be more visible over
00172  * background. */
00173 
00174 #endif /* VGFX_H */

Generated on Tue Dec 25 18:39:29 2007 for blat by  doxygen 1.5.2