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;
+ 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 fill(size_t r, size_t g, size_t b, size_t a) noexcept;
int rotate(float degree) noexcept override;
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;
static std::unique_ptr<Shape> gen() noexcept;
size_t w, h;
};
-enum RenderUpdateFlag {None = 0, Path = 1, Fill = 2, Transform = 4, All = 8};
+enum RenderUpdateFlag {None = 0, Path = 1, Fill = 2, Stroke = 4, Transform = 8, All = 16};
struct RenderTransform
{
}
+int Shape::stroke(size_t width) noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->strokeWidth(width)) return -1;
+
+ return 0;
+}
+
+
+size_t Shape::stroke() const noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->stroke) return -1;
+ return impl->stroke->width;
+}
+
+
+int Shape::stroke(size_t r, size_t g, size_t b, size_t a) noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->strokeColor(r, g, b, a)) return -1;
+
+ return 0;
+}
+
+
+int Shape::stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept
+{
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->stroke) return -1;
+
+ if (r) *r = impl->stroke->color[0];
+ if (g) *g = impl->stroke->color[1];
+ if (b) *b = impl->stroke->color[2];
+ if (a) *a = impl->stroke->color[3];
+
+ return 0;
+}
+
+
+int Shape::stroke(const size_t* dashPattern, size_t cnt) noexcept
+{
+ if (cnt < 2 || !dashPattern) return -1;
+
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->strokeDash(dashPattern, cnt)) return -1;
+
+ return 0;
+}
+
+
+size_t Shape::stroke(const size_t** dashPattern) const noexcept
+{
+ assert(dashPattern);
+
+ auto impl = pImpl.get();
+ assert(impl);
+
+ if (!impl->stroke) return 0;
+
+ *dashPattern = impl->stroke->dashPattern;
+ return impl->stroke->dashCnt;
+}
+
+
#endif //_TVG_SHAPE_CPP_
struct ShapeStroke
{
+ size_t width = 0;
+ size_t color[4] = {0, 0, 0, 0};
+ size_t* dashPattern = nullptr;
+ size_t dashCnt = 0;
+
+ ~ShapeStroke()
+ {
+ if (dashPattern) free(dashPattern);
+ }
};
return 0;
}
+
+ bool strokeWidth(size_t width)
+ {
+ //TODO: Size Exception?
+
+ if (!stroke) stroke = new ShapeStroke();
+ assert(stroke);
+
+ stroke->width = width;
+ flag |= RenderUpdateFlag::Stroke;
+
+ return 0;
+ }
+
+ bool strokeColor(size_t r, size_t g, size_t b, size_t a)
+ {
+ if (!stroke) stroke = new ShapeStroke();
+ assert(stroke);
+
+ stroke->color[0] = r;
+ stroke->color[1] = g;
+ stroke->color[2] = b;
+ stroke->color[3] = a;
+
+ flag |= RenderUpdateFlag::Stroke;
+
+ return 0;
+ }
+
+ bool strokeDash(const size_t* pattern, size_t cnt)
+ {
+ assert(pattern);
+
+ if (!stroke) stroke = new ShapeStroke();
+ assert(stroke);
+
+ if (stroke->dashCnt != cnt) {
+ if (stroke->dashPattern) free(stroke->dashPattern);
+ stroke->dashPattern = nullptr;
+ }
+
+ if (!stroke->dashPattern) stroke->dashPattern = static_cast<size_t*>(malloc(sizeof(size_t) * cnt));
+ assert(stroke->dashPattern);
+
+ memcpy(stroke->dashPattern, pattern, cnt);
+ stroke->dashCnt = cnt;
+
+ flag |= RenderUpdateFlag::Stroke;
+
+ return 0;
+
+ }
};
#endif //_TVG_SHAPE_IMPL_H_
\ No newline at end of file