loader/lottie: add the rounded corner feature

The rounded rectangle property should be propagated to the root
through the lottie model scene-tree.
This commit is contained in:
Hermet Park 2023-08-09 16:16:13 +09:00 committed by Hermet Park
parent 8f4f3d6f1b
commit 345ef54e26
3 changed files with 23 additions and 14 deletions

View file

@ -296,16 +296,11 @@ static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseSha
TVGERR("LOTTIE", "TODO: update Polystar");
break;
}
case LottieObject::RoundedCorner: {
TVGERR("LOTTIE", "TODO: update Round Corner");
break;
}
case LottieObject::Image: {
_updateImage(parent, static_cast<LottieImage*>(*child), frameNo, baseShape);
break;
}
default: {
TVGERR("LOTTIE", "TODO: Missing type??");
break;
}
}

View file

@ -144,13 +144,6 @@ struct LottieRect : LottieShape
return roundedCorner ? roundedCorner->radius(frameNo) : round(frameNo);
}
bool roundnessChanged(int prevFrame, int curFrame)
{
//return roundedCorner ? roundedCorner->radius.changed(prevFrame, curFrame) : round.changed(prevFrame, curFrame);
TVGERR("LOTTIE", "TODO: LottieRect::roundnessChanged()");
return 0;
}
LottieRoundedCorner* roundedCorner = nullptr;
LottiePosition position = Point{0.0f, 0.0f};
LottiePoint size = Point{0.0f, 0.0f};
@ -382,6 +375,7 @@ struct LottieLayer : LottieGroup
Type type = Null;
bool autoOrient = false;
bool mask = false;
bool roundedCorner = false;
};

View file

@ -74,6 +74,24 @@ static void _decodeB64(const uint8_t* input, const size_t len, Array<char>& outp
}
static void _updateRoundedCorner(LottieGroup* parent, LottieRoundedCorner* roundedCorner)
{
for (auto child = parent->children.data; child < parent->children.end(); ++child) {
auto obj = *child;
if (obj->type == LottieObject::Rect) {
auto rect = static_cast<LottieRect*>(obj);
rect->roundedCorner = roundedCorner;
rect->statical &= roundedCorner->statical;
parent->statical &= roundedCorner->statical;
continue;
}
if (obj->type == LottieObject::Group || obj->type == LottieObject::Layer) {
_updateRoundedCorner(static_cast<LottieGroup*>(obj), roundedCorner);
}
}
}
BlendMethod LottieParser::getBlendMethod()
{
switch (getInt()) {
@ -670,6 +688,8 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner()
auto corner = new LottieRoundedCorner;
if (!corner) return nullptr;
context->layer->roundedCorner = true;
while (auto key = nextObjectKey()) {
if (!strcmp(key, "nm")) corner->name = getStringCopy();
else if (!strcmp(key, "r")) parseProperty(corner->radius);
@ -768,7 +788,6 @@ LottieObject* LottieParser::parseObject()
TVGLOG("LOTTIE", "Polystar(sr) is not supported");
return parsePolyStar();
} else if (!strcmp(type, "rd")) {
TVGLOG("LOTTIE", "RoundedCorner(rd) is not supported");
return parseRoundedCorner();
} else if (!strcmp(type, "gf")) {
return parseGradientFill();
@ -794,8 +813,9 @@ void LottieParser::parseObject(LottieGroup* parent)
if (!strcmp(key, "ty")) {
auto child = parseObject();
if (child && !child->hidden) {
//propagate the rounded corner properties.
if (child->type == LottieObject::RoundedCorner) {
//TODO:
_updateRoundedCorner(parent, static_cast<LottieRoundedCorner*>(child));
}
parent->children.push(child);
} else delete(child);