diff --git a/inc/tizenvg.h b/inc/tizenvg.h index 64c8ee47..e8974396 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -93,7 +93,7 @@ public: 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; diff --git a/src/lib/tvgShapeNode.cpp b/src/lib/tvgShapeNode.cpp index 6ee0b7ae..a6e45114 100644 --- a/src/lib/tvgShapeNode.cpp +++ b/src/lib/tvgShapeNode.cpp @@ -135,19 +135,20 @@ int ShapeNode::pathCoords(const Point** pts) const 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; @@ -173,7 +174,7 @@ int ShapeNode::appendRect(float x, float y, float w, float h, float cornerRadius 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); diff --git a/test/testMultipleShapes.cpp b/test/testMultipleShapes.cpp index f1bdfe84..a73d2b6d 100644 --- a/test/testMultipleShapes.cpp +++ b/test/testMultipleShapes.cpp @@ -17,7 +17,7 @@ void tvgtest() 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 @@ -25,10 +25,16 @@ void tvgtest() //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();