ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/xplot.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R5, rad3R6
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * X window plotting functions
6 *
7 * 2/26/86
8 */
9
10
11 #include "meta.h"
12
13 #include "plot.h"
14
15 #undef TRUE
16
17 #undef FALSE
18
19 #include <X/Xlib.h>
20
21
22 #define BORWIDTH 5
23
24 #define mapx(x) CONV(x,dxsize)
25 #define mapy(y) CONV((XYSIZE-1)-(y),dysize)
26
27 #define fill(xmin,ymin,xmax,ymax,pm) \
28 XTileSet(wind,xmin,ymin,(xmax)-(xmin)+1,(ymax)-(ymin)+1,pm)
29
30 #define MAXVERT 128
31
32 #define MAXCOLOR 65535
33
34 /* X window fonts */
35 static struct {
36 char *name; /* font name */
37 Font id; /* font id */
38 } font[] = {
39 {"9x15", 0},
40 {"8x13", 0},
41 {"6x13", 0},
42 {"vtdwidth", 0},
43 {"accordbfx", 0}
44 };
45
46 /* map to our matrix string types */
47 static int fontmap[16] = {0,3,0,3,1,3,1,3,2,4,2,4,2,4,2,4};
48
49 /* colors */
50 int pixel[4];
51
52 int dxsize, dysize; /* window size */
53
54 Window wind; /* our window */
55
56 extern Pixmap pixpat();
57
58
59
60 init(name, geom) /* initialize window */
61 char *name;
62 char *geom;
63 {
64 WindowInfo Info;
65 OpaqueFrame mainframe;
66 char defgeom[32];
67 Color cdef[4];
68 int dummy;
69
70 if (XOpenDisplay("") == NULL)
71 error(SYSTEM, "can't open display");
72 mainframe.bdrwidth = BORWIDTH;
73 mainframe.border = BlackPixmap;
74 mainframe.background = WhitePixmap;
75 dxsize = DisplayWidth() - 2*BORWIDTH-4;
76 dysize = DisplayHeight() - 2*BORWIDTH-26;
77 if (dxsize > dysize)
78 dxsize = dysize;
79 else
80 dysize = dxsize;
81 sprintf(defgeom, "=%dx%d+2+25", dxsize, dysize);
82 wind = XCreate("Metafile display", progname, geom,
83 defgeom, &mainframe, 64, 64);
84 if (wind == 0)
85 error(SYSTEM, "can't create window");
86 XStoreName(wind, name);
87 XMapWindow(wind);
88 XSelectInput(wind, ButtonPressed|ExposeWindow|ExposeRegion);
89 dxsize = mainframe.width;
90 dysize = mainframe.height;
91 if (DisplayPlanes() < 2 || XGetColorCells(0, 4, 0, &dummy, pixel) == 0) {
92 pixel[0] = pixel[1] = pixel[2] = pixel[3] = BlackPixel;
93 } else {
94 cdef[0].red = cdef[0].green = cdef[0].blue = 0;
95 cdef[0].pixel = pixel[0];
96 cdef[1].red = MAXCOLOR; cdef[1].green = cdef[1].blue = 0;
97 cdef[1].pixel = pixel[1];
98 cdef[2].red = cdef[2].blue = 0; cdef[2].green = MAXCOLOR;
99 cdef[2].pixel = pixel[2];
100 cdef[3].red = cdef[3].green = 0; cdef[3].blue = MAXCOLOR;
101 cdef[3].pixel = pixel[3];
102 XStoreColors(4, cdef);
103 }
104 }
105
106
107
108 endpage() /* end of this graph */
109 {
110 XExposeEvent evnt;
111
112 XFeep(0);
113 for ( ; ; ) {
114 XNextEvent(&evnt);
115 if (evnt.type == ExposeWindow) {
116 dxsize = evnt.width;
117 dysize = evnt.height;
118 if (dxsize > dysize)
119 dxsize = dysize;
120 else
121 dysize = dxsize;
122 replay(0, 0, XYSIZE, XYSIZE);
123 } else if (evnt.type == ExposeRegion) {
124 replay((int)((long)XYSIZE*evnt.x/dxsize),
125 (int)((long)XYSIZE*(dysize-evnt.y-evnt.height)/dysize),
126 (int)((long)XYSIZE*(evnt.x+evnt.width)/dxsize),
127 (int)((long)XYSIZE*(dysize-evnt.y)/dysize));
128 } else
129 break;
130 }
131 XClear(wind);
132
133 }
134
135
136
137 printstr(p) /* output a string */
138
139 register PRIMITIVE *p;
140
141 {
142 int fn;
143
144 fn = fontmap[(p->arg0 >> 2) & 017]; /* get font number */
145 /* set font */
146 if (font[fn].id == 0) {
147 font[fn].id = XGetFont(font[fn].name);
148 if (font[fn].id == 0) {
149 sprintf(errmsg, "can't open font \"%s\"", font[fn].name);
150 error(SYSTEM, errmsg);
151 }
152 }
153
154 XTextPad(wind, mapx(p->xy[XMN]), mapy(p->xy[YMN]), p->args, strlen(p->args),
155 font[fn].id, 0, 0, pixel[p->arg0&03], WhitePixel,
156 GXcopy, AllPlanes);
157
158 }
159
160
161
162
163
164 plotlseg(p) /* plot a line segment */
165
166 register PRIMITIVE *p;
167
168 {
169 int x1, y1, x2, y2;
170 int pp, ps, pw, ph;
171 Pixmap pm;
172
173 pp = (p->arg0 >> 4) & 03;
174 if (p->arg0 & 0100 && pp != 0)
175 pp += 03;
176
177 pm = pixpat(pp, p->arg0&03);
178
179 ps = WIDTH((p->arg0 >> 2) & 03);
180 pw = CONV((ps)/2, dxsize);
181 ph = CONV((ps)/2, dysize);
182
183 x1 = mapx(p->xy[XMN]);
184 x2 = mapx(p->xy[XMX]);
185 if (p->arg0 & 0100) { /* reverse slope */
186 y1 = mapy(p->xy[YMX]);
187 y2 = mapy(p->xy[YMN]);
188 } else {
189 y1 = mapy(p->xy[YMN]);
190 y2 = mapy(p->xy[YMX]);
191 }
192
193 if (pm != BlackPixmap || pw+ph > 0)
194 paintline(x1,y1,x2-x1,y2-y1,pw,ph,pm,0L,0L,-1);
195 else
196 XLine(wind,x1,y1,x2,y2,2*pw+1,2*ph+1,BlackPixel,GXcopy,AllPlanes);
197
198
199 }
200
201
202
203 /*
204 * This routine paints a line with calls to fill(). The line can
205 * start and end at arbitrary points on a longer line segment.
206 */
207
208 paintline(x, y, run, rise, hrad, vrad, pm, run2, rise2, n)
209
210 register int x, y;
211 int run, rise;
212 int hrad, vrad;
213 Pixmap pm;
214 long run2, rise2;
215 int n;
216
217 {
218 int xstep, ystep;
219
220 if (run >= 0)
221 xstep = 1;
222 else {
223 xstep = -1;
224 run = -run;
225 }
226 if (rise >= 0)
227 ystep = 1;
228 else {
229 ystep = -1;
230 rise = -rise;
231 }
232 if (n < 0)
233 n = max(run, rise);
234
235 if (run > rise)
236 while (n >= 0)
237 if (run2 >= rise2) {
238 fill(x-hrad, y-vrad, x+hrad, y+vrad, pm);
239 n--;
240 x += xstep;
241 rise2 += rise;
242 } else {
243 y += ystep;
244 run2 += run;
245 }
246 else
247 while (n >= 0)
248 if (rise2 >= run2) {
249 fill(x-hrad, y-vrad, x+hrad, y+vrad, pm);
250 n--;
251 y += ystep;
252 run2 += run;
253 } else {
254 x += xstep;
255 rise2 += rise;
256 }
257
258 }
259
260
261
262
263 Pixmap
264 pixpat(pp, pc) /* return Pixmap for pattern number */
265
266 int pp, pc;
267
268 {
269 static int curpat = -1; /* current pattern */
270 static int curcol = -1; /* current color */
271 static Pixmap curpix = 0; /* current Pixmap id */
272 short bitval[16];
273 Bitmap bm;
274 register int i, j;
275
276 if (pp == curpat && pc == curcol) /* already set */
277 return(curpix);
278
279 if (pp == 0 && pc == 0) /* all black */
280 return(BlackPixmap);
281
282 if (curpix != 0) /* free old Pixmap */
283 XFreePixmap(curpix);
284
285 if (pp == 0) /* constant Pixmap */
286 curpix = XMakeTile(pixel[pc]);
287 else {
288 #if (PATSIZE != 16)
289 error(SYSTEM, "bad code segment in pixpat");
290 #else
291 for (i = 0; i < 16; i++) {
292 bitval[15-i] = 0;
293 for (j = 0; j < 16; j++)
294 bitval[15-i] |= ((pattern[pp][i>>3][j] >> (i&07)) & 01) << j;
295 }
296 bm = XStoreBitmap(16, 16, bitval);
297 curpix = XMakePixmap(bm, pixel[pc], WhitePixel);
298 XFreeBitmap(bm);
299 #endif
300 }
301 curpat = pp;
302 curcol = pc;
303 return(curpix);
304
305 }
306
307
308
309 fillrect(p) /* fill a rectangle */
310
311 register PRIMITIVE *p;
312
313 {
314 int left, right, top, bottom;
315
316 left = mapx(p->xy[XMN]);
317 bottom = mapy(p->xy[YMN]);
318 right = mapx(p->xy[XMX]);
319 top = mapy(p->xy[YMX]);
320
321 fill(left, top, right, bottom, pixpat(pati[(p->arg0>>2)&03],p->arg0&03));
322
323 }
324
325
326
327 #ifdef nyet
328
329 filltri(p) /* fill a triangle */
330
331 register PRIMITIVE *p;
332
333 {
334 Vertex v[4];
335 int left, right, top, bottom;
336
337 left = mapx(p->xy[XMN]);
338 right = mapx(p->xy[XMX]);
339 top = mapy(p->xy[YMX]);
340 bottom = mapy(p->xy[YMN]);
341
342 switch (p->arg0 & 060) {
343 case 0: /* right (& down) */
344 v[0].x = left; v[0].y = bottom;
345 v[1].x = right; v[1].y = bottom;
346 v[2].x = right; v[2].y = top;
347 break;
348 case 020: /* up */
349 v[0].x = right; v[0].y = bottom;
350 v[1].x = right; v[1].y = top;
351 v[2].x = left; v[2].y = top;
352 break;
353 case 040: /* left */
354 v[0].x = right; v[0].y = top;
355 v[1].x = left; v[1].y = top;
356 v[2].x = left; v[2].y = bottom;
357 break;
358 case 060: /* down */
359 v[0].x = left; v[0].y = top;
360 v[1].x = left; v[1].y = bottom;
361 v[2].x = right; v[2].y = bottom;
362 break;
363 }
364 v[3].x = v[0].x; v[3].y = v[0].y;
365 v[0].flags = v[1].flags = v[2].flags = v[3].flags = 0;
366
367 XDrawTiled(wind, v, 4, pixpat(pati[(p->arg0>>2)&03],p->arg0&03),
368 GXcopy, AllPlanes);
369
370 }
371
372
373
374 xform(xp, yp, p) /* transform a point according to p */
375
376 register int *xp, *yp;
377 register PRIMITIVE *p;
378
379 {
380 int x, y;
381
382 switch (p->arg0 & 060) {
383 case 0: /* right */
384 x = *xp;
385 y = *yp;
386 break;
387 case 020: /* up */
388 x = (XYSIZE-1) - *yp;
389 y = *xp;
390 break;
391 case 040: /* left */
392 x = (XYSIZE-1) - *xp;
393 y = (XYSIZE-1) - *yp;
394 break;
395 case 060: /* down */
396 x = *yp;
397 y = (XYSIZE-1) - *xp;
398 break;
399 }
400
401 *xp = CONV(x, p->xy[XMX] - p->xy[XMN]) + p->xy[XMN];
402 *yp = CONV(y, p->xy[YMX] - p->xy[YMN]) + p->xy[YMN];
403
404 }
405
406
407
408 fillpoly(p) /* fill a polygon */
409
410 register PRIMITIVE *p;
411
412 {
413 int x0, y0, curx, cury;
414 PolyHandle polyh;
415 char *nextscan();
416 register char *s;
417
418 polyh = OpenPoly();
419
420 if ((s = nextscan(nextscan(p->args, "%d", &x0), "%d", &y0)) == NULL)
421 error(USER, "illegal polygon spec in fillpoly");
422
423 xform(&x0, &y0, p);
424 x0 = mapx(x0); y0 = mapy(y0);
425 MoveTo(x0, y0);
426
427 while ((s = nextscan(nextscan(s, "%d", &curx), "%d", &cury)) != NULL) {
428 xform(&curx, &cury, p);
429 curx = mapx(curx); cury = mapy(cury);
430 LineTo(curx, cury);
431 }
432 LineTo(x0, y0);
433
434 ClosePoly();
435
436 if (p->arg0 & 0100) { /* draw border */
437 if (curpat != 0) {
438 PenPat(macpat[0]);
439 curpat = 0;
440 }
441 if (curpsiz != 1) {
442 PenSize(1, 1);
443 curpsiz = 1;
444 }
445 if (curpmod != patOr) {
446 PenMode(patOr);
447 curpmod = patOr;
448 }
449 FramePoly(polyh);
450 }
451
452 setfill(p->arg0 & 077);
453 PaintPoly(polyh);
454 KillPoly(polyh);
455 xpos = -1;
456 ypos = -1;
457
458 }
459
460 #else
461
462 filltri() {}
463 fillpoly() {}
464
465 #endif