📄 x10.c
字号:
X_Update(){ XSync(0);}X_Clear(){ XClear(DEVDEP(currentgraph).window);}X_MakeMenu(){/* note: */}X_MakeDialog(){/* note: */}X_Track(){/* note: */}static handleXev(){ XEvent ev; XNextEvent(&ev);#ifdef HAS_XT XtDispatchEvent(&ev);#else eventhandler(&ev, (char *) NULL);#endif}/*ARGSUSED*/static void eventhandler(ev, data)XEvent *ev;char *data;{ GRAPH *graph; XKeyOrButtonEvent *buttonev; XKeyPressedEvent *keyev; XExposeEvent *exposeev; char *text; int nbytes; char buf[128]; /* for KeyPressed text */#ifdef HAS_XT graph = (GRAPH *) data;#else graph = (GRAPH *) XLookUpAssoc(xtable, (int) ev->window);#endif if (!graph) { externalerror("Can't find graph."); return; } switch (ev->type) { case ButtonPressed: buttonev = (XKeyOrButtonEvent *) ev; switch (buttonev->detail) { case LeftButton: slopelocation(graph, buttonev->x, buttonev->y); break; case MiddleButton: killwin(graph); break; case RightButton: zoomin(graph); break; default: break; } break; case ExposeWindow: case ExposeRegion: exposeev = (XExposeEvent *) ev; if ((ev->type == ExposeWindow) && ((exposeev->width != graph->absolute.height) || (exposeev->height) != graph->absolute.width)) { /* a resize event */ resize(graph, exposeev->width, exposeev->height); } redraw(graph); break; case KeyPressed: keyev = (XKeyPressedEvent *) ev; text = XLookupMapping(keyev, &nbytes); /* write it */ PushGraphContext(graph); strncpy(buf, text, nbytes); buf[nbytes] = '\0'; SetColor(1); Text(buf, keyev->x, graph->absolute.height - keyev->y); /* save it */ SaveText(graph, buf, keyev->x, graph->absolute.height - keyev->y); /* warp mouse so user can type in sequence */ XWarpMouse(DEVDEP(graph).window, keyev->x + XStringWidth(buf, DEVDEP(graph).fontinfo, 0, 0), keyev->y); PopGraphContext(); break; default: break; }}slopelocation(graph, x0, y0)GRAPH *graph;int x0, y0; /* initial position of mouse */{ int x1, y1; int x, y; Window subw; short state; double fx0, fx1, fy0, fy1; x1 = x0; y1 = y0; XQueryMouseButtons(DEVDEP(graph).window, &x, &y, &subw, &state); XLine(DEVDEP(graph).window, x0, y0, x0, y1-1, 1, 1, 1, GXxor, AllPlanes); XLine(DEVDEP(graph).window, x0, y1, x1, y1, 1, 1, 1, GXxor, AllPlanes); while (state & LeftMask) { if (x != x1 || y != y1) { XLine(DEVDEP(graph).window, x0, y0, x0, y1-1, 1, 1, 1, GXxor, AllPlanes); XLine(DEVDEP(graph).window, x0, y1, x1, y1, 1, 1, 1, GXxor, AllPlanes); x1 = x; y1 = y; XLine(DEVDEP(graph).window, x0, y0, x0, y1-1, 1, 1, 1, GXxor, AllPlanes); XLine(DEVDEP(graph).window, x0, y1, x1, y1, 1, 1, 1, GXxor, AllPlanes); } XQueryMouseButtons(DEVDEP(graph).window, &x, &y, &subw, &state); } XLine(DEVDEP(graph).window, x0, y0, x0, y1-1, 1, 1, 1, GXxor, AllPlanes); XLine(DEVDEP(graph).window, x0, y1, x1, y1, 1, 1, 1, GXxor, AllPlanes); X_ScreentoData(graph, x0, y0, &fx0, &fy0); X_ScreentoData(graph, x1, y1, &fx1, &fy1); /* print it out */ if (x1 == x0 && y1 == y0) { /* only one location */ fprintf(stdout, "\nx0 = %g, y0 = %g\n", fx0, fy0); } else { /* need to print info about two points */ fprintf(stdout, "\nx0 = %g, y0 = %g x1 = %g, y1 = %g\n", fx0, fy0, fx1, fy1); fprintf(stdout, "dx = %g, dy = %g\n", fx1-fx0, fy1 - fy0); if (x1 != x0 && y1 != y0) { /* add slope info if both dx and dy are zero, because otherwise either dy/dx or dx/dy is zero, which is uninteresting */ fprintf(stdout, "dy/dx = %g dx/dy = %g\n", (fy1-fy0)/(fx1-fx0), (fx1-fx0)/(fy1-fy0)); } } return;}/* should be able to do this by sleight of hand on graph parameters */zoomin(graph)GRAPH *graph;{/* note: need to add circular boxes XXX */ int x0, y0, x1, y1; Window subw; Vertex vlist[5]; double fx0, fx1, fy0, fy1, ftemp; XEvent ev; char buf[BSIZE_SP]; wordlist *wl; int dummy; /* open box and get area to zoom in on */ XQueryMouse(DEVDEP(graph).window, &x0, &y0, &subw); x1 = x0 + BOXSIZE; y1 = y0 + BOXSIZE; XWarpMouse(DEVDEP(graph).window, x1, y1); vlist[0].x = x0; vlist[0].y = y0; vlist[0].flags = VertexStartClosed; vlist[1].x = x1; vlist[1].y = y0; vlist[1].flags = 0; vlist[2].x = x1; vlist[2].y = y1; vlist[2].flags = 0; vlist[3].x = x0; vlist[3].y = y1; vlist[3].flags = 0; vlist[4].x = x0; vlist[4].y = y0; vlist[4].flags = VertexEndClosed | VertexDrawLastPoint; XDraw(DEVDEP(graph).window, vlist, 5, 1, 1, 1, GXxor, AllPlanes); XSelectInput(DEVDEP(graph).window, MouseMoved | ButtonReleased); for (;;) { XWindowEvent(DEVDEP(graph).window, MouseMoved | ButtonReleased, &ev); x1 = ((XKeyOrButtonEvent *) &ev)->x; y1 = ((XKeyOrButtonEvent *) &ev)->y; if (ev.type == MouseMoved) { XDraw(DEVDEP(graph).window, vlist, 5, 1, 1, 1, GXxor, AllPlanes); vlist[1].x = vlist[2].x = x1; vlist[2].y = vlist[3].y = y1; XDraw(DEVDEP(graph).window, vlist, 5, 1, 1, 1, GXxor, AllPlanes); } else { XDraw(DEVDEP(graph).window, vlist, 5, 1, 1, 1, GXxor, AllPlanes); XSelectInput(DEVDEP(graph).window, INPUTMASK); break; } } X_ScreentoData(graph, x0, y0, &fx0, &fy0); X_ScreentoData(graph, x1, y1, &fx1, &fy1); if (fx0 > fx1) { ftemp = fx0; fx0 = fx1; fx1 = ftemp; } if (fy0 > fy1) { ftemp = fy0; fy0 = fy1; fy1 = ftemp; } if (!eq(plot_cur->pl_typename, graph->plotname)) { (void) sprintf(buf, "setplot %s ; %s xlimit %lg %lg ylimit %lg %lg ; setplot $curplot\n", graph->plotname, graph->commandline, fx0, fx1, fy0, fy1); } else { (void) sprintf(buf, "%s xlimit %lg %lg ylimit %lg %lg\n", graph->commandline, fx0, fx1, fy0, fy1); } /* hack for Gordon Jacobs */ /* add to history list if plothistory is set */ if (cp_getvar("plothistory", VT_BOOL, (char *) &dummy)) { wl = cp_parse(buf); (void) cp_addhistent(cp_event++, wl); } (void) cp_evloop(buf);}killwin(graph)GRAPH *graph;{ XDestroyWindow(DEVDEP(graph).window); XDeleteAssoc(xtable, DEVDEP(graph).window); DestroyGraph(graph->graphid);}/* call higher gr_redraw routine */redraw(graph)GRAPH *graph;{ gr_redraw(graph);}resize(graph, width, height)GRAPH *graph;int width, height;{ graph->absolute.width = width; graph->absolute.height = height; gr_resize(graph);}X_Input(request, response) REQUEST *request; RESPONSE *response;{ XEvent ev; int nfds, readfds; switch (request->option) { case char_option:#ifdef HAS_XT do { XtNextEvent(&ev); XtDispatchEvent(&ev); } while (!EXTERNkey); break;#else/* note: XXX move this loop up out of char_option */ nfds = dpyno() > fileno(request->fp) ? dpyno() : fileno(request->fp); while (1) { /* first read off the queue before doing the select */ while (XPending()) { handleXev(); } readfds = 1 << dpyno() | 1 << fileno(request->fp); /* block on dpyno and request->fp */ select(nfds+1, &readfds, (int *) NULL, (int *) NULL, NULL); /* handle X events first */ if (readfds & (1 << dpyno())) { /* handle ALL X events */ do { handleXev(); } while (XPending()); } if (readfds & (1 << fileno(request->fp))) { response->reply.ch = inchar(request->fp); goto out; } }#endif case click_option: /* inform user to hit a key */ fprintf(cp_out, "click on the desired graph\n"); /* note: do we want to do a grab here just to change the cursor? */ XMaskEvent(ButtonPressed, &ev); response->reply.graph = (GRAPH *) XLookUpAssoc(xtable, (int) ev.window); if (!response->reply.graph) { externalerror("Can't find graph."); response->option = error_option; return; } break; case button_option: /* sit and handle events until get a button selection */ internalerror("button_option not implemented"); response->option = error_option; return; case checkup_option: while (XPending()) {#ifdef HAS_XT XtNextEvent(&ev); XtDispatchEvent(&ev);#else handleXev();#endif } break; default: internalerror("unrecognized input type"); response->option = error_option; return; }out: if (response) response->option = request->option; return;}static X_ScreentoData(graph, x, y, fx, fy)GRAPH *graph;int x,y;double *fx, *fy;{ double low, high; /* note: figure something out for polar grids, etc XXX */ if ((graph->grid.gridtype == GRID_LOGLOG) || (graph->grid.gridtype == GRID_XLOG)) { low = mylog10(graph->datawindow.xmin); high = mylog10(graph->datawindow.xmax); *fx = pow( (double) 10, (((double) x - graph->viewportxoff) / graph->viewport.width * (high - low) + low) ); } else { *fx = (x - graph->viewportxoff) * graph->aspectratiox + graph->datawindow.xmin; } if ((graph->grid.gridtype == GRID_LOGLOG) || (graph->grid.gridtype == GRID_YLOG)) { low = mylog10(graph->datawindow.ymin); high = mylog10(graph->datawindow.ymax); *fy = pow( (double) 10, (((double) (graph->absolute.height - y) - graph->viewportyoff) / graph->viewport.height * (high - low) + low) ); } else { *fy = ((graph->absolute.height - y) - graph->viewportyoff) * graph->aspectratioy + graph->datawindow.ymin; }}#endif /* HAS_X10 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -