void circle(const Point& center, int radius, const Color& color, bool filled) { if (filled) gdImageFilledEllipse(im_, center.x, center.y, radius*2, radius*2, color2gd(color)); else gdImageArc(im_, center.x, center.y, radius*2, radius*2, 0, 360, color2gd(color)); }
void rectangle(const Point& point1, const Point& point2, const Color& color, bool filled) { if (filled) gdImageFilledRectangle(im_, point1.x, point1.y, point2.x, point2.y, color2gd(color)); else gdImageRectangle(im_, point1.x, point1.y, point2.x, point2.y, color2gd(color)); }
void pixel(const Point& point, const Color& color) { if (scaled_) // might actually need more than one pixel { // gd rectangle is inclusive, so find scaled pixel just outside and back off Point p1(SCALEX(point.x),SCALEY(point.y)); Point p2(SCALEX(point.x+1),SCALEY(point.y+1)); // far edge of rectangle of 1x1 logical pixels if (p2.x > p1.x) p2.x--; if (p2.y > p1.y) p2.y--; gdImageFilledRectangle(im_,p1.x,p1.y,p2.x,p2.y,color2gd(color)); } else gdImageSetPixel(im_, point.x, point.y, color2gd(color)); }
void string(const std::string& text, const Point& point, const Color& color, Size size, int align) { // copy text into gd-friendly (unsigned char) buffer vector<unsigned char> buffer; copy(text.begin(), text.end(), back_inserter(buffer)); buffer.push_back('\0'); // choose font gdFontPtr font; switch (size) { case Tiny: font = gdFontGetTiny(); break; case Small: font = gdFontGetSmall(); break; case MediumBold: font = gdFontGetMediumBold(); break; case Large: font = gdFontGetLarge(); break; case Giant: font = gdFontGetGiant(); break; default: throw runtime_error("[ImageImpl::string()] This isn't happening."); } // calculate position Point position = point; int length = (int)text.size() * font->w; int height = font->h; if (align & CenterX) position.x -= length/2; else if (align & Right) position.x -= length; if (align & CenterY) position.y -= height/2; else if (align & Bottom) position.y -= height; // draw the string gdImageString(im_, font, position.x, position.y, &buffer[0], color2gd(color)); }
void line(const Point& point1, const Point& point2, const Color& color) { gdImageLine(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color)); }
void circle(const Point& center, int radius, const Color& color, bool filled) { if (filled) gdImageFilledEllipse(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), color2gd(color)); else gdImageArc(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), 0, 360, color2gd(color)); }
void line(const Point& point1, const Point& point2, const Color& color) { gdImageLine(im_, point1.x, point1.y, point2.x, point2.y, color2gd(color)); }
void pixel(const Point& point, const Color& color) { gdImageSetPixel(im_, point.x, point.y, color2gd(color)); }