ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
Revision: 3.26
Committed: Wed Jun 17 15:44:07 1998 UTC (25 years, 10 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.25: +9 -1 lines
Log Message:
added dev_auxcom() for auxiliary command handling

File Contents

# User Rev Content
1 gwlarson 3.26 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 gregl 3.1
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.20 #ifndef RAYQLEN
22     #define RAYQLEN 50000 /* max. rays to queue before flush */
23     #endif
24    
25 gregl 3.11 #ifndef FEQ
26     #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
27     #endif
28    
29 gregl 3.1 #define GAMMA 2.2 /* default gamma correction */
30    
31 gregl 3.13 #define MOVPCT 7 /* percent distance to move /frame */
32 gregl 3.2 #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
33 gregl 3.13 #define MOVDEG (-5) /* degrees to orbit CW/down /frame */
34     #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
35 gregl 3.2
36 gregl 3.1 #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 gregl 3.2 ButtonPressMask|ButtonReleaseMask)
47 gregl 3.1
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 gregl 3.2 static int headlocked = 0; /* lock vertical motion */
70 gregl 3.1
71     static int getpixels(), xnewcolr(), freepixels(), resizewindow(),
72 gregl 3.2 getevent(), getkey(), moveview(), getmove(), fixwindow();
73 gregl 3.1 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 gregl 3.20 return(TM_F_CAMERA|TM_F_NOSTDERR);
89 gregl 3.1 if (cp-tail == 4 && !strncmp(tail, "x11h", 4))
90 gregl 3.20 return(TM_F_HUMAN|TM_F_NOSTDERR);
91 gregl 3.1 error(USER, "illegal driver name");
92     }
93    
94    
95     dev_open(id) /* initialize X11 driver */
96     char *id;
97     {
98     extern char *getenv();
99 gregl 3.24 static RGBPRIMS myprims = STDPRIMS;
100     char *ev;
101 gregl 3.1 double gamval = GAMMA;
102 gregl 3.24 RGBPRIMP dpri = stdprims;
103 gregl 3.1 int nplanes;
104     XSetWindowAttributes ourwinattr;
105     XWMHints ourxwmhints;
106     XSizeHints oursizhints;
107 gregl 3.2 /* set quadtree globals */
108 gregl 3.4 qtMinNodesiz = 2;
109 gregl 3.1 /* 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 gregl 3.24 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 gregl 3.1 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 gregl 3.18 /* 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 gregl 3.1 /* map the window and get its size */
182     XMapWindow(ourdisplay, gwind);
183 gregl 3.18 dev_input(); /* sets size and view angles */
184 gregl 3.2 /* allocate our leaf pile */
185     if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
186 gregl 3.21 DisplayHeight(ourdisplay,ourscreen) * 3 /
187     (qtMinNodesiz*qtMinNodesiz*2)))
188 gregl 3.2 error(SYSTEM, "insufficient memory for leaf storage");
189 gregl 3.1 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 gregl 3.23
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 gregl 3.13 int
222 gregl 3.1 dev_view(nv) /* assign new driver view */
223     VIEW *nv;
224     {
225 gregl 3.13 if (nv->type == VT_PAR || /* check view legality */
226 gregl 3.17 nv->horiz > 160. || nv->vert > 160.) {
227 gregl 3.13 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 gregl 3.11 if (nv != &odev.v) {
239     if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */
240     !FEQ(nv->vert,odev.v.vert)) {
241 gregl 3.13 int dw = DisplayWidth(ourdisplay,ourscreen);
242     int dh = DisplayHeight(ourdisplay,ourscreen);
243    
244     dw -= 25; /* for window frame */
245 gregl 3.16 dh -= 50;
246 gregl 3.12 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 gregl 3.13 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 gregl 3.11 XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
259 gregl 3.18 dev_input(); /* wait for resize event */
260 gregl 3.11 }
261 gregl 3.1 copystruct(&odev.v, nv);
262 gregl 3.11 }
263 gregl 3.1 qtReplant();
264 gregl 3.13 return(1);
265 gwlarson 3.26 }
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 gregl 3.1 }
274    
275    
276 gwlarson 3.25 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 gregl 3.1 int
289     dev_input() /* get X11 input */
290     {
291     inpresflags = 0;
292 gregl 3.5
293 gregl 3.1 do
294     getevent();
295    
296     while (XQLength(ourdisplay) > 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 gregl 3.20 rayqleft = RAYQLEN;
325 gregl 3.1 return(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 gregl 3.2 getmove(levptr(XButtonPressedEvent));
455 gregl 3.1 break;
456     }
457     }
458    
459    
460     static
461 gregl 3.9 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.,1.,FHUGE};
466     FVECT ip[2];
467     /* not exactly right, but who cares? */
468     viewloc(ip[0], &odev.v, wp[0]);
469     viewloc(ip[1], &odev.v, wp[1]);
470     if (!clip(ip[0], ip[1], vmin, vmax))
471     return(0);
472     dp[0][0] = ip[0][0]*odev.hres;
473     dp[0][1] = ip[0][1]*odev.vres;
474     dp[1][0] = ip[1][0]*odev.hres;
475     dp[1][1] = ip[1][1]*odev.vres;
476     return(1);
477     }
478    
479    
480     static
481     draw3dline(wp) /* draw 3d line in world coordinates */
482     FVECT wp[2];
483     {
484     int dp[2][2];
485    
486     if (!ilclip(dp, wp))
487     return;
488     XDrawLine(ourdisplay, gwind, ourgc,
489     dp[0][0], odev.vres-1 - dp[0][1],
490     dp[1][0], odev.vres-1 - dp[1][1]);
491     }
492    
493    
494     static
495     draw_grids() /* draw holodeck section grids */
496     {
497     static BYTE gridrgb[3] = {0x0, 0xff, 0xff};
498     unsigned long pixel;
499    
500 gregl 3.19 if (!mapped)
501 gregl 3.9 return;
502     if (ncolors > 0)
503     pixel = pixval[get_pixel(gridrgb, xnewcolr)];
504     else
505     pixel = true_pixel(gridrgb);
506     XSetForeground(ourdisplay, ourgc, pixel);
507     /* draw each grid line */
508     gridlines(draw3dline);
509     }
510    
511    
512     static
513 gregl 3.13 moveview(dx, dy, mov, orb) /* move our view */
514     int dx, dy, mov, orb;
515 gregl 3.2 {
516     VIEW nv;
517 gregl 3.17 FVECT odir, v1;
518 gregl 3.2 double d;
519 gregl 3.13 register int li;
520 gregl 3.2 /* start with old view */
521     copystruct(&nv, &odev.v);
522     /* change view direction */
523 gregl 3.13 if (mov | orb) {
524 gregl 3.4 if ((li = qtFindLeaf(dx, dy)) < 0)
525 gregl 3.2 return(0); /* not on window */
526 gregl 3.17 VSUM(odir, qtL.wp[li], nv.vp, -1.);
527 gregl 3.2 } else {
528     if (viewray(nv.vp, nv.vdir, &odev.v,
529     (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
530     return(0); /* outside view */
531     }
532 gregl 3.13 if (orb && mov) { /* orbit left/right */
533 gregl 3.17 spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
534     VSUM(nv.vp, qtL.wp[li], odir, -1.);
535     spinvector(nv.vdir, nv.vdir, nv.vup, d);
536 gregl 3.13 } else if (orb) { /* orbit up/down */
537 gregl 3.17 fcross(v1, odir, nv.vup);
538 gregl 3.13 if (normalize(v1) == 0.)
539     return(0);
540 gregl 3.17 spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
541     VSUM(nv.vp, qtL.wp[li], odir, -1.);
542     spinvector(nv.vdir, nv.vdir, v1, d);
543 gregl 3.13 } else if (mov) { /* move forward/backward */
544     d = MOVPCT/100. * mov;
545 gregl 3.17 VSUM(nv.vp, nv.vp, odir, d);
546 gregl 3.2 }
547 gregl 3.13 if (!mov ^ !orb && headlocked) { /* restore head height */
548     VSUM(v1, odev.v.vp, nv.vp, -1.);
549     d = DOT(v1, odev.v.vup);
550     VSUM(nv.vp, nv.vp, odev.v.vup, d);
551     }
552 gregl 3.2 if (setview(&nv) != NULL)
553     return(0); /* illegal view */
554     dev_view(&nv);
555 gregl 3.14 inpresflags |= DFL(DC_SETVIEW);
556 gregl 3.2 return(1);
557     }
558    
559    
560     static
561     getmove(ebut) /* get view change */
562     XButtonPressedEvent *ebut;
563     {
564 gregl 3.13 int movdir = MOVDIR(ebut->button);
565     int movorb = MOVORB(ebut->state);
566 gregl 3.2 int oldnodesiz = qtMinNodesiz;
567     Window rootw, childw;
568     int rootx, rooty, wx, wy;
569     unsigned int statemask;
570    
571     qtMinNodesiz = 16; /* for quicker update */
572 gregl 3.9 XNoOp(ourdisplay);
573 gregl 3.2
574 gregl 3.9 while (!XCheckMaskEvent(ourdisplay,
575     ButtonReleaseMask, levptr(XEvent))) {
576    
577 gregl 3.2 if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
578     &rootx, &rooty, &wx, &wy, &statemask))
579     break; /* on another screen */
580    
581 gregl 3.13 if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
582 gregl 3.2 sleep(1);
583 gregl 3.9 continue;
584     }
585     XClearWindow(ourdisplay, gwind);
586     qtUpdate();
587     draw_grids();
588     }
589 gregl 3.14 if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
590 gregl 3.13 movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
591 gregl 3.2 wx = levptr(XButtonReleasedEvent)->x;
592     wy = levptr(XButtonReleasedEvent)->y;
593 gregl 3.13 moveview(wx, odev.vres-1-wy, movdir, movorb);
594 gregl 3.2 }
595 gregl 3.9 dev_flush();
596 gregl 3.2
597     qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */
598     }
599    
600    
601     static
602 gregl 3.1 getkey(ekey) /* get input key */
603     register XKeyPressedEvent *ekey;
604     {
605     int n;
606     char buf[8];
607    
608     n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
609     if (n != 1)
610     return;
611     switch (buf[0]) {
612     case 'h': /* turn on height motion lock */
613 gregl 3.2 headlocked = 1;
614 gregl 3.1 return;
615     case 'H': /* turn off height motion lock */
616 gregl 3.2 headlocked = 0;
617 gregl 3.13 return;
618     case 'l': /* retrieve last view */
619 gregl 3.14 inpresflags |= DFL(DC_LASTVIEW);
620 gregl 3.1 return;
621 gregl 3.2 case 'p': /* pause computation */
622 gregl 3.14 inpresflags |= DFL(DC_PAUSE);
623 gregl 3.2 return;
624 gregl 3.7 case 'v': /* spit out view */
625 gregl 3.14 inpresflags |= DFL(DC_GETVIEW);
626 gregl 3.7 return;
627 gregl 3.2 case '\n':
628 gregl 3.5 case '\r': /* resume computation */
629 gregl 3.14 inpresflags |= DFL(DC_RESUME);
630 gregl 3.2 return;
631 gregl 3.7 case CTRL('R'): /* redraw screen */
632     if (ncolors > 0)
633     new_ctab(ncolors);
634     qtRedraw(0, 0, odev.hres, odev.vres);
635     return;
636     case CTRL('L'): /* refresh from server */
637 gregl 3.14 if (inpresflags & DFL(DC_REDRAW))
638 gregl 3.8 return;
639 gregl 3.7 XClearWindow(ourdisplay, gwind);
640 gregl 3.9 draw_grids();
641 gregl 3.8 XFlush(ourdisplay);
642 gregl 3.6 qtCompost(100); /* unload the old tree */
643 gregl 3.3 if (ncolors > 0)
644     new_ctab(ncolors);
645 gregl 3.14 inpresflags |= DFL(DC_REDRAW); /* resend values from server */
646 gregl 3.22 rayqleft = 0; /* hold off update */
647 gregl 3.3 return;
648 gregl 3.15 case 'K': /* kill rtrace process(es) */
649     inpresflags |= DFL(DC_KILL);
650     break;
651     case 'R': /* restart rtrace */
652     inpresflags |= DFL(DC_RESTART);
653     break;
654     case 'C': /* clobber holodeck */
655     inpresflags |= DFL(DC_CLOBBER);
656     break;
657 gregl 3.1 case 'q': /* quit the program */
658 gregl 3.14 inpresflags |= DFL(DC_QUIT);
659 gregl 3.1 return;
660     default:
661     XBell(ourdisplay, 0);
662     return;
663     }
664     }
665    
666    
667     static
668     fixwindow(eexp) /* repair damage to window */
669     register XExposeEvent *eexp;
670     {
671     if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
672     odev.hres = eexp->width;
673     odev.vres = eexp->height;
674     }
675     qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
676     eexp->x + eexp->width, odev.vres - eexp->y);
677     }
678    
679    
680     static
681     resizewindow(ersz) /* resize window */
682     register XConfigureEvent *ersz;
683     {
684     if (ersz->width == odev.hres && ersz->height == odev.vres)
685     return;
686    
687     odev.hres = ersz->width;
688     odev.vres = ersz->height;
689    
690 gregl 3.12 odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
691     odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
692    
693 gregl 3.14 inpresflags |= DFL(DC_SETVIEW);
694 gregl 3.1 }