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

📄 axes.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
	labelca = fa->max_bounds.ascent;	labelcd = fa->max_bounds.descent;	labelch = fa->max_bounds.ascent+fa->max_bounds.descent;	labelcw = fa->max_bounds.lbearing+fa->max_bounds.rbearing;	ft = XQueryFont(dpy,titlefont);	XSetFont(dpy,gct,titlefont);	titleca = ft->max_bounds.ascent;	titlecd = ft->max_bounds.descent;	titlech = ft->max_bounds.ascent+ft->max_bounds.descent;	titlecw = ft->max_bounds.lbearing+ft->max_bounds.rbearing;	/* determine tic size */	ticsize = labelcw;	/* determine numbered tic intervals */	n1num = (style==XcwpNORMAL ? width : height)/(8*labelcw);	scaxis(x1beg,x1end,&n1num,&d1num,&f1num);	n2num = (style==XcwpNORMAL ? height : width)/(8*labelcw);	scaxis(x2beg,x2end,&n2num,&d2num,&f2num);	/* draw horizontal axis */	if (style==XcwpNORMAL) {		amin = (x1beg<x1end)?x1beg:x1end;		amax = (x1beg>x1end)?x1beg:x1end;		dnum = d1num;  fnum = f1num;  ntic = n1tic;		scale = width/(x1end+p1end-x1beg-p1beg);		base = x-scale*(x1beg+p1beg);		ya = y+height;		ticb = ticsize;		numb = ticb+labelca;		labelb = numb+labelch;		grid = grid1;		label = label1;	} else {		amin = (x2beg<x2end)?x2beg:x2end;		amax = (x2beg>x2end)?x2beg:x2end;		dnum = d2num;  fnum = f2num;  ntic = n2tic;		scale = width/(x2end+p2end-x2beg-p2beg);		base = x-scale*(x2beg+p2beg);		ya = y;		ticb = -ticsize;		numb = ticb-labelcd;		labelb = numb-labelch;		grid = grid2;		label = label2;	}	if (grid==XcwpSOLID) {		XSetLineAttributes(dpy,gcg,1L,LineSolid,CapButt,JoinMiter);		grided = True;	} else if (grid==XcwpDASH) {		grided = True;		XSetLineAttributes(dpy,gcg,1L,LineOnOffDash,CapButt,JoinMiter);		dash[0] = 8;  dash[1] = 4;		XSetDashes(dpy,gcg,0,dash,2);	} else if (grid==XcwpDOT) {		grided = True;		XSetLineAttributes(dpy,gcg,1L,LineOnOffDash,CapButt,JoinMiter);		dash[0] = 1;  dash[1] = 4;		XSetDashes(dpy,gcg,0,dash,2);	} else		grided = False;	azero = 0.0001*(amax-amin);	for (anum=fnum; anum<=amax; anum+=dnum) {		if (anum<amin) continue;		xa = base+scale*anum;		if (grided) XDrawLine(dpy,win,gcg,xa,y,xa,y+height);		XDrawLine(dpy,win,gca,xa,ya,xa,ya+ticb);		if (anum>-azero && anum<azero)			sprintf(str,"%1.5g",0.0);		else			sprintf(str,"%1.5g",anum);		lstr = strlen(str);		tw = XTextWidth(fa,str,lstr);		XDrawString(dpy,win,gca,xa-tw/2,ya+numb,str,lstr);	}	dtic = dnum/ntic;	for (atic=fnum-ntic*dtic-dtic; atic<=amax; atic+=dtic) {		if (atic<amin) continue;		xa = base+scale*atic;		XDrawLine(dpy,win,gca,xa,ya,xa,ya+ticb/2);	}	lstr = strlen(label);	tw = XTextWidth(fa,label,lstr);	XDrawString(dpy,win,gca,x+width-tw,ya+labelb,label,lstr);	/* draw vertical axis */	if (style==XcwpNORMAL) {		amin = (x2beg<x2end)?x2beg:x2end;		amax = (x2beg>x2end)?x2beg:x2end;		dnum = d2num;  fnum = f2num;  ntic = n2tic;		scale = -height/(x2end+p2end-x2beg-p2beg);		base = y+height-scale*(x2beg+p2beg);		grid = grid2;		label = label2;	} else {		amin = (x1beg<x1end)?x1beg:x1end;		amax = (x1beg>x1end)?x1beg:x1end;		dnum = d1num;  fnum = f1num;  ntic = n1tic;		scale = height/(x1end+p1end-x1beg-p1beg);		base = y-scale*(x1beg+p1beg);		grid = grid1;		label = label1;	}	xa = x;	ticb = -ticsize;	numb = ticb-ticsize/4;	if (grid==XcwpSOLID) {		XSetLineAttributes(dpy,gcg,1L,LineSolid,CapButt,JoinMiter);		grided = True;	} else if (grid==XcwpDASH) {		grided = True;		XSetLineAttributes(dpy,gcg,1L,LineOnOffDash,CapButt,JoinMiter);		dash[0] = 8;  dash[1] = 4;		XSetDashes(dpy,gcg,0,dash,2);	} else if (grid==XcwpDOT) {		grided = True;		XSetLineAttributes(dpy,gcg,1L,LineOnOffDash,CapButt,JoinMiter);		dash[0] = 1;  dash[1] = 4;		XSetDashes(dpy,gcg,0,dash,2);	} else		grided = False;	azero = 0.0001*(amax-amin);	for (anum=fnum; anum<=amax; anum+=dnum) {		if (anum<amin) continue;		ya = base+scale*anum;		if (grided) XDrawLine(dpy,win,gcg,x,ya,x+width,ya);		XDrawLine(dpy,win,gca,xa,ya,xa+ticb,ya);		if (anum>-azero && anum<azero)			sprintf(str,"%1.5g",0.0);		else			sprintf(str,"%1.5g",anum);		lstr = strlen(str);		tw = XTextWidth(fa,str,lstr);		XDrawString(dpy,win,gca,xa+numb-tw,ya+labelca/4,str,lstr);	}	dtic = dnum/ntic;	for (atic=fnum-ntic*dtic-dtic; atic<=amax; atic+=dtic) {		if (atic<amin) continue;		ya = base+scale*atic;		XDrawLine(dpy,win,gca,xa,ya,xa+ticb/2,ya);	}	lstr = strlen(label);	if (style==XcwpNORMAL)		XDrawString(dpy,win,gca,			x+ticb-9*labelcw,			y+labelca/4-labelch,label,lstr);	else		XDrawString(dpy,win,gca,			x+ticb-9*labelcw,			y+height+labelca/4+labelch,label,lstr);		/* draw title */	lstr = strlen(title);	tw = XTextWidth(ft,title,lstr);	if (style==XcwpNORMAL)		XDrawString(dpy,win,gct,			x+width/2-tw/2,			y+labelca/4-labelch-labelch,title,lstr);	else		XDrawString(dpy,win,gct,			x+width/2-tw/2,			y+height+labelca/4+labelch+titleca,title,lstr);	/* draw axes box */	XDrawRectangle(dpy,win,gca,x,y,width,height);		/* free GCs */	XFreeGC(dpy,gca);	XFreeGC(dpy,gcg);	XFreeGC(dpy,gct);}static Boolean SetValues (XcwpAxesWidget current, 	XcwpAxesWidget request, 	XcwpAxesWidget new){	Boolean redraw = FALSE;		return redraw; } /* utilities */static void fillCallbackStruct (XcwpAxesWidget w,	int reason, XEvent *event, XcwpAxesCallbackStruct *cb){	cb->reason = reason;	cb->event = event;	cb->x = w->axes.x;	cb->y = w->axes.y;	cb->width = w->axes.width;	cb->height = w->axes.height;	cb->x1beg = w->axes.x1beg;	cb->x1end = w->axes.x1end;	cb->x2beg = w->axes.x2beg;	cb->x2end = w->axes.x2end;	cb->p1beg = w->axes.p1beg;	cb->p1end = w->axes.p1end;	cb->p2beg = w->axes.p2beg;	cb->p2end = w->axes.p2end;	cb->style = w->axes.style;}	/* action procedures */static void inputAxes (XcwpAxesWidget w, XEvent *event, 	char *args[], int nargs){	XcwpAxesCallbackStruct cb;			/* call callback */	fillCallbackStruct(w,XcwpCR_INPUT,event,&cb);	XtCallCallbacks (w,XtNinputCallback,&cb);} /* public functions */Boolean XcwpPointInAxesRectangle (XcwpAxesWidget w, Position x, Position y){	Position xa=w->axes.x,ya=w->axes.y;	Dimension wa=w->axes.width,ha=w->axes.height;		return (x>=xa && x<=xa+wa && y>=ya && y<=ya+ha);}void XcwpSetAxesValues (XcwpAxesWidget w,	float x1beg, float x1end, float x2beg, float x2end){	w->axes.x1beg = x1beg;	w->axes.x1end = x1end;	w->axes.x2beg = x2beg;	w->axes.x2end = x2end;}void XcwpSetAxesPads (XcwpAxesWidget w,	float p1beg, float p1end, float p2beg, float p2end){	w->axes.p1beg = p1beg;	w->axes.p1end = p1end;	w->axes.p2beg = p2beg;	w->axes.p2end = p2end;}/* resource type converters */void XcwpStringToAxesGrid (XrmValue *args, int *nargs, 	XrmValue *fromVal, XrmValue *toVal){	static int result;	char *string=fromVal->addr;		/* convert axes grid string in fromVal to int in toVal */	if (strcmp(string,"none")==0)		result = XcwpNONE;	else if (strcmp(string,"dot")==0)		result = XcwpDOT;	else if (strcmp(string,"dash")==0)		result = XcwpDASH;	else if (strcmp(string,"solid")==0)		result = XcwpSOLID;	else {		result = XcwpNONE;		XtWarning("Invalid AxesGrid specification!");	}	toVal->size = sizeof(int);	toVal->addr = (caddr_t)&result;}void XcwpStringToAxesStyle (XrmValue *args, int *nargs, 	XrmValue *fromVal, XrmValue *toVal){	static int result;	char *string=fromVal->addr;		/* convert axes style string in fromVal to int in toVal */	if (strcmp(string,"normal")==0)		result = XcwpNORMAL;	else if (strcmp(string,"seismic")==0)		result = XcwpSEISMIC;	else {		result = XcwpNORMAL;		XtWarning("Invalid AxesStyle specification!");	}	toVal->size = sizeof(int);	toVal->addr = (caddr_t)&result;}

⌨️ 快捷键说明

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