ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
Revision: 3.28
Committed: Thu Aug 27 19:32:27 1998 UTC (25 years, 7 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.27: +23 -7 lines
Log Message:
finally fixed problem with grid drawing

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