From: Hermet Park Date: Sat, 23 May 2020 04:32:28 +0000 (+0900) Subject: common shape: introduce stroke cap and join styles. X-Git-Tag: accepted/tizen/unified/20200806.062539~141 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4799426396f16d29a21c1d4632caae32fa383d73;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git common shape: introduce stroke cap and join styles. + revise the getter functions for avoiding invalid overloading. Change-Id: Ie8b0cbe57435253d75871e864c7cd263a14d6df3 --- diff --git a/inc/tizenvg.h b/inc/tizenvg.h index dbdcd66..08c8556 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -53,7 +53,9 @@ protected: \ namespace tvg { -enum class TIZENVG_EXPORT PathCommand { Close, MoveTo, LineTo, CubicTo }; +enum class TIZENVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo }; +enum class TIZENVG_EXPORT StrokeCap { Square = 0, Round, Butt }; +enum class TIZENVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter }; class RenderMethod; class Scene; @@ -127,34 +129,44 @@ public: int reset() noexcept; + //Path int moveTo(float x, float y) noexcept; int lineTo(float x, float y) noexcept; int cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept; int close() noexcept; + //Shape int appendRect(float x, float y, float w, float h, float cornerRadius) noexcept; int appendCircle(float cx, float cy, float radiusW, float radiusH) noexcept; int appendPath(const PathCommand* cmds, size_t cmdCnt, const Point* pts, size_t ptsCnt) noexcept; + //Stroke int stroke(size_t width) noexcept; int stroke(size_t r, size_t g, size_t b, size_t a) noexcept; int stroke(const size_t* dashPattern, size_t cnt) noexcept; + int stroke(StrokeCap cap) noexcept; + int stroke(StrokeJoin join) noexcept; + //Fill int fill(size_t r, size_t g, size_t b, size_t a) noexcept; + //Transform int rotate(float degree) noexcept override; int scale(float factor) noexcept override; int translate(float x, float y) noexcept override; + //Getters size_t pathCommands(const PathCommand** cmds) const noexcept; size_t pathCoords(const Point** pts) const noexcept; int fill(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept; - size_t stroke() const noexcept; - int stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept; - size_t stroke(const size_t** dashPattern) const noexcept; - int bounds(float* x, float* y, float* w, float* h) const noexcept override; + size_t strokeWidth() const noexcept; + int strokeColor(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept; + size_t strokeDash(const size_t** dashPattern) const noexcept; + StrokeCap strokeCap() const noexcept; + StrokeJoin strokeJoin() const noexcept; + static std::unique_ptr gen() noexcept; _TIZENVG_DECLARE_ACCESSOR(Scene); diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index c8483e1..a17c53b 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -291,7 +291,7 @@ int Shape::stroke(size_t width) noexcept } -size_t Shape::stroke() const noexcept +size_t Shape::strokeWidth() const noexcept { auto impl = pImpl.get(); assert(impl); @@ -312,7 +312,7 @@ int Shape::stroke(size_t r, size_t g, size_t b, size_t a) noexcept } -int Shape::stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept +int Shape::strokeColor(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept { auto impl = pImpl.get(); assert(impl); @@ -341,18 +341,60 @@ int Shape::stroke(const size_t* dashPattern, size_t cnt) noexcept } -size_t Shape::stroke(const size_t** dashPattern) const noexcept +size_t Shape::strokeDash(const size_t** dashPattern) const noexcept { - assert(dashPattern); - auto impl = pImpl.get(); assert(impl); if (!impl->stroke) return 0; - *dashPattern = impl->stroke->dashPattern; + if (dashPattern) *dashPattern = impl->stroke->dashPattern; return impl->stroke->dashCnt; } +int Shape::stroke(StrokeCap cap) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->strokeCap(cap)) return -1; + + return 0; +} + + +int Shape::stroke(StrokeJoin join) noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->strokeJoin(join)) return -1; + + return 0; +} + + +StrokeCap Shape::strokeCap() const noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->stroke) return StrokeCap::Square; + + return impl->stroke->cap; +} + + +StrokeJoin Shape::strokeJoin() const noexcept +{ + auto impl = pImpl.get(); + assert(impl); + + if (!impl->stroke) return StrokeJoin::Bevel; + + return impl->stroke->join; +} + + #endif //_TVG_SHAPE_CPP_ diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 1800b70..682c29b 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -34,6 +34,8 @@ struct ShapeStroke size_t color[4] = {0, 0, 0, 0}; size_t* dashPattern = nullptr; size_t dashCnt = 0; + StrokeCap cap = StrokeCap::Square; + StrokeJoin join = StrokeJoin::Bevel; ~ShapeStroke() { @@ -164,6 +166,28 @@ struct Shape::Impl return 0; } + bool strokeCap(StrokeCap cap) + { + if (!stroke) stroke = new ShapeStroke(); + assert(stroke); + + stroke->cap = cap; + flag |= RenderUpdateFlag::Stroke; + + return 0; + } + + bool strokeJoin(StrokeJoin join) + { + if (!stroke) stroke = new ShapeStroke(); + assert(stroke); + + stroke->join = join; + flag |= RenderUpdateFlag::Stroke; + + return 0; + } + bool strokeColor(size_t r, size_t g, size_t b, size_t a) { if (!stroke) stroke = new ShapeStroke();