int clear() noexcept;
int appendRect(float x, float y, float w, float h, float cornerRadius) noexcept;
- int appendCircle(float cx, float cy, float radius) noexcept;
+ int appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept;
int fill(size_t r, size_t g, size_t b, size_t a) noexcept;
}
-int ShapeNode::appendCircle(float cx, float cy, float radius) noexcept
+int ShapeNode::appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept
{
auto impl = pImpl.get();
assert(impl);
- auto halfKappa = radius * PATH_KAPPA;
+ auto halfKappaW = radiusW * PATH_KAPPA;
+ auto halfKappaH = radiusH * PATH_KAPPA;
impl->path->reserve(6, 13);
- impl->path->moveTo(cx, cy - radius);
- impl->path->cubicTo(cx + halfKappa, cy - radius, cx + radius, cy - halfKappa, cx + radius, cy);
- impl->path->cubicTo(cx + radius, cy + halfKappa, cx + halfKappa, cy + radius, cx, cy + radius);
- impl->path->cubicTo(cx - halfKappa, cy + radius, cx - radius, cy + halfKappa, cx - radius, cy);
- impl->path->cubicTo(cx - radius, cy - halfKappa, cx - halfKappa, cy - radius, cx, cy - radius);
+ impl->path->moveTo(cx, cy - radiusH);
+ impl->path->cubicTo(cx + halfKappaW, cy - radiusH, cx + radiusW, cy - halfKappaH, cx + radiusW, cy);
+ impl->path->cubicTo(cx + radiusW, cy + halfKappaH, cx + halfKappaW, cy + radiusH, cx, cy + radiusH);
+ impl->path->cubicTo(cx - halfKappaW, cy + radiusH, cx - radiusW, cy + halfKappaH, cx - radiusW, cy);
+ impl->path->cubicTo(cx - radiusW, cy - halfKappaH, cx - halfKappaW, cy - radiusH, cx, cy - radiusH);
impl->path->close();
return 0;
impl->path->close();
//circle
} else if (w == h && cornerRadius * 2 == w) {
- return appendCircle(x + (w * 0.5f), y + (h * 0.5f), cornerRadius);
+ return appendCircle(x + (w * 0.5f), y + (h * 0.5f), cornerRadius, cornerRadius);
} else {
auto halfKappa = cornerRadius * 0.5;
impl->path->reserve(10, 17);
auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
//canvas->reserve(2); //reserve 2 shape nodes (optional)
- //Prepare Rectangle
+ //Prepare Round Rectangle
auto shape1 = tvg::ShapeNode::gen();
shape1->appendRect(0, 0, 400, 400, 50); //x, y, w, h, cornerRadius
shape1->fill(0, 255, 0, 255); //r, g, b, a
//Prepare Circle
auto shape2 = tvg::ShapeNode::gen();
- shape2->appendCircle(400, 400, 200); //cx, cy, radius
+ shape2->appendCircle(400, 400, 200, 200); //cx, cy, radiusW, radiusH
shape2->fill(255, 255, 0, 255); //r, g, b, a
canvas->push(move(shape2));
+ //Prepare Ellipse
+ auto shape3 = tvg::ShapeNode::gen();
+ shape3->appendCircle(600, 600, 150, 100); //cx, cy, radiusW, radiusH
+ shape3->fill(0, 255, 255, 255); //r, g, b, a
+ canvas->push(move(shape3));
+
//Draw the Shapes onto the Canvas
canvas->draw();
canvas->sync();