1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
10 |
|
*/ |
11 |
|
|
12 |
|
#include "standard.h" |
13 |
– |
#include "rhd_qtree.h" |
14 |
– |
|
13 |
|
#include <X11/Xlib.h> |
14 |
|
#include <X11/cursorfont.h> |
15 |
|
#include <X11/Xutil.h> |
16 |
< |
|
16 |
> |
#include "rhd_qtree.h" |
17 |
|
#include "x11icon.h" |
18 |
|
|
19 |
|
#ifndef RAYQLEN |
26 |
|
|
27 |
|
#define GAMMA 2.2 /* default gamma correction */ |
28 |
|
|
29 |
+ |
#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) |
30 |
+ |
|
31 |
|
#define MOVPCT 7 /* percent distance to move /frame */ |
32 |
|
#define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) |
33 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
49 |
|
|
50 |
|
struct driver odev; /* global device driver structure */ |
51 |
|
|
52 |
+ |
char odev_args[64]; /* command arguments */ |
53 |
+ |
|
54 |
|
static XEvent currentevent; /* current event */ |
55 |
|
|
56 |
|
static int ncolors = 0; /* color table size */ |
70 |
|
|
71 |
|
static int headlocked = 0; /* lock vertical motion */ |
72 |
|
|
73 |
< |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), |
73 |
> |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), |
74 |
|
getevent(), getkey(), moveview(), getmove(), fixwindow(); |
75 |
|
static unsigned long true_pixel(); |
76 |
|
|
98 |
|
char *id; |
99 |
|
{ |
100 |
|
extern char *getenv(); |
101 |
< |
char *gv; |
101 |
> |
static RGBPRIMS myprims = STDPRIMS; |
102 |
> |
char *ev; |
103 |
|
double gamval = GAMMA; |
104 |
+ |
RGBPRIMP dpri = stdprims; |
105 |
|
int nplanes; |
106 |
|
XSetWindowAttributes ourwinattr; |
107 |
|
XWMHints ourxwmhints; |
134 |
|
ourwhite = WhitePixel(ourdisplay,ourscreen); |
135 |
|
} |
136 |
|
/* set gamma and tone mapping */ |
137 |
< |
if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
138 |
< |
|| (gv = getenv("DISPLAY_GAMMA")) != NULL) |
139 |
< |
gamval = atof(gv); |
140 |
< |
if (tmInit(mytmflags(), stdprims, gamval) == NULL) |
137 |
> |
if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
138 |
> |
|| (ev = getenv("DISPLAY_GAMMA")) != NULL) |
139 |
> |
gamval = atof(ev); |
140 |
> |
if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && |
141 |
> |
sscanf(ev, "%f %f %f %f %f %f %f %f", |
142 |
> |
&myprims[RED][CIEX],&myprims[RED][CIEY], |
143 |
> |
&myprims[GRN][CIEX],&myprims[GRN][CIEY], |
144 |
> |
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
145 |
> |
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
146 |
> |
dpri = myprims; |
147 |
> |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
148 |
|
error(SYSTEM, "not enough memory in dev_open"); |
149 |
|
/* open window */ |
150 |
|
ourwinattr.background_pixel = ourblack; |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
+ |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
271 |
+ |
char *cmd, *args; |
272 |
+ |
{ |
273 |
+ |
sprintf(errmsg, "%s: unknown command", cmd); |
274 |
+ |
error(COMMAND, errmsg); |
275 |
+ |
} |
276 |
+ |
|
277 |
+ |
|
278 |
+ |
VIEW * |
279 |
+ |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
280 |
+ |
int n; |
281 |
+ |
int hvres[2]; |
282 |
+ |
{ |
283 |
+ |
if (n) |
284 |
+ |
return(NULL); |
285 |
+ |
hvres[0] = odev.hres; hvres[1] = odev.vres; |
286 |
+ |
return(&odev.v); |
287 |
+ |
} |
288 |
+ |
|
289 |
+ |
|
290 |
|
int |
291 |
|
dev_input() /* get X11 input */ |
292 |
|
{ |
295 |
|
do |
296 |
|
getevent(); |
297 |
|
|
298 |
< |
while (XQLength(ourdisplay) > 0); |
298 |
> |
while (XPending(ourdisplay) > 0); |
299 |
|
|
300 |
+ |
odev.inpready = 0; |
301 |
+ |
|
302 |
|
return(inpresflags); |
303 |
|
} |
304 |
|
|
326 |
|
{ |
327 |
|
qtUpdate(); |
328 |
|
rayqleft = RAYQLEN; |
329 |
< |
return(XPending(ourdisplay)); |
329 |
> |
return(odev.inpready = XPending(ourdisplay)); |
330 |
|
} |
331 |
|
|
332 |
|
|
455 |
|
getkey(levptr(XKeyPressedEvent)); |
456 |
|
break; |
457 |
|
case ButtonPress: |
458 |
< |
getmove(levptr(XButtonPressedEvent)); |
458 |
> |
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
459 |
> |
getframe(levptr(XButtonPressedEvent)); |
460 |
> |
else |
461 |
> |
getmove(levptr(XButtonPressedEvent)); |
462 |
|
break; |
463 |
|
} |
464 |
|
} |
469 |
|
int dp[2][2]; |
470 |
|
FVECT wp[2]; |
471 |
|
{ |
472 |
< |
static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; |
473 |
< |
FVECT ip[2]; |
474 |
< |
/* not exactly right, but who cares? */ |
475 |
< |
viewloc(ip[0], &odev.v, wp[0]); |
476 |
< |
viewloc(ip[1], &odev.v, wp[1]); |
472 |
> |
static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; |
473 |
> |
FVECT wpc[2], ip[2]; |
474 |
> |
double d, d0, d1; |
475 |
> |
/* check for points behind view */ |
476 |
> |
d = DOT(odev.v.vp, odev.v.vdir); |
477 |
> |
d0 = DOT(wp[0], odev.v.vdir) - d; |
478 |
> |
d1 = DOT(wp[1], odev.v.vdir) - d; |
479 |
> |
/* work on copy of world points */ |
480 |
> |
if (d0 <= d1) { |
481 |
> |
VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]); |
482 |
> |
} else { |
483 |
> |
d = d0; d0 = d1; d1 = d; |
484 |
> |
VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]); |
485 |
> |
} |
486 |
> |
if (d0 <= FTINY) { |
487 |
> |
if (d1 <= FTINY) return(0); |
488 |
> |
VSUB(wpc[0], wpc[0], wpc[1]); |
489 |
> |
d = .99*d1/(d1-d0); |
490 |
> |
VSUM(wpc[0], wpc[1], wpc[0], d); |
491 |
> |
} |
492 |
> |
/* get view coordinates and clip to window */ |
493 |
> |
viewloc(ip[0], &odev.v, wpc[0]); |
494 |
> |
viewloc(ip[1], &odev.v, wpc[1]); |
495 |
|
if (!clip(ip[0], ip[1], vmin, vmax)) |
496 |
|
return(0); |
497 |
|
dp[0][0] = ip[0][0]*odev.hres; |
522 |
|
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
523 |
|
unsigned long pixel; |
524 |
|
|
471 |
– |
if (!mapped) |
472 |
– |
return; |
525 |
|
if (ncolors > 0) |
526 |
|
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
527 |
|
else |
581 |
|
|
582 |
|
|
583 |
|
static |
584 |
+ |
getframe(ebut) /* get focus frame */ |
585 |
+ |
XButtonPressedEvent *ebut; |
586 |
+ |
{ |
587 |
+ |
int startx = ebut->x, starty = ebut->y; |
588 |
+ |
int endx, endy; |
589 |
+ |
|
590 |
+ |
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
591 |
+ |
endx = levptr(XButtonReleasedEvent)->x; |
592 |
+ |
endy = levptr(XButtonReleasedEvent)->y; |
593 |
+ |
if (endx == startx | endy == starty) { |
594 |
+ |
XBell(ourdisplay, 0); |
595 |
+ |
return; |
596 |
+ |
} |
597 |
+ |
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
598 |
+ |
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
599 |
+ |
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
600 |
+ |
(startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, |
601 |
+ |
(endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); |
602 |
+ |
inpresflags |= DFL(DC_FOCUS); |
603 |
+ |
} |
604 |
+ |
|
605 |
+ |
|
606 |
+ |
static |
607 |
|
getmove(ebut) /* get view change */ |
608 |
|
XButtonPressedEvent *ebut; |
609 |
|
{ |
648 |
|
getkey(ekey) /* get input key */ |
649 |
|
register XKeyPressedEvent *ekey; |
650 |
|
{ |
651 |
+ |
Window rootw, childw; |
652 |
+ |
int rootx, rooty, wx, wy; |
653 |
+ |
unsigned int statemask; |
654 |
|
int n; |
655 |
|
char buf[8]; |
656 |
|
|
666 |
|
return; |
667 |
|
case 'l': /* retrieve last view */ |
668 |
|
inpresflags |= DFL(DC_LASTVIEW); |
669 |
+ |
return; |
670 |
+ |
case 'f': /* frame view position */ |
671 |
+ |
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
672 |
+ |
&rootx, &rooty, &wx, &wy, &statemask)) |
673 |
+ |
return; /* on another screen */ |
674 |
+ |
sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres, |
675 |
+ |
1.-(wy+.5)/odev.vres); |
676 |
+ |
inpresflags |= DFL(DC_FOCUS); |
677 |
+ |
return; |
678 |
+ |
case 'F': /* unfocus */ |
679 |
+ |
odev_args[0] = '\0'; |
680 |
+ |
inpresflags |= DFL(DC_FOCUS); |
681 |
|
return; |
682 |
|
case 'p': /* pause computation */ |
683 |
|
inpresflags |= DFL(DC_PAUSE); |