void GraphicWindow::line(double xfrom, double yfrom, double xto, double yto) { XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawLine(display, win, xgc, user_to_disp_x(xfrom), user_to_disp_y(yfrom), user_to_disp_x(xto), user_to_disp_y(yto)); XDrawLine(display, _ppm, xgc, user_to_disp_x(xfrom), user_to_disp_y(yfrom), user_to_disp_x(xto), user_to_disp_y(yto)); }
void GraphicWindow::text(string t, double x, double y) { int dx = user_to_disp_x(x); int dy = user_to_disp_y(y); for (int i = 0; i < t.length(); i++) set(dx + i, dy, t[i]); dirty = true; }
void GraphicWindow::point(double x, double y) { int cx = user_to_disp_x(x); int cy = user_to_disp_y(y); set(cx, cy); dirty = true; }
void GraphicWindow::line(double xfrom, double yfrom, double xto, double yto) { int x1 = user_to_disp_x(xfrom); int x2 = user_to_disp_x(xto); int y1 = user_to_disp_y(yfrom); int y2 = user_to_disp_y(yto); int dx = x2 - x1; int dy = y2 - y1; if (abs(dy) < abs(dx)) // |slope| < 1 { if (dx < 0) { int temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp; dx = -dx; dy = -dy; } double y = y1 + 0.5; for (int x = x1; x != x2; x++) { set(x, int(y)); y += double(dy) / double(dx); } } else { if (dy < 0) { int temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp; dx = -dx; dy = -dy; } double x = x1 + 0.5; for (int y = y1; y != y2; y++) { set(int(x), y); x += double(dx) / double(dy); } } set(x2, y2); dirty = true; }
void GraphicWindow::point(double x, double y) { const int POINT_RADIUS = 3; int disp_x = user_to_disp_x(x); int disp_y = user_to_disp_y(y); XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawArc(display, win, xgc, disp_x - POINT_RADIUS, disp_y - POINT_RADIUS, 2 * POINT_RADIUS, 2 * POINT_RADIUS, 0 , 360 * 64); XDrawArc(display, _ppm, xgc, disp_x - POINT_RADIUS, disp_y - POINT_RADIUS, 2 * POINT_RADIUS, 2 * POINT_RADIUS, 0 , 360 * 64); }
void GraphicWindow::text(const char t[], double x, double y) { int direction, ascent, descent; XCharStruct overall; XTextExtents(_fontinfo_ptr, t, strlen(t), &direction, &ascent, &descent, &overall); int disp_x = user_to_disp_x(x); int disp_y = user_to_disp_y(y) + ascent; XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawString(display, win, xgc, disp_x, disp_y, t, strlen(t)); XDrawString(display, _ppm, xgc, disp_x, disp_y, t, strlen(t)); }
void GraphicWindow::ellipse(double center_x, double center_y, double ra, double rb) { int cx = user_to_disp_x(center_x); int cy = user_to_disp_y(center_y); double a = fabs(user_to_disp_dx(ra)); double b = fabs(user_to_disp_dy(rb)); int x = 0; int y = (int)(b + 0.5); double d1 = b * b - a * a * b + a * a / 4; set4(x, y, cx, cy); while (a * a * (y - 0.5) > b * b * (x + 1)) { if (d1 < 0) { d1 += b * b * (2 * x + 3); x++; } else { d1 += b * b * (2 * x + 3) + a * a * (-2 * y + 2); x++; y--; } set4(x, y, cx, cy); } double d2 = b * b * (x + 0.5) * (x + 0.5) + a * a * (y - 1) * (y - 1) - a * a * b * b; while (y > 0) { if (d2 < 0) { d2 += b * b * (2 * x + 2) + a * a * (-2 * y + 3); x++; y--; } else { d2 += a * a * (-2 * y + 3); y--; } set4(x, y, cx, cy); } dirty = true; }
void GraphicWindow::ellipse(double x, double y, double ra, double rb) { int disp_x = user_to_disp_x(x); int disp_y = user_to_disp_y(y); int disp_rx = abs(user_to_disp_dx(ra)); int disp_ry = abs(user_to_disp_dy(rb)); XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawArc(display, win, xgc, // the drawable disp_x - disp_rx, // the x coord of upperleft corner of bounding rect disp_y - disp_ry, // the y coord of upperleft corner of bounding rect disp_rx * 2, // the major axis length disp_ry * 2, // the minor axis length 0, // offset from 3 o'clock 360 * 64); // complete circle (360 degrees * 64 clicks per degree) XDrawArc(display, _ppm, xgc, disp_x - disp_rx, disp_y - disp_ry, disp_rx * 2, disp_ry * 2, 0, 360 * 64); }