📄 tkplot.c
字号:
bbox[0].y = eventPtr->xbutton.y; break; default: break; }*/}static voidPlotDisplay(ClientData clientData){ TkPlot *plotPtr = (TkPlot *) clientData; Tk_Window tkwin = plotPtr->tkwin; if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* make sure the plot widget still exists and is mapped */ plotPtr->flags &= ~(REDRAW_PENDING); /* copy the pixmap to the screen */ if (plotPtr->pixmap != None) { XCopyArea(plotPtr->display, plotPtr->pixmap, Tk_WindowId(tkwin), plotPtr->pixmapGC, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, 0); }}static voidPlotDestroy(ClientData clientData){ register TkPlot *plotPtr = (TkPlot *) clientData; if (plotPtr->pixmapGC != None) { Tk_FreeGC(plotPtr->display, plotPtr->pixmapGC); } if (plotPtr->plotGC != None) { XFreeGC(plotPtr->display, plotPtr->plotGC); } if (plotPtr->pixmap != None) { Tk_FreePixmap(plotPtr->display, plotPtr->pixmap); } if (plotPtr->flags & REDRAW_PENDING) { Tk_CancelIdleCall(PlotDisplay, (ClientData) plotPtr); } Tk_FreeOptions(configSpecs, (char *) plotPtr, plotPtr->display, 0); ckfree((char *) plotPtr);}voidTk_PlotClear(TkPlot * plotPtr){ Tk_Window tkwin = plotPtr->tkwin; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) { build_pixmap(plotPtr); } else { /* otherwise clear the pixmap */ XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, Tk_3DBorderColor(plotPtr->bgBorder)->pixel); XFillRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin)); } /* set up a redisplay event */ if (plotPtr->tkwin && !(plotPtr->flags & REDRAW_PENDING)) { Tk_DoWhenIdle(PlotDisplay, (ClientData) plotPtr); plotPtr->flags |= REDRAW_PENDING; }}voidTk_PlotQueueRefresh(TkPlot * plotPtr){ /* set up a redisplay event */ if (plotPtr->tkwin && !(plotPtr->flags & REDRAW_PENDING)) { Tk_DoWhenIdle(PlotDisplay, (ClientData) plotPtr); plotPtr->flags |= REDRAW_PENDING; }}voidTk_PlotRubberBox(plotPtr, x, y, w, h) TkPlot *plotPtr; int x; int y; int w; int h;{ Tk_Window tkwin = plotPtr->tkwin; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) build_pixmap(plotPtr); /* * set the "best" foreground color for the rubber box * set the xor function to "erase" the box when it's drawn twice * draw the rectangle */ XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[3]->pixel); XSetFunction(Tk_Display(tkwin), plotPtr->plotGC, GXxor); XDrawRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x, y, w, h); XDrawRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x, y, w, h); /* reset the GC to copy drawing */ XSetFunction(Tk_Display(tkwin), plotPtr->plotGC, GXcopy);}voidbuild_pixmap(TkPlot * plotPtr){ Tk_Window tkwin = plotPtr->tkwin; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* if one is already built, destroy and rebuild */ if (plotPtr->pixmap != None) { Tk_FreePixmap(plotPtr->display, plotPtr->pixmap); } plotPtr->pixmap = Tk_GetPixmap(plotPtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, Tk_3DBorderColor(plotPtr->bgBorder)->pixel); XFillRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin));}voidTk_PlotString(plotPtr, x, y, color, pstr, psize) TkPlot *plotPtr; int x; int y; int color; char *pstr; unsigned int psize;{ Tk_Window tkwin = plotPtr->tkwin; int s, len = strlen(pstr); /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) build_pixmap(plotPtr); /* make sure it is in valid range! */ color = color % NCOLORS; XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[color]->pixel); psize++; s = psize / 2; XDrawString(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x + s, y + s, pstr, len); XDrawString(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x + s, y + s, pstr, len);}voidTk_PlotSymbol(plotPtr, x, y, color, psymbol, psize) TkPlot *plotPtr; int x; int y; int color; int psymbol; unsigned int psize;{ Tk_Window tkwin = plotPtr->tkwin; int i, u, v, s; XPoint tri[4]; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) build_pixmap(plotPtr); /* make sure it is in valid range! */ color = color % NCOLORS; XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[color]->pixel); /* * plot the specified symbol */ switch (psymbol) { case POINT: psize++; s = psize / 2; XFillRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x - s, y - s, psize, psize); XFillRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - s, y - s, psize, psize); break; case CROSS: s = psize + 1; psize = 2 * s; XFillRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x - s, y - 3 * s, psize, 3 * psize); XFillRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x - 3 * s, y - s, 3 * psize, psize); XFillRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - s, y - 3 * s, psize, 3 * psize); XFillRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - 3 * s, y - s, 3 * psize, psize); break; case BOX: s = psize + 2; XDrawRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x - s, y - s, 2 * s, 2 * s); XDrawRectangle(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - s, y - s, 2 * s, 2 * s); break; case TRIANGLE: s = psize + 2; tri[0].x = x; tri[0].y = y - s; tri[1].x = x - s; tri[1].y = y + s; tri[2].x = x + s; tri[2].y = y + s; tri[3].x = x; tri[3].y = y - s; XDrawLines(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, tri, 4, CoordModeOrigin); XDrawLines(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, tri, 4, CoordModeOrigin); break; case CROSSHAIR: /* draw on window *//* XDrawLine(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x-psize,y,x+psize,y); XDrawLine(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x,y-psize,x,y+psize); */ /* and on pixmap */ XDrawLine(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - psize, y, x + psize, y); XDrawLine(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x, y - psize, x, y + psize); break; case CIRCLE: s = psize * 2; /* draw on window *//* XDrawArc(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x-psize,y-psize, s, s, 0, 360*64); */ /* and on pixmap */ XDrawArc(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - psize, y - psize, s, s, 0, 360 * 64); break; case DISK: s = psize * 2; /* draw on window *//* XFillArc(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, x-psize,y-psize, s, s, 0, 360*64); */ /* and on pixmap */ XFillArc(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, x - psize, y - psize, s, s, 0, 360 * 64); break; case TEST_SYMBOL: for (i = 0; i < 5000; i = i + 1) { u = (int) (i * sin(i / 10.0) / 50.0) + x; v = (int) (i * cos(i / 10.0) / 50.0) + y; XDrawPoint(Tk_Display(tkwin), Tk_WindowId(tkwin), plotPtr->plotGC, u, v); XDrawPoint(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, u, v); } break; default: break; }}voidTk_PlotGrid(TkPlot * plotPtr, grid * g, int *color, int max_color){ unsigned int i, j; int ci; int *data = g->data; Tk_Window tkwin = plotPtr->tkwin; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) build_pixmap(plotPtr); for (i = 0; i < g->height; i++) { for (j = 0; j < g->width; j++) { ci = *(data++); if (ci > max_color) ci = max_color; XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[color[*(data++)]]->pixel); XDrawPoint(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, j, i); } }}voidTk_PlotGridForeground(TkPlot * plotPtr, grid * g, unsigned char *foreground, int *color, int foreground_color){ unsigned int i, j; int ci; int *data = g->data; Tk_Window tkwin = plotPtr->tkwin; /* check if mapped! */ if (!tkwin) return; if (!Tk_IsMapped(tkwin)) return; /* build pixmap if necessary */ if (plotPtr->pixmap == None) build_pixmap(plotPtr); for (i = 0; i < g->height; i++) { for (j = 0; j < g->width; j++) { if (*(foreground++) > 0) { XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[color[foreground_color]]->pixel); } else { ci = *data; if (ci >= foreground_color) ci = foreground_color - 1; XSetForeground(Tk_Display(tkwin), plotPtr->plotGC, colormap[color[ci]]->pixel); } data++; XDrawPoint(Tk_Display(tkwin), plotPtr->pixmap, plotPtr->plotGC, j, i); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -