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

📄 axes.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//*********************** self documentation **********************//******************************************************************************AXES - the Axes WidgetXtcwpPointInAxesRectangle	returns TRUE if point is inside axes				rectangle, otherwise FALSEXtcwpSetAxesValues	set axes valuesXtcwpSetAxesPads	set axes pads******************************************************************************Function Prototype:Boolean XtcwpPointInAxesRectangle (Widget w, Position x, Position y);void XtcwpSetAxesValues (Widget w, float x1beg, float x1end, float x2beg,				float x2end);void XtcwpSetAxesPads (Widget w, float p1beg, float p1end, float p2beg,				float p2end);******************************************************************************XtcwpPointInAxesRectangle:Input:w		axes widgetx		x coordinate of pointy		y coordinate of point******************************************************************************XtcwpSetAxesValues:Input:w		axes widgetx1beg		axis value at beginning of axis 1x1end		axis value at end of axis 1x2beg		axis value at beginning of axis 2x2end		axis value at end of axis 2******************************************************************************XtcwpSetAxesPads:Input:w		axes widgetp1beg		axis pad at beginning of axis 1p1end		axis pad at end of axis 1p2beg		axis pad at beginning of axis 2p2end		axis pad at end of axis 2******************************************************************************Notes:XtcwpPointInAxesRectangle:This function is useful for determining whether or not input eventsoccured with the pointer inside the axes rectangle.  I.e., the inputcallback function will typically call this function.XtcwpSetAxesPads:Pad values must be specified in the same units as the corresponding axes values.  These pads are useful when the contents of the axes boxrequire more space than implied by the axes values.  For example, thefirst and last seismic wiggle traces plotted inside an axes boxwill typically extend beyond the axes values corresponding to thefirst and last traces.  However, all tics will lie within the limitsspecified in the axes values (x1beg, x1end, x2beg, and x2end).*******************************************************************************Author:  Dave Hale, Colorado School of Mines, 08/28/90*******************************************************************************Modified:  Craig Artley, Colorado School of Mines, 06/03/93, Rotate label for	   vertical axis (Courtesy Dave Hale, Advance Geophysical).******************************************************************************//**************** end self doc ********************************/#include "Xtcwp/Xtcwp.h"#include "Xtcwp/AxesP.h"/* resources */static XtResource resources[] = {	{XtNgrid1,XtcwpCAxesGrid,XtcwpRAxesGrid,sizeof(int),		XtOffset(XtcwpAxesWidget,axes.grid1), 		XtRString,"none"},	{XtNgrid2,XtcwpCAxesGrid,XtcwpRAxesGrid,sizeof(int),		XtOffset(XtcwpAxesWidget,axes.grid2), 		XtRString,"none"},	{XtNnTic1,XtCParameter,XtRInt,sizeof(int),		XtOffset(XtcwpAxesWidget,axes.n1tic), 		XtRString,"1"},	{XtNnTic2,XtCParameter,XtRInt,sizeof(int),		XtOffset(XtcwpAxesWidget,axes.n2tic), 		XtRString,"1"},	{XtNlabel1,XtCString,XtRString,sizeof(String),		XtOffset(XtcwpAxesWidget,axes.label1), 		XtRString,""},	{XtNlabel2,XtCString,XtRString,sizeof(String),		XtOffset(XtcwpAxesWidget,axes.label2), 		XtRString,""},	{XtNtitle,XtCString,XtRString,sizeof(String),		XtOffset(XtcwpAxesWidget,axes.title), 		XtRString,""},	{XtNstyle,XtcwpCAxesStyle,XtcwpRAxesStyle,sizeof(int),		XtOffset(XtcwpAxesWidget,axes.style), 		XtRString,"seismic"},	{XtNaxesColor,XtCColor,XtRPixel,sizeof(Pixel),		XtOffset(XtcwpAxesWidget,axes.axescolor), 		XtRString,"black"},	{XtNgridColor,XtCColor,XtRPixel,sizeof(Pixel),		XtOffset(XtcwpAxesWidget,axes.gridcolor), 		XtRString,"black"},	{XtNtitleColor,XtCColor,XtRPixel,sizeof(Pixel),		XtOffset(XtcwpAxesWidget,axes.titlecolor), 		XtRString,"black"},	{XtNlabelFont,XtCFont,XtRFont,sizeof(Font),		XtOffset(XtcwpAxesWidget,axes.labelfont), 		XtRString,"fixed"},	{XtNtitleFont,XtCFont,XtRFont,sizeof(Font),		XtOffset(XtcwpAxesWidget,axes.titlefont), 		XtRString,"fixed"},	{XtNresizeCallback,XtCCallback,XtRCallback,sizeof(char *),		XtOffset(XtcwpAxesWidget,axes.resize), 		XtRCallback,NULL},	{XtNexposeCallback,XtCCallback,XtRCallback,sizeof(char *),		XtOffset(XtcwpAxesWidget,axes.expose), 		XtRCallback,NULL},	{XtNinputCallback,XtCCallback,XtRCallback,sizeof(char *),		XtOffset(XtcwpAxesWidget,axes.input), 		XtRCallback,NULL},};/* functions defined and used internally */static void ClassInitialize (void);static void Initialize (XtcwpAxesWidget request, XtcwpAxesWidget new_widget);static void Destroy (XtcwpAxesWidget w);static void Resize (XtcwpAxesWidget w);static void Redisplay (XtcwpAxesWidget w, XEvent *event, Region region);static Boolean SetValues (XtcwpAxesWidget current, 	XtcwpAxesWidget request, 	XtcwpAxesWidget new_widget);static void fillCallbackStruct (XtcwpAxesWidget w,	int reason, XEvent *event, Region region, XtcwpAxesCallbackStruct *cb);static void inputAxes (XtcwpAxesWidget w, XEvent *event, 	char *args[], int nargs);static void XtcwpStringToAxesGrid (XrmValue *args, int *nargs, 	XrmValue *fromVal, XrmValue *toVal);static void XtcwpStringToAxesStyle (XrmValue *args, int *nargs, 	XrmValue *fromVal, XrmValue *toVal);/* translations */static char defaultTranslations[] = 	"<Btn1Down>: input()\n"	"<Btn1Up>: input()\n"	"<Btn1Motion>: input()\n";/* action procedures */static XtActionsRec actionsList[] = {	{"input",(XtActionProc)inputAxes},};/* class record */XtcwpAxesClassRec  XtcwpaxesClassRec = {	/* CoreClassPart */	{	(WidgetClass) &widgetClassRec,  /* superclass            */	(String) "XtcwpAxes",           /* class_name            */	(Cardinal) sizeof(XtcwpAxesRec),  /* widget_size           */	(XtProc) ClassInitialize,       /* class_initialize      */	(XtWidgetClassProc) NULL,       /* class_part_initialize */	(XtEnum) FALSE,                 /* class_inited          */	(XtInitProc) Initialize,        /* initialize            */	(XtArgsProc) NULL,              /* initialize_hook       */	(XtRealizeProc) XtInheritRealize,  /* realize               */	(XtActionList) actionsList,        /* actions               */	(Cardinal) XtNumber(actionsList),  /* num_actions           */	(XtResourceList) resources,        /* resources             */	(Cardinal) XtNumber(resources),  /* num_resources         */	(XrmClass) NULLQUARK,           /* xrm_class             */	(Boolean) TRUE,                 /* compress_motion       */	(XtEnum) TRUE,                  /* compress_exposure     */	(Boolean) TRUE,                 /* compress_enterleave   */	(Boolean) TRUE,                 /* visible_interest      */	(XtWidgetProc) Destroy,         /* destroy               */	(XtWidgetProc) Resize,          /* resize                */	(XtExposeProc) Redisplay,       /* expose                */	(XtSetValuesFunc) SetValues,     /* set_values            */	(XtArgsFunc) NULL,              /* set_values_hook       */	(XtAlmostProc) XtInheritSetValuesAlmost,   /* set_values_almost     */	(XtArgsProc) NULL,              /* get_values_hook       */	(XtAcceptFocusProc) NULL,       /* accept_focus          */	(XtVersionType) XtVersion,      /* version               */	(XtPointer) NULL,               /* callback private      */	(String) defaultTranslations,   /* tm_table              */	(XtGeometryHandler) NULL,       /* query_geometry        */	(XtStringProc) NULL,            /* display_accelerator   */	(XtPointer) NULL,               /* extension             */	},	/* Axes class fields */	{	0,                              /* ignore                */	}};WidgetClass xtcwpAxesWidgetClass = (WidgetClass) &XtcwpaxesClassRec;/* class functions */static void ClassInitialize (void){	/* add type converters */	XtAddConverter(XtRString,XtcwpRAxesGrid, (XtConverter) XtcwpStringToAxesGrid,NULL,0);	XtAddConverter(XtRString,XtcwpRAxesStyle,(XtConverter) XtcwpStringToAxesStyle,NULL,0);}static void Initialize (XtcwpAxesWidget request, XtcwpAxesWidget new_widget){	/* initialize axes values and pads */	new_widget->axes.x1beg = 0.0;	new_widget->axes.x1end = 1.0;	new_widget->axes.x2beg = 0.0;	new_widget->axes.x2end = 1.0;	new_widget->axes.p1beg = 0.0;	new_widget->axes.p1end = 0.0;	new_widget->axes.p2beg = 0.0;	new_widget->axes.p2end = 0.0;		/* ensure window size is not zero */		if (request->core.width==0) new_widget->core.width = 200;	if (request->core.height==0) new_widget->core.height = 200;	/* set parameters that depend on window size */	Resize(new_widget);}static void Destroy (XtcwpAxesWidget w){	XtRemoveAllCallbacks((Widget) w,XtNresizeCallback);	XtRemoveAllCallbacks((Widget) w,XtNexposeCallback);	XtRemoveAllCallbacks((Widget) w,XtNinputCallback);}static void Resize (XtcwpAxesWidget w){	XtcwpAxesCallbackStruct cb;	XFontStruct *fa,*ft;	XCharStruct cs;	int labelch,labelcw,titlech,bl,bt,br,bb,ticsize,dummy;		/* get fonts and determine character dimensions */	fa = XQueryFont(XtDisplay(w),w->axes.labelfont);	XTextExtents(fa,"2",1,&dummy,&dummy,&dummy,&cs);	labelch = cs.ascent+cs.descent;	labelcw = cs.width;	ft = XQueryFont(XtDisplay(w),w->axes.titlefont);	titlech = ft->max_bounds.ascent+ft->max_bounds.descent;	/* determine axes rectangle position and dimensions */	ticsize = labelcw;	bl = labelch+7*labelcw;	br = w->core.width-5*labelcw;	while (br<bl) {		br += labelcw;		bl -= labelcw;	}	if (bl<0) bl = 0;	if (br>((int) w->core.width)) br = w->core.width; 	if (w->axes.style==XtcwpNORMAL) {		bt = labelch+labelch/2+titlech;		bb = w->core.height-3*ticsize/2-2*labelch;	} else {		bt = 3*ticsize/2+2*labelch;		bb = w->core.height-labelch-labelch/2-titlech;	}	while (bb<bt) {		bb += labelch;		bt -= labelch;	}	if (bt<0) bt = 0;	if (bb>((int) w->core.height)) bb = w->core.height;		w->axes.x = bl;	w->axes.y = bt;	w->axes.width = br-bl;	w->axes.height = bb-bt;			/* Free font info */	XFreeFontInfo(NULL,fa,1);	XFreeFontInfo(NULL,ft,1);			/* call callbacks */	fillCallbackStruct(w,XtcwpCR_RESIZE,NULL,NULL,&cb);	XtCallCallbacks ((Widget) w,XtNresizeCallback,&cb);} static void Redisplay (XtcwpAxesWidget w, XEvent *event, Region region){	Display *dpy=XtDisplay(w);	Window win=XtWindow(w);	int x=w->axes.x;	int y=w->axes.y;	int width=w->axes.width;	int height=w->axes.height;	float x1beg=w->axes.x1beg;	float x1end=w->axes.x1end;	float x2beg=w->axes.x2beg;	float x2end=w->axes.x2end;	float p1beg=w->axes.p1beg;	float p1end=w->axes.p1end;	float p2beg=w->axes.p2beg;	float p2end=w->axes.p2end;	int n1tic=w->axes.n1tic;	int n2tic=w->axes.n2tic;	int grid1=w->axes.grid1;	int grid2=w->axes.grid2;	char *label1=w->axes.label1;	char *label2=w->axes.label2;	char *title=w->axes.title;	Font labelfont=w->axes.labelfont;	Font titlefont=w->axes.titlefont;	Pixel axescolor=w->axes.axescolor;	Pixel gridcolor=w->axes.gridcolor;	Pixel titlecolor=w->axes.titlecolor;	int style=w->axes.style;	XGCValues values;	GC gca,gcg,gct;	XtcwpAxesCallbackStruct cb;	XFontStruct *fa,*ft;	XCharStruct cs;	int labelca,labelcd,labelch,labelcw,titleca,titlech,		ntic,xa,ya,tw,ticsize,ticb,numb,labelb,grided,grid,		n1num,n2num,dummy;	size_t lstr;

⌨️ 快捷键说明

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