void CXTPTaskPanelGroup::OnAnimate(int nStep) { if (nStep < 1) { m_rcGroupCurrent = m_rcGroupTarget; } else { MOVETO(m_rcGroupCurrent.top, m_rcGroupTarget.top, nStep); MOVETO(m_rcGroupCurrent.bottom, m_rcGroupTarget.bottom, nStep); } if (!IsDirty() && m_bExpanding) { m_bExpanding = FALSE; m_pPanel->NotifyOwner(XTP_TPN_GROUPEXPANDED, (LPARAM)this); } for (int i = 0; i < GetItemCount(); i++) { CXTPTaskPanelGroupItem* pItem = GetAt(i); pItem->OnAnimate(nStep); } }
void CXTPPopupControl::Animate(int nStep) { // if step == 0 set current state to target state if (nStep < 1) { m_stateCurrent = m_stateTarget; } else { //move MOVETO(m_stateCurrent.rcPopup.top, m_stateTarget.rcPopup.top, nStep); MOVETO(m_stateCurrent.rcPopup.left, m_stateTarget.rcPopup.left, nStep); MOVETO(m_stateCurrent.rcPopup.right, m_stateTarget.rcPopup.right, nStep); MOVETO(m_stateCurrent.rcPopup.bottom, m_stateTarget.rcPopup.bottom, nStep); MOVETO(m_stateCurrent.nTransparency, m_stateTarget.nTransparency, nStep); } //update view state UpdateState(); }
/* Draws box around plot and plot labels */ static void write_box(FILE * out) { fprintf(out, "newpath\n"); MOVETO(x_low, y_low); LINETO(x_high, y_low); LINETO(x_high, y_high); LINETO(x_low, y_high); fprintf(out, "closepath\n"); fprintf(out, "0 setgray\n"); fprintf(out, "1 setlinewidth\n"); fprintf(out, "stroke\n\n"); fprintf(out, "/Helvetica findfont\n"); fprintf(out, "12 scalefont setfont\n"); write_axis_units(out, 0); write_axis_units(out, 1); }
void mf_hp2627_paintrow (screenrow row, pixelcolor init_color, transspec transition_vector, screencol vector_size) { register color; char outbuf[512*6]; /* enough to hold an alternate color */ /* in each column */ register char *op; register x, y, oldx, oldy; int currentformat; color = (init_color == 0)? 0 : 1; /* * We put all escape sequences in a buffer so the write * has a chance of being atomic, and not interrupted by * other independent output to our TTY. Also to avoid * (literally millions) of stdio calls. */ op = outbuf; /* * Select current pen to be the color of the first segment: * * our strategy here is to paint a long line from the first * transition_vector value (left edge of row) to the last * transition_vector entry (right edge of row). Then we switch * colors to the contrasting color, and paint alternate * segments with that color. Would that the HP2627 would provide * a mode to paint the "background" color while the PEN is lifted. * However, this is faster than using rectangular area fills. */ *op++ = '\033'; *op++ = '*'; *op++ = 'm'; *op++ = mf_hp2627_pencolors[color]; *op++ = 'X'; /* * Reset our "remembered" state for (X,Y) positioning and plot * command format */ oldx = oldy = -999; currentformat = ASCIILABS; /* * Now, paint across the entire width of this row, make it the * initial segment color. */ x = *transition_vector; y = HP2627_MAXY-row; *op++ = '\033'; *op++ = '*'; *op++ = 'p'; MOVETO(x,y,1); x = transition_vector[vector_size]; MOVETO(x,y,0); *op++ = 'Z'; /* * If there remain other segments (of contrasting color) to paint, * switch pens colors and draw them */ if (--vector_size > 0) { *op++ = '\033'; *op++ = '*'; *op++ = 'm'; *op++ = mf_hp2627_pencolors[1-color]; *op++ = 'X'; color = 1-color; oldx = oldy = -999; currentformat = ASCIILABS; *op++ = '\033'; *op++ = '*'; *op++ = 'p'; x = *++transition_vector; MOVETO(x,y,1); while (vector_size-- > 0) { x = *++transition_vector; MOVETO(x,y,(color==init_color)); color = 1 - color; }; *op++ = 'Z'; }; /* * Write the resulting plot commands, hopefully atomically */ (void) write(fileno(stdout), outbuf, op-outbuf); }
/* write description of axis, can be used for both horizontal * and vertical axis as specified by 'horizontal' flag */ static void write_axis_units(FILE * out, int horizontal) { double size; double axis_scale; double power; double unit_size; double unit_position; int print_precision = 0; /* x axis */ if (horizontal) size = x_high - x_low; /* y axis */ else size = y_high - y_low; /* Find scale of corresponding axis such that there will be no more than * MAX_UNITS labels. */ power = ceil(log10(size / (MAX_UNITS - 1)) - 1); /* try all three allowed subdivisions (1, 2, 5) */ if (size / (2 * pow(10, power)) < (MAX_UNITS - 1)) axis_scale = 2; else if (size / (5 * pow(10, power)) < (MAX_UNITS - 1)) axis_scale = 5; else { axis_scale = 1; power++; } /* find distance between two consecutive labels */ unit_size = axis_scale * pow(10, power); /* find position of first label */ if (horizontal) { unit_position = x_low - fmod(x_low, unit_size); if (x_low > 0) unit_position += unit_size; } else { unit_position = y_low - fmod(y_low, unit_size); if (y_low > 0) unit_position += unit_size; } /* Only print this many digits. There is no need for labels to have * more digits printed than necessary. Eg. we want 1.05, not 1.05000 */ if (power < 0) print_precision = -(int) power; fprintf(out, "newpath\n"); /* branch on x or y axis */ if (horizontal) { do { MOVETO(unit_position, y_low); fprintf(out, "%d %d rlineto\n", LINE_LEN, 0); fprintf(out, "%d %d rmoveto\n", 2 * LINE_LEN, 0); fprintf(out, "90 rotate\n"); fprintf(out, "(%.*f) show\n", print_precision, unit_position); fprintf(out, "-90 rotate\n"); unit_position += unit_size; } while (unit_position <= x_high); /* case of vertical axis, rotate more */ } else { do { MOVETO(x_low, unit_position); fprintf(out, "%d %d rlineto\n", 0, -LINE_LEN); fprintf(out, "%d %d rmoveto\n", 0, -2 * LINE_LEN); fprintf(out, "180 rotate\n"); fprintf(out, "(%.*f) show\n", print_precision, unit_position); fprintf(out, "-180 rotate\n"); unit_position += unit_size; } while (unit_position <= y_high); } /* stroke all plot labels */ fprintf(out, "0 setgray\n"); fprintf(out, "0.4 setlinewidth\n"); fprintf(out, "stroke\n\n"); }
/* Plotting procedure. * X-axis is segmented according to 'delta' distance, that is distance between * consecutive x's (x_i to x_{i + 1} distance). Infinity and NaN checks are * performed and corresponding action is taken to prevent mess. * Infinity case is handled by computing intersect with plot-box. NaNs * are not plotted at all. * Adaptive smoothing is performed at the end of plot loop. */ static void plot(FILE * out, parsed_expr p) { double delta = (x_high - x_low) / SMOOTHNESS; double x_1 = x_low; double x_2 = x_low + delta; double y_1 = evaluate(p, x_1); double y_2 = evaluate(p, x_2); double old_x; double old_y; /* if y-value out of box, compute intersection of line with box */ double x_intersect; int last_out = 1, last_nan = 0; int SMOOTHNESS_LVL = MAX_SMOOTHNESS_LVL; /* Transformation of real number coordinates to plot box coordinates. * Plot is in lanscape mode, real x-coordinates are mappend to plot * y-coordinate and vice versa. * Plot y-coordinates are flipped vertically */ #define COORD_X(x) (((x) - x_low) * scale_x + LLY + BLANK) #define COORD_Y(y) (URX - BLANK - (((y) - y_low) * scale_y)) /* Redefine postscript lineto and moveto commands, such that there is * no need to take care of coordinate transformations. * x and y coordinates are swapped here. */ #define LINETO(x, y) fprintf(out, "%.3f %.3f lineto\n", \ COORD_Y(y), COORD_X(x)) #define MOVETO(x, y) fprintf(out, "%.3f %.3f moveto\n", \ COORD_Y(y), COORD_X(x)) /* find intersection with y-boundary */ #define INTERSECT(boundary) (x_1 + ((boundary) - y_1) * \ (x_2 - x_1) / (y_2 - y_1)); if (y_1 < y_low) y_1 = y_low; else if (y_1 > y_high) y_1 = y_high; else last_out = 0; /* New path exclusively for function plot */ fprintf(out, "newpath\n"); if (!IS_NAN(y_1)) MOVETO(x_1, y_1); else last_nan = 1; old_x = x_1; old_y = y_1; /* plotting loop */ while (x_2 <= x_high) { if (IS_NAN(y_2)) last_nan = 1; /* next point is in bounding box, thus can be plotted */ else if (y_low <= y_2 && y_2 <= y_high) { /* handle case where last point was NaN */ if (last_nan) { MOVETO(x_2, y_2); last_nan = 0; /* handle case where last point was out of box, * find intersections with box. Next line will start * from this point */ } else if (last_out) { /* point is too high or too low? */ if (y_2 > y_1) { x_intersect = INTERSECT(y_low); if (IS_NAN(x_intersect)) x_intersect = x_1; MOVETO(x_intersect, y_low); } else { x_intersect = INTERSECT(y_high); if (IS_NAN(x_intersect)) x_intersect = x_1; MOVETO(x_intersect, y_high); } } /* Draw a valid line. This plots most of the lines. */ LINETO(x_2, y_2); last_out = 0; /* case where next point is out of the box */ } else { /* if last point was in the box, stroke a line to the intersection * with y-boundary */ if (!last_out && !last_nan) { if (y_2 > y_1) { x_intersect = INTERSECT(y_high); if (IS_NAN(x_intersect)) x_intersect = x_1; LINETO(x_intersect, y_high); } else { x_intersect = INTERSECT(y_low); if (IS_NAN(x_intersect)) x_intersect = x_1; LINETO(x_intersect, y_low); } } last_out = 1; } /** smoothing procedure **/ /* SLOPE_JUMP is numerically evaluated second derivative, that is * difference of first derivatives. Expression is simplified algebraically */ #define SLOPE_JUMP (y_2 - y_1 - ((y_1 - old_y)*(x_2 - x_1))/(x_1 - old_x)) #define TOO_SHARP() (fabs(SLOPE_JUMP) > THRESHOLD) #define TOO_SMOOTH() (fabs(SLOPE_JUMP) < THRESHOLD / 4) old_x = x_1; old_y = y_1; x_1 = x_2; y_1 = y_2; x_2 = x_1 + delta; y_2 = evaluate(p, x_2); /* If the plot is too sharp or too smooth, * find appropriate smoothness lvl * by increasing/decreasing smoothness until right one is found. */ if (TOO_SHARP()) { while (SMOOTHNESS_LVL < MAX_SMOOTHNESS_LVL && TOO_SHARP()) { delta /= 2; x_2 = x_1 + delta; y_2 = evaluate(p, x_2); SMOOTHNESS_LVL++; } } else { while (SMOOTHNESS_LVL > 0 && TOO_SMOOTH()) { delta *= 2; x_2 = x_1 + delta; y_2 = evaluate(p, x_2); SMOOTHNESS_LVL--; } } /* make sure the last point is on the right boundary */ if (x_1 < x_high && x_1 + delta > x_high) { x_2 = x_high; y_2 = evaluate(p, x_2); } } /* stroke the path */ fprintf(out, "%s setrgbcolor\n", PLOT_COLOR); fprintf(out, "0.5 setlinewidth\n"); fprintf(out, "stroke\n\n\n"); }