ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/metacalls.c
Revision: 1.4
Committed: Tue Mar 16 15:55:27 2004 UTC (20 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -2 lines
Log Message:
Increased argument capacity for polygons

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.4 static const char RCSid[] = "$Id: metacalls.c,v 1.3 2003/11/15 02:13:37 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * metacalls.c - functional interface to metafile.
6     *
7     * 2/24/86
8     */
9    
10     #include "meta.h"
11 schorsch 1.3 #include "plot.h"
12 greg 1.1
13    
14     #define RIGHT 0
15     #define UP 1
16     #define LEFT 2
17     #define DOWN 3
18    
19     #define pflush() if (inpoly) closepoly()
20    
21     #define putdec(v) if (v) decival(v); else *cap++ = '0';
22    
23    
24     static int curx = 0;
25     static int cury = 0;
26     static int cura0 = 0;
27     static int inpoly = FALSE;
28 greg 1.4 static char curargs[6*MAXARGS] = "";
29 greg 1.1 static char *cap;
30    
31    
32 schorsch 1.2 static int let_dir( register int c);
33     static void closepoly(void);
34     static void polyval( register int x, register int y);
35     static void decival( register int v);
36    
37    
38     void
39     mendpage(void) /* end of page */
40 greg 1.1 {
41     pflush();
42     pglob(PEOP, 0200, NULL);
43     }
44    
45 schorsch 1.2 void
46     mdone(void) /* end of graphics metafile */
47 greg 1.1 {
48     pflush();
49     pglob(PEOF, 0200, NULL);
50     }
51    
52 schorsch 1.2 void
53     minclude( /* include a file */
54     char *fname
55     )
56 greg 1.1 {
57     pflush();
58     pglob(PINCL, 1, fname);
59     }
60    
61 schorsch 1.2 void
62     msetpat( /* set a pattern */
63     int pn,
64     char *pat
65     )
66 greg 1.1 {
67     pflush();
68     pglob(PSET, pn+4, pat);
69     }
70    
71    
72 schorsch 1.2 void
73     mopenseg( /* open a segment */
74     char *sname
75     )
76 greg 1.1 {
77     pflush();
78     pglob(POPEN, 0, sname);
79     }
80    
81    
82 schorsch 1.2 void
83     mcloseseg(void) /* close current segment */
84 greg 1.1 {
85     pflush();
86     pglob(PCLOSE, 0200, NULL);
87     }
88    
89    
90 schorsch 1.2 void
91     mline( /* start a line */
92     int x, int y,
93     int type, int thick, int color
94     )
95 greg 1.1 {
96     pflush();
97     cura0 = (type<<4 & 060) | (thick<<2 & 014) | (color & 03);
98     curx = x;
99     cury = y;
100     }
101    
102    
103 schorsch 1.2 void
104     mrectangle( /* fill a rectangle */
105     int xmin, int ymin, int xmax, int ymax,
106     int pat, int color
107     )
108 greg 1.1 {
109     pflush();
110     cura0 = (pat<<2 & 014) | (color & 03);
111     pprim(PRFILL, cura0, xmin, ymin, xmax, ymax, NULL);
112     }
113    
114    
115 schorsch 1.2 void
116     mtriangle( /* fill a triangle */
117     int xmin, int ymin, int xmax, int ymax,
118     int d, int pat, int color
119     )
120 greg 1.1 {
121     pflush();
122     cura0 = (let_dir(d)<<4 & 060) | (pat<<2 & 014) | (color & 03);
123     pprim(PTFILL, cura0, xmin, ymin, xmax, ymax, NULL);
124     }
125    
126    
127 schorsch 1.2 void
128     mpoly( /* start a polygon */
129     int x, int y,
130     int border, int pat, int color
131     )
132 greg 1.1 {
133     pflush();
134     cura0 = (border<<6 & 0100) | (pat<<2 & 014) | (color & 03);
135     cap = curargs;
136     inpoly = TRUE;
137     putdec(x);
138     *cap++ = ' ';
139     putdec(y);
140     }
141    
142    
143 schorsch 1.2 void
144     mtext( /* matrix string */
145     int x, int y,
146     char *s,
147     int cpi,
148     int color
149     )
150 greg 1.1 {
151     pflush();
152     cura0 = (color & 03);
153     if (cpi < 10) {
154     cura0 += 04;
155     cpi *= 2;
156     }
157     if (cpi > 11)
158     cura0 += 020;
159     if (cpi > 14)
160     cura0 += 020;
161     if (cpi > 18)
162     cura0 += 020;
163     pprim(PMSTR, cura0, x, y, x, y, s);
164     }
165    
166    
167 schorsch 1.2 void
168     mvstr( /* vector string */
169     int xmin, int ymin, int xmax, int ymax,
170     char *s,
171     int d, int thick, int color
172     )
173 greg 1.1 {
174     pflush();
175     cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
176     pprim(PVSTR, cura0, xmin, ymin, xmax, ymax, s);
177     }
178    
179    
180 schorsch 1.2 void
181     msegment( /* segment */
182     int xmin, int ymin, int xmax, int ymax,
183     char *sname,
184     int d, int thick, int color
185     )
186 greg 1.1 {
187     pflush();
188     cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
189     pprim(PSEG, cura0, xmin, ymin, xmax, ymax, sname);
190     }
191    
192    
193 schorsch 1.2 void
194     mdraw( /* draw to next point */
195     int x, int y
196     )
197 greg 1.1 {
198     if (inpoly) {
199     polyval(x, y);
200     } else if (x != curx || y != cury) {
201     plseg(cura0, curx, cury, x, y);
202     curx = x;
203     cury = y;
204     }
205     }
206    
207    
208 schorsch 1.2 static void
209     decival( /* add value to polygon */
210     register int v
211     )
212 greg 1.1 {
213     if (!v)
214     return;
215     decival(v/10);
216     *cap++ = v%10 + '0';
217     }
218    
219    
220 schorsch 1.2 static void
221     polyval( /* add vertex to a polygon */
222     register int x,
223     register int y
224     )
225 greg 1.1 {
226     *cap++ = ' ';
227     putdec(x);
228     *cap++ = ' ';
229     putdec(y);
230     }
231    
232    
233 schorsch 1.2 static void
234     closepoly(void) /* close current polygon */
235 greg 1.1 {
236     *cap = '\0';
237     pprim(PPFILL, cura0, 0, 0, XYSIZE-1, XYSIZE-1, curargs);
238     inpoly = FALSE;
239     }
240    
241    
242     static int
243 schorsch 1.2 let_dir( /* convert letter to corresponding direction */
244     register int c
245     )
246 greg 1.1 {
247     switch (c) {
248     case 'R':
249     case 'r':
250     return(RIGHT);
251     case 'U':
252     case 'u':
253     return(UP);
254     case 'L':
255     case 'l':
256     return(LEFT);
257     case 'D':
258     case 'd':
259     return(DOWN);
260     }
261     return(0);
262     }