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.12 by gregl, Tue Dec 9 14:04:11 1997 UTC vs.
Revision 3.47 by greg, Fri Feb 12 00:53:56 2021 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 FEQ
25 < #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
24 > #ifndef RAYQLEN
25 > #define RAYQLEN         50000           /* max. rays to queue before flush */
26   #endif
27  
25 #define CTRL(c)         ((c)-'@')
26
28   #define GAMMA           2.2             /* default gamma correction */
29  
30 < #define MOVPCT          10              /* percent distance to move */
30 > #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
31 >
32 > #define MOVPCT          7               /* percent distance to move /frame */
33   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
34 + #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
35 + #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
36  
37   #define MINWIDTH        480             /* minimum graphics window width */
38   #define MINHEIGHT       400             /* minimum graphics window height */
# Line 45 | Line 50 | static char SCCSid[] = "$SunId$ SGI";
50  
51   struct driver   odev;                   /* global device driver structure */
52  
53 + TMstruct        *tmGlobal;              /* global tone-mapping structure */
54 +
55 + char odev_args[64];                     /* command arguments */
56 +
57   static XEvent  currentevent;            /* current event */
58  
59   static int  ncolors = 0;                /* color table size */
# Line 64 | Line 73 | static int     inpresflags;            /* input result flags */
73  
74   static int      headlocked = 0;         /* lock vertical motion */
75  
67 static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
68                getevent(), getkey(), moveview(), getmove(), fixwindow();
69 static unsigned long  true_pixel();
76  
77 + static int mytmflags(void);
78 + static void xnewcolr(int  ndx, int r, int g, int b);
79 + static int getpixels(void);
80 + static void freepixels(void);
81 + static unsigned long true_pixel(uby8 rgb[3]);
82 + static void getevent(void);
83 + static int ilclip(int dp[2][2], FVECT wp[2]);
84 + static void draw3dline(FVECT wp[2]);
85 + static void draw_grids(void);
86 + static int moveview(int dx, int dy, int mov, int orb);
87 + static void getframe(XButtonPressedEvent *ebut);
88 + static void waitabit(void);
89 + static void getmove(XButtonPressedEvent *ebut);
90 + static void getkey(XKeyPressedEvent *ekey);
91 + static void fixwindow(XExposeEvent *eexp);
92 + static void resizewindow(XConfigureEvent *ersz);
93  
94 +
95   static int
96 < mytmflags()                     /* figure out tone mapping flags */
96 > mytmflags(void)                 /* figure out tone mapping flags */
97   {
98          extern char     *progname;
99 <        register char   *cp, *tail;
99 >        char    *cp, *tail;
100                                          /* find basic name */
101          for (cp = tail = progname; *cp; cp++)
102                  if (*cp == '/')
# Line 81 | Line 104 | mytmflags()                    /* figure out tone mapping flags */
104          for (cp = tail; *cp && *cp != '.'; cp++)
105                  ;
106          if (cp-tail == 3 && !strncmp(tail, "x11", 3))
107 <                return(TM_F_CAMERA);
107 >                return(TM_F_CAMERA|TM_F_NOSTDERR);
108          if (cp-tail == 4 && !strncmp(tail, "x11h", 4))
109 <                return(TM_F_HUMAN);
109 >                return(TM_F_HUMAN|TM_F_NOSTDERR);
110          error(USER, "illegal driver name");
111 +        return 0; /* pro forma return */
112   }
113  
114  
115 < dev_open(id)                    /* initialize X11 driver */
116 < char  *id;
115 > void
116 > dev_open(                       /* initialize X11 driver */
117 >        char  *id
118 > )
119   {
120 <        extern char  *getenv();
121 <        char  *gv;
120 >        static RGBPRIMS myprims = STDPRIMS;
121 >        char  *ev;
122          double  gamval = GAMMA;
123 +        RGBPRIMP        dpri = stdprims;
124          int  nplanes;
125          XSetWindowAttributes    ourwinattr;
126          XWMHints  ourxwmhints;
# Line 126 | Line 153 | char  *id;
153                  ourwhite = WhitePixel(ourdisplay,ourscreen);
154          }
155                                          /* set gamma and tone mapping */
156 <        if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
157 <                        || (gv = getenv("DISPLAY_GAMMA")) != NULL)
158 <                gamval = atof(gv);
159 <        if (tmInit(mytmflags(), stdprims, gamval) == NULL)
156 >        if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
157 >                        || (ev = getenv("DISPLAY_GAMMA")) != NULL)
158 >                gamval = atof(ev);
159 >        if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
160 >                        sscanf(ev, "%f %f %f %f %f %f %f %f",
161 >                                &myprims[RED][CIEX],&myprims[RED][CIEY],
162 >                                &myprims[GRN][CIEX],&myprims[GRN][CIEY],
163 >                                &myprims[BLU][CIEX],&myprims[BLU][CIEY],
164 >                                &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
165 >                dpri = myprims;
166 >        tmGlobal = tmInit(mytmflags(), dpri, gamval);
167 >        if (tmGlobal == NULL)
168                  error(SYSTEM, "not enough memory in dev_open");
169                                          /* open window */
170          ourwinattr.background_pixel = ourblack;
# Line 151 | Line 186 | char  *id;
186                                          /* set window manager hints */
187          ourxwmhints.flags = InputHint|IconPixmapHint;
188          ourxwmhints.input = True;
189 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
190 <                        gwind, x11icon_bits, x11icon_width, x11icon_height);
189 >        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
190 >                        (char *)x11icon_bits, x11icon_width, x11icon_height);
191          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
192          oursizhints.min_width = MINWIDTH;
193          oursizhints.min_height = MINHEIGHT;
194          oursizhints.flags = PMinSize;
195          XSetNormalHints(ourdisplay, gwind, &oursizhints);
161                                        /* map the window and get its size */
162        XMapWindow(ourdisplay, gwind);
163        dev_input();
164                                        /* 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
196                                          /* figure out sensible view */
197          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
198                          DisplayWidth(ourdisplay, ourscreen);
199          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
200                          DisplayHeight(ourdisplay, ourscreen);
201 <        copystruct(&odev.v, &stdview);
176 <        odev.name = id;
201 >        odev.v = stdview;
202          odev.v.type = VT_PER;
203 <        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
204 <        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
203 >                                        /* map the window and get its size */
204 >        XMapWindow(ourdisplay, gwind);
205 >        dev_input();                    /* sets size and view angles */
206 >                                        /* allocate our leaf pile */
207 >        if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
208 >                        DisplayHeight(ourdisplay,ourscreen) * 3 /
209 >                        (qtMinNodesiz*qtMinNodesiz*2)))
210 >                error(SYSTEM, "insufficient memory for leaf storage");
211 >        odev.name = id;
212          odev.ifd = ConnectionNumber(ourdisplay);
213   }
214  
215  
216 < dev_close()                     /* close our display */
216 > void
217 > dev_close(void)                 /* close our display */
218   {
219          freepixels();
220          XFreeGC(ourdisplay, ourgc);
# Line 191 | Line 224 | dev_close()                    /* close our display */
224          XCloseDisplay(ourdisplay);
225          ourdisplay = NULL;
226          qtFreeLeaves();
227 <        tmDone(NULL);
227 >        tmDone(tmGlobal);
228          odev.v.type = 0;
229          odev.hres = odev.vres = 0;
230          odev.ifd = -1;
231   }
232  
233  
234 < dev_view(nv)                    /* assign new driver view */
235 < VIEW    *nv;
234 > void
235 > dev_clear(void)                 /* clear our quadtree */
236   {
237 +        qtCompost(100);
238 +        if (ncolors > 0)
239 +                new_ctab(ncolors);
240 +        rayqleft = 0;                   /* hold off update */
241 + }
242 +
243 +
244 + int
245 + dev_view(                       /* assign new driver view */
246 +        VIEW    *nv
247 + )
248 + {
249 +        if (nv->type == VT_PAR ||               /* check view legality */
250 +                        nv->horiz > 160. || nv->vert > 160.) {
251 +                error(COMMAND, "illegal view type/angle");
252 +                nv->type = VT_PER;
253 +                nv->horiz = odev.v.horiz;
254 +                nv->vert = odev.v.vert;
255 +                return(0);
256 +        }
257 +        if (nv->vfore > FTINY) {
258 +                error(COMMAND, "cannot handle fore clipping");
259 +                nv->vfore = 0.;
260 +                return(0);
261 +        }
262          if (nv != &odev.v) {
263 <                if (!FEQ(nv->horiz,odev.v.horiz) ||     /* resize window? */
264 <                                !FEQ(nv->vert,odev.v.vert)) {
263 >                if (!FABSEQ(nv->horiz,odev.v.horiz) ||  /* resize window? */
264 >                                !FABSEQ(nv->vert,odev.v.vert)) {
265 >                        int     dw = DisplayWidth(ourdisplay,ourscreen);
266 >                        int     dh = DisplayHeight(ourdisplay,ourscreen);
267 >
268 >                        dw -= 25;       /* for window frame */
269 >                        dh -= 50;
270                          odev.hres = 2.*VIEWDIST/pwidth *
271                                          tan(PI/180./2.*nv->horiz);
272                          odev.vres = 2.*VIEWDIST/pheight *
273                                          tan(PI/180./2.*nv->vert);
274 +                        if (odev.hres > dw) {
275 +                                odev.vres = dw * odev.vres / odev.hres;
276 +                                odev.hres = dw;
277 +                        }
278 +                        if (odev.vres > dh) {
279 +                                odev.hres = dh * odev.hres / odev.vres;
280 +                                odev.vres = dh;
281 +                        }
282                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
283 +                        dev_input();    /* wait for resize event */
284                  }
285 <                copystruct(&odev.v, nv);
285 >                odev.v = *nv;
286          }
287          qtReplant();
288 +        return(1);
289   }
290  
291  
292 + void
293 + dev_section(            /* add octree for geometry rendering */
294 +        char    *gfn,
295 +        char    *pfn
296 + )
297 + {
298 +        /* unimplemented */
299 + }
300 +
301 +
302 + void
303 + dev_auxcom(             /* process an auxiliary command */
304 +        char    *cmd,
305 +        char    *args
306 + )
307 + {
308 +        sprintf(errmsg, "%s: unknown command", cmd);
309 +        error(COMMAND, errmsg);
310 + }
311 +
312 +
313 + VIEW *
314 + dev_auxview(            /* return nth auxiliary view */
315 +        int     n,
316 +        int     hvres[2]
317 + )
318 + {
319 +        if (n)
320 +                return(NULL);
321 +        hvres[0] = odev.hres; hvres[1] = odev.vres;
322 +        return(&odev.v);
323 + }
324 +
325 +
326   int
327 < dev_input()                     /* get X11 input */
327 > dev_input(void)                 /* get X11 input */
328   {
329          inpresflags = 0;
330  
331          do
332                  getevent();
333  
334 <        while (XQLength(ourdisplay) > 0);
334 >        while (XPending(ourdisplay) > 0);
335  
336 +        odev.inpready = 0;
337 +
338          return(inpresflags);
339   }
340  
341  
342 < dev_paintr(rgb, xmin, ymin, xmax, ymax)         /* fill a rectangle */
343 < BYTE    rgb[3];
344 < int  xmin, ymin, xmax, ymax;
342 > void
343 > dev_paintr(             /* fill a rectangle */
344 >        uby8    rgb[3],
345 >        int  xmin,
346 >        int  ymin,
347 >        int  xmax,
348 >        int  ymax
349 > )
350   {
351          unsigned long  pixel;
352  
# Line 249 | Line 363 | int  xmin, ymin, xmax, ymax;
363  
364  
365   int
366 < dev_flush()                     /* flush output */
366 > dev_flush(void)                 /* flush output */
367   {
368          qtUpdate();
369 <        return(XPending(ourdisplay));
369 >        rayqleft = RAYQLEN;
370 >        return(odev.inpready = XPending(ourdisplay));
371   }
372  
373  
374 < static
375 < xnewcolr(ndx, r, g, b)          /* enter a color into hardware table */
376 < int  ndx;
377 < int  r, g, b;
374 > static void
375 > xnewcolr(               /* enter a color into hardware table */
376 >        int  ndx,
377 >        int r,
378 >        int g,
379 >        int b
380 > )
381   {
382          XColor  xcolor;
383  
# Line 274 | Line 392 | int  r, g, b;
392  
393  
394   static int
395 < getpixels()                             /* get the color map */
395 > getpixels(void)                         /* get the color map */
396   {
397          XColor  thiscolor;
398 <        register int  i, j;
398 >        int  i, j;
399  
400          if (ncolors > 0)
401                  return(ncolors);
# Line 296 | Line 414 | loop:
414                          return(ncolors = 0);
415                  if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors))
416                          break;
417 <                free((char *)pixval);
417 >                free((void *)pixval);
418                  pixval = NULL;
419          }
420          if (pixval == NULL) {
# Line 325 | Line 443 | loop:
443   }
444  
445  
446 < static
447 < freepixels()                            /* free our pixels */
446 > static void
447 > freepixels(void)                                /* free our pixels */
448   {
449          if (ncolors == 0)
450                  return;
451          XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L);
452 <        free((char *)pixval);
452 >        free((void *)pixval);
453          pixval = NULL;
454          ncolors = 0;
455          if (ourmap != DefaultColormap(ourdisplay,ourscreen))
# Line 341 | Line 459 | freepixels()                           /* free our pixels */
459  
460  
461   static unsigned long
462 < true_pixel(rgb)                 /* return true pixel value for color */
463 < register BYTE   rgb[3];
462 > true_pixel(                     /* return true pixel value for color */
463 >        uby8    rgb[3]
464 > )
465   {
466 <        register unsigned long  rval;
466 >        unsigned long  rval;
467  
468          rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
469          rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
# Line 353 | Line 472 | register BYTE  rgb[3];
472   }
473  
474  
475 < static
476 < getevent()                      /* get next event */
475 > static void
476 > getevent(void)                  /* get next event */
477   {
478          XNextEvent(ourdisplay, levptr(XEvent));
479          switch (levptr(XEvent)->type) {
# Line 381 | Line 500 | getevent()                     /* get next event */
500                  getkey(levptr(XKeyPressedEvent));
501                  break;
502          case ButtonPress:
503 <                getmove(levptr(XButtonPressedEvent));
503 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
504 >                        getframe(levptr(XButtonPressedEvent));
505 >                else
506 >                        switch (levptr(XButtonPressedEvent)->button) {
507 >                        case Button4:           /* wheel up */
508 >                        case Button5:           /* wheel down */
509 >                                break;
510 >                        default:
511 >                                getmove(levptr(XButtonPressedEvent));
512 >                                break;
513 >                        }
514                  break;
515          }
516   }
517  
518  
519 < static
520 < ilclip(dp, wp)                  /* clip world coordinates to device */
521 < int     dp[2][2];
522 < FVECT   wp[2];
519 > static int
520 > ilclip(                 /* clip world coordinates to device */
521 >        int     dp[2][2],
522 >        FVECT   wp[2]
523 > )
524   {
525 <        static FVECT    vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE};
526 <        FVECT   ip[2];
527 <                                /* not exactly right, but who cares? */
528 <        viewloc(ip[0], &odev.v, wp[0]);
529 <        viewloc(ip[1], &odev.v, wp[1]);
525 >        static FVECT    vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE};
526 >        FVECT   wpc[2], ip[2];
527 >        double  d, d0, d1;
528 >                                /* check for points behind view */
529 >        d = DOT(odev.v.vp, odev.v.vdir);
530 >        d0 = DOT(wp[0], odev.v.vdir) - d;
531 >        d1 = DOT(wp[1], odev.v.vdir) - d;
532 >                                /* work on copy of world points */
533 >        if (d0 <= d1) {
534 >                VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]);
535 >        } else {
536 >                d = d0; d0 = d1; d1 = d;
537 >                VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]);
538 >        }
539 >        if (d0 <= FTINY) {
540 >                if (d1 <= FTINY) return(0);
541 >                VSUB(wpc[0], wpc[0], wpc[1]);
542 >                d = .99*d1/(d1-d0);
543 >                VSUM(wpc[0], wpc[1], wpc[0], d);
544 >        }
545 >                                /* get view coordinates and clip to window */
546 >        viewloc(ip[0], &odev.v, wpc[0]);
547 >        viewloc(ip[1], &odev.v, wpc[1]);
548          if (!clip(ip[0], ip[1], vmin, vmax))
549                  return(0);
550          dp[0][0] = ip[0][0]*odev.hres;
# Line 407 | Line 555 | FVECT  wp[2];
555   }
556  
557  
558 < static
559 < draw3dline(wp)                  /* draw 3d line in world coordinates */
560 < FVECT   wp[2];
558 > static void
559 > draw3dline(                     /* draw 3d line in world coordinates */
560 >        FVECT   wp[2]
561 > )
562   {
563          int     dp[2][2];
564  
# Line 421 | Line 570 | FVECT  wp[2];
570   }
571  
572  
573 < static
574 < draw_grids()                    /* draw holodeck section grids */
573 > static void
574 > draw_grids(void)                        /* draw holodeck section grids */
575   {
576 <        static BYTE     gridrgb[3] = {0x0, 0xff, 0xff};
576 >        static uby8     gridrgb[3] = {0x0, 0xff, 0xff};
577          unsigned long  pixel;
578  
430        if (!mapped || odev.v.type != VT_PER)
431                return;
579          if (ncolors > 0)
580                  pixel = pixval[get_pixel(gridrgb, xnewcolr)];
581          else
# Line 439 | Line 586 | draw_grids()                   /* draw holodeck section grids */
586   }
587  
588  
589 < static
590 < moveview(dx, dy, move)          /* move our view */
591 < int     dx, dy, move;
589 > static int
590 > moveview(       /* move our view */
591 >        int     dx,
592 >        int     dy,
593 >        int     mov,
594 >        int     orb
595 > )
596   {
597          VIEW    nv;
598 +        FVECT   odir, v1;
599          double  d;
600 <        register int    i, li;
600 >        int     li;
601                                  /* start with old view */
602 <        copystruct(&nv, &odev.v);
602 >        nv = odev.v;
603                                  /* change view direction */
604 <        if (move) {
604 >        if (mov | orb) {
605                  if ((li = qtFindLeaf(dx, dy)) < 0)
606                          return(0);      /* not on window */
607 <                for (i = 0; i < 3; i++)
456 <                        nv.vdir[i] = qtL.wp[li][i] - nv.vp[i];
607 >                VSUM(odir, qtL.wp[li], nv.vp, -1.);
608          } else {
609                  if (viewray(nv.vp, nv.vdir, &odev.v,
610                                  (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
611                          return(0);      /* outside view */
612          }
613 <                                /* move viewpoint */
614 <        if (move > 0)
615 <                for (i = 0; i < 3; i++)
616 <                        nv.vp[i] += MOVPCT/100. * nv.vdir[i];
617 <        else if (move < 0)
618 <                for (i = 0; i < 3; i++)
619 <                        nv.vp[i] -= MOVPCT/100. * nv.vdir[i];
620 <        if (move && headlocked) {
621 <                d = 0;          /* bring head back to same height */
622 <                for (i = 0; i < 3; i++)
623 <                        d += odev.v.vup[i] * (odev.v.vp[i] - nv.vp[i]);
624 <                for (i = 0; i < 3; i++)
625 <                        nv.vp[i] += d * odev.v.vup[i];
613 >        if (orb && mov) {               /* orbit left/right */
614 >                spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
615 >                VSUM(nv.vp, qtL.wp[li], odir, -1.);
616 >                spinvector(nv.vdir, nv.vdir, nv.vup, d);
617 >        } else if (orb) {               /* orbit up/down */
618 >                if (geodesic(odir, odir, nv.vup,
619 >                                d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
620 >                        return(0);
621 >                VSUM(nv.vp, qtL.wp[li], odir, -1.);
622 >                geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD);
623 >        } else if (mov) {               /* move forward/backward */
624 >                d = MOVPCT/100. * mov;
625 >                VSUM(nv.vp, nv.vp, odir, d);
626          }
627 +        if (!mov ^ !orb && headlocked) {        /* restore head height */
628 +                VSUM(v1, odev.v.vp, nv.vp, -1.);
629 +                d = DOT(v1, odev.v.vup);
630 +                VSUM(nv.vp, nv.vp, odev.v.vup, d);
631 +        }
632          if (setview(&nv) != NULL)
633                  return(0);      /* illegal view */
634          dev_view(&nv);
635 <        inpresflags |= DEV_NEWVIEW;
635 >        inpresflags |= DFL(DC_SETVIEW);
636          return(1);
637   }
638  
639  
640 < static
641 < getmove(ebut)                           /* get view change */
642 < XButtonPressedEvent     *ebut;
640 > static void
641 > getframe(                               /* get focus frame */
642 >        XButtonPressedEvent     *ebut
643 > )
644   {
645 <        int     whichbutton = ebut->button;
645 >        int     startx = ebut->x, starty = ebut->y;
646 >        int     endx, endy, midx, midy;
647 >        FVECT   v1;
648 >        int     li;
649 >                                        /* get mouse drag */
650 >        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
651 >        endx = levptr(XButtonReleasedEvent)->x;
652 >        endy = levptr(XButtonReleasedEvent)->y;
653 >        midx = (startx + endx) >> 1;
654 >        midy = (starty + endy) >> 1;
655 >                                        /* set focus distance */
656 >        if ((li = qtFindLeaf(midx, midy)) < 0)
657 >                return;                 /* not on window */
658 >        VCOPY(v1, qtL.wp[li]);
659 >        odev.v.vdist = sqrt(dist2(odev.v.vp, v1));
660 >                                        /* set frame for rendering */
661 >        if ((endx == startx) | (endy == starty))
662 >                return;
663 >        if (endx < startx) {int c = endx; endx = startx; startx = c;}
664 >        if (endy < starty) {int c = endy; endy = starty; starty = c;}
665 >        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
666 >                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
667 >                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
668 >        inpresflags |= DFL(DC_FOCUS);
669 > }
670 >
671 >
672 > static void
673 > waitabit(void)                          /* pause a moment */
674 > {
675 >        struct timespec ts;
676 >        ts.tv_sec = 0;
677 >        ts.tv_nsec = 100000000;
678 >        nanosleep(&ts, NULL);
679 > }
680 >
681 >
682 > static void
683 > getmove(                                /* get view change */
684 >        XButtonPressedEvent     *ebut
685 > )
686 > {
687 >        int     movdir = MOVDIR(ebut->button);
688 >        int     movorb = MOVORB(ebut->state);
689          int     oldnodesiz = qtMinNodesiz;
690          Window  rootw, childw;
691          int     rootx, rooty, wx, wy;
# Line 496 | Line 696 | XButtonPressedEvent    *ebut;
696  
697          while (!XCheckMaskEvent(ourdisplay,
698                          ButtonReleaseMask, levptr(XEvent))) {
699 <
699 >                waitabit();
700                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
701                                  &rootx, &rooty, &wx, &wy, &statemask))
702                          break;          /* on another screen */
703  
704 <                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) {
704 >                if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
705                          sleep(1);
706                          continue;
707                  }
# Line 509 | Line 709 | XButtonPressedEvent    *ebut;
709                  qtUpdate();
710                  draw_grids();
711          }
712 <        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
713 <                whichbutton = levptr(XButtonReleasedEvent)->button;
712 >        if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
713 >                movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
714                  wx = levptr(XButtonReleasedEvent)->x;
715                  wy = levptr(XButtonReleasedEvent)->y;
716 <                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
716 >                moveview(wx, odev.vres-1-wy, movdir, movorb);
717          }
718          dev_flush();
719  
# Line 521 | Line 721 | XButtonPressedEvent    *ebut;
721   }
722  
723  
724 < static
725 < getkey(ekey)                            /* get input key */
726 < register XKeyPressedEvent  *ekey;
724 > static void
725 > getkey(                         /* get input key */
726 >        XKeyPressedEvent  *ekey
727 > )
728   {
729 +        Window  rootw, childw;
730 +        int     rootx, rooty, wx, wy;
731 +        unsigned int    statemask;
732          int  n;
733          char    buf[8];
734  
# Line 538 | Line 742 | register XKeyPressedEvent  *ekey;
742          case 'H':                       /* turn off height motion lock */
743                  headlocked = 0;
744                  return;
745 <        case CTRL('S'):
745 >        case 'l':                       /* retrieve last view */
746 >                inpresflags |= DFL(DC_LASTVIEW);
747 >                return;
748 >        case 'f':                       /* frame view position */
749 >                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
750 >                                &rootx, &rooty, &wx, &wy, &statemask))
751 >                        return;         /* on another screen */
752 >                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
753 >                                1.-(wy+.5)/odev.vres);
754 >                inpresflags |= DFL(DC_FOCUS);
755 >                return;
756 >        case 'F':                       /* unfocus */
757 >                odev_args[0] = '\0';
758 >                inpresflags |= DFL(DC_FOCUS);
759 >                return;
760          case 'p':                       /* pause computation */
761 <                inpresflags |= DEV_WAIT;
761 >                inpresflags |= DFL(DC_PAUSE);
762                  return;
763          case 'v':                       /* spit out view */
764 <                inpresflags |= DEV_PUTVIEW;
764 >                inpresflags |= DFL(DC_GETVIEW);
765                  return;
548        case CTRL('Q'):
766          case '\n':
767          case '\r':                      /* resume computation */
768 <                inpresflags |= DEV_RESUME;
768 >                inpresflags |= DFL(DC_RESUME);
769                  return;
770          case CTRL('R'):                 /* redraw screen */
771                  if (ncolors > 0)
# Line 556 | Line 773 | register XKeyPressedEvent  *ekey;
773                  qtRedraw(0, 0, odev.hres, odev.vres);
774                  return;
775          case CTRL('L'):                 /* refresh from server */
776 <                if (inpresflags & DEV_REDRAW)
776 >                if (inpresflags & DFL(DC_REDRAW))
777                          return;
778                  XClearWindow(ourdisplay, gwind);
779                  draw_grids();
# Line 564 | Line 781 | register XKeyPressedEvent  *ekey;
781                  qtCompost(100);                 /* unload the old tree */
782                  if (ncolors > 0)
783                          new_ctab(ncolors);
784 <                inpresflags |= DEV_REDRAW;      /* resend values from server */
784 >                inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
785 >                rayqleft = 0;                   /* hold off update */
786                  return;
787 <        case CTRL('D'):
788 <        case 'Q':
787 >        case 'K':                       /* kill rtrace process(es) */
788 >                inpresflags |= DFL(DC_KILL);
789 >                break;
790 >        case 'R':                       /* restart rtrace */
791 >                inpresflags |= DFL(DC_RESTART);
792 >                break;
793 >        case 'C':                       /* clobber holodeck */
794 >                inpresflags |= DFL(DC_CLOBBER);
795 >                break;
796          case 'q':                       /* quit the program */
797 <                inpresflags |= DEV_SHUTDOWN;
797 >                inpresflags |= DFL(DC_QUIT);
798                  return;
799          default:
800                  XBell(ourdisplay, 0);
# Line 578 | Line 803 | register XKeyPressedEvent  *ekey;
803   }
804  
805  
806 < static
807 < fixwindow(eexp)                         /* repair damage to window */
808 < register XExposeEvent  *eexp;
806 > static void
807 > fixwindow(                              /* repair damage to window */
808 >        XExposeEvent  *eexp
809 > )
810   {
811          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
812                  odev.hres = eexp->width;
813                  odev.vres = eexp->height;
588                inpresflags |= DEV_NEWSIZE;
814          }
815          qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
816                          eexp->x + eexp->width, odev.vres - eexp->y);
817   }
818  
819  
820 < static
821 < resizewindow(ersz)                      /* resize window */
822 < register XConfigureEvent  *ersz;
820 > static void
821 > resizewindow(                   /* resize window */
822 >        XConfigureEvent  *ersz
823 > )
824   {
825          if (ersz->width == odev.hres && ersz->height == odev.vres)
826                  return;
# Line 605 | Line 831 | register XConfigureEvent  *ersz;
831          odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
832          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
833  
834 <        inpresflags |= DEV_NEWSIZE|DEV_NEWVIEW;
834 >        inpresflags |= DFL(DC_SETVIEW);
835   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines