📄 xpig.c
字号:
break; }}/*----------------------------------------------------------------------------*/void WPigGetTextExtent (const char * string, float *str_width, float *str_height, const Long dummy_len){ float dummy_ascent, dummy_descent; PIGDBG1("void WPigGetTextExtent (char * string, float *str_width, float *str_height)(%s)\n", string); iXPigGetTextExtent (string, str_width, str_height, &dummy_ascent, &dummy_descent);}/*----------------------------------------------------------------------------*/void WPigSetCharSpacing(const float *spacing){/* PIGDBG1("void WPigSetCharSpacing(float spacing)(%f)\n", (float) *spacing); */ /* Null Operation */}/*----------------------------------------------------------------------------*/void WPigSetWindowNum(const Long *Num){if( (*Num <= NULL_WIN) && (*Num >= 0) ) { PIGDBG1("void WPigSetWindowNum(Long Num)(%li)(%s)\n", (long)*Num, pig_window_names[(long) *Num]);} else { PIGDBG1("void WPigSetWindowNum(Long Num)(%li)(%s)\n", (long)*Num, "Illegal");} switch (*Num) { case PIG_MAIN_WIN: current_pig_window = PIG_MAIN_WIN; CurrentXCanvas = MainXCanvas; break; case PIG_CONTROL_WIN: current_pig_window = PIG_CONTROL_WIN; last_ctrl_or_prfl = PIG_CONTROL_WIN; CurrentXCanvas = ControlXCanvas; break; case PIG_PROFILE_WIN: current_pig_window = PIG_PROFILE_WIN; last_ctrl_or_prfl = PIG_PROFILE_WIN; CurrentXCanvas = ProfileXCanvas; break; case PIG_STATUS_WIN: current_pig_window = PIG_STATUS_WIN; CurrentXCanvas = MainXCanvas; break; case PIG_SCREEN_WIN: current_pig_window = PIG_PROFILE_WIN; CurrentXCanvas = ControlXCanvas; break; default: { char msg[120]; sprintf(msg,"Illegal window number [%li]", (long)*Num); iWPigFatal(msg); } }}/*----------------------------------------------------------------------------*/void WPigSetZoomFlag(void){PIGDBG1("void WPigSetZoomFlag(void)\n"); Zoom_flag = True;}/*----------------------------------------------------------------------------*/Long WPigGetZoomFlag(void){PIGDBG1("int WPigGetZoomFlag(void)\n"); return ((Long) Zoom_flag);}/*----------------------------------------------------------------------------*/static void DrawRubberLine(int x1, int y1, int x2, int y2){ XDrawLine(XtDisplay(MainXCanvas), XtWindow(MainXCanvas), Xor_gc, x1, y1, x2, y2);}/*----------------------------------------------------------------------------*/static void DrawRubberRect(int x1, int y1, int x2, int y2){ int draw_x1, draw_y1, draw_height, draw_width; if (x1 > x2) { draw_x1 = x2; } else { draw_x1 = x1; } draw_width = abs(x1 - x2); if (y1 > y2) { draw_y1 = y2; } else { draw_y1 = y1; } draw_height = abs(y1 - y2); XDrawRectangle(XtDisplay(MainXCanvas), XtWindow(MainXCanvas), Xor_gc, draw_x1, draw_y1, draw_width, draw_height);}/*----------------------------------------------------------------------------*/void WPigGetZoomArea(float *xlow, float *xhigh, float *ylow, float *yhigh){ XEvent event; int temp_int; int x1, y1, x2, y2; double ret_x1, ret_y1, ret_x2, ret_y2; int in_window, waiting_for_initial_mouse_click, motion_waiting_for_release, bad_data, exit_zoom_loop;PIGDBG1("void WPigGetZoomArea(float *xlow, float *xhigh, float *ylow, float *yhigh)\n"); /* * the only way I've figured to make this screw up is to press a cascade button so the * mouse turns the other way, then press the button to make it zoom. One can be freed from * this state by pressing the control key -- only because it is a non-mouse-generated event */ Zoom_flag = False; waiting_for_initial_mouse_click = True; in_window = True; motion_waiting_for_release = False; bad_data = False; exit_zoom_loop = False; for (;;) { XtAppNextEvent(context, &event); PIGDBG2("--- Event ---- : %s\t", Xevent_type[event.type] ); if ( (event.type == ButtonPress) || (event.type == LeaveNotify) || (event.type == EnterNotify) || (event.type == MotionNotify) || (event.type == ButtonRelease) || (event.type == KeyPress) ) { if (waiting_for_initial_mouse_click == True) { PIGDBG2("First Loop \n"); switch (event.type) { case ButtonPress: if ( (in_window) && (event.xbutton.window == XtWindow(MainXCanvas)) ) { waiting_for_initial_mouse_click = False; motion_waiting_for_release = True; x1 = event.xbutton.x; y1 = event.xbutton.y; x2 = x1; y2 = y1; } else { waiting_for_initial_mouse_click = False; motion_waiting_for_release = False; bad_data = True; exit_zoom_loop = True; } break; case LeaveNotify: in_window = False; break; case EnterNotify: in_window = True; break; case MotionNotify: break; case KeyPress: default: waiting_for_initial_mouse_click = False; motion_waiting_for_release = False; bad_data = True; exit_zoom_loop = True; break; } } else if (motion_waiting_for_release == True) { PIGDBG2("Second Loop \n"); switch (event.type) { case MotionNotify: if ( (in_window) && (event.xmotion.window == XtWindow(MainXCanvas)) ) { DrawRubberRect(x1, y1, x2, y2); x2 = event.xmotion.x; y2 = event.xmotion.y; DrawRubberRect(x1, y1, x2, y2); } else { } break; case ButtonRelease: if ( (in_window) && (event.xmotion.window == XtWindow(MainXCanvas)) ) { DrawRubberRect(x1, y1, x2, y2); x2 = event.xbutton.x; y2 = event.xbutton.y; waiting_for_initial_mouse_click = False; motion_waiting_for_release = False; exit_zoom_loop = True; } else { waiting_for_initial_mouse_click = False; motion_waiting_for_release = False; bad_data = True; exit_zoom_loop = True; } break; case LeaveNotify: in_window = False; break; case EnterNotify: in_window = True; break; case KeyPress: default: waiting_for_initial_mouse_click = False; motion_waiting_for_release = False; bad_data = True; exit_zoom_loop = True; break; } } if (exit_zoom_loop == True) { break; /*for*/ } } } PIGDBG3("co-ordinates taken: (%d, %d) to (%d, %d)\n\n", x1, y1, x2, y2); /* trap "too-small" selections ... ie. user pressed and released real quick */ /* trap mouse events to only capture legal events (see above) */ if ( (abs(x2 -x1) < 12) || (abs(y2 - y1) < 12 ) || (bad_data == True)) { *xlow = (float) WorldX1; *xhigh = (float) WorldX2; *ylow = (float) WorldY1; *yhigh = (float) WorldY2; } else { if (x1 > x2) { temp_int = x2; x2 = x1; x1 = temp_int; } if (y1 > y2) { temp_int = y2; y2 = y1; y1 = temp_int; } iXPigUnresolvePoint(PIG_MAIN_WIN, x1, y1, &ret_x1, &ret_y1); iXPigUnresolvePoint(PIG_MAIN_WIN, x2, y2, &ret_x2, &ret_y2); PIGDBG3("co-ordinates are: (%f, %f) to (%f, %f)\n\n",ret_x1, ret_y1,ret_x2, ret_y2); *xlow = (float) ret_x1; *xhigh = (float) ret_x2; *ylow = (float) ret_y1; *yhigh = (float) ret_y2; } return;}/*----------------------------------------------------------------------------*/void WPigSetLineWidth (const float *width){PIGDBG1("void WPigSetLineWidth (float width)(%f)\n", (float) *width); XSetLineAttributes(XtDisplay(CurrentXCanvas), GraphicsContext, (int) *width, LineSolid, CapButt, JoinMiter);}/*----------------------------------------------------------------------------*//*---------------- Set Colour Routines ---------------------------------------*//*----------------------------------------------------------------------------*/static char *iXcolourname(const Long *NewColour){ if((*NewColour >= 0) && (*NewColour < 16)) { return Xcolour_names[(long) *NewColour]; } else { return "Illegal colour number"; }}void WPigSetLineColour (const Long *NewColour){PIGDBG1("void WPigSetLineColour(%s)\n", iXcolourname(NewColour) ); XLineColour = (int) *NewColour;}/*----------------------------------------------------------------------------*/void WPigSetTextColour (const Long *NewColour){PIGDBG1("void WPigSetTextColour(%s)\n", iXcolourname(NewColour) ); XTextColour = (int) *NewColour;}/*----------------------------------------------------------------------------*/void WPigSetFillColour (const Long *NewColour){PIGDBG1("void WPigSetFillColour(%s)\n", iXcolourname(NewColour) ); XFillColour = (int) *NewColour;}/*----------------------------------------------------------------------------*/void WPigSetForegrColour (const Long *NewColour){PIGDBG1("void WPigSetForegrColour(%s)\n", iXcolourname(NewColour) ); XForegrColour = (int) *NewColour;PIGDBG1("XForegrColour=%li\n", (long)XForegrColour);PIGDBG1("*NewColour=%li\n", (long)*NewColour);PIGDBG1("CmsColourDefs[XForegrColour]=%li\n", (long)CmsColourDefs[XForegrColour]);PIGDBG1("XtDisplay(CurrentXCanvas=%li)=%li\n", (long)CurrentXCanvas, (long)XtDisplay(CurrentXCanvas));PIGDBG1("CmsColourDefs[XForegrColour]=%li\n", (long)CmsColourDefs[XForegrColour]); XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XForegrColour]);PIGDBG1("leaving void WPigSetForegrColour\n");PIGDBG1("leaving void WPigSetForegrColour(%s)\n", iXcolourname(NewColour) );}/*----------------------------------------------------------------------------*/void WPigSetBackgrColour (const Long *NewColour){PIGDBG1("void WPigSetBackgrColour(%s)\n", iXcolourname(NewColour) ); XBackgrColour = (int) *NewColour; XSetBackground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XBackgrColour]);}/*----------------------------------------------------------------------------*/void WPigSetSymbolColour (const Long *NewColour){PIGDBG1("void WPigSetSymbolColour(%s)\n", iXcolourname(NewColour) ); XSymbolColour = (int) *NewColour;}/*----------------------------------------------------------------------------*/void WPigSetSymbolNumber (const Long *NewNumber){PIGDBG1("void WPigSetSymbolNumber (Long *NewNumber)(%s)\n",Xsymbol_names[labs((long) *NewNumber)]); XSymbolNumber = (int) labs(*NewNumber);}/*----------------------------------------------------------------------------*/void WPigSetSymbolSize (const float *NewSize){PIGDBG1("void WPigSetSymbolSize (float *NewSize)(%f)\n", (float) *NewSize); XSymbolSize = (double) *NewSize;}/*----------------------------------------------------------------------------*/void WPigDrawPolyLine(const Long *NPoints, const float *xarray, const float *yarray){PIGDBG1("void WPigDrawPolyLine(Long *NPoints, float *xarray, float *yarray)(NPoints = %li)\n", (long) *NPoints); if (current_pig_window == PIG_STATUS_WIN) return; XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XLineColour]);#define MAXFASTPOINTS 5 if(*NPoints <= MAXFASTPOINTS) { int NumPoints; static XPoint points[MAXFASTPOINTS]; short x, y; double xd, yd; for (NumPoints = 0; NumPoints < (int) *NPoints; NumPoints++) { xd = (double)xarray[NumPoints]; yd = (double)yarray[NumPoints]; /* PIGDBG2("\tpoint #%i\t(%f, %f)\n", NumPoints + 1, *Xarray, *Yarray); */ iXPigResolvePoint(xd, yd, &x, &y); /* load up 'points' array */ points[NumPoints].x = (short) x; points[NumPoints].y = (short) y; } XDrawLines(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext, points, (int)*NPoints, CoordModeOrigin);#undef MAXFASTPOINTS } else {/* #define MAXFASTPOINTS 8192 */#define MAXFASTPOINTS 512/* #define MAXFASTPOINTS (*NPoints+1) */ int NumPoints, n; int j; static XPoint points[MAXFASTPOINTS]; short x, y; double xd, yd; for (j= 0; j < *NPoints; j += MAXFASTPOINTS - 1) { n = ((*NPoints - j) < MAXFASTPOINTS) ? (*NPoints - j) : MAXFASTPOINTS; /* PIGDBG2("\tj = %li, n=%li\n", (long)j, (long)n); */ for (NumPoints = 0; NumPoints < n; NumPoints++) { /* PIGDBG2("\tj = %li, n=%li, NumPoints=%li\n", (long)j, (long)n, (long)NumPoints); */ xd = (double) xarray[j+NumPoints]; yd = (double) yarray[j+NumPoints]; x = 0; y = 0; iXPigResolvePoint(xd, yd, &x, &y); /* load up 'points' array */ points[NumPoints].x = (short) x; points[NumPoints].y = (short) y; /* PIGDBG2("\tj = %li, n=%li, NumPoints=%li, xarray=%f, yarray=%f, xd=%f, yd=%f, x=%li, y=%li, point.x=%li, point.y = %li\n", */ /* (long)j, (long)n, (long)NumPoints, */ /* (double)xarray[j+NumPoints], (double)yarray[j+NumPoints], */ /* xd, yd, */ /* (long)x, (long)y, */ /* (long)(points[NumPoints].x), (long)(points[NumPoints].y)); */ } XDrawLines(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), GraphicsContext, points, n, CoordModeOrigin); } /* pause(); */#undef MAXFASTPOINTS } XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XForegrColour]);}/*--------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -