/* call higher gr_redraw routine */ static void redraw(Widget w, XtPointer client_data, XEvent *event, Boolean *continue_dispatch) { GRAPH *graph = (GRAPH *) client_data; XExposeEvent *pev = & event->xexpose; XEvent ev; XRectangle rects[30]; int n = 1; NG_IGNORE(w); NG_IGNORE(continue_dispatch); DEVDEP(graph).isopen = 1; rects[0].x = (Position) pev->x; rects[0].y = (Position) pev->y; rects[0].width = (Dimension) pev->width; rects[0].height = (Dimension) pev->height; /* XXX */ /* pull out all other expose regions that need to be redrawn */ while (n < 30 && XCheckWindowEvent(display, DEVDEP(graph).window, ExposureMask, &ev)) { pev = (XExposeEvent *) &ev; rects[n].x = (Position) pev->x; rects[n].y = (Position) pev->y; rects[n].width = (Dimension) pev->width; rects[n].height = (Dimension) pev->height; n++; } XSetClipRectangles(display, DEVDEP(graph).gc, 0, 0, rects, n, Unsorted); noclear = True; { GRAPH *tmp = currentgraph; currentgraph = graph; gr_redraw(graph); currentgraph = tmp; } noclear = False; XSetClipMask(display, DEVDEP(graph).gc, None); }
/* call higher gr_redraw routine */ void redraw(Widget w, caddr_t client_data, caddr_t call_data) { GRAPH *graph = (GRAPH *) client_data; XExposeEvent *pev = (XExposeEvent *) call_data; XEvent ev; XRectangle rects[30]; int n = 1; DEVDEP(graph).isopen = 1; rects[0].x = pev->x; rects[0].y = pev->y; rects[0].width = pev->width; rects[0].height = pev->height; /* XXX */ /* pull out all other expose regions that need to be redrawn */ while (n < 30 && XCheckWindowEvent(display, DEVDEP(graph).window, (long) ExposureMask, &ev)) { pev = (XExposeEvent *) &ev; rects[n].x = pev->x; rects[n].y = pev->y; rects[n].width = pev->width; rects[n].height = pev->height; n++; } XSetClipRectangles(display, DEVDEP(graph).gc, 0, 0, rects, n, Unsorted); noclear = True; gr_redraw(graph); noclear = False; XSetClipMask(display, DEVDEP(graph).gc, None); }
/* call this routine after viewport size changes */ void gr_resize(GRAPH *graph) { double oldxratio, oldyratio; double scalex, scaley; struct _keyed *k; oldxratio = graph->aspectratiox; oldyratio = graph->aspectratioy; graph->grid.xsized = 0; graph->grid.ysized = 0; gr_resize_internal(graph); /* scale keyed text */ scalex = oldxratio / graph->aspectratiox; scaley = oldyratio / graph->aspectratioy; for (k = graph->keyed; k; k = k->next) { k->x = (int)((k->x - graph->viewportxoff) * scalex + graph->viewportxoff); k->y = (int)((k->y - graph->viewportyoff) * scaley + graph->viewportyoff); } /* X also generates an expose after a resize. This is handled in X10 by not redrawing on resizes and waiting for the expose event to redraw. In X11, the expose routine tries to be clever and only redraws the region specified in an expose event, which does not cover the entire region of the plot if the resize was from a small window to a larger window. So in order to keep the clever X11 expose event handling, we have the X11 resize routine pull out expose events for that window, and we redraw on resize also. */ #ifdef X_DISPLAY_MISSING gr_redraw(graph); #endif }
static int iplot(struct plot *pl, int id) { int len = pl->pl_scale->v_length; struct dvec *v, *xs = pl->pl_scale; double *lims, dy; double start, stop, step; register int j; bool changed = FALSE; int yt; char *yl = NULL; double xlims[2], ylims[2]; static REQUEST reqst = { checkup_option, NULL }; int inited = 0; char commandline[513]; for (j = 0, v = pl->pl_dvecs; v; v = v->v_next) if (v->v_flags & VF_PLOT) j++; if (!j) return (0); if (ft_grdb) fprintf(cp_err, "Entering iplot, len = %d\n", len); if (len < IPOINTMIN) { /* Nothing yet */ return (0); } else if (len == IPOINTMIN || !id) { resumption = FALSE; /* Draw the grid for the first time, and plot everything. */ lims = ft_minmax(xs, TRUE); xlims[0] = lims[0]; xlims[1] = lims[1]; ylims[0] = HUGE; ylims[1] = - ylims[0]; for (v = pl->pl_dvecs; v; v = v->v_next) if (v->v_flags & VF_PLOT) { lims = ft_minmax(v, TRUE); if (ylims[0] > lims[0]) ylims[0] = lims[0]; if (ylims[1] < lims[1]) ylims[1] = lims[1]; if (!yl) yl = v->v_name; } /* generate a small difference between ymin and ymax to catch the y=const case */ if (ylims[0] == ylims[1]) ylims[1] += 1e-9; if (ft_grdb) fprintf(cp_err, "iplot: after 5, xlims = %G, %G, ylims = %G, %G\n", xlims[0], xlims[1], ylims[0], ylims[1]); for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v; v = v->v_next) if ((v->v_flags & VF_PLOT) && (v->v_type != yt)) { yt = SV_NOTYPE; break; } /* note: have command options for iplot to specify xdelta, etc. So don't need static variables hack. Assume default values for now. */ sprintf(commandline, "plot %s", yl); (void) gr_init(xlims, ylims, xs->v_name, pl->pl_title, NULL, j, 0.0, 0.0, GRID_LIN, PLOT_LIN, xs->v_name, yl, xs->v_type, yt, plot_cur->pl_typename, commandline); for (v = pl->pl_dvecs; v; v = v->v_next) if (v->v_flags & VF_PLOT) { gr_start_internal(v, FALSE); ft_graf(v, xs, TRUE); } inited = 1; } else { /* plot the last points and resize if needed */ Input(&reqst, NULL); /* First see if we have to make the screen bigger */ dy = (isreal(xs) ? xs->v_realdata[len - 1] : realpart(xs->v_compdata[len - 1])); if (ft_grdb) fprintf(cp_err, "x = %G\n", dy); if (!if_tranparams(ft_curckt, &start, &stop, &step) || !ciprefix("tran", pl->pl_typename)) { stop = HUGE; start = - stop; } /* checking for x lo */ while (dy < currentgraph->data.xmin) { changed = TRUE; if (ft_grdb) fprintf(cp_err, "resize: xlo %G -> %G\n", currentgraph->data.xmin, currentgraph->data.xmin - (currentgraph->data.xmax - currentgraph->data.xmin) * XFACTOR); /* set the new x lo value */ currentgraph->data.xmin -= (currentgraph->data.xmax - currentgraph->data.xmin) * XFACTOR; if (currentgraph->data.xmin < start) { currentgraph->data.xmin = start; break; } } if (currentgraph->data.xmax < currentgraph->data.xmin) currentgraph->data.xmax = currentgraph->data.xmin; /* checking for x hi */ while (dy > currentgraph->data.xmax) { changed = TRUE; if (ft_grdb) fprintf(cp_err, "resize: xhi %G -> %G\n", currentgraph->data.xmax, currentgraph->data.xmax + (currentgraph->data.xmax - currentgraph->data.xmin) * XFACTOR); /* set the new x hi value */ currentgraph->data.xmax += (currentgraph->data.xmax - currentgraph->data.xmin) * XFACTOR; if (currentgraph->data.xmax > stop) { currentgraph->data.xmax = stop; break; } } /* checking for all y values */ for (v = pl->pl_dvecs; v; v = v->v_next) { if (!(v->v_flags & VF_PLOT)) continue; dy = (isreal(v) ? v->v_realdata[len - 1] : realpart(v->v_compdata[len - 1])); if (ft_grdb) fprintf(cp_err, "y = %G\n", dy); /* checking for y lo */ while (dy < currentgraph->data.ymin) { changed = TRUE; if (ft_grdb) fprintf(cp_err, "resize: ylo %G -> %G\n", currentgraph->data.ymin, currentgraph->data.ymin - (currentgraph->data.ymax - currentgraph->data.ymin) * YFACTOR); /* set the new y lo value */ currentgraph->data.ymin -= (currentgraph->data.ymax - currentgraph->data.ymin) * YFACTOR; /* currentgraph->data.ymin += (dy - currentgraph->data.ymin) * YFACTOR;*/ /* currentgraph->data.ymin = dy; currentgraph->data.ymin *= (1 + YFACTOR); */ } if (currentgraph->data.ymax < currentgraph->data.ymin) currentgraph->data.ymax = currentgraph->data.ymin; /* checking for y hi */ while (dy > currentgraph->data.ymax) { changed = TRUE; if (ft_grdb) fprintf(cp_err, "resize: yhi %G -> %G\n", currentgraph->data.ymax, currentgraph->data.ymax + (currentgraph->data.ymax - currentgraph->data.ymin) * YFACTOR); /* set the new y hi value */ currentgraph->data.ymax += (currentgraph->data.ymax - currentgraph->data.ymin) * YFACTOR; /* currentgraph->data.ymax += (dy - currentgraph->data.ymax) * YFACTOR;*/ /* currentgraph->data.ymax = dy; currentgraph->data.ymax *= (1 + YFACTOR); */ } } if (changed) { /* Redraw everything. */ gr_pmsg("Resizing screen"); gr_resize(currentgraph); #ifndef X_DISPLAY_MISSING gr_redraw(currentgraph); #endif } else { /* Just connect the last two points. This won't be done * with curve interpolation, so it might look funny. */ for (v = pl->pl_dvecs; v; v = v->v_next) if (v->v_flags & VF_PLOT) { gr_point(v, (isreal(xs) ? xs->v_realdata[len - 1] : realpart(xs->v_compdata[len - 1])), (isreal(v) ? v->v_realdata[len - 1] : realpart(v->v_compdata[len - 1])), (isreal(xs) ? xs->v_realdata[len - 2] : realpart(xs->v_compdata[len - 2])), (isreal(v) ? v->v_realdata[len - 2] : realpart(v->v_compdata[len - 2])), len - 1); } } } DevUpdate(); return (inited); }