📄 xwinplt.c
字号:
else return;}label(s) char s[];{/* struct pr_size size, pf_textwidth(); * * pw_text(pw, xpos, ypos, PIX_SRC, SunFont, s); */ XDrawString (display, MCWindow, mc_gc, xpos, ypos, s, strlen (s)); /* size = pf_textwidth(strlen(s), SunFont, s); */ xpos += XTextWidth (font_info, s, strlen (s));}line(x1, y1, x2, y2) int x1, y1, x2, y2;{ move(x1, y1); cont(x2, y2);}circle(x, y, r) int x, y, r;{ static tblinited = 0; static double sine[NCIRC], cosine[NCIRC]; int i, scaledx, scaledy, scaledr, oldx, oldy, newx, newy; if (!tblinited) { /* cache of NCIRC sines and cosines */ double theta, incr; tblinited = 1; incr = (2 * PI) / NCIRC; for (theta = incr, i = 1; i < NCIRC; theta += incr, i++) { sine[i] = sin(theta); cosine[i] = cos(theta); } } scaledx = scalex(x); scaledy = scaley(y); scaledr =.5 + scalex(r); oldx = scaledx + scaledr; oldy = scaledy; XSetForeground(display, mc_gc, BlackPixel (display, screen)); for (i = 1; i < NCIRC; i++) { newx = scaledx + scaledr * cosine[i]; newy = scaledy + scaledr * sine[i]; /* pw_vector(pw, oldx, oldy, newx, newy, PIX_SRC, 1); */ XDrawLine (display, MCWindow, mc_gc, oldx, oldy, newx, newy); oldx = newx; oldy = newy; } /* close up */ /* pw_vector(pw, oldx, oldy, scaledx + scaledr, scaledy, PIX_SRC, 1); */ XDrawLine (display, MCWindow, mc_gc, oldx, oldy, scaledx + scaledr, scaledy);}static doublebear(x0, y0, x1, y1) int x0, y0, x1, y1;{ return atan2((double) y1 - (double) y0, (double) x1 - (double) x0);}/* * like UNIX hypot, but takes integers as arguments; returns a double */static doublemyhypot(x, y) int x, y;{ return sqrt((double) x * (double) x + (double) y * (double) y);}arc(x, y, x0, y0, x1, y1) int x, y, x0, y0, x1, y1;{ double theta0, theta1, theta, incr; int r; r = (int) myhypot(x0 - x, y0 - y); theta0 = bear(x, y, x0, y0); theta1 = bear(x, y, x1, y1); if (theta0 >= theta1) theta1 += 2 * PI; incr = (2 * PI) / NARC; move((int) (x + r * cos(theta0)), (int) (y + r * sin(theta0))); for (theta = theta0; theta <= theta1; theta += incr) cont((int) (x + r * cos(theta)), (int) (y + r * sin(theta))); /* one extra to close up */ cont((int) (x + r * cos(theta1)), (int) (y + r * sin(theta1))); }move(x, y) int x, y;{ xpos = scalex(x); ypos = scaley(y);}cont(x, y) int x, y;{ int oldx = xpos, oldy = ypos; move(x, y); /* pw_vector(pw, oldx, oldy, xpos, ypos, PIX_SRC, 1); */ XSetForeground(display, mc_gc, BlackPixel (display, screen)); XDrawLine (display, MCWindow, mc_gc, oldx, oldy, xpos, ypos);}point(x, y) int x, y;{ move(x, y); label(".");}linemod(s) char s[];{}space(x0, y0, x1, y1) int x0, y0, x1, y1;{ char *Module = "space"; XWindowAttributes windowattr; /* width = (int) window_get(canvas, CANVAS_WIDTH); * height = (int) window_get(canvas, CANVAS_HEIGHT)-text_offset; */ if (debug & 0x4) fprintf (stderr, "%s: get window attributes\n", Module); if (WidgetsCreated) { XGetWindowAttributes (display, MCWindow, &windowattr); width = windowattr.width; height = windowattr.height; } else { width = DEFAULT_WIDTH; height = DEFAULT_HEIGHT; } if (debug & 0x4) fprintf (stderr, "%s: width = %d, height = %d\n", Module, width, height); xlow = x0; ylow = y0; xhigh = x1; yhigh = y1; xorig = 1; yorig = 1;}static voidrepaint_canvas(){ do_plot(); box_start = scalex(BOX_START); box_end = box_start + scalex(BOX_END); box_top = scaley(-BOX_TOP); box_bottom = scaley(-BOX_BOTTOM); if (R_flag && first_paint) { s_text (msg1_ptr, 20, 20); /* display help bar */ get_common(); first_paint = 0; } mark_x = cursor_x = 0; range_state = 1; /* window_set(canvas, CANVAS_REPAINT_PROC, (int (*)()) NULL, 0); */}voidstart_plot(){ char *Module = "start_plot"; XEvent report; int process_events = 1; XWMHints hints; if (debug & 0x2) fprintf(stderr, "%s: in start plot. . .\n", Module); /* window_main_loop(frame); */ /* wait until window is created before drawing */ WidgetsCreated = 1; XtRealizeWidget(toplevel); if (debug & 0x2) fprintf(stderr, "%s: making icon.\n", Module); hints.flags = IconPixmapHint; hints.icon_pixmap = make_icon(display, screen, icon_name); XSetWMHints(display, XtWindow(toplevel), &hints); if (debug & 0x2) fprintf(stderr, "%s: starting main loop.\n", Module); XtMainLoop();#ifdef COMMENT while (XNextEvent (display, &report)) if (report.type == Expose) break; do_plot (); if (debug & 0x2) fprintf (stderr, "%s: processing events . . .\n", Module); /*********************************/ /* P R O C E S S E V E N T S */ /*********************************/ while (process_events) { XNextEvent (display, &report); switch (report.type) { case ResizeRequest: { erase (); do_plot (); repaint_canvas (); } break; case Expose: { do_plot (); repaint_canvas (); } break; case KeyPress: { char buffer[20]; int bufsize = 20; KeySym key; XComposeStatus compose; XLookupString (&report, buffer, bufsize, &key, &compose); if (key == XK_q || key == XK_Q) process_events = 0; } break; default: /* NOT REACHED */ break; } /* end switch (report.type) */ } /* end while (process_events) */ XCloseDisplay (display);#endif COMMENT}voids_text(s, x, y) char *s; int x, y;{/* pw_text(pw, x, y-10, PIX_SRC, SunFont, SPACES); pw_text(pw, x, y-10, PIX_SRC, SunFont, s); */ if (!s) return; XDrawString (display, MCWindow, mc_gc, x, y-10, SPACES, strlen (SPACES)); XDrawString (display, MCWindow, mc_gc, x, y-10, s, strlen (s));}voids_imagetext(s, x, y) char *s; int x, y;{ /* XDrawImageString (display, MCWindow, mc_gc, * x, y-10, * SPACES, strlen (SPACES)); *//* XSetForeground(display, mc_gc, BlackPixel (display, screen)); XSetBackground(display, mc_gc, WhitePixel (display, screen));*/ XDrawImageString (display, MCWindow, mc_gc, x, y-10, s, strlen (s));}voidget_common(){ (void) read_params((char *) NULL, SC_CHECK_FILE, (char *) NULL); if (symtype("beginplot") == ST_UNDEF || symtype("endplot") == ST_UNDEF){ Fprintf(stderr, "mcd: no beginplot or endplot in Common file\n"); exit(1); } filename = getsym_s("filename"); beginplot = getsym_i("beginplot"); endplot = getsym_i("endplot"); points = endplot - beginplot + 1;}voidsave_common(){ if (putsym_s("filename", filename) == -1) Fprintf(stderr, "mcd: could not write into ESPS Common file.\n"); if (putsym_i("start", new_start) == -1) Fprintf(stderr, "mcd: could not write into ESPS Common file.\n"); if (putsym_i("nan", new_nan - new_start + 1) == -1) Fprintf(stderr, "mcd: could not write into ESPS Common file.\n"); if (putsym_s("prog", "range") == -1) Fprintf(stderr, "mcd: could not write into ESPS Common file.\n");}voidplay_file(){ (void)sprintf(range_arg,"-p%ld:+%ld ",beginplot,points); (void)strcpy(buf,"play "); (void)strcat(buf,range_arg); if (play_options) (void)strcat(buf,play_options); (void)strcat(buf," "); (void)strcat(buf,filename); s_text(buf,20,40); (void)system(buf); s_text(" ",20,40);}voidplay_range(){ (void)sprintf(range_arg,"-p%ld:+%ld ",new_start, new_nan-new_start+1); (void)strcpy(buf,"play "); (void)strcat(buf,range_arg); if (play_options) (void)strcat(buf,play_options); (void)strcat(buf," "); (void)strcat(buf,filename); s_text(buf,20,40); (void)system(buf); (void) sprintf(buf, "Range selected is from %d to %d", new_start, new_nan); s_text(buf, 20, 40);}voidzoom_in(){ char *Module = "zoom_in"; (void)sprintf(buf,"Replotting points %ld through %ld ...", new_start,new_nan); s_text(buf,20,40); (void)sprintf(range_arg,"-p%ld:+%ld",new_start, new_nan-new_start+1); (void)strcpy(buf,"plotsd -E.1 -D "); (void)strcat(buf,range_arg); (void)strcat(buf," -Tgps "); (void)strcat(buf,filename); (void)strcat(buf," > "); (void)strcat(buf,tmpname); (void)system(buf); erase(); do_plot(); box_start = scalex(BOX_START); box_end = box_start + scalex(BOX_END); s_text("",20,40); s_text(msg1_ptr,20,20); get_common(); range_state=1; cursor_x=mark_x=0;}voidzoom_out(){ s_text("Zooming out...\n",20,40); (void)strcpy(buf,"plotsd -p1: -D "); (void)strcat(buf," -Tgps "); (void)strcat(buf,filename); (void)strcat(buf," > "); (void)strcat(buf,tmpname); (void)system(buf); erase(); do_plot(); box_start = scalex(BOX_START); box_end = box_start + scalex(BOX_END); s_text("",20,40); s_text(msg1_ptr,20,20); get_common(); range_state=1; cursor_x=mark_x=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -