mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 14:41:50 +00:00
lottie/model: Added some essential functions through expressions.
These internal methods have been introduced to search for content within an object (parent) using a given parameter (name or index). - LottieLayer* LottieGroup::asset(const char* name) - LottieLayer* LottieComposition::asset(const char* name) - LottieLayer* LottieComposition::layer(uint16_t id) - LottieLayer* LottieComposition::layer(const char* name) This converts the frame number to the corresponding time. - float LottieComposition::timeAtFrame(float frameNo)
This commit is contained in:
parent
ce1fb53c9a
commit
4d02cda350
1 changed files with 46 additions and 0 deletions
|
@ -586,6 +586,20 @@ struct LottieGroup : LottieObject
|
||||||
void prepare(LottieObject::Type type = LottieObject::Group);
|
void prepare(LottieObject::Type type = LottieObject::Group);
|
||||||
bool mergeable() override { return allowMerge; }
|
bool mergeable() override { return allowMerge; }
|
||||||
|
|
||||||
|
LottieObject* content(const char* id)
|
||||||
|
{
|
||||||
|
if (name && !strcmp(name, id)) return this;
|
||||||
|
|
||||||
|
//source has children, find recursively.
|
||||||
|
for (auto c = children.begin(); c < children.end(); ++c) {
|
||||||
|
auto child = *c;
|
||||||
|
if (child->type == LottieObject::Type::Group || type == LottieObject::Type::Layer) {
|
||||||
|
if (auto ret = static_cast<LottieGroup*>(child)->content(id)) return ret;
|
||||||
|
} else if (child->name && !strcmp(child->name, id)) return child;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Scene* scene = nullptr; //tvg render data
|
Scene* scene = nullptr; //tvg render data
|
||||||
Array<LottieObject*> children;
|
Array<LottieObject*> children;
|
||||||
|
|
||||||
|
@ -761,11 +775,43 @@ struct LottieComposition
|
||||||
return p * frameCnt();
|
return p * frameCnt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float timeAtFrame(float frameNo)
|
||||||
|
{
|
||||||
|
return (frameNo - startFrame) / frameRate;
|
||||||
|
}
|
||||||
|
|
||||||
float frameCnt() const
|
float frameCnt() const
|
||||||
{
|
{
|
||||||
return endFrame - startFrame;
|
return endFrame - startFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LottieLayer* layer(const char* name)
|
||||||
|
{
|
||||||
|
for (auto child = root->children.begin(); child < root->children.end(); ++child) {
|
||||||
|
auto layer = static_cast<LottieLayer*>(*child);
|
||||||
|
if (layer->name && !strcmp(layer->name, name)) return layer;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
LottieLayer* layer(int16_t id)
|
||||||
|
{
|
||||||
|
for (auto child = root->children.begin(); child < root->children.end(); ++child) {
|
||||||
|
auto layer = static_cast<LottieLayer*>(*child);
|
||||||
|
if (layer->id == id) return layer;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
LottieLayer* asset(const char* name)
|
||||||
|
{
|
||||||
|
for (auto asset = assets.begin(); asset < assets.end(); ++asset) {
|
||||||
|
auto layer = static_cast<LottieLayer*>(*asset);
|
||||||
|
if (layer->name && !strcmp(layer->name, name)) return layer;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
LottieLayer* root = nullptr;
|
LottieLayer* root = nullptr;
|
||||||
char* version = nullptr;
|
char* version = nullptr;
|
||||||
char* name = nullptr;
|
char* name = nullptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue