--- ray/src/util/xglaresrc.c 1991/07/31 15:28:03 1.9 +++ ray/src/util/xglaresrc.c 2003/02/22 02:07:30 2.6 @@ -1,9 +1,6 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: xglaresrc.c,v 2.6 2003/02/22 02:07:30 greg Exp $"; #endif - /* * Circle sources in a displayed image. * @@ -12,14 +9,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" #include "view.h" +#include "vfork.h" #include #include #include -#ifndef BSD -#define vfork fork -#endif - #define XIM "ximage" #define NSEG 30 /* number of segments per circle */ @@ -29,7 +23,7 @@ static char SCCSid[] = "$SunId$ LBL"; float col[3] = {1.,0.,0.}; /* color */ VIEW ourview = STDVIEW; /* view for picture */ -int xres, yres; /* picture resolution */ +RESOLU pres; /* picture resolution */ char *progname; /* program name */ @@ -46,7 +40,6 @@ main(argc, argv) int argc; char *argv[]; { - extern double atof(); char *windowname = NULL; FILE *fp; @@ -91,8 +84,9 @@ char *pname, *wname; XWindowAttributes wa; XColor xc; XGCValues gcv; + register int i; /* get the viewing parameters */ - if (viewfile(pname, &ourview, &xres, &yres) <= 0 || + if (viewfile(pname, &ourview, &pres) <= 0 || setview(&ourview) != NULL) { fprintf(stderr, "%s: cannot get view from \"%s\"\n", progname, pname); @@ -106,18 +100,25 @@ char *pname, *wname; exit(1); } /* find our window */ - if (wname == NULL) - wname = pname; - gwind = xfindwind(theDisplay, rwind, wname, 2); + if (wname == NULL) { + /* remove directory prefix from name */ + for (i = strlen(pname); i-- > 0; ) + if (pname[i] == '/') + break; + wname = pname+i+1; + i = 0; + } else + i = 1; + gwind = xfindwind(theDisplay, rwind, wname, 4); if (gwind == None) { - if (wname != pname) { + if (i) { fprintf(stderr, "%s: cannot find \"%s\" window\n", progname, wname); exit(2); } /* start ximage */ if (vfork() == 0) { - execlp(XIM, XIM, pname, 0); + execlp(XIM, XIM, "-c", "256", pname, 0); perror(XIM); fprintf(stderr, "%s: cannot start %s\n", progname, XIM); @@ -126,19 +127,24 @@ char *pname, *wname; } do sleep(8); - while ((gwind=xfindwind(theDisplay,rwind,pname,2)) == None); + while ((gwind=xfindwind(theDisplay,rwind,wname,4)) == None); } else XMapRaised(theDisplay, gwind); do { XGetWindowAttributes(theDisplay, gwind, &wa); sleep(6); } while (wa.map_state != IsViewable); - if (wa.width != xres || wa.height != yres) { + if (wa.width != scanlen(&pres) || wa.height != numscans(&pres)) { fprintf(stderr, "%s: warning -- window seems to be the wrong size!\n", progname); - xres = wa.width; - yres = wa.height; + if (pres.rt & YMAJOR) { + pres.xr = wa.width; + pres.yr = wa.height; + } else { + pres.xr = wa.height; + pres.yr = wa.width; + } } /* set graphics context */ gcv.font = XLoadFont(theDisplay, FONTNAME); @@ -205,7 +211,8 @@ double dom; { FVECT start, cur; XPoint pt[NSEG+1]; - double px, py, pz; + FVECT pp; + int ip[2]; register int i; fcross(cur, dir, ourview.vup); @@ -217,11 +224,12 @@ double dom; cur[0] += ourview.vp[0]; cur[1] += ourview.vp[1]; cur[2] += ourview.vp[2]; - viewpixel(&px, &py, &pz, &ourview, cur); - if (pz <= 0.0) + viewloc(pp, &ourview, cur); + if (pp[2] <= 0.0) goto fail; - pt[i].x = px*xres; - pt[i].y = yres-1 - (int)(py*yres); + loc2pix(ip, &pres, pp[0], pp[1]); + pt[i].x = ip[0]; + pt[i].y = ip[1]; } XDrawLines(theDisplay, gwind, vecGC, pt, NSEG+1, CoordModeOrigin); return; @@ -236,17 +244,18 @@ FVECT dir; double v; { FVECT pos; - double px, py, pz; + FVECT pp; + int ip[2]; char buf[32]; pos[0] = ourview.vp[0] + dir[0]; pos[1] = ourview.vp[1] + dir[1]; pos[2] = ourview.vp[2] + dir[2]; - viewpixel(&px, &py, &pz, &ourview, pos); - if (pz <= 0.0) + viewloc(pp, &ourview, pos); + if (pp[2] <= 0.0) return; + loc2pix(ip, &pres, pp[0], pp[1]); sprintf(buf, "%.0f", v); XDrawImageString(theDisplay, gwind, strGC, - (int)(px*xres), yres-1-(int)(py*yres), - buf, strlen(buf)); + ip[0], ip[1], buf, strlen(buf)); }