From c8092e9f673122138f70e9857e8d58f6b902c738 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Mon, 16 Jun 2025 21:06:07 +0200 Subject: [PATCH] lottie: chaining modifiers - ellipse/polystar Refactoring ellipse/polygon/star update to prepare for chained modifiers. --- src/loaders/lottie/tvgLottieBuilder.cpp | 32 +++++++++++++++--------- src/loaders/lottie/tvgLottieModifier.cpp | 8 ------ src/loaders/lottie/tvgLottieModifier.h | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 5c72ad40..f637552d 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -434,17 +434,22 @@ void LottieBuilder::updateRect(LottieGroup* parent, LottieObject** child, float static void _appendCircle(Shape* shape, Point& center, Point& radius, bool clockwise, RenderContext* ctx) { - if (ctx->offset) ctx->offset->modifyEllipse(radius); + auto temp = (ctx->modifier) ? Shape::gen() : shape; + auto cnt = SHAPE(temp)->rs.path.pts.count; - auto cnt = SHAPE(shape)->rs.path.pts.count; - - shape->appendCircle(center.x, center.y, radius.x, radius.y, clockwise); + temp->appendCircle(center.x, center.y, radius.x, radius.y, clockwise); if (ctx->transform) { - for (auto i = cnt; i < SHAPE(shape)->rs.path.pts.count; ++i) { - SHAPE(shape)->rs.path.pts[i] *= *ctx->transform; + for (auto i = cnt; i < SHAPE(temp)->rs.path.pts.count; ++i) { + SHAPE(temp)->rs.path.pts[i] *= *ctx->transform; } } + + if (ctx->modifier) { + auto& path = SHAPE(temp)->rs.path; + ctx->modifier->modifyPath(path.cmds.data, path.cmds.count, path.pts.data, path.pts.count, nullptr, SHAPE(shape)->rs.path); + delete(temp); + } } @@ -510,10 +515,11 @@ void LottieBuilder::updateStar(LottiePolyStar* star, float frameNo, Matrix* tran auto numPoints = size_t(ceilf(ptsCnt) * 2); auto direction = star->clockwise ? 1.0f : -1.0f; auto hasRoundness = false; - bool roundedCorner = ctx->roundness && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness)); Shape* shape; - if (roundedCorner || ctx->offset) { + auto modifier = ctx->modifier; + if (modifier && modifier == ctx->roundness && !tvg::zero(innerRoundness) && !tvg::zero(outerRoundness)) modifier = modifier->next; + if (modifier) { shape = star->pooling(); shape->reset(); } else { @@ -602,7 +608,7 @@ void LottieBuilder::updateStar(LottiePolyStar* star, float frameNo, Matrix* tran _close(SHAPE(shape)->rs.path.pts, in, hasRoundness); shape->close(); - if (ctx->modifier) ctx->modifier->modifyPolystar(SHAPE(shape)->rs.path, SHAPE(merging)->rs.path, outerRoundness, hasRoundness); + if (modifier) modifier->modifyPolystar(SHAPE(shape)->rs.path, SHAPE(merging)->rs.path, outerRoundness, hasRoundness); } @@ -618,14 +624,13 @@ void LottieBuilder::updatePolygon(LottieGroup* parent, LottiePolyStar* star, flo auto anglePerPoint = 2.0f * MATH_PI / float(ptsCnt); auto direction = star->clockwise ? 1.0f : -1.0f; auto hasRoundness = !tvg::zero(outerRoundness); - bool roundedCorner = ctx->roundness && !hasRoundness; auto x = radius * cosf(angle); auto y = radius * sinf(angle); angle += anglePerPoint * direction; Shape* shape; - if (roundedCorner || ctx->offset) { + if (ctx->modifier) { shape = star->pooling(); shape->reset(); } else { @@ -672,7 +677,10 @@ void LottieBuilder::updatePolygon(LottieGroup* parent, LottiePolyStar* star, flo _close(SHAPE(shape)->rs.path.pts, in, hasRoundness); shape->close(); - if (ctx->modifier) ctx->modifier->modifyPolystar(SHAPE(shape)->rs.path, SHAPE(merging)->rs.path, 0.0f, false); + if (ctx->modifier) { + auto& path = SHAPE(shape)->rs.path; + ctx->modifier->modifyPath(path.cmds.data, path.cmds.count, path.pts.data, path.pts.count, nullptr, SHAPE(merging)->rs.path); + } } diff --git a/src/loaders/lottie/tvgLottieModifier.cpp b/src/loaders/lottie/tvgLottieModifier.cpp index 26626422..fe992b02 100644 --- a/src/loaders/lottie/tvgLottieModifier.cpp +++ b/src/loaders/lottie/tvgLottieModifier.cpp @@ -388,12 +388,4 @@ bool LottieOffsetModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, P bool LottieOffsetModifier::modifyPolystar(RenderPath& in, RenderPath& out, TVG_UNUSED float, TVG_UNUSED bool) { return modifyPath(in.cmds.data, in.cmds.count, in.pts.data, in.pts.count, nullptr, out); -} - - -bool LottieOffsetModifier::modifyEllipse(Point& radius) -{ - radius.x += offset; - radius.y += offset; - return true; } \ No newline at end of file diff --git a/src/loaders/lottie/tvgLottieModifier.h b/src/loaders/lottie/tvgLottieModifier.h index fd082901..952304ed 100644 --- a/src/loaders/lottie/tvgLottieModifier.h +++ b/src/loaders/lottie/tvgLottieModifier.h @@ -90,7 +90,6 @@ struct LottieOffsetModifier : LottieModifier bool modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, Matrix* transform, RenderPath& out) override; bool modifyPolystar(RenderPath& in, RenderPath& out, float outerRoundness, bool hasRoundness) override; - bool modifyEllipse(Point& radius); private: struct State