lottie: clean up code and minor bugs by mistake.

This commit is contained in:
Hermet Park 2024-02-23 16:11:06 +09:00 committed by Hermet Park
parent 625146853e
commit 65e8fe2791
4 changed files with 26 additions and 13 deletions

View file

@ -52,7 +52,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (canvas->push(std::move(shape)) != tvg::Result::Success) return; if (canvas->push(std::move(shape)) != tvg::Result::Success) return;
const char* slotData = R"(({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})"; const char* slotJson = R"({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})";
if (picture->load(EXAMPLE_DIR"/slotsample.json") != tvg::Result::Success) { if (picture->load(EXAMPLE_DIR"/slotsample.json") != tvg::Result::Success) {
cout << "Lottie is not supported. Did you enable Lottie Loader?" << endl; cout << "Lottie is not supported. Did you enable Lottie Loader?" << endl;
@ -79,8 +79,11 @@ void tvgDrawCmds(tvg::Canvas* canvas)
canvas->push(tvg::cast(picture)); canvas->push(tvg::cast(picture));
//Override slot data //Override slot data
animation->override(slotData); if (animation->override(slotJson) == tvg::Result::Success) {
canvas->update(); canvas->update();
} else {
cout << "Failed to override the slot" << endl;
}
//Run animation loop //Run animation loop
elm_transit_duration_set(transit, animation->duration()); elm_transit_duration_set(transit, animation->duration());

View file

@ -23,9 +23,9 @@ public:
~LottieAnimation(); ~LottieAnimation();
/** /**
* @brief Rewrite lottie properties through the slot data * @brief Override Lottie properties using slot data.
* *
* @param[in] slot The lottie slot data * @param[in] slot The Lottie slot data in JSON format.
* *
* @retval Result::Success When succeed. * @retval Result::Success When succeed.
* @retval Result::InsufficientCondition When the given parameter is invalid. * @retval Result::InsufficientCondition When the given parameter is invalid.

View file

@ -304,19 +304,25 @@ bool LottieLoader::override(const char* slot)
{ {
if (!slot) return false; if (!slot) return false;
//TODO: Crashed, does this necessary?
auto temp = strdup(slot);
//parsing slot json //parsing slot json
LottieParser parser(slot, dirName); LottieParser parser(temp, dirName);
auto sid = parser.sid(); auto sid = parser.sid();
if (!sid) return false; if (!sid) {
free(temp);
return false;
}
bool ret = false; bool ret = false;
for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) { for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) {
if (!strcmp((*s)->sid, sid)) continue; if (strcmp((*s)->sid, sid)) continue;
ret = parser.parse(*s); ret = parser.parse(*s);
break; break;
} }
free(temp);
return ret; return ret;
} }

View file

@ -253,7 +253,8 @@ struct LottieGenericProperty : LottieProperty
{ {
//shallow copy, used for slot overriding //shallow copy, used for slot overriding
delete(frames); delete(frames);
*this = other; frames = other.frames;
value = other.value;
const_cast<T&>(other).frames = nullptr; const_cast<T&>(other).frames = nullptr;
return *this; return *this;
} }
@ -446,7 +447,9 @@ struct LottieColorStop : LottieProperty
{ {
//shallow copy, used for slot overriding //shallow copy, used for slot overriding
delete(frames); delete(frames);
*this = other; frames = other.frames;
value = other.value;
count = other.count;
const_cast<LottieColorStop&>(other).frames = nullptr; const_cast<LottieColorStop&>(other).frames = nullptr;
return *this; return *this;
} }
@ -566,7 +569,8 @@ struct LottieTextDoc : LottieProperty
{ {
//shallow copy, used for slot overriding //shallow copy, used for slot overriding
delete(frames); delete(frames);
*this = other; frames = other.frames;
value = other.value;
const_cast<LottieTextDoc&>(other).frames = nullptr; const_cast<LottieTextDoc&>(other).frames = nullptr;
return *this; return *this;
} }