void Shape2D_Impl::add_rotated_curve(Path2D &path, const Pointf ¢er, const Angle &angle, Pointf point_1, Pointf point_2, Pointf point_3) { if (angle.to_radians() != 0.0f) { point_1.rotate(center, angle); point_2.rotate(center, angle); point_3.rotate(center, angle); } BezierCurve curve; curve.add_control_point(point_1); curve.add_control_point(point_2); curve.add_control_point(point_3); path.add_curve(curve); }
void Shape2D::add_rounded_line(const Pointf &start, const Pointf &end, float line_width, float cap_rounding, bool reverse) { float distance = start.distance(end); Sizef size(distance, line_width); Angle angle(start.angle_line(end)); Pointf center(start.x + size.width / 2.0f, start.y + size.height / 2.0f ); Vec2f rotated = start; rotated.rotate(center, angle); Vec2f origin( start.x + (start.x - rotated.x), start.y + (start.y - rotated.y)); rotated = Vec2f(0.0f, line_width/2.0f); rotated.rotate(Vec2f(), angle); origin.x -= rotated.x; origin.y -= rotated.y; add_rounded_rect(origin, size, cap_rounding, angle, reverse); }
//Draw to renderer void Sprite_Subimage::Draw(Renderer* renderer,const Pointf& point) { renderer->DrawTextureRegion(texturePage.get(),tex_x,tex_y,tex_width,tex_height,(int)point.X(),(int)point.Y(),width,height); }
void QTRenderer::SetClipRect(const Pointf& point, const Sizef& size) { painter->setClipRect(point.X(),point.Y(),size.W(),size.H()); }
void QTRenderer::DrawLine(const Pointf& p1, const Pointf& p2) { painter->drawLine((int)p1.X(),(int)p1.Y(),(int)p2.X(),(int)p2.Y()); }
void QTRenderer::DrawRectangle(const Pointf& point, const Sizef& size, const Color& outlineColor, float thickness) { QPen p(QColor(outlineColor.R(),outlineColor.G(),outlineColor.B(),outlineColor.A())); p.setWidth((int)thickness); painter->setPen(p); painter->drawRect(point.X(),point.Y(),size.W(),size.H()); }
void QTRenderer::DrawFilledRectangle(const Pointf& point, const Sizef& size, const Color& fillColor) { painter->fillRect(point.X(),point.Y(),size.W(),size.H(),QBrush(QColor(fillColor.R(),fillColor.G(),fillColor.B(),fillColor.A()))); }
void QTRenderer::Translate(const Pointf& point) { painter->translate(point.X(),point.Y()); }
void Canvas::fill_circle(const Pointf ¢er, const Pointf ¢ergradient, float radius, const Gradient &gradient) { float offset_x = 0; float offset_y = 0; float rotationcount = max(5.0f, (radius - 3.0f)); float halfpi = 1.5707963267948966192313216916398f; float turn = halfpi / rotationcount; if(center.distance(center + centergradient) < radius) { offset_x = centergradient.x; offset_y = -centergradient.y; } Vec4f colors[3] = { Vec4f(gradient.top_left.get_red(), gradient.top_left.get_green(), gradient.top_left.get_blue(), gradient.top_left.get_alpha()), Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha()), Vec4f(gradient.bottom_right.get_red(), gradient.bottom_right.get_green(), gradient.bottom_right.get_blue(), gradient.bottom_right.get_alpha()) }; Vec4f triangle_colors[4*3]; for (int i=0; i<3; i++) { triangle_colors[0*3+i] = colors[i]; triangle_colors[1*3+i] = colors[i]; triangle_colors[2*3+i] = colors[i]; triangle_colors[3*3+i] = colors[i]; } RenderBatchTriangle *batcher = impl->batcher.get_triangle_batcher(); for(float i = 0; i < rotationcount ; i++) { float pos1 = cos(i * turn); float pos2 = sin(i * turn); float pos3 = cos((i+1) * turn); float pos4 = sin((i+1) * turn); Vec2f positions[4*3] = { // 90 triangle: Vec2f(center.x + offset_x , center.y + offset_y), Vec2f(center.x + ((float)radius * pos1), center.y + ((float)radius * pos2)), Vec2f(center.x + ((float)radius * pos3), center.y + ((float)radius * pos4)), // 0 triangle: Vec2f(center.x + offset_x , center.y + offset_y), Vec2f(center.x + ((float)radius * pos2), center.y - ((float)radius * pos1)), Vec2f(center.x + ((float)radius * pos4), center.y - ((float)radius * pos3)), // 270 triangle: Vec2f(center.x + offset_x , center.y + offset_y), Vec2f(center.x - ((float)radius * pos1), center.y - ((float)radius * pos2)), Vec2f(center.x - ((float)radius * pos3), center.y - ((float)radius * pos4)), // 180 triangle: Vec2f(center.x + offset_x , center.y + offset_y), Vec2f(center.x - ((float)radius * pos2), center.y + ((float)radius * pos1)), Vec2f(center.x - ((float)radius * pos4), center.y + ((float)radius * pos3)) }; batcher->fill_triangle(*this, positions, triangle_colors, 4*3); } }