⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xwigb.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
				strcat(cmdline," style=normal ");				strcat(cmdline," title=\"");				strcat(cmdline,title); strcat(cmdline,"\"");				strcat(cmdline," label1=\"");				strcat(cmdline,label1); strcat(cmdline,"\"");				strcat(cmdline," label2=\"");				strcat(cmdline,label2); strcat(cmdline,"\"");				sprintf(cmdtemp," > %s ", plotfile);				strcat(cmdline,cmdtemp);				if (debug) 				    fprintf(stderr,"%s\n",cmdline);								/* pipe data to pswigb and write to plotfile *GK*/				plotfp = epopen(cmdline, "w");				free(cmdline);				rewind(infp);				efwrite(z,FSIZE,nz,plotfp);				epclose(plotfp);										} else {				continue;			}		/* else if button down (1 == zoom, 2 == mouse tracking */		} else if (event.type==ButtonPress) {			/* if 1st button: zoom */			if (event.xbutton.button==Button1) {				/* track pointer and get new box */				xRubberBox(dpy,win,event,&xb,&yb,&wb,&hb);							/* if new box has tiny width or height */				if (wb<4 || hb<4) {									/* reset box to initial values */					x1begb = x1beg;					x1endb = x1end;					x2begb = x2beg;					x2endb = x2end;							/* else, if new box has non-zero width */				/* if new box has zero width or height */				} else {								/* calculate new box parameters */					zoomBox(x,y,width,height,						xb,yb,wb,hb,						x2begb,x2endb,						x1begb,x1endb,						&x2begb,&x2endb,						&x1begb,&x1endb,                                                style);				}				/* clear area and force an expose event */				XClearArea(dpy,win,0,0,0,0,True);							/* note that image is out of date */				imageOutOfDate = 1;						/* else if 2nd button down: display mouse coords */			} else if (event.xbutton.button==Button2) {				showloc = 1;				xMouseLoc(dpy,win,event,style,showloc,					  x,y,width,height,x1begb,x1endb,					  x2begb,x2endb,p2beg,p2end);			} else {				continue;			}		/* else if pointer has moved */		} else if (event.type==MotionNotify) {						/* if button2 down, show mouse location */			if (showloc)				xMouseLoc(dpy,win,event,style,True,					x,y,width,height,x1begb,x1endb,					x2begb,x2endb,p2beg,p2end);		/* else if button2 released, stop tracking */		} else if (event.type==ButtonRelease &&			   event.xbutton.button==Button2) {			showloc = 0;		}	} /* end of event loop */	/* close connection to X server */	XCloseDisplay(dpy);	if (curve) {		free1int(npair);		for (i=0; i<curve; i++) {			free1float(x1curve[i]);			free1float(x2curve[i]);		}		free((void**)x1curve);		free((void**)x2curve);		free((void**)curvefile);		free((void**)curvecolor);	}	free1float(z);	return EXIT_SUCCESS;}			/* update parameters associated with zoom box */static void zoomBox (int x, int y, int w, int h, 	int xb, int yb, int wb, int hb,	float x1, float x2,	float y1, float y2,	float *x1b, float *x2b,	float *y1b, float *y2b,        int style){	/* if width and/or height of box are zero, just copy values */	if (wb==0 || hb==0) {		*x1b = x1; *x2b = x2;		*y1b = y1; *y2b = y2;		return;			} 		/* clip box */	if (xb<x) {		wb -= x-xb;		xb = x;	}	if (yb<y) {		hb -= y-yb;		yb = y;	}	if (xb+wb>x+w) wb = x-xb+w;	if (yb+hb>y+h) hb = y-yb+h;			/* determine box limits */        if (style == SEISMIC) {                *x1b = x1+(xb-x)*(x2-x1)/w;                *x2b = x1+(xb+wb-x)*(x2-x1)/w;                *y1b = y1+(yb-y)*(y2-y1)/h;                *y2b = y1+(yb+hb-y)*(y2-y1)/h;        } else {                *x2b = x2+(yb-y)*(x1-x2)/h;                *x1b = x2+(yb+hb-y)*(x1-x2)/h;                *y1b = y1+(xb-x)*(y2-y1)/w;                *y2b = y1+(xb+wb-x)*(y2-y1)/w;        }}/* return pointer to new image bitmap of rasterized wiggles */static XImage *newBitmap (Display *dpy, int width, int height,	int n1, float d1, float f1, int n2, float *x2, float *z,	float x1beg, float x1end, float x2beg, float x2end,	float xcur, float clip, int wt, int va,	float *p2begp, float *p2endp, int endian, int interp,	int wigclip, int style){	int widthpad,nbpr,i1beg,i1end,if1r,n1r,b1fz,b1lz,i2,i,n2in;	float x2min,x2max,p2beg,p2end,bscale,boffset,bxcur,bx2;	unsigned char *bits;	int scr=DefaultScreen(dpy);	XImage *image,*image2;	float	x2margin,clip1,clip2;	int	bx1max,bx2min,bx2max,b2f,b2l;	int	width1,height1;	/* determine bitmap dimensions and allocate space for bitmap */	width1 =  (style==SEISMIC) ? width : height;	height1 = (style==SEISMIC) ? height : width;	widthpad = (1+(width1-1)/(BitmapPad(dpy)/8))*BitmapPad(dpy)/8;	nbpr = 1+(widthpad-1)/8;	bits = ealloc1(nbpr*height1,sizeof(unsigned char));	for (i=0; i<nbpr*height1; ++i) bits[i] = 0;	/* determine number of traces that fall within axis 2 bounds */	x2min = MIN(x2beg,x2end);	x2max = MAX(x2beg,x2end);	for (i2=0,n2in=0; i2<n2; i2++)		if (x2[i2]>=x2min && x2[i2]<=x2max) n2in++;	/* determine pads for wiggle excursion along axis 2 */	xcur = fabs(xcur);	if (n2in>1) xcur *= (x2max-x2min)/(n2in-1);	x2margin = (wigclip && n2in>1) ? (x2max-x2min)/(2*(n2in-1)) : xcur;	p2beg = (x2end>=x2beg)?-x2margin:x2margin;	p2end = -p2beg;	bx2min = 0;	bx2max = width1 - 1;	bx1max = height1 - 1;	/* determine scale and offset to map x2 units to bitmap units */	bscale = bx2max/(x2end+p2end-x2beg-p2beg);	boffset = -(x2beg+p2beg)*bscale;	bxcur = xcur*bscale;	/* adjust x1beg and x1end to fall on sampled values */	i1beg = NINT((x1beg-f1)/d1);	i1beg = MAX(0,MIN(n1-1,i1beg));	x1beg = f1+i1beg*d1;	i1end = NINT((x1end-f1)/d1);	i1end = MAX(0,MIN(n1-1,i1end));	x1end = f1+i1end*d1;	/* determine first sample and number of samples to rasterize */	if1r = MIN(i1beg,i1end);	n1r = MAX(i1beg,i1end)-if1r+1;	/* determine bits corresponding to first and last samples */	b1fz = (x1end > x1beg) ? 0 : bx1max;	b1lz = (x1end > x1beg) ? bx1max : 0;	/* rasterize traces */	for (i2=0; i2<n2; i2++,z+=n1) {		/* skip traces not in bounds */		if (x2[i2]<x2min || x2[i2]>x2max) continue;		/* determine bitmap coordinate of trace */		bx2 = boffset+x2[i2]*bscale;		b2f = (int)(bx2-bxcur);		b2l = (int)(bx2+bxcur);		clip1 = -clip;		clip2 = clip;		if (b2f < bx2min) {			clip1 *= ((bx2-bx2min) / bxcur);			b2f = bx2min;		}		if (b2l > bx2max) {			clip2 *= ((bx2max-bx2) / bxcur);			b2l = bx2max;		}		/* rasterize one trace */		if (interp==0) { /* don't use interpolation */			rfwtva(n1r,&z[if1r],clip1,clip2,va?0:clip2,				b2f,b2l,b1fz,b1lz,				wt,nbpr,bits,endian);		} else { /* use 8 point sinc interpolation */			rfwtvaint(n1r,&z[if1r],clip1,clip2,va?0:clip2,				b2f,b2l,b1fz,b1lz,				wt,nbpr,bits,endian);		}			}		/* return axis 2 pads */	*p2begp = p2beg;  *p2endp = p2end;		/* get pointer to image */	image = XCreateImage(	(Display *) dpy,				(Visual *) DefaultVisual(dpy,scr),				(unsigned int) 1,				(int) XYBitmap,				(int) 0,				(char *) bits,				(unsigned int) widthpad,				(unsigned int) height1,				(int) BitmapPad(dpy),				(int) nbpr);	if (style == NORMAL) {		image2 = RotImage90(dpy,image);		XDestroyImage(image);		image = image2;	}	return image;}	void xMouseLoc(Display *dpy, Window win, XEvent event, int style, Bool show,	int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,	float p2beg, float p2end){	static XFontStruct *fs=NULL;	static XCharStruct overall;	static GC gc;	int dummy,xoffset=5,yoffset=5;	float x1,x2;	char string[256];	/* if first time, get font attributes and make gc */	if (fs==NULL) {		fs = XLoadQueryFont(dpy,"fixed");		gc = XCreateGC(dpy,win,0,NULL);		/* make sure foreground/background are black/white */		XSetForeground(dpy,gc,BlackPixel(dpy,DefaultScreen(dpy)));		XSetBackground(dpy,gc,WhitePixel(dpy,DefaultScreen(dpy)));		XSetFont(dpy,gc,fs->fid);		overall.width = 1;		overall.ascent = 1;		overall.descent = 1;	}	/* erase previous string */	XClearArea(dpy,win,xoffset,yoffset,		overall.width,overall.ascent+overall.descent,False);	/* if not showing, then return */	if (!show) return;	/* convert mouse location to (x1,x2) coordinates */	if (style==NORMAL) {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width;		x2 = p2end+x2endb+(p2beg+x2begb-x2endb-p2end)*			(event.xmotion.y-y)/height;	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = p2beg+x2begb+(p2end+x2endb-x2begb-p2beg)*			(event.xmotion.x-x)/width;	}	/* draw string indicating mouse location */	sprintf(string,"(%0.6g,%0.6g)",x1,x2);	XTextExtents(fs,string,(int)strlen(string),&dummy,&dummy,&dummy,&overall);	XDrawString(dpy,win,gc,xoffset,yoffset+overall.ascent,		string,(int)strlen(string));}void xMousePrint(XEvent event, int style, FILE *mpicksfp,		 int x, int y, int width, int height,		 float x1begb, float x1endb, float x2begb, float x2endb,		 float p2beg, float p2end){	float x1;	int x2;	/* convert mouse location to (x1,x2) coordinates */	if (style==NORMAL) {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width;		x2 = NINT(p2end+x2endb+(p2beg+x2begb-x2endb-p2end)*			(event.xmotion.y-y)/height);	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = NINT(p2beg+x2begb+(p2end+x2endb-x2begb-p2beg)*			(event.xmotion.x-x)/width);	}	/* write string indicating mouse location */	fprintf(mpicksfp, "%0.6g  %d\n", x1, x2);}/*********************************************************/static XImage *RotImage90(Display *dpy, XImage *oldImage){	int	widthpad,x1,y1,x2,y2,i,nbpr;	unsigned char	*bits;	XImage	*image;	int	width1 =		oldImage->width;	int	width2 =		oldImage->height;	int	height2 =	oldImage->width;	int	scr =			DefaultScreen(dpy);	widthpad = (1 + (width2-1)/(BitmapPad(dpy)/8))*BitmapPad(dpy)/8;	nbpr = 1 + (widthpad-1)/8;	bits = ealloc1(nbpr*height2,sizeof(unsigned char));	image = XCreateImage(	(Display *) dpy,				(Visual *) DefaultVisual(dpy,scr),				(unsigned int) 1,				(int) XYBitmap,				(int) 0,				(char *) bits,				(unsigned int) widthpad,				(unsigned int) height2,				(int) BitmapPad(dpy),				(int) nbpr);	for (i = 0; i < nbpr*height2; i++)	bits[i]=0;	for (x2 = 0; x2 < width2; x2++) {		y1 = x2;		for (y2 = 0; y2 < height2; y2++) {			x1 = width1 - 1 - y2;			XPutPixel(image,x2,y2,XGetPixel(oldImage,x1,y1));		}	}	return image;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -