/* External Class Implementation */
/************************************************************************/
-Shape :: Shape() : pImpl(make_unique<Impl>(this))
+Shape :: Shape() : pImpl(new Impl(this))
{
- Paint::IMPL->method(new PaintMethod<Shape::Impl>(IMPL));
+ Paint::pImpl->method(new PaintMethod<Shape::Impl>(pImpl));
}
Shape :: ~Shape()
{
+ delete(pImpl);
}
Result Shape::reset() noexcept
{
- IMPL->path->reset();
+ pImpl->path->reset();
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
{
if (!cmds) return 0;
- *cmds = IMPL->path->cmds;
+ *cmds = pImpl->path->cmds;
- return IMPL->path->cmdCnt;
+ return pImpl->path->cmdCnt;
}
{
if (!pts) return 0;
- *pts = IMPL->path->pts;
+ *pts = pImpl->path->pts;
- return IMPL->path->ptsCnt;
+ return pImpl->path->ptsCnt;
}
{
if (cmdCnt == 0 || ptsCnt == 0 || !pts || !ptsCnt) return Result::InvalidArguments;
- IMPL->path->grow(cmdCnt, ptsCnt);
- IMPL->path->append(cmds, cmdCnt, pts, ptsCnt);
+ pImpl->path->grow(cmdCnt, ptsCnt);
+ pImpl->path->append(cmds, cmdCnt, pts, ptsCnt);
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::moveTo(float x, float y) noexcept
{
- IMPL->path->moveTo(x, y);
+ pImpl->path->moveTo(x, y);
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::lineTo(float x, float y) noexcept
{
- IMPL->path->lineTo(x, y);
+ pImpl->path->lineTo(x, y);
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept
{
- IMPL->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
+ pImpl->path->cubicTo(cx1, cy1, cx2, cy2, x, y);
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::close() noexcept
{
- IMPL->path->close();
+ pImpl->path->close();
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
{
- auto impl = pImpl.get();
-
auto rxKappa = rx * PATH_KAPPA;
auto ryKappa = ry * PATH_KAPPA;
- impl->path->grow(6, 13);
- impl->path->moveTo(cx, cy - ry);
- impl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy);
- impl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry);
- impl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy);
- impl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry);
- impl->path->close();
+ pImpl->path->grow(6, 13);
+ pImpl->path->moveTo(cx, cy - ry);
+ pImpl->path->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy);
+ pImpl->path->cubicTo(cx + rx, cy + ryKappa, cx + rxKappa, cy + ry, cx, cy + ry);
+ pImpl->path->cubicTo(cx - rxKappa, cy + ry, cx - rx, cy + ryKappa, cx - rx, cy);
+ pImpl->path->cubicTo(cx - rx, cy - ryKappa, cx - rxKappa, cy - ry, cx, cy - ry);
+ pImpl->path->close();
- impl->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
//just circle
if (sweep >= 360) return appendCircle(cx, cy, radius, radius);
- auto impl = pImpl.get();
-
startAngle = (startAngle * M_PI) / 180;
sweep = sweep * M_PI / 180;
Point start = {radius * cos(startAngle), radius * sin(startAngle)};
if (pie) {
- impl->path->moveTo(cx, cy);
- impl->path->lineTo(start.x + cx, start.y + cy);
+ pImpl->path->moveTo(cx, cy);
+ pImpl->path->lineTo(start.x + cx, start.y + cy);
}else {
- impl->path->moveTo(start.x + cx, start.y + cy);
+ pImpl->path->moveTo(start.x + cx, start.y + cy);
}
for (int i = 0; i < nCurves; ++i) {
Point ctrl1 = {ax - k2 * ay + cx, ay + k2 * ax + cy};
Point ctrl2 = {bx + k2 * by + cx, by - k2 * bx + cy};
- impl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y);
+ pImpl->path->cubicTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y);
startAngle = endAngle;
}
if (pie) {
- impl->path->moveTo(cx, cy);
- impl->path->close();
+ pImpl->path->moveTo(cx, cy);
+ pImpl->path->close();
}
- IMPL->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) noexcept
{
- auto impl = pImpl.get();
-
auto halfW = w * 0.5f;
auto halfH = h * 0.5f;
//rectangle
if (rx == 0 && ry == 0) {
- impl->path->grow(5, 4);
- impl->path->moveTo(x, y);
- impl->path->lineTo(x + w, y);
- impl->path->lineTo(x + w, y + h);
- impl->path->lineTo(x, y + h);
- impl->path->close();
+ pImpl->path->grow(5, 4);
+ pImpl->path->moveTo(x, y);
+ pImpl->path->lineTo(x + w, y);
+ pImpl->path->lineTo(x + w, y + h);
+ pImpl->path->lineTo(x, y + h);
+ pImpl->path->close();
//circle
} else if (fabsf(rx - halfW) < FLT_EPSILON && fabsf(ry - halfH) < FLT_EPSILON) {
return appendCircle(x + (w * 0.5f), y + (h * 0.5f), rx, ry);
} else {
auto hrx = rx * 0.5f;
auto hry = ry * 0.5f;
- impl->path->grow(10, 17);
- impl->path->moveTo(x + rx, y);
- impl->path->lineTo(x + w - rx, y);
- impl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry);
- impl->path->lineTo(x + w, y + h - ry);
- impl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h);
- impl->path->lineTo(x + rx, y + h);
- impl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry);
- impl->path->lineTo(x, y + ry);
- impl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y);
- impl->path->close();
+ pImpl->path->grow(10, 17);
+ pImpl->path->moveTo(x + rx, y);
+ pImpl->path->lineTo(x + w - rx, y);
+ pImpl->path->cubicTo(x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry);
+ pImpl->path->lineTo(x + w, y + h - ry);
+ pImpl->path->cubicTo(x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h);
+ pImpl->path->lineTo(x + rx, y + h);
+ pImpl->path->cubicTo(x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry);
+ pImpl->path->lineTo(x, y + ry);
+ pImpl->path->cubicTo(x, y + ry - hry, x + rx - hrx, y, x + rx, y);
+ pImpl->path->close();
}
- impl->flag |= RenderUpdateFlag::Path;
+ pImpl->flag |= RenderUpdateFlag::Path;
return Result::Success;
}
Result Shape::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
{
- auto impl = pImpl.get();
-
- impl->color[0] = r;
- impl->color[1] = g;
- impl->color[2] = b;
- impl->color[3] = a;
- impl->flag |= RenderUpdateFlag::Color;
-
- if (impl->fill) {
- delete(impl->fill);
- impl->fill = nullptr;
- impl->flag |= RenderUpdateFlag::Gradient;
+ pImpl->color[0] = r;
+ pImpl->color[1] = g;
+ pImpl->color[2] = b;
+ pImpl->color[3] = a;
+ pImpl->flag |= RenderUpdateFlag::Color;
+
+ if (pImpl->fill) {
+ delete(pImpl->fill);
+ pImpl->fill = nullptr;
+ pImpl->flag |= RenderUpdateFlag::Gradient;
}
return Result::Success;
Result Shape::fill(unique_ptr<Fill> f) noexcept
{
- auto impl = pImpl.get();
-
auto p = f.release();
if (!p) return Result::MemoryCorruption;
- if (impl->fill && impl->fill != p) delete(impl->fill);
- impl->fill = p;
- impl->flag |= RenderUpdateFlag::Gradient;
+ if (pImpl->fill && pImpl->fill != p) delete(pImpl->fill);
+ pImpl->fill = p;
+ pImpl->flag |= RenderUpdateFlag::Gradient;
return Result::Success;
}
Result Shape::fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
{
- auto impl = pImpl.get();
-
- if (r) *r = impl->color[0];
- if (g) *g = impl->color[1];
- if (b) *b = impl->color[2];
- if (a) *a = impl->color[3];
+ if (r) *r = pImpl->color[0];
+ if (g) *g = pImpl->color[1];
+ if (b) *b = pImpl->color[2];
+ if (a) *a = pImpl->color[3];
return Result::Success;
}
const Fill* Shape::fill() const noexcept
{
- return IMPL->fill;
+ return pImpl->fill;
}
Result Shape::stroke(float width) noexcept
{
- if (!IMPL->strokeWidth(width)) return Result::FailedAllocation;
+ if (!pImpl->strokeWidth(width)) return Result::FailedAllocation;
return Result::Success;
}
float Shape::strokeWidth() const noexcept
{
- if (!IMPL->stroke) return 0;
- return IMPL->stroke->width;
+ if (!pImpl->stroke) return 0;
+ return pImpl->stroke->width;
}
Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
{
- if (!IMPL->strokeColor(r, g, b, a)) return Result::FailedAllocation;
+ if (!pImpl->strokeColor(r, g, b, a)) return Result::FailedAllocation;
return Result::Success;
}
Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept
{
- auto impl = pImpl.get();
-
- if (!impl->stroke) return Result::InsufficientCondition;
+ if (!pImpl->stroke) return Result::InsufficientCondition;
- 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];
+ if (r) *r = pImpl->stroke->color[0];
+ if (g) *g = pImpl->stroke->color[1];
+ if (b) *b = pImpl->stroke->color[2];
+ if (a) *a = pImpl->stroke->color[3];
return Result::Success;
}
{
if (cnt < 2 || !dashPattern) return Result::InvalidArguments;
- if (!IMPL->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
+ if (!pImpl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation;
return Result::Success;
}
uint32_t Shape::strokeDash(const float** dashPattern) const noexcept
{
- if (!IMPL->stroke) return 0;
+ if (!pImpl->stroke) return 0;
- if (dashPattern) *dashPattern = IMPL->stroke->dashPattern;
- return IMPL->stroke->dashCnt;
+ if (dashPattern) *dashPattern = pImpl->stroke->dashPattern;
+ return pImpl->stroke->dashCnt;
}
Result Shape::stroke(StrokeCap cap) noexcept
{
- if (!IMPL->strokeCap(cap)) return Result::FailedAllocation;
+ if (!pImpl->strokeCap(cap)) return Result::FailedAllocation;
return Result::Success;
}
Result Shape::stroke(StrokeJoin join) noexcept
{
- if (!IMPL->strokeJoin(join)) return Result::FailedAllocation;
+ if (!pImpl->strokeJoin(join)) return Result::FailedAllocation;
return Result::Success;
}
StrokeCap Shape::strokeCap() const noexcept
{
- if (!IMPL->stroke) return StrokeCap::Square;
+ if (!pImpl->stroke) return StrokeCap::Square;
- return IMPL->stroke->cap;
+ return pImpl->stroke->cap;
}
StrokeJoin Shape::strokeJoin() const noexcept
{
- if (!IMPL->stroke) return StrokeJoin::Bevel;
+ if (!pImpl->stroke) return StrokeJoin::Bevel;
- return IMPL->stroke->join;
-}
+ return pImpl->stroke->join;
+}
\ No newline at end of file