common shape: introduce stroke cap and join styles.

+ revise the getter functions for avoiding invalid overloading.

Change-Id: Ie8b0cbe57435253d75871e864c7cd263a14d6df3
This commit is contained in:
Hermet Park 2020-05-23 13:32:28 +09:00
parent a0521c83c3
commit 4799426396
3 changed files with 89 additions and 11 deletions

View file

@ -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<Shape> gen() noexcept;
_TIZENVG_DECLARE_ACCESSOR(Scene);

View file

@ -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_

View file

@ -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();