lottie: chaining modifiers - rectangles

Enables applying modifiers to rectangles in any order.
This commit is contained in:
Mira Grudzinska 2025-06-16 20:35:13 +02:00
parent 87af337497
commit 2814376962
3 changed files with 5 additions and 25 deletions

View file

@ -394,7 +394,7 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx)
{
auto temp = (ctx->offset) ? Shape::gen() : shape;
auto temp = ctx->modifier ? Shape::gen() : shape;
auto cnt = SHAPE(temp)->rs.path.pts.count;
temp->appendRect(pos.x, pos.y, size.x, size.y, r, r, clockwise);
@ -405,8 +405,9 @@ void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, b
}
}
if (ctx->offset) {
ctx->offset->modifyRect(SHAPE(temp)->rs.path, SHAPE(shape)->rs.path);
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);
}
}
@ -417,13 +418,7 @@ void LottieBuilder::updateRect(LottieGroup* parent, LottieObject** child, float
auto rect = static_cast<LottieRect*>(*child);
auto size = rect->size(frameNo, tween, exps);
auto pos = rect->position(frameNo, tween, exps) - size * 0.5f;
auto r = rect->radius(frameNo, tween, exps);
if (r == 0.0f) {
if (ctx->roundness) ctx->roundness->modifyRect(size, r);
} else {
r = std::min({r, size.x * 0.5f, size.y * 0.5f});
}
auto r = std::min({rect->radius(frameNo, tween, exps), size.x * 0.5f, size.y * 0.5f});
if (ctx->repeaters.empty()) {
_draw(parent, rect, ctx);

View file

@ -305,13 +305,6 @@ bool LottieRoundnessModifier::modifyPolystar(RenderPath& in, RenderPath& out, fl
}
bool LottieRoundnessModifier::modifyRect(Point& size, float& r)
{
r = std::min(this->r, std::max(size.x, size.y) * 0.5f);
return true;
}
bool LottieOffsetModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, Point* inPts, uint32_t inPtsCnt, TVG_UNUSED Matrix* transform, RenderPath& out)
{
auto& path = next ? (inCmds == buffer[0].cmds.data ? buffer[1] : buffer[0]) : out;
@ -398,12 +391,6 @@ bool LottieOffsetModifier::modifyPolystar(RenderPath& in, RenderPath& out, TVG_U
}
bool LottieOffsetModifier::modifyRect(RenderPath& in, RenderPath& out)
{
return modifyPath(in.cmds.data, in.cmds.count, in.pts.data, in.pts.count, nullptr, out);
}
bool LottieOffsetModifier::modifyEllipse(Point& radius)
{
radius.x += offset;

View file

@ -74,7 +74,6 @@ struct LottieRoundnessModifier : 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 modifyRect(Point& size, float& r);
};
@ -91,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 modifyRect(RenderPath& in, RenderPath& out);
bool modifyEllipse(Point& radius);
private: