Back to index

radiance  4R0+20100331
metacalls.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: metacalls.c,v 1.5 2004/03/22 02:24:23 greg Exp $";
00003 #endif
00004 /*
00005  *  metacalls.c - functional interface to metafile.
00006  *
00007  *     2/24/86
00008  */
00009 
00010 #include  "meta.h"
00011 #include  "plot.h"
00012 
00013 
00014 #define  RIGHT              0
00015 #define  UP          1
00016 #define  LEFT        2
00017 #define  DOWN        3
00018 
00019 #define  pflush()    if (inpoly) closepoly()
00020 
00021 #define  putdec(v)   if (v) decival(v); else *cap++ = '0';
00022 
00023 
00024 static int  curx = 0;
00025 static int  cury = 0;
00026 static int  cura0 = 0;
00027 static int  inpoly = FALSE;
00028 static char  curargs[MAXARGS] = "";
00029 static char  *cap;
00030 
00031 
00032 static int let_dir( register int  c);
00033 static void closepoly(void);
00034 static void polyval( register int  x, register int y);
00035 static void decival( register int  v);
00036 
00037 
00038 void
00039 mendpage(void)                     /* end of page */
00040 {
00041     pflush();
00042     pglob(PEOP, 0200, NULL);
00043 }
00044 
00045 void
00046 mdone(void)                        /* end of graphics metafile */
00047 {
00048     pflush();
00049     pglob(PEOF, 0200, NULL);
00050 }
00051 
00052 void
00053 minclude(                   /* include a file */
00054 char  *fname
00055 )
00056 {
00057     pflush();
00058     pglob(PINCL, 1, fname);
00059 }
00060 
00061 void
00062 msetpat(             /* set a pattern */
00063 int  pn,
00064 char  *pat
00065 )
00066 {
00067     pflush();
00068     pglob(PSET, pn+4, pat);
00069 }
00070 
00071 
00072 void
00073 mopenseg(                   /* open a segment */
00074 char  *sname
00075 )
00076 {
00077     pflush();
00078     pglob(POPEN, 0, sname);
00079 }
00080 
00081 
00082 void
00083 mcloseseg(void)                    /* close current segment */
00084 {
00085     pflush();
00086     pglob(PCLOSE, 0200, NULL);
00087 }
00088 
00089 
00090 void
00091 mline(        /* start a line */
00092 int  x, int y,
00093 int  type, int thick, int color
00094 )
00095 {
00096     pflush();
00097     cura0 = (type<<4 & 060) | (thick<<2 & 014) | (color & 03);
00098     curx = x;
00099     cury = y;
00100 }
00101 
00102 
00103 void
00104 mrectangle(   /* fill a rectangle */
00105 int  xmin, int ymin, int xmax, int ymax,
00106 int  pat, int color
00107 )
00108 {
00109     pflush();
00110     cura0 = (pat<<2 & 014) | (color & 03);
00111     pprim(PRFILL, cura0, xmin, ymin, xmax, ymax, NULL);
00112 }
00113 
00114 
00115 void
00116 mtriangle(    /* fill a triangle */
00117 int  xmin, int ymin, int xmax, int ymax,
00118 int  d, int pat, int color
00119 )
00120 {
00121     pflush();
00122     cura0 = (let_dir(d)<<4 & 060) | (pat<<2 & 014) | (color & 03);
00123     pprim(PTFILL, cura0, xmin, ymin, xmax, ymax, NULL);
00124 }
00125 
00126 
00127 void
00128 mpoly(        /* start a polygon */
00129 int  x, int y,
00130 int  border, int pat, int color
00131 )
00132 {
00133     pflush();
00134     cura0 = (border<<6 & 0100) | (pat<<2 & 014) | (color & 03);
00135     cap = curargs;
00136     inpoly = TRUE;
00137     putdec(x);
00138     *cap++ = ' ';
00139     putdec(y);
00140 }
00141 
00142 
00143 void
00144 mtext(        /* matrix string */
00145 int  x, int y,
00146 char  *s,
00147 int  cpi,
00148 int  color
00149 )
00150 {
00151     pflush();
00152     cura0 = (color & 03);
00153     if (cpi < 10) {
00154        cura0 += 04;
00155        cpi *= 2;
00156     }
00157     if (cpi > 11)
00158        cura0 += 020;
00159     if (cpi > 14)
00160        cura0 += 020;
00161     if (cpi > 18)
00162        cura0 += 020;
00163     pprim(PMSTR, cura0, x, y, x, y, s);
00164 }
00165 
00166 
00167 void
00168 mvstr( /* vector string */
00169 int  xmin, int ymin, int xmax, int ymax,
00170 char  *s,
00171 int  d, int thick, int color
00172 )
00173 {
00174     pflush();
00175     cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
00176     pprim(PVSTR, cura0, xmin, ymin, xmax, ymax, s);
00177 }
00178 
00179 
00180 void
00181 msegment(     /* segment */
00182 int  xmin, int ymin, int xmax, int ymax,
00183 char  *sname,
00184 int  d, int thick, int color
00185 )
00186 {
00187     pflush();
00188     cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
00189     pprim(PSEG, cura0, xmin, ymin, xmax, ymax, sname);
00190 }
00191 
00192 
00193 void
00194 mdraw(                      /* draw to next point */
00195 int  x, int y
00196 )
00197 {
00198     if (inpoly) {
00199        polyval(x, y);
00200     } else if (x != curx || y != cury) {
00201        plseg(cura0, curx, cury, x, y);
00202        curx = x;
00203        cury = y;
00204     }
00205 }
00206 
00207 
00208 static void
00209 decival(                           /* add value to polygon */
00210 register int  v
00211 )
00212 {
00213     if (!v)
00214        return;
00215     decival(v/10);
00216     *cap++ = v%10 + '0';
00217 }
00218 
00219 
00220 static void
00221 polyval(                           /* add vertex to a polygon */
00222 register int  x,
00223 register int y
00224 )
00225 {
00226     *cap++ = ' ';
00227     putdec(x);
00228     *cap++ = ' ';
00229     putdec(y);
00230 }
00231 
00232 
00233 static void
00234 closepoly(void)                           /* close current polygon */
00235 {
00236     *cap = '\0';
00237     pprim(PPFILL, cura0, 0, 0, XYSIZE-1, XYSIZE-1, curargs);
00238     inpoly = FALSE;
00239 }
00240 
00241 
00242 static int
00243 let_dir(             /* convert letter to corresponding direction */
00244 register int  c
00245 )
00246 {
00247     switch (c) {
00248     case 'R':
00249     case 'r':
00250        return(RIGHT);
00251     case 'U':
00252     case 'u':
00253        return(UP);
00254     case 'L':
00255     case 'l':
00256        return(LEFT);
00257     case 'D':
00258     case 'd':
00259        return(DOWN);
00260     }
00261     return(0);
00262 }