--- ray/src/meta/x11plot.c 2003/02/22 02:07:26 1.1 +++ ray/src/meta/x11plot.c 2019/11/18 22:12:32 1.5 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: x11plot.c,v 1.1 2003/02/22 02:07:26 greg Exp $"; +static const char RCSid[] = "$Id: x11plot.c,v 1.5 2019/11/18 22:12:32 greg Exp $"; #endif /* * X window plotting functions @@ -12,20 +12,23 @@ static const char RCSid[] = "$Id: x11plot.c,v 1.1 2003 #include "plot.h" +#include "string.h" + #undef TRUE #undef FALSE #include +extern void replay(int xmin, int ymin, int xmax, int ymax); #define BORWIDTH 5 #define BlackPix BlackPixel(dpy,0 ) #define WhitePix WhitePixel(dpy,0 ) -#define mapx(x) CONV(x,dxsize) -#define mapy(y) CONV((XYSIZE-1)-(y),dysize) +#define mapx(x) CONV(x,dxsiz) +#define mapy(y) CONV((XYSIZE-1)-(y),dysiz) #define MAXVERT 128 @@ -79,9 +82,20 @@ int curcol; /* current color */ int curlinetype; /* current line style */ XGCValues gcval; int pixel[4]; -int dxsize, dysize; /* window size */ +int dxsiz, dysiz; /* window size */ int debug = False; /* use XSynchronize if true */ +static void +adjustsize() +{ + if (dxsiz > dysiz) + dxsiz = dysiz; + else + dysiz = dxsiz; +} + + +void init(name, geom) /* initialize window */ char *name; char *geom; @@ -89,7 +103,6 @@ char *geom; char defgeom[32]; XColor cdef,dum; XEvent evnt; - int dummy; curfont = curfill = curcol = -1; curlinetype = 0; @@ -101,20 +114,17 @@ char *geom; if (debug) (void) XSynchronize(dpy, True); - dxsize = DisplayWidth(dpy,0) - 2*BORWIDTH-4; - dysize = DisplayHeight(dpy,0) - 2*BORWIDTH-26; - - /* temporary */ - dxsize = dxsize = 800; + dxsiz = DisplayWidth(dpy,0) - 2*BORWIDTH-4; + dysiz = DisplayHeight(dpy,0) - 2*BORWIDTH-100; adjustsize(); - sprintf(defgeom, "=%dx%d+2+25", dxsize, dysize); + sprintf(defgeom, "=%dx%d+2+25", dxsiz, dysiz); /* XUseGeometry(dpy,0,geom,defgeom,BORWIDTH,100,100,100,100, - &xoff,&yoff,&dxsize,&dysize); */ + &xoff,&yoff,&dxsiz,&dysiz); */ gc = DefaultGC(dpy,0); /* get default gc */ cmap = DefaultColormap(dpy,0); /* and colormap */ - wind = XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),0,0,dxsize,dysize, + wind = XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),0,0,dxsiz,dysiz, BORWIDTH,BlackPix,WhitePix); if (wind == 0) error(SYSTEM, "can't create window"); @@ -153,8 +163,8 @@ char *geom; if (evnt.type == ConfigureNotify) /* wait for first ConfigureNotify */ break; } - dxsize = evnt.xconfigure.width; - dysize = evnt.xconfigure.height; + dxsiz = evnt.xconfigure.width; + dysiz = evnt.xconfigure.height; adjustsize(); while (1) { @@ -164,14 +174,8 @@ char *geom; } } -adjustsize() - { - if (dxsize > dysize) - dxsize = dysize; - else - dysize = dxsize; - } +void endpage() /* end of this graph */ { XEvent evnt; @@ -183,15 +187,15 @@ endpage() /* end of this graph */ XNextEvent(dpy, &evnt); switch (evnt.type) { case ConfigureNotify: - dxsize = evnt.xconfigure.width; - dysize = evnt.xconfigure.height; + dxsiz = evnt.xconfigure.width; + dysiz = evnt.xconfigure.height; adjustsize(); break; case Expose: - replay((int)((long)XYSIZE*evnt.xexpose.x/dxsize), - (int)((long)XYSIZE*(dysize-evnt.xexpose.y-evnt.xexpose.height)/dysize), - (int)((long)XYSIZE*(evnt.xexpose.x+evnt.xexpose.width)/dxsize), - (int)((long)XYSIZE*(dysize-evnt.xexpose.y)/dysize)); + replay((int)((long)XYSIZE*evnt.xexpose.x/dxsiz), + (int)((long)XYSIZE*(dysiz-evnt.xexpose.y-evnt.xexpose.height)/dysiz), + (int)((long)XYSIZE*(evnt.xexpose.x+evnt.xexpose.width)/dxsiz), + (int)((long)XYSIZE*(dysiz-evnt.xexpose.y)/dysiz)); break; case ButtonPress: quit = True; @@ -204,6 +208,7 @@ endpage() /* end of this graph */ +void printstr(p) /* output a string */ register PRIMITIVE *p; @@ -243,6 +248,7 @@ register PRIMITIVE *p; +void plotlseg(p) /* plot a line segment */ register PRIMITIVE *p; @@ -257,7 +263,7 @@ register PRIMITIVE *p; col = p->arg0 & 03; /* color */ ps = WIDTH((p->arg0 >> 2) & 03); - pw = CONV((ps)/2, dxsize); + pw = CONV((ps)/2, dxsiz); x1 = mapx(p->xy[XMN]); x2 = mapx(p->xy[XMX]); @@ -294,8 +300,30 @@ register PRIMITIVE *p; } +void +pXFlush() +{ + XFlush(dpy); +} + + #ifdef nyet +static void +fill(xmin,ymin,xmax,ymax,pm) +int xmin,ymin,xmax,ymax; +Pixmap pm; +{ + if (pm != 0 && curpat != pm) + { + XSetTile(dpy, gc, pm); + curpat = pm; + } + XFillRectangle(dpy, wind, gc, xmin, ymin, xmax-xmin+1, ymax-ymin+1); +} + + +void fillrect(p) /* fill a rectangle */ register PRIMITIVE *p; @@ -315,6 +343,7 @@ register PRIMITIVE *p; +void filltri(p) /* fill a triangle */ register PRIMITIVE *p; @@ -362,7 +391,7 @@ register PRIMITIVE *p; } - +vpod xform(xp, yp, p) /* transform a point according to p */ register int *xp, *yp; @@ -396,7 +425,7 @@ register PRIMITIVE *p; } - +void fillpoly(p) /* fill a polygon */ register PRIMITIVE *p; @@ -449,23 +478,10 @@ register PRIMITIVE *p; } -fill(xmin,ymin,xmax,ymax,pm) -int xmin,ymin,xmax,ymax; -Pixmap pm; - { - if (pm != 0 && curpat != pm) - { - XSetTile(dpy, gc, pm); - curpat = pm; - } - XFillRectangle(dpy, wind, gc, xmin, ymin, xmax-xmin+1, ymax-ymin+1); - } - #else -filltri() {} -fillpoly() {} -fillrect() {} - +void filltri(PRIMITIVE *p) {} +void fillpoly(PRIMITIVE *p) {} +void fillrect(PRIMITIVE *p) {} #endif