--- ray/src/hd/rhd_x11.c 1998/08/27 19:32:27 3.28 +++ ray/src/hd/rhd_x11.c 2003/02/22 02:07:24 3.32 @@ -1,21 +1,17 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_x11.c,v 3.32 2003/02/22 02:07:24 greg Exp $"; #endif - /* * X11 driver for holodeck display. * Based on rview driver. */ #include "standard.h" -#include "rhd_qtree.h" - #include #include #include - +#include +#include "rhd_qtree.h" #include "x11icon.h" #ifndef RAYQLEN @@ -28,6 +24,8 @@ static char SCCSid[] = "$SunId$ SGI"; #define GAMMA 2.2 /* default gamma correction */ +#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) + #define MOVPCT 7 /* percent distance to move /frame */ #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) #define MOVDEG (-5) /* degrees to orbit CW/down /frame */ @@ -49,6 +47,8 @@ static char SCCSid[] = "$SunId$ SGI"; struct driver odev; /* global device driver structure */ +char odev_args[64]; /* command arguments */ + static XEvent currentevent; /* current event */ static int ncolors = 0; /* color table size */ @@ -68,7 +68,7 @@ static int inpresflags; /* input result flags */ static int headlocked = 0; /* lock vertical motion */ -static int getpixels(), xnewcolr(), freepixels(), resizewindow(), +static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), getevent(), getkey(), moveview(), getmove(), fixwindow(); static unsigned long true_pixel(); @@ -265,6 +265,13 @@ VIEW *nv; } +dev_section(ofn) /* add octree for geometry rendering */ +char *ofn; +{ + /* unimplemented */ +} + + dev_auxcom(cmd, args) /* process an auxiliary command */ char *cmd, *args; { @@ -368,7 +375,7 @@ loop: return(ncolors = 0); if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) break; - free((char *)pixval); + free((void *)pixval); pixval = NULL; } if (pixval == NULL) { @@ -403,7 +410,7 @@ freepixels() /* free our pixels */ if (ncolors == 0) return; XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); - free((char *)pixval); + free((void *)pixval); pixval = NULL; ncolors = 0; if (ourmap != DefaultColormap(ourdisplay,ourscreen)) @@ -453,7 +460,10 @@ getevent() /* get next event */ getkey(levptr(XKeyPressedEvent)); break; case ButtonPress: - getmove(levptr(XButtonPressedEvent)); + if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) + getframe(levptr(XButtonPressedEvent)); + else + getmove(levptr(XButtonPressedEvent)); break; } } @@ -576,6 +586,39 @@ int dx, dy, mov, orb; static +getframe(ebut) /* get focus frame */ +XButtonPressedEvent *ebut; +{ + int startx = ebut->x, starty = ebut->y; + int endx, endy; + + XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); + endx = levptr(XButtonReleasedEvent)->x; + endy = levptr(XButtonReleasedEvent)->y; + if (endx == startx | endy == starty) { + XBell(ourdisplay, 0); + return; + } + if (endx < startx) {register int c = endx; endx = startx; startx = c;} + if (endy < starty) {register int c = endy; endy = starty; starty = c;} + sprintf(odev_args, "%.3f %.3f %.3f %.3f", + (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, + (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); + inpresflags |= DFL(DC_FOCUS); +} + + +static +waitabit() /* pause a moment */ +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 5000000; + nanosleep(&ts, NULL); +} + + +static getmove(ebut) /* get view change */ XButtonPressedEvent *ebut; { @@ -591,7 +634,7 @@ XButtonPressedEvent *ebut; while (!XCheckMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent))) { - + waitabit(); if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, &rootx, &rooty, &wx, &wy, &statemask)) break; /* on another screen */ @@ -620,6 +663,9 @@ static getkey(ekey) /* get input key */ register XKeyPressedEvent *ekey; { + Window rootw, childw; + int rootx, rooty, wx, wy; + unsigned int statemask; int n; char buf[8]; @@ -635,6 +681,18 @@ register XKeyPressedEvent *ekey; return; case 'l': /* retrieve last view */ inpresflags |= DFL(DC_LASTVIEW); + return; + case 'f': /* frame view position */ + if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, + &rootx, &rooty, &wx, &wy, &statemask)) + return; /* on another screen */ + sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres, + 1.-(wy+.5)/odev.vres); + inpresflags |= DFL(DC_FOCUS); + return; + case 'F': /* unfocus */ + odev_args[0] = '\0'; + inpresflags |= DFL(DC_FOCUS); return; case 'p': /* pause computation */ inpresflags |= DFL(DC_PAUSE);