mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
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:
parent
8f4f3d6f1b
commit
345ef54e26
3 changed files with 23 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue