📄 xbuplot.c
字号:
int height; char character [2]; x = mm_to_pixels (*x_mm); y = win_height - mm_to_pixels (*y_mm); height = mm_to_pixels (*height_mm); character [1] = 0; ndp = *num_dec_points; if (*number > 0.0) { rounded_number = (float) ((long) (*number * pwr (10.0, ndp) + 0.5) / pwr (10.0, ndp)); } else { rounded_number = (float) ((long) (*number * pwr (10.0, ndp) - 0.5) / pwr (10.0, ndp)); } sprintf (string, "%g", rounded_number); num_chars = strlen (string); if ((int) (*angle + 0.5) == 0) { XDrawString (display, win, gc, x, y, string, num_chars); } else if ((int) (*angle + 0.5) == 90) { for (i = 1; i <= num_chars; i++) { character [0] = string [i - 1]; XDrawString (display, win, gc, x, (unsigned int) (y - ((num_chars - i) * 1.2 * height)), character, 1); } }#if XFLUSH XFlush (display);#endif}/******** xbuerase_ ********/void xbuerase_ (){ XClearArea (display, win, 0, 0, 0, 0, False);#if XFLUSH XFlush (display);#endif}/******** xbuflush_ ********/void xbuflush_ (){ XFlush (display);}/******** xbuclose_ ********/void xbuclose_ (){ XUnloadFont (display, font_info->fid); XFreeGC (display, gc); XCloseDisplay (display);}/******** mm_to_pixels ********/unsigned int mm_to_pixels (mm) float mm;{ return ((unsigned int) (mm * PIXELS_PER_INCH / MM_PER_INCH + 0.5));}/******** pwr ********/float pwr (number, exponent) float number; int exponent;{ int i; float value; value = 1.0; for (i = 1; i <= exponent; i++) { value *= number; } return (value);}/******** colour_available ********//* find out in the display supports colour. * i.e. PseudoColor, TrueColor, DirectColor, and StaticColor * return 0 is colour_available == false * return 1 is colour_available == true */int colour_available (){ int default_depth; int class = 5; XVisualInfo visual_info; default_depth = DefaultDepth (display, screen_num); if (default_depth == 1) { /* Must be static grey. use black and white */ /* return value of 0 for "colour_available == false" */ return (0); } /* check to see if a visual class that supports colour is available */ while (!XMatchVisualInfo (display, screen_num, default_depth, class--, &visual_info)) ; class++; /* set class back to which class was found */ if (class < 2) /* colour visual classes are 2 to 5 */ { /* No color visual available at default_depth. use black and white */ /* return value of 0 for "colour_available == false" */ return (0); } /* color visual is available. colours are available */ /* return value of 1 for "colour_available == true" */ return (1);}/******** get_colour ********//* returns pixel value for given colour *//* allocates colour if necessary */unsigned long get_colour (colour) int colour;{ Colormap default_colour_map; XColor exact_def; /* check to make sure colour is in range, if not return white */ if (colour > MAX_COLOURS - 1) return (WhitePixel (display, screen_num)); /* check to see if colour has alread been allocated. if so return value */ if (colour_value [colour]) /* colour_value is non-zero if allocated */ return (colour_value [colour]); /* get default colour map */ default_colour_map = DefaultColormap (display, screen_num); /* parse colour name to see if colour is available. if not use white */ if (!XParseColor (display, default_colour_map, colour_name [colour], &exact_def)) return (WhitePixel (display, screen_num)); /* allocate colour. if not available use white */ if (!XAllocColor (display, default_colour_map, &exact_def)) return (WhitePixel (display, screen_num)); /* we got the colour so store it and return it's pixel value */ colour_value [colour] = exact_def.pixel; return (exact_def.pixel);}/******** xbucolour ********//* set the foreground colour in the gc to the value of colour */void xbucolour_ (colour) int *colour;{ if (can_use_colours) XSetForeground (display, gc, get_colour (*colour));}/******** xburect ********//* draw a rectangle and, possibly, fill it */void xburect_ (x1_mm, y1_mm, x2_mm, y2_mm, fill) float *x1_mm, *y1_mm; /* bottom left corner in mm */ float *x2_mm, *y2_mm; /* top right corner in mm */ int *fill; /* fill flag: 0 == no fill, 1 == fill */{ unsigned int x1, y1; /* bottom left corner in pixels */ unsigned int x2, y2; /* top right right corner in pixels */ x1 = mm_to_pixels (*x1_mm);/* MA following line changed from y1 = win_height - mm_to_pixels (*y1_mm) */ y1 = mm_to_pixels (*y1_mm); x2 = mm_to_pixels (*x2_mm);/* MA following line changed from y2 = win_height - mm_to_pixels (*y2_mm) */ y2 = mm_to_pixels (*y2_mm); if (*fill) { XDrawRectangle (display, win, gc, x1, y1, x2 - x1, y2 - y1); XFillRectangle (display, win, gc, x1 + 1, y1 + 1, x2 - x1 - 1, y2 - y1 - 1); } else { XDrawRectangle (display, win, gc, x1, y1, x2 - x1, y2 - y1); XFillRectangle (display, win, gc, x1 + 1, y1 + 1, x2 - x1 - 1, y2 - y1 - 1); }}/******** xbuevent ********//* wait for a button or key press event */void xbuevent_ (x_mm, y_mm, button, key) float *x_mm, *y_mm; /* position of cursor in mm */ int *button; /* button that was pressed */ char *key; /* key that was pressed */{ XEvent event; KeySym keysym; XComposeStatus compose; char buffer = 0; int buflen = 1; int got_event = 0; *button = *key = 0; /* initialize button and key to zero */ /* loop until we get a key or button press that we want */ while (!got_event) { /* get next button or key press event */ XMaskEvent (display, ButtonPressMask | KeyPressMask, &event); switch (event.type) { case ButtonPress: *button = event.xbutton.button; *x_mm = (double) event.xbutton.x / (double) win_width * win_width_mm; *y_mm = (double) (win_height - event.xbutton.y) / (double) win_height * win_height_mm; got_event++; break; case KeyPress: XLookupString (&event, &buffer, buflen, &keysym, &compose); switch (keysym) { case XK_Shift_L: /* ignore a key press from a key modifier */ case XK_Shift_R: case XK_Control_L: case XK_Control_R: case XK_Caps_Lock: case XK_Shift_Lock: case XK_Meta_L: case XK_Meta_R: case XK_Alt_L: case XK_Alt_R: case XK_Super_L: case XK_Super_R: case XK_Hyper_L: case XK_Hyper_R: break; default: *key = buffer; *x_mm = (double) event.xkey.x / (double) win_width * win_width_mm; *y_mm = (double) (win_height - event.xkey.y) / (double) win_height * win_height_mm; got_event++; break; } } }}/******** xbucircle ********//* draw a circle */void xbucircle_ (x_mm, y_mm, size_mm, fill_flag) float *x_mm, *y_mm; /* position of cursor in mm */ float *size_mm; /* size of circle */ int *fill_flag; /* fill flag: 0 = no fill, 1 = fill */{ int x, y; /* x y coords of center of circle in pixels */ int size; /* size of circle in pixels */ x = mm_to_pixels (*x_mm); y = win_height - mm_to_pixels (*y_mm); size = mm_to_pixels (*size_mm); XDrawArc (display, win, gc, x, y, size, size, 0, 64 * 360); if (*fill_flag) XFillArc (display, win, gc, x, y, size, size, 0, 64 * 360);#if XFLUSH XFlush (display);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -