ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/metacalls.c
Revision: 1.5
Committed: Mon Mar 22 02:24:23 2004 UTC (20 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.4: +2 -2 lines
Log Message:
Increased MAXARGS from 512 to 2048 & undid previous change to metacalls.c

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: metacalls.c,v 1.4 2004/03/16 15:55:27 greg Exp $";
3 #endif
4 /*
5 * metacalls.c - functional interface to metafile.
6 *
7 * 2/24/86
8 */
9
10 #include "meta.h"
11 #include "plot.h"
12
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 static char curargs[MAXARGS] = "";
29 static char *cap;
30
31
32 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 {
41 pflush();
42 pglob(PEOP, 0200, NULL);
43 }
44
45 void
46 mdone(void) /* end of graphics metafile */
47 {
48 pflush();
49 pglob(PEOF, 0200, NULL);
50 }
51
52 void
53 minclude( /* include a file */
54 char *fname
55 )
56 {
57 pflush();
58 pglob(PINCL, 1, fname);
59 }
60
61 void
62 msetpat( /* set a pattern */
63 int pn,
64 char *pat
65 )
66 {
67 pflush();
68 pglob(PSET, pn+4, pat);
69 }
70
71
72 void
73 mopenseg( /* open a segment */
74 char *sname
75 )
76 {
77 pflush();
78 pglob(POPEN, 0, sname);
79 }
80
81
82 void
83 mcloseseg(void) /* close current segment */
84 {
85 pflush();
86 pglob(PCLOSE, 0200, NULL);
87 }
88
89
90 void
91 mline( /* start a line */
92 int x, int y,
93 int type, int thick, int color
94 )
95 {
96 pflush();
97 cura0 = (type<<4 & 060) | (thick<<2 & 014) | (color & 03);
98 curx = x;
99 cury = y;
100 }
101
102
103 void
104 mrectangle( /* fill a rectangle */
105 int xmin, int ymin, int xmax, int ymax,
106 int pat, int color
107 )
108 {
109 pflush();
110 cura0 = (pat<<2 & 014) | (color & 03);
111 pprim(PRFILL, cura0, xmin, ymin, xmax, ymax, NULL);
112 }
113
114
115 void
116 mtriangle( /* fill a triangle */
117 int xmin, int ymin, int xmax, int ymax,
118 int d, int pat, int color
119 )
120 {
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 void
128 mpoly( /* start a polygon */
129 int x, int y,
130 int border, int pat, int color
131 )
132 {
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 void
144 mtext( /* matrix string */
145 int x, int y,
146 char *s,
147 int cpi,
148 int color
149 )
150 {
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 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 {
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 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 {
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 void
194 mdraw( /* draw to next point */
195 int x, int y
196 )
197 {
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 static void
209 decival( /* add value to polygon */
210 register int v
211 )
212 {
213 if (!v)
214 return;
215 decival(v/10);
216 *cap++ = v%10 + '0';
217 }
218
219
220 static void
221 polyval( /* add vertex to a polygon */
222 register int x,
223 register int y
224 )
225 {
226 *cap++ = ' ';
227 putdec(x);
228 *cap++ = ' ';
229 putdec(y);
230 }
231
232
233 static void
234 closepoly(void) /* close current polygon */
235 {
236 *cap = '\0';
237 pprim(PPFILL, cura0, 0, 0, XYSIZE-1, XYSIZE-1, curargs);
238 inpoly = FALSE;
239 }
240
241
242 static int
243 let_dir( /* convert letter to corresponding direction */
244 register int c
245 )
246 {
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 }