ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
Revision: 3.29
Committed: Fri Nov 13 14:25:52 1998 UTC (25 years, 4 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.28: +1 -3 lines
Log Message:
fixed BYTE definition problem in header

File Contents

# Content
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ SGI";
5 #endif
6
7 /*
8 * X11 driver for holodeck display.
9 * Based on rview driver.
10 */
11
12 #include "standard.h"
13 #include <X11/Xlib.h>
14 #include <X11/cursorfont.h>
15 #include <X11/Xutil.h>
16 #include "rhd_qtree.h"
17 #include "x11icon.h"
18
19 #ifndef RAYQLEN
20 #define RAYQLEN 50000 /* max. rays to queue before flush */
21 #endif
22
23 #ifndef FEQ
24 #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
25 #endif
26
27 #define GAMMA 2.2 /* default gamma correction */
28
29 #define MOVPCT 7 /* percent distance to move /frame */
30 #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
31 #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
32 #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
33
34 #define MINWIDTH 480 /* minimum graphics window width */
35 #define MINHEIGHT 400 /* minimum graphics window height */
36
37 #define VIEWDIST 356 /* assumed viewing distance (mm) */
38
39 #define BORWIDTH 5 /* border width */
40
41 #define ourscreen DefaultScreen(ourdisplay)
42 #define ourroot RootWindow(ourdisplay,ourscreen)
43 #define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\
44 ButtonPressMask|ButtonReleaseMask)
45
46 #define levptr(etype) ((etype *)&currentevent)
47
48 struct driver odev; /* global device driver structure */
49
50 static XEvent currentevent; /* current event */
51
52 static int ncolors = 0; /* color table size */
53 static int mapped = 0; /* window is mapped? */
54 static unsigned long *pixval = NULL; /* allocated pixels */
55 static unsigned long ourblack=0, ourwhite=1;
56
57 static Display *ourdisplay = NULL; /* our display */
58 static XVisualInfo ourvinfo; /* our visual information */
59 static Window gwind = 0; /* our graphics window */
60 static GC ourgc = 0; /* our graphics context for drawing */
61 static Colormap ourmap = 0; /* our color map */
62
63 static double pwidth, pheight; /* pixel dimensions (mm) */
64
65 static int inpresflags; /* input result flags */
66
67 static int headlocked = 0; /* lock vertical motion */
68
69 static int getpixels(), xnewcolr(), freepixels(), resizewindow(),
70 getevent(), getkey(), moveview(), getmove(), fixwindow();
71 static unsigned long true_pixel();
72
73
74 static int
75 mytmflags() /* figure out tone mapping flags */
76 {
77 extern char *progname;
78 register char *cp, *tail;
79 /* find basic name */
80 for (cp = tail = progname; *cp; cp++)
81 if (*cp == '/')
82 tail = cp+1;
83 for (cp = tail; *cp && *cp != '.'; cp++)
84 ;
85 if (cp-tail == 3 && !strncmp(tail, "x11", 3))
86 return(TM_F_CAMERA|TM_F_NOSTDERR);
87 if (cp-tail == 4 && !strncmp(tail, "x11h", 4))
88 return(TM_F_HUMAN|TM_F_NOSTDERR);
89 error(USER, "illegal driver name");
90 }
91
92
93 dev_open(id) /* initialize X11 driver */
94 char *id;
95 {
96 extern char *getenv();
97 static RGBPRIMS myprims = STDPRIMS;
98 char *ev;
99 double gamval = GAMMA;
100 RGBPRIMP dpri = stdprims;
101 int nplanes;
102 XSetWindowAttributes ourwinattr;
103 XWMHints ourxwmhints;
104 XSizeHints oursizhints;
105 /* set quadtree globals */
106 qtMinNodesiz = 2;
107 /* open display server */
108 ourdisplay = XOpenDisplay(NULL);
109 if (ourdisplay == NULL)
110 error(USER, "cannot open X-windows; DISPLAY variable set?\n");
111 /* find a usable visual */
112 nplanes = DisplayPlanes(ourdisplay, ourscreen);
113 if (XMatchVisualInfo(ourdisplay,ourscreen,
114 nplanes>12?nplanes:24,TrueColor,&ourvinfo) ||
115 XMatchVisualInfo(ourdisplay,ourscreen,
116 nplanes>12?nplanes:24,DirectColor,&ourvinfo)) {
117 ourblack = 0;
118 ourwhite = ourvinfo.red_mask |
119 ourvinfo.green_mask |
120 ourvinfo.blue_mask ;
121 } else {
122 if (nplanes < 4)
123 error(INTERNAL, "not enough colors\n");
124 if (!XMatchVisualInfo(ourdisplay,ourscreen,
125 nplanes,PseudoColor,&ourvinfo) &&
126 !XMatchVisualInfo(ourdisplay,ourscreen,
127 nplanes,GrayScale,&ourvinfo))
128 error(INTERNAL, "unsupported visual type\n");
129 ourblack = BlackPixel(ourdisplay,ourscreen);
130 ourwhite = WhitePixel(ourdisplay,ourscreen);
131 }
132 /* set gamma and tone mapping */
133 if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
134 || (ev = getenv("DISPLAY_GAMMA")) != NULL)
135 gamval = atof(ev);
136 if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
137 sscanf(ev, "%f %f %f %f %f %f %f %f",
138 &myprims[RED][CIEX],&myprims[RED][CIEY],
139 &myprims[GRN][CIEX],&myprims[GRN][CIEY],
140 &myprims[BLU][CIEX],&myprims[BLU][CIEY],
141 &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
142 dpri = myprims;
143 if (tmInit(mytmflags(), dpri, gamval) == NULL)
144 error(SYSTEM, "not enough memory in dev_open");
145 /* open window */
146 ourwinattr.background_pixel = ourblack;
147 ourwinattr.border_pixel = ourblack;
148 ourwinattr.event_mask = ourmask;
149 /* this is stupid */
150 ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
151 ourvinfo.visual, AllocNone);
152 gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
153 DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
154 DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
155 BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
156 CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
157 if (gwind == 0)
158 error(SYSTEM, "cannot create window\n");
159 XStoreName(ourdisplay, gwind, id);
160 /* get graphics context */
161 ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
162 /* set window manager hints */
163 ourxwmhints.flags = InputHint|IconPixmapHint;
164 ourxwmhints.input = True;
165 ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
166 gwind, x11icon_bits, x11icon_width, x11icon_height);
167 XSetWMHints(ourdisplay, gwind, &ourxwmhints);
168 oursizhints.min_width = MINWIDTH;
169 oursizhints.min_height = MINHEIGHT;
170 oursizhints.flags = PMinSize;
171 XSetNormalHints(ourdisplay, gwind, &oursizhints);
172 /* figure out sensible view */
173 pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
174 DisplayWidth(ourdisplay, ourscreen);
175 pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
176 DisplayHeight(ourdisplay, ourscreen);
177 copystruct(&odev.v, &stdview);
178 odev.v.type = VT_PER;
179 /* map the window and get its size */
180 XMapWindow(ourdisplay, gwind);
181 dev_input(); /* sets size and view angles */
182 /* allocate our leaf pile */
183 if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
184 DisplayHeight(ourdisplay,ourscreen) * 3 /
185 (qtMinNodesiz*qtMinNodesiz*2)))
186 error(SYSTEM, "insufficient memory for leaf storage");
187 odev.name = id;
188 odev.ifd = ConnectionNumber(ourdisplay);
189 }
190
191
192 dev_close() /* close our display */
193 {
194 freepixels();
195 XFreeGC(ourdisplay, ourgc);
196 XDestroyWindow(ourdisplay, gwind);
197 gwind = 0;
198 ourgc = 0;
199 XCloseDisplay(ourdisplay);
200 ourdisplay = NULL;
201 qtFreeLeaves();
202 tmDone(NULL);
203 odev.v.type = 0;
204 odev.hres = odev.vres = 0;
205 odev.ifd = -1;
206 }
207
208
209
210 dev_clear() /* clear our quadtree */
211 {
212 qtCompost(100);
213 if (ncolors > 0)
214 new_ctab(ncolors);
215 rayqleft = 0; /* hold off update */
216 }
217
218
219 int
220 dev_view(nv) /* assign new driver view */
221 VIEW *nv;
222 {
223 if (nv->type == VT_PAR || /* check view legality */
224 nv->horiz > 160. || nv->vert > 160.) {
225 error(COMMAND, "illegal view type/angle");
226 nv->type = VT_PER;
227 nv->horiz = odev.v.horiz;
228 nv->vert = odev.v.vert;
229 return(0);
230 }
231 if (nv->vfore > FTINY) {
232 error(COMMAND, "cannot handle fore clipping");
233 nv->vfore = 0.;
234 return(0);
235 }
236 if (nv != &odev.v) {
237 if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
238 !FEQ(nv->vert,odev.v.vert)) {
239 int dw = DisplayWidth(ourdisplay,ourscreen);
240 int dh = DisplayHeight(ourdisplay,ourscreen);
241
242 dw -= 25; /* for window frame */
243 dh -= 50;
244 odev.hres = 2.*VIEWDIST/pwidth *
245 tan(PI/180./2.*nv->horiz);
246 odev.vres = 2.*VIEWDIST/pheight *
247 tan(PI/180./2.*nv->vert);
248 if (odev.hres > dw) {
249 odev.vres = dw * odev.vres / odev.hres;
250 odev.hres = dw;
251 }
252 if (odev.vres > dh) {
253 odev.hres = dh * odev.hres / odev.vres;
254 odev.vres = dh;
255 }
256 XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
257 dev_input(); /* wait for resize event */
258 }
259 copystruct(&odev.v, nv);
260 }
261 qtReplant();
262 return(1);
263 }
264
265
266 dev_auxcom(cmd, args) /* process an auxiliary command */
267 char *cmd, *args;
268 {
269 sprintf(errmsg, "%s: unknown command", cmd);
270 error(COMMAND, errmsg);
271 }
272
273
274 VIEW *
275 dev_auxview(n, hvres) /* return nth auxiliary view */
276 int n;
277 int hvres[2];
278 {
279 if (n)
280 return(NULL);
281 hvres[0] = odev.hres; hvres[1] = odev.vres;
282 return(&odev.v);
283 }
284
285
286 int
287 dev_input() /* get X11 input */
288 {
289 inpresflags = 0;
290
291 do
292 getevent();
293
294 while (XPending(ourdisplay) > 0);
295
296 odev.inpready = 0;
297
298 return(inpresflags);
299 }
300
301
302 dev_paintr(rgb, xmin, ymin, xmax, ymax) /* fill a rectangle */
303 BYTE rgb[3];
304 int xmin, ymin, xmax, ymax;
305 {
306 unsigned long pixel;
307
308 if (!mapped)
309 return;
310 if (ncolors > 0)
311 pixel = pixval[get_pixel(rgb, xnewcolr)];
312 else
313 pixel = true_pixel(rgb);
314 XSetForeground(ourdisplay, ourgc, pixel);
315 XFillRectangle(ourdisplay, gwind,
316 ourgc, xmin, odev.vres-ymax, xmax-xmin, ymax-ymin);
317 }
318
319
320 int
321 dev_flush() /* flush output */
322 {
323 qtUpdate();
324 rayqleft = RAYQLEN;
325 return(odev.inpready = XPending(ourdisplay));
326 }
327
328
329 static
330 xnewcolr(ndx, r, g, b) /* enter a color into hardware table */
331 int ndx;
332 int r, g, b;
333 {
334 XColor xcolor;
335
336 xcolor.pixel = pixval[ndx];
337 xcolor.red = r << 8;
338 xcolor.green = g << 8;
339 xcolor.blue = b << 8;
340 xcolor.flags = DoRed|DoGreen|DoBlue;
341
342 XStoreColor(ourdisplay, ourmap, &xcolor);
343 }
344
345
346 static int
347 getpixels() /* get the color map */
348 {
349 XColor thiscolor;
350 register int i, j;
351
352 if (ncolors > 0)
353 return(ncolors);
354 if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
355 ourmap = DefaultColormap(ourdisplay,ourscreen);
356 goto loop;
357 }
358 newmap:
359 ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
360 loop:
361 for (ncolors = ourvinfo.colormap_size;
362 ncolors > ourvinfo.colormap_size/3;
363 ncolors = ncolors*.937) {
364 pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
365 if (pixval == NULL)
366 return(ncolors = 0);
367 if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors))
368 break;
369 free((char *)pixval);
370 pixval = NULL;
371 }
372 if (pixval == NULL) {
373 if (ourmap == DefaultColormap(ourdisplay,ourscreen))
374 goto newmap; /* try it with our map */
375 else
376 return(ncolors = 0); /* failed */
377 }
378 if (ourmap != DefaultColormap(ourdisplay,ourscreen))
379 for (i = 0; i < ncolors; i++) { /* reset black and white */
380 if (pixval[i] != ourblack && pixval[i] != ourwhite)
381 continue;
382 thiscolor.pixel = pixval[i];
383 thiscolor.flags = DoRed|DoGreen|DoBlue;
384 XQueryColor(ourdisplay,
385 DefaultColormap(ourdisplay,ourscreen),
386 &thiscolor);
387 XStoreColor(ourdisplay, ourmap, &thiscolor);
388 for (j = i; j+1 < ncolors; j++)
389 pixval[j] = pixval[j+1];
390 ncolors--;
391 i--;
392 }
393 XSetWindowColormap(ourdisplay, gwind, ourmap);
394 return(ncolors);
395 }
396
397
398 static
399 freepixels() /* free our pixels */
400 {
401 if (ncolors == 0)
402 return;
403 XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L);
404 free((char *)pixval);
405 pixval = NULL;
406 ncolors = 0;
407 if (ourmap != DefaultColormap(ourdisplay,ourscreen))
408 XFreeColormap(ourdisplay, ourmap);
409 ourmap = 0;
410 }
411
412
413 static unsigned long
414 true_pixel(rgb) /* return true pixel value for color */
415 register BYTE rgb[3];
416 {
417 register unsigned long rval;
418
419 rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
420 rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
421 rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
422 return(rval);
423 }
424
425
426 static
427 getevent() /* get next event */
428 {
429 XNextEvent(ourdisplay, levptr(XEvent));
430 switch (levptr(XEvent)->type) {
431 case ConfigureNotify:
432 resizewindow(levptr(XConfigureEvent));
433 break;
434 case UnmapNotify:
435 mapped = 0;
436 freepixels();
437 break;
438 case MapNotify:
439 if (ourvinfo.class == PseudoColor ||
440 ourvinfo.class == GrayScale) {
441 if (getpixels() == 0)
442 error(SYSTEM, "cannot allocate colors\n");
443 new_ctab(ncolors);
444 }
445 mapped = 1;
446 break;
447 case Expose:
448 fixwindow(levptr(XExposeEvent));
449 break;
450 case KeyPress:
451 getkey(levptr(XKeyPressedEvent));
452 break;
453 case ButtonPress:
454 getmove(levptr(XButtonPressedEvent));
455 break;
456 }
457 }
458
459
460 static
461 ilclip(dp, wp) /* clip world coordinates to device */
462 int dp[2][2];
463 FVECT wp[2];
464 {
465 static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE};
466 FVECT wpc[2], ip[2];
467 double d, d0, d1;
468 /* check for points behind view */
469 d = DOT(odev.v.vp, odev.v.vdir);
470 d0 = DOT(wp[0], odev.v.vdir) - d;
471 d1 = DOT(wp[1], odev.v.vdir) - d;
472 /* work on copy of world points */
473 if (d0 <= d1) {
474 VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]);
475 } else {
476 d = d0; d0 = d1; d1 = d;
477 VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]);
478 }
479 if (d0 <= FTINY) {
480 if (d1 <= FTINY) return(0);
481 VSUB(wpc[0], wpc[0], wpc[1]);
482 d = .99*d1/(d1-d0);
483 VSUM(wpc[0], wpc[1], wpc[0], d);
484 }
485 /* get view coordinates and clip to window */
486 viewloc(ip[0], &odev.v, wpc[0]);
487 viewloc(ip[1], &odev.v, wpc[1]);
488 if (!clip(ip[0], ip[1], vmin, vmax))
489 return(0);
490 dp[0][0] = ip[0][0]*odev.hres;
491 dp[0][1] = ip[0][1]*odev.vres;
492 dp[1][0] = ip[1][0]*odev.hres;
493 dp[1][1] = ip[1][1]*odev.vres;
494 return(1);
495 }
496
497
498 static
499 draw3dline(wp) /* draw 3d line in world coordinates */
500 FVECT wp[2];
501 {
502 int dp[2][2];
503
504 if (!ilclip(dp, wp))
505 return;
506 XDrawLine(ourdisplay, gwind, ourgc,
507 dp[0][0], odev.vres-1 - dp[0][1],
508 dp[1][0], odev.vres-1 - dp[1][1]);
509 }
510
511
512 static
513 draw_grids() /* draw holodeck section grids */
514 {
515 static BYTE gridrgb[3] = {0x0, 0xff, 0xff};
516 unsigned long pixel;
517
518 if (ncolors > 0)
519 pixel = pixval[get_pixel(gridrgb, xnewcolr)];
520 else
521 pixel = true_pixel(gridrgb);
522 XSetForeground(ourdisplay, ourgc, pixel);
523 /* draw each grid line */
524 gridlines(draw3dline);
525 }
526
527
528 static
529 moveview(dx, dy, mov, orb) /* move our view */
530 int dx, dy, mov, orb;
531 {
532 VIEW nv;
533 FVECT odir, v1;
534 double d;
535 register int li;
536 /* start with old view */
537 copystruct(&nv, &odev.v);
538 /* change view direction */
539 if (mov | orb) {
540 if ((li = qtFindLeaf(dx, dy)) < 0)
541 return(0); /* not on window */
542 VSUM(odir, qtL.wp[li], nv.vp, -1.);
543 } else {
544 if (viewray(nv.vp, nv.vdir, &odev.v,
545 (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
546 return(0); /* outside view */
547 }
548 if (orb && mov) { /* orbit left/right */
549 spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
550 VSUM(nv.vp, qtL.wp[li], odir, -1.);
551 spinvector(nv.vdir, nv.vdir, nv.vup, d);
552 } else if (orb) { /* orbit up/down */
553 fcross(v1, odir, nv.vup);
554 if (normalize(v1) == 0.)
555 return(0);
556 spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
557 VSUM(nv.vp, qtL.wp[li], odir, -1.);
558 spinvector(nv.vdir, nv.vdir, v1, d);
559 } else if (mov) { /* move forward/backward */
560 d = MOVPCT/100. * mov;
561 VSUM(nv.vp, nv.vp, odir, d);
562 }
563 if (!mov ^ !orb && headlocked) { /* restore head height */
564 VSUM(v1, odev.v.vp, nv.vp, -1.);
565 d = DOT(v1, odev.v.vup);
566 VSUM(nv.vp, nv.vp, odev.v.vup, d);
567 }
568 if (setview(&nv) != NULL)
569 return(0); /* illegal view */
570 dev_view(&nv);
571 inpresflags |= DFL(DC_SETVIEW);
572 return(1);
573 }
574
575
576 static
577 getmove(ebut) /* get view change */
578 XButtonPressedEvent *ebut;
579 {
580 int movdir = MOVDIR(ebut->button);
581 int movorb = MOVORB(ebut->state);
582 int oldnodesiz = qtMinNodesiz;
583 Window rootw, childw;
584 int rootx, rooty, wx, wy;
585 unsigned int statemask;
586
587 qtMinNodesiz = 16; /* for quicker update */
588 XNoOp(ourdisplay);
589
590 while (!XCheckMaskEvent(ourdisplay,
591 ButtonReleaseMask, levptr(XEvent))) {
592
593 if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
594 &rootx, &rooty, &wx, &wy, &statemask))
595 break; /* on another screen */
596
597 if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
598 sleep(1);
599 continue;
600 }
601 XClearWindow(ourdisplay, gwind);
602 qtUpdate();
603 draw_grids();
604 }
605 if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
606 movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
607 wx = levptr(XButtonReleasedEvent)->x;
608 wy = levptr(XButtonReleasedEvent)->y;
609 moveview(wx, odev.vres-1-wy, movdir, movorb);
610 }
611 dev_flush();
612
613 qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
614 }
615
616
617 static
618 getkey(ekey) /* get input key */
619 register XKeyPressedEvent *ekey;
620 {
621 int n;
622 char buf[8];
623
624 n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
625 if (n != 1)
626 return;
627 switch (buf[0]) {
628 case 'h': /* turn on height motion lock */
629 headlocked = 1;
630 return;
631 case 'H': /* turn off height motion lock */
632 headlocked = 0;
633 return;
634 case 'l': /* retrieve last view */
635 inpresflags |= DFL(DC_LASTVIEW);
636 return;
637 case 'p': /* pause computation */
638 inpresflags |= DFL(DC_PAUSE);
639 return;
640 case 'v': /* spit out view */
641 inpresflags |= DFL(DC_GETVIEW);
642 return;
643 case '\n':
644 case '\r': /* resume computation */
645 inpresflags |= DFL(DC_RESUME);
646 return;
647 case CTRL('R'): /* redraw screen */
648 if (ncolors > 0)
649 new_ctab(ncolors);
650 qtRedraw(0, 0, odev.hres, odev.vres);
651 return;
652 case CTRL('L'): /* refresh from server */
653 if (inpresflags & DFL(DC_REDRAW))
654 return;
655 XClearWindow(ourdisplay, gwind);
656 draw_grids();
657 XFlush(ourdisplay);
658 qtCompost(100); /* unload the old tree */
659 if (ncolors > 0)
660 new_ctab(ncolors);
661 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
662 rayqleft = 0; /* hold off update */
663 return;
664 case 'K': /* kill rtrace process(es) */
665 inpresflags |= DFL(DC_KILL);
666 break;
667 case 'R': /* restart rtrace */
668 inpresflags |= DFL(DC_RESTART);
669 break;
670 case 'C': /* clobber holodeck */
671 inpresflags |= DFL(DC_CLOBBER);
672 break;
673 case 'q': /* quit the program */
674 inpresflags |= DFL(DC_QUIT);
675 return;
676 default:
677 XBell(ourdisplay, 0);
678 return;
679 }
680 }
681
682
683 static
684 fixwindow(eexp) /* repair damage to window */
685 register XExposeEvent *eexp;
686 {
687 if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
688 odev.hres = eexp->width;
689 odev.vres = eexp->height;
690 }
691 qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
692 eexp->x + eexp->width, odev.vres - eexp->y);
693 }
694
695
696 static
697 resizewindow(ersz) /* resize window */
698 register XConfigureEvent *ersz;
699 {
700 if (ersz->width == odev.hres && ersz->height == odev.vres)
701 return;
702
703 odev.hres = ersz->width;
704 odev.vres = ersz->height;
705
706 odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
707 odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
708
709 inpresflags |= DFL(DC_SETVIEW);
710 }