ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
(Generate patch)

Comparing ray/src/hd/rhd_x11.c (file contents):
Revision 3.1 by gregl, Wed Nov 19 18:01:03 1997 UTC vs.
Revision 3.38 by greg, Fri Jan 7 20:33:02 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * X11 driver for holodeck display.
6   * Based on rview driver.
7   */
8  
9 < #include "standard.h"
10 < #include "rhd_qtree.h"
14 <
9 > #include  <stdlib.h>
10 > #include  <stdio.h>
11   #include  <X11/Xlib.h>
12   #include  <X11/cursorfont.h>
13   #include  <X11/Xutil.h>
14 + #include  <time.h>
15  
16 < #include  "x11icon.h"
16 > #include "platform.h"
17 > #include "rtmath.h"
18 > #include "rterror.h"
19 > #include "plocate.h"
20 > #include "rhdisp.h"
21 > #include "rhd_qtree.h"
22 > #include "x11icon.h"
23  
24 + #ifndef RAYQLEN
25 + #define RAYQLEN         50000           /* max. rays to queue before flush */
26 + #endif
27 +
28 + #ifndef FEQ
29 + #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
30 + #endif
31 +
32   #define GAMMA           2.2             /* default gamma correction */
33  
34 + #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
35 +
36 + #define MOVPCT          7               /* percent distance to move /frame */
37 + #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
38 + #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
39 + #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
40 +
41   #define MINWIDTH        480             /* minimum graphics window width */
42   #define MINHEIGHT       400             /* minimum graphics window height */
43  
# Line 30 | Line 48 | static char SCCSid[] = "$SunId$ SGI";
48   #define  ourscreen      DefaultScreen(ourdisplay)
49   #define  ourroot        RootWindow(ourdisplay,ourscreen)
50   #define  ourmask        (StructureNotifyMask|ExposureMask|KeyPressMask|\
51 <                        ButtonPressMask)
51 >                        ButtonPressMask|ButtonReleaseMask)
52  
53   #define  levptr(etype)  ((etype *)&currentevent)
54  
55   struct driver   odev;                   /* global device driver structure */
56  
57 + TMstruct        *tmGlobal;              /* global tone-mapping structure */
58 +
59 + char odev_args[64];                     /* command arguments */
60 +
61   static XEvent  currentevent;            /* current event */
62  
63   static int  ncolors = 0;                /* color table size */
# Line 44 | Line 66 | static unsigned long  *pixval = NULL;  /* allocated pix
66   static unsigned long  ourblack=0, ourwhite=1;
67  
68   static Display  *ourdisplay = NULL;     /* our display */
47
69   static XVisualInfo  ourvinfo;           /* our visual information */
49
70   static Window  gwind = 0;               /* our graphics window */
51
71   static GC  ourgc = 0;                   /* our graphics context for drawing */
53
72   static Colormap ourmap = 0;             /* our color map */
73  
74   static double   pwidth, pheight;        /* pixel dimensions (mm) */
75  
76   static int      inpresflags;            /* input result flags */
77  
78 < static int      heightlocked = 0;       /* lock vertical motion */
78 > static int      headlocked = 0;         /* lock vertical motion */
79  
62 static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
63                getevent(), getkey(), fixwindow();
64 static unsigned long  true_pixel();
80  
81 + static int mytmflags(void);
82 + static void xnewcolr(int  ndx, int r, int g, int b);
83 + static int getpixels(void);
84 + static void freepixels(void);
85 + static unsigned long true_pixel(register BYTE rgb[3]);
86 + static void getevent(void);
87 + static int ilclip(int dp[2][2], FVECT wp[2]);
88 + static void draw3dline(FVECT wp[2]);
89 + static void draw_grids(void);
90 + static int moveview(int dx, int dy, int mov, int orb);
91 + static void getframe(XButtonPressedEvent *ebut);
92 + static void waitabit(void);
93 + static void getmove(XButtonPressedEvent *ebut);
94 + static void getkey(register XKeyPressedEvent *ekey);
95 + static void fixwindow(register XExposeEvent *eexp);
96 + static void resizewindow(register XConfigureEvent *ersz);
97  
98 +
99   static int
100 < mytmflags()                     /* figure out tone mapping flags */
100 > mytmflags(void)                 /* figure out tone mapping flags */
101   {
102          extern char     *progname;
103          register char   *cp, *tail;
# Line 76 | Line 108 | mytmflags()                    /* figure out tone mapping flags */
108          for (cp = tail; *cp && *cp != '.'; cp++)
109                  ;
110          if (cp-tail == 3 && !strncmp(tail, "x11", 3))
111 <                return(TM_F_CAMERA);
111 >                return(TM_F_CAMERA|TM_F_NOSTDERR);
112          if (cp-tail == 4 && !strncmp(tail, "x11h", 4))
113 <                return(TM_F_HUMAN);
113 >                return(TM_F_HUMAN|TM_F_NOSTDERR);
114          error(USER, "illegal driver name");
115 +        return 0; /* pro forma return */
116   }
117  
118  
119 < dev_open(id)                    /* initialize X11 driver */
120 < char  *id;
119 > extern void
120 > dev_open(                       /* initialize X11 driver */
121 >        char  *id
122 > )
123   {
124 <        extern char  *getenv();
125 <        char  *gv;
124 >        static RGBPRIMS myprims = STDPRIMS;
125 >        char  *ev;
126          double  gamval = GAMMA;
127 +        RGBPRIMP        dpri = stdprims;
128          int  nplanes;
93        int  n;
129          XSetWindowAttributes    ourwinattr;
130          XWMHints  ourxwmhints;
131          XSizeHints      oursizhints;
132 +                                        /* set quadtree globals */
133 +        qtMinNodesiz = 2;
134                                          /* open display server */
135          ourdisplay = XOpenDisplay(NULL);
136          if (ourdisplay == NULL)
# Line 120 | Line 157 | char  *id;
157                  ourwhite = WhitePixel(ourdisplay,ourscreen);
158          }
159                                          /* set gamma and tone mapping */
160 <        if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
161 <                        || (gv = getenv("DISPLAY_GAMMA")) != NULL)
162 <                gamval = atof(gv);
163 <        if (tmInit(mytmflags(), stdprims, gamval) == NULL)
160 >        if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
161 >                        || (ev = getenv("DISPLAY_GAMMA")) != NULL)
162 >                gamval = atof(ev);
163 >        if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
164 >                        sscanf(ev, "%f %f %f %f %f %f %f %f",
165 >                                &myprims[RED][CIEX],&myprims[RED][CIEY],
166 >                                &myprims[GRN][CIEX],&myprims[GRN][CIEY],
167 >                                &myprims[BLU][CIEX],&myprims[BLU][CIEY],
168 >                                &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
169 >                dpri = myprims;
170 >        tmGlobal = tmInit(mytmflags(), dpri, gamval);
171 >        if (tmGlobal == NULL)
172                  error(SYSTEM, "not enough memory in dev_open");
173                                          /* open window */
174          ourwinattr.background_pixel = ourblack;
# Line 152 | Line 197 | char  *id;
197          oursizhints.min_height = MINHEIGHT;
198          oursizhints.flags = PMinSize;
199          XSetNormalHints(ourdisplay, gwind, &oursizhints);
155                                        /* map the window and get its size */
156        XMapWindow(ourdisplay, gwind);
157        dev_input();
200                                          /* figure out sensible view */
201          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
202                          DisplayWidth(ourdisplay, ourscreen);
203          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
204                          DisplayHeight(ourdisplay, ourscreen);
205 <        copystruct(&odev.v, &stdview);
164 <        odev.name = id;
205 >        odev.v = stdview;
206          odev.v.type = VT_PER;
207 <        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
208 <        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
209 <        odev.ifd = ConnectionNumber(ourdisplay);
207 >                                        /* map the window and get its size */
208 >        XMapWindow(ourdisplay, gwind);
209 >        dev_input();                    /* sets size and view angles */
210                                          /* allocate our leaf pile */
211 <        qtDepthEps = 0.02;
212 <        n = odev.hres < odev.vres ? odev.hres : odev.vres;
213 <        qtMinNodesiz = 1;
173 <        if (!qtAllocLeaves(n*n/(qtMinNodesiz*qtMinNodesiz)))
211 >        if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
212 >                        DisplayHeight(ourdisplay,ourscreen) * 3 /
213 >                        (qtMinNodesiz*qtMinNodesiz*2)))
214                  error(SYSTEM, "insufficient memory for leaf storage");
215 +        odev.name = id;
216 +        odev.ifd = ConnectionNumber(ourdisplay);
217   }
218  
219  
220 < dev_close()                     /* close our display */
220 > extern void
221 > dev_close(void)                 /* close our display */
222   {
223          freepixels();
224          XFreeGC(ourdisplay, ourgc);
# Line 185 | Line 228 | dev_close()                    /* close our display */
228          XCloseDisplay(ourdisplay);
229          ourdisplay = NULL;
230          qtFreeLeaves();
231 <        tmDone(NULL);
231 >        tmDone(tmGlobal);
232          odev.v.type = 0;
233          odev.hres = odev.vres = 0;
234          odev.ifd = -1;
235   }
236  
237  
238 < dev_view(nv)                    /* assign new driver view */
239 < VIEW    *nv;
238 > extern void
239 > dev_clear(void)                 /* clear our quadtree */
240   {
241 <        if (nv != &odev.v)
242 <                copystruct(&odev.v, nv);
241 >        qtCompost(100);
242 >        if (ncolors > 0)
243 >                new_ctab(ncolors);
244 >        rayqleft = 0;                   /* hold off update */
245 > }
246 >
247 >
248 > extern int
249 > dev_view(                       /* assign new driver view */
250 >        VIEW    *nv
251 > )
252 > {
253 >        if (nv->type == VT_PAR ||               /* check view legality */
254 >                        nv->horiz > 160. || nv->vert > 160.) {
255 >                error(COMMAND, "illegal view type/angle");
256 >                nv->type = VT_PER;
257 >                nv->horiz = odev.v.horiz;
258 >                nv->vert = odev.v.vert;
259 >                return(0);
260 >        }
261 >        if (nv->vfore > FTINY) {
262 >                error(COMMAND, "cannot handle fore clipping");
263 >                nv->vfore = 0.;
264 >                return(0);
265 >        }
266 >        if (nv != &odev.v) {
267 >                if (!FEQ(nv->horiz,odev.v.horiz) ||     /* resize window? */
268 >                                !FEQ(nv->vert,odev.v.vert)) {
269 >                        int     dw = DisplayWidth(ourdisplay,ourscreen);
270 >                        int     dh = DisplayHeight(ourdisplay,ourscreen);
271 >
272 >                        dw -= 25;       /* for window frame */
273 >                        dh -= 50;
274 >                        odev.hres = 2.*VIEWDIST/pwidth *
275 >                                        tan(PI/180./2.*nv->horiz);
276 >                        odev.vres = 2.*VIEWDIST/pheight *
277 >                                        tan(PI/180./2.*nv->vert);
278 >                        if (odev.hres > dw) {
279 >                                odev.vres = dw * odev.vres / odev.hres;
280 >                                odev.hres = dw;
281 >                        }
282 >                        if (odev.vres > dh) {
283 >                                odev.hres = dh * odev.hres / odev.vres;
284 >                                odev.vres = dh;
285 >                        }
286 >                        XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
287 >                        dev_input();    /* wait for resize event */
288 >                }
289 >                odev.v = *nv;
290 >        }
291          qtReplant();
292 +        return(1);
293   }
294  
295  
296 < int
297 < dev_input()                     /* get X11 input */
296 > extern void
297 > dev_section(            /* add octree for geometry rendering */
298 >        char    *ofn
299 > )
300   {
301 +        /* unimplemented */
302 + }
303 +
304 +
305 + extern void
306 + dev_auxcom(             /* process an auxiliary command */
307 +        char    *cmd,
308 +        char    *args
309 + )
310 + {
311 +        sprintf(errmsg, "%s: unknown command", cmd);
312 +        error(COMMAND, errmsg);
313 + }
314 +
315 +
316 + extern VIEW *
317 + dev_auxview(            /* return nth auxiliary view */
318 +        int     n,
319 +        int     hvres[2]
320 + )
321 + {
322 +        if (n)
323 +                return(NULL);
324 +        hvres[0] = odev.hres; hvres[1] = odev.vres;
325 +        return(&odev.v);
326 + }
327 +
328 +
329 + extern int
330 + dev_input(void)                 /* get X11 input */
331 + {
332          inpresflags = 0;
333 +
334          do
335                  getevent();
336  
337 <        while (XQLength(ourdisplay) > 0);
337 >        while (XPending(ourdisplay) > 0);
338  
339 +        odev.inpready = 0;
340 +
341          return(inpresflags);
342   }
343  
344  
345 < dev_paintr(rgb, xmin, ymin, xmax, ymax)         /* fill a rectangle */
346 < BYTE    rgb[3];
347 < int  xmin, ymin, xmax, ymax;
345 > extern void
346 > dev_paintr(             /* fill a rectangle */
347 >        BYTE    rgb[3],
348 >        int  xmin,
349 >        int  ymin,
350 >        int  xmax,
351 >        int  ymax
352 > )
353   {
354          unsigned long  pixel;
355  
# Line 232 | Line 365 | int  xmin, ymin, xmax, ymax;
365   }
366  
367  
368 < int
369 < dev_flush()                     /* flush output */
368 > extern int
369 > dev_flush(void)                 /* flush output */
370   {
371          qtUpdate();
372 <        return(XPending(ourdisplay));
372 >        rayqleft = RAYQLEN;
373 >        return(odev.inpready = XPending(ourdisplay));
374   }
375  
376  
377 < static
378 < xnewcolr(ndx, r, g, b)          /* enter a color into hardware table */
379 < int  ndx;
380 < int  r, g, b;
377 > static void
378 > xnewcolr(               /* enter a color into hardware table */
379 >        int  ndx,
380 >        int r,
381 >        int g,
382 >        int b
383 > )
384   {
385          XColor  xcolor;
386  
# Line 258 | Line 395 | int  r, g, b;
395  
396  
397   static int
398 < getpixels()                             /* get the color map */
398 > getpixels(void)                         /* get the color map */
399   {
400          XColor  thiscolor;
401          register int  i, j;
# Line 280 | Line 417 | loop:
417                          return(ncolors = 0);
418                  if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors))
419                          break;
420 <                free((char *)pixval);
420 >                free((void *)pixval);
421                  pixval = NULL;
422          }
423          if (pixval == NULL) {
# Line 309 | Line 446 | loop:
446   }
447  
448  
449 < static
450 < freepixels()                            /* free our pixels */
449 > static void
450 > freepixels(void)                                /* free our pixels */
451   {
452          if (ncolors == 0)
453                  return;
454          XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L);
455 <        free((char *)pixval);
455 >        free((void *)pixval);
456          pixval = NULL;
457          ncolors = 0;
458          if (ourmap != DefaultColormap(ourdisplay,ourscreen))
# Line 325 | Line 462 | freepixels()                           /* free our pixels */
462  
463  
464   static unsigned long
465 < true_pixel(rgb)                 /* return true pixel value for color */
466 < register BYTE   rgb[3];
465 > true_pixel(                     /* return true pixel value for color */
466 >        register BYTE   rgb[3]
467 > )
468   {
469          register unsigned long  rval;
470  
# Line 337 | Line 475 | register BYTE  rgb[3];
475   }
476  
477  
478 < static
479 < getevent()                      /* get next event */
478 > static void
479 > getevent(void)                  /* get next event */
480   {
481          XNextEvent(ourdisplay, levptr(XEvent));
482          switch (levptr(XEvent)->type) {
# Line 365 | Line 503 | getevent()                     /* get next event */
503                  getkey(levptr(XKeyPressedEvent));
504                  break;
505          case ButtonPress:
506 <                /* getmove(levptr(XButtonPressedEvent)); */
506 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
507 >                        getframe(levptr(XButtonPressedEvent));
508 >                else
509 >                        getmove(levptr(XButtonPressedEvent));
510                  break;
511          }
512   }
513  
514  
515 < static
516 < getkey(ekey)                            /* get input key */
517 < register XKeyPressedEvent  *ekey;
515 > static int
516 > ilclip(                 /* clip world coordinates to device */
517 >        int     dp[2][2],
518 >        FVECT   wp[2]
519 > )
520   {
521 +        static FVECT    vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE};
522 +        FVECT   wpc[2], ip[2];
523 +        double  d, d0, d1;
524 +                                /* check for points behind view */
525 +        d = DOT(odev.v.vp, odev.v.vdir);
526 +        d0 = DOT(wp[0], odev.v.vdir) - d;
527 +        d1 = DOT(wp[1], odev.v.vdir) - d;
528 +                                /* work on copy of world points */
529 +        if (d0 <= d1) {
530 +                VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]);
531 +        } else {
532 +                d = d0; d0 = d1; d1 = d;
533 +                VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]);
534 +        }
535 +        if (d0 <= FTINY) {
536 +                if (d1 <= FTINY) return(0);
537 +                VSUB(wpc[0], wpc[0], wpc[1]);
538 +                d = .99*d1/(d1-d0);
539 +                VSUM(wpc[0], wpc[1], wpc[0], d);
540 +        }
541 +                                /* get view coordinates and clip to window */
542 +        viewloc(ip[0], &odev.v, wpc[0]);
543 +        viewloc(ip[1], &odev.v, wpc[1]);
544 +        if (!clip(ip[0], ip[1], vmin, vmax))
545 +                return(0);
546 +        dp[0][0] = ip[0][0]*odev.hres;
547 +        dp[0][1] = ip[0][1]*odev.vres;
548 +        dp[1][0] = ip[1][0]*odev.hres;
549 +        dp[1][1] = ip[1][1]*odev.vres;
550 +        return(1);
551 + }
552 +
553 +
554 + static void
555 + draw3dline(                     /* draw 3d line in world coordinates */
556 +        FVECT   wp[2]
557 + )
558 + {
559 +        int     dp[2][2];
560 +
561 +        if (!ilclip(dp, wp))
562 +                return;
563 +        XDrawLine(ourdisplay, gwind, ourgc,
564 +                        dp[0][0], odev.vres-1 - dp[0][1],
565 +                        dp[1][0], odev.vres-1 - dp[1][1]);
566 + }
567 +
568 +
569 + static void
570 + draw_grids(void)                        /* draw holodeck section grids */
571 + {
572 +        static BYTE     gridrgb[3] = {0x0, 0xff, 0xff};
573 +        unsigned long  pixel;
574 +
575 +        if (ncolors > 0)
576 +                pixel = pixval[get_pixel(gridrgb, xnewcolr)];
577 +        else
578 +                pixel = true_pixel(gridrgb);
579 +        XSetForeground(ourdisplay, ourgc, pixel);
580 +                                        /* draw each grid line */
581 +        gridlines(draw3dline);
582 + }
583 +
584 +
585 + static int
586 + moveview(       /* move our view */
587 +        int     dx,
588 +        int     dy,
589 +        int     mov,
590 +        int     orb
591 + )
592 + {
593 +        VIEW    nv;
594 +        FVECT   odir, v1;
595 +        double  d;
596 +        register int    li;
597 +                                /* start with old view */
598 +        nv = odev.v;
599 +                                /* change view direction */
600 +        if (mov | orb) {
601 +                if ((li = qtFindLeaf(dx, dy)) < 0)
602 +                        return(0);      /* not on window */
603 +                VSUM(odir, qtL.wp[li], nv.vp, -1.);
604 +        } else {
605 +                if (viewray(nv.vp, nv.vdir, &odev.v,
606 +                                (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
607 +                        return(0);      /* outside view */
608 +        }
609 +        if (orb && mov) {               /* orbit left/right */
610 +                spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
611 +                VSUM(nv.vp, qtL.wp[li], odir, -1.);
612 +                spinvector(nv.vdir, nv.vdir, nv.vup, d);
613 +        } else if (orb) {               /* orbit up/down */
614 +                fcross(v1, odir, nv.vup);
615 +                if (normalize(v1) == 0.)
616 +                        return(0);
617 +                spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
618 +                VSUM(nv.vp, qtL.wp[li], odir, -1.);
619 +                spinvector(nv.vdir, nv.vdir, v1, d);
620 +        } else if (mov) {               /* move forward/backward */
621 +                d = MOVPCT/100. * mov;
622 +                VSUM(nv.vp, nv.vp, odir, d);
623 +        }
624 +        if (!mov ^ !orb && headlocked) {        /* restore head height */
625 +                VSUM(v1, odev.v.vp, nv.vp, -1.);
626 +                d = DOT(v1, odev.v.vup);
627 +                VSUM(nv.vp, nv.vp, odev.v.vup, d);
628 +        }
629 +        if (setview(&nv) != NULL)
630 +                return(0);      /* illegal view */
631 +        dev_view(&nv);
632 +        inpresflags |= DFL(DC_SETVIEW);
633 +        return(1);
634 + }
635 +
636 +
637 + static void
638 + getframe(                               /* get focus frame */
639 +        XButtonPressedEvent     *ebut
640 + )
641 + {
642 +        int     startx = ebut->x, starty = ebut->y;
643 +        int     endx, endy;
644 +
645 +        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
646 +        endx = levptr(XButtonReleasedEvent)->x;
647 +        endy = levptr(XButtonReleasedEvent)->y;
648 +        if ((endx == startx) | (endy == starty)) {
649 +                XBell(ourdisplay, 0);
650 +                return;
651 +        }
652 +        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
653 +        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
654 +        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
655 +                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
656 +                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
657 +        inpresflags |= DFL(DC_FOCUS);
658 + }
659 +
660 +
661 + static void
662 + waitabit(void)                          /* pause a moment */
663 + {
664 +        struct timespec ts;
665 +        ts.tv_sec = 0;
666 +        ts.tv_nsec = 100000000;
667 +        nanosleep(&ts, NULL);
668 + }
669 +
670 +
671 + static void
672 + getmove(                                /* get view change */
673 +        XButtonPressedEvent     *ebut
674 + )
675 + {
676 +        int     movdir = MOVDIR(ebut->button);
677 +        int     movorb = MOVORB(ebut->state);
678 +        int     oldnodesiz = qtMinNodesiz;
679 +        Window  rootw, childw;
680 +        int     rootx, rooty, wx, wy;
681 +        unsigned int    statemask;
682 +
683 +        qtMinNodesiz = 16;              /* for quicker update */
684 +        XNoOp(ourdisplay);
685 +
686 +        while (!XCheckMaskEvent(ourdisplay,
687 +                        ButtonReleaseMask, levptr(XEvent))) {
688 +                waitabit();
689 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
690 +                                &rootx, &rooty, &wx, &wy, &statemask))
691 +                        break;          /* on another screen */
692 +
693 +                if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
694 +                        sleep(1);
695 +                        continue;
696 +                }
697 +                XClearWindow(ourdisplay, gwind);
698 +                qtUpdate();
699 +                draw_grids();
700 +        }
701 +        if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
702 +                movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
703 +                wx = levptr(XButtonReleasedEvent)->x;
704 +                wy = levptr(XButtonReleasedEvent)->y;
705 +                moveview(wx, odev.vres-1-wy, movdir, movorb);
706 +        }
707 +        dev_flush();
708 +
709 +        qtMinNodesiz = oldnodesiz;      /* restore quadtree resolution */
710 + }
711 +
712 +
713 + static void
714 + getkey(                         /* get input key */
715 +        register XKeyPressedEvent  *ekey
716 + )
717 + {
718 +        Window  rootw, childw;
719 +        int     rootx, rooty, wx, wy;
720 +        unsigned int    statemask;
721          int  n;
722          char    buf[8];
723  
# Line 383 | Line 726 | register XKeyPressedEvent  *ekey;
726                  return;
727          switch (buf[0]) {
728          case 'h':                       /* turn on height motion lock */
729 <                heightlocked = 1;
729 >                headlocked = 1;
730                  return;
731          case 'H':                       /* turn off height motion lock */
732 <                heightlocked = 0;
732 >                headlocked = 0;
733                  return;
734 <        case 'Q':
734 >        case 'l':                       /* retrieve last view */
735 >                inpresflags |= DFL(DC_LASTVIEW);
736 >                return;
737 >        case 'f':                       /* frame view position */
738 >                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
739 >                                &rootx, &rooty, &wx, &wy, &statemask))
740 >                        return;         /* on another screen */
741 >                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
742 >                                1.-(wy+.5)/odev.vres);
743 >                inpresflags |= DFL(DC_FOCUS);
744 >                return;
745 >        case 'F':                       /* unfocus */
746 >                odev_args[0] = '\0';
747 >                inpresflags |= DFL(DC_FOCUS);
748 >                return;
749 >        case 'p':                       /* pause computation */
750 >                inpresflags |= DFL(DC_PAUSE);
751 >                return;
752 >        case 'v':                       /* spit out view */
753 >                inpresflags |= DFL(DC_GETVIEW);
754 >                return;
755 >        case '\n':
756 >        case '\r':                      /* resume computation */
757 >                inpresflags |= DFL(DC_RESUME);
758 >                return;
759 >        case CTRL('R'):                 /* redraw screen */
760 >                if (ncolors > 0)
761 >                        new_ctab(ncolors);
762 >                qtRedraw(0, 0, odev.hres, odev.vres);
763 >                return;
764 >        case CTRL('L'):                 /* refresh from server */
765 >                if (inpresflags & DFL(DC_REDRAW))
766 >                        return;
767 >                XClearWindow(ourdisplay, gwind);
768 >                draw_grids();
769 >                XFlush(ourdisplay);
770 >                qtCompost(100);                 /* unload the old tree */
771 >                if (ncolors > 0)
772 >                        new_ctab(ncolors);
773 >                inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
774 >                rayqleft = 0;                   /* hold off update */
775 >                return;
776 >        case 'K':                       /* kill rtrace process(es) */
777 >                inpresflags |= DFL(DC_KILL);
778 >                break;
779 >        case 'R':                       /* restart rtrace */
780 >                inpresflags |= DFL(DC_RESTART);
781 >                break;
782 >        case 'C':                       /* clobber holodeck */
783 >                inpresflags |= DFL(DC_CLOBBER);
784 >                break;
785          case 'q':                       /* quit the program */
786 <                inpresflags |= DEV_SHUTDOWN;
786 >                inpresflags |= DFL(DC_QUIT);
787                  return;
788          default:
789                  XBell(ourdisplay, 0);
# Line 399 | Line 792 | register XKeyPressedEvent  *ekey;
792   }
793  
794  
795 < static
796 < fixwindow(eexp)                         /* repair damage to window */
797 < register XExposeEvent  *eexp;
795 > static void
796 > fixwindow(                              /* repair damage to window */
797 >        register XExposeEvent  *eexp
798 > )
799   {
800          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
407 eputs("Resizing window in fixwindow\n");
801                  odev.hres = eexp->width;
802                  odev.vres = eexp->height;
410                inpresflags |= DEV_NEWSIZE;
803          }
804          qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
805                          eexp->x + eexp->width, odev.vres - eexp->y);
806   }
807  
808  
809 < static
810 < resizewindow(ersz)                      /* resize window */
811 < register XConfigureEvent  *ersz;
809 > static void
810 > resizewindow(                   /* resize window */
811 >        register XConfigureEvent  *ersz
812 > )
813   {
814          if (ersz->width == odev.hres && ersz->height == odev.vres)
815                  return;
816  
424        if (odev.hres != 0 && odev.vres != 0) {
425                odev.v.horiz = 2.*180./PI * atan(
426                        tan(PI/180./2.*odev.v.horiz) * ersz->width/odev.hres );
427                odev.v.vert = 2.*180./PI * atan(
428                        tan(PI/180./2.*odev.v.vert) * ersz->height/odev.vres );
429                inpresflags |= DEV_NEWVIEW;
430        }
817          odev.hres = ersz->width;
818          odev.vres = ersz->height;
819  
820 <        inpresflags |= DEV_NEWSIZE;
820 >        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
821 >        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
822 >
823 >        inpresflags |= DFL(DC_SETVIEW);
824   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines