ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
Revision: 3.17
Committed: Fri Dec 19 14:44:58 1997 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.16: +11 -9 lines
Log Message:
vastly improved interactive view changes

File Contents

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