193 |
|
getevent(); /* main loop */ |
194 |
|
userr: |
195 |
|
fprintf(stderr, |
196 |
< |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
196 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n", |
197 |
|
progname); |
198 |
< |
quit(1); |
198 |
> |
exit(1); |
199 |
|
} |
200 |
|
|
201 |
|
|
234 |
|
getbestvis(); |
235 |
|
/* store image */ |
236 |
|
getras(); |
237 |
+ |
/* get size and position */ |
238 |
+ |
bzero((char *)&oursizhints, sizeof(oursizhints)); |
239 |
+ |
oursizhints.width = xmax; oursizhints.height = ymax; |
240 |
+ |
if (geometry != NULL) { |
241 |
+ |
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
242 |
+ |
(unsigned *)&oursizhints.width, |
243 |
+ |
(unsigned *)&oursizhints.height); |
244 |
+ |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
245 |
+ |
oursizhints.flags |= USSize; |
246 |
+ |
else |
247 |
+ |
oursizhints.flags |= PSize; |
248 |
+ |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
249 |
+ |
oursizhints.flags |= USPosition; |
250 |
+ |
if (i & XNegative) |
251 |
+ |
oursizhints.x += DisplayWidth(thedisplay, |
252 |
+ |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
253 |
+ |
if (i & YNegative) |
254 |
+ |
oursizhints.y += DisplayHeight(thedisplay, |
255 |
+ |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
256 |
+ |
} |
257 |
+ |
} |
258 |
|
/* open window */ |
259 |
|
ourwinattr.border_pixel = ourblack; |
260 |
|
ourwinattr.background_pixel = ourwhite; |
261 |
|
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
262 |
|
ourvis.visual, AllocNone); |
263 |
< |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
263 |
> |
wind = XCreateWindow(thedisplay, ourroot, oursizhints.x, oursizhints.y, |
264 |
> |
oursizhints.width, oursizhints.height, BORWIDTH, |
265 |
|
ourvis.depth, InputOutput, ourvis.visual, |
266 |
|
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
267 |
|
if (wind == 0) |
280 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
281 |
|
XC_diamond_cross)); |
282 |
|
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
283 |
< |
if (geometry != NULL) { |
262 |
< |
bzero((char *)&oursizhints, sizeof(oursizhints)); |
263 |
< |
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
264 |
< |
(unsigned *)&oursizhints.width, |
265 |
< |
(unsigned *)&oursizhints.height); |
266 |
< |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
267 |
< |
oursizhints.flags |= USSize; |
268 |
< |
else { |
269 |
< |
oursizhints.width = xmax; |
270 |
< |
oursizhints.height = ymax; |
271 |
< |
oursizhints.flags |= PSize; |
272 |
< |
} |
273 |
< |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
274 |
< |
oursizhints.flags |= USPosition; |
275 |
< |
if (i & XNegative) |
276 |
< |
oursizhints.x += DisplayWidth(thedisplay, |
277 |
< |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
278 |
< |
if (i & YNegative) |
279 |
< |
oursizhints.y += DisplayHeight(thedisplay, |
280 |
< |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
281 |
< |
} |
283 |
> |
if (oursizhints.flags) |
284 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
283 |
– |
} |
285 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
286 |
|
ourxwmhints.input = True; |
287 |
|
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
508 |
|
case ButtonPress: |
509 |
|
if (e.b.state & (ShiftMask|ControlMask)) |
510 |
|
moveimage(&e.b); |
511 |
+ |
else if (e.b.button == Button2) |
512 |
+ |
traceray(e.b.x, e.b.y); |
513 |
|
else |
514 |
|
getbox(&e.b); |
515 |
|
break; |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
< |
docom(ekey) /* execute command */ |
520 |
> |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
521 |
> |
int xpos, ypos; |
522 |
> |
{ |
523 |
> |
FLOAT hv[2]; |
524 |
> |
FVECT rorg, rdir; |
525 |
> |
|
526 |
> |
if (!gotview) { /* no view, no can do */ |
527 |
> |
XBell(thedisplay, 0); |
528 |
> |
return(-1); |
529 |
> |
} |
530 |
> |
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
531 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
532 |
> |
return(-1); |
533 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
534 |
> |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
535 |
> |
fflush(stdout); |
536 |
> |
return(0); |
537 |
> |
} |
538 |
> |
|
539 |
> |
|
540 |
> |
docom(ekey) /* execute command */ |
541 |
|
XKeyPressedEvent *ekey; |
542 |
|
{ |
543 |
|
char buf[80]; |
546 |
|
int com, n; |
547 |
|
double comp; |
548 |
|
FLOAT hv[2]; |
526 |
– |
FVECT rorg, rdir; |
549 |
|
|
550 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
551 |
|
if (n == 0) |
553 |
|
com = buf[0]; |
554 |
|
switch (com) { /* interpret command */ |
555 |
|
case 'q': |
556 |
+ |
case 'Q': |
557 |
|
case CTRL('D'): /* quit */ |
558 |
< |
quit(0); |
558 |
> |
quiterr(NULL); |
559 |
|
case '\n': |
560 |
|
case '\r': |
561 |
|
case 'l': |
601 |
|
buf, strlen(buf)); |
602 |
|
return(0); |
603 |
|
case 't': /* trace */ |
604 |
< |
if (!gotview) { |
582 |
< |
XBell(thedisplay, 0); |
583 |
< |
return(-1); |
584 |
< |
} |
585 |
< |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
586 |
< |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
587 |
< |
return(-1); |
588 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
589 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
590 |
< |
fflush(stdout); |
591 |
< |
return(0); |
604 |
> |
return(traceray(ekey->x, ekey->y)); |
605 |
|
case '=': /* adjust exposure */ |
606 |
|
if (avgbox(cval) == -1) |
607 |
|
return(-1); |
625 |
|
map_rcolors(ourras, wind); |
626 |
|
if (fast) |
627 |
|
make_rpixmap(ourras, wind); |
628 |
+ |
redraw(0, 0, width, height); |
629 |
+ |
return(0); |
630 |
+ |
case '0': /* recenter origin */ |
631 |
+ |
if (xoff == 0 & yoff == 0) |
632 |
+ |
return(0); |
633 |
+ |
xoff = yoff = 0; |
634 |
+ |
XClearWindow(thedisplay, wind); |
635 |
|
redraw(0, 0, width, height); |
636 |
|
return(0); |
637 |
|
case ' ': /* clear */ |