examples/slot: added example for expressions slot overriding

This commit is contained in:
Jinny You 2025-02-24 17:24:33 +08:00 committed by Hermet Park
parent 0e76ba3e47
commit 010364174e
2 changed files with 24 additions and 2 deletions

View file

@ -39,6 +39,7 @@ struct UserExample : tvgexam::Example
unique_ptr<tvg::LottieAnimation> slot7;
unique_ptr<tvg::LottieAnimation> slot8;
unique_ptr<tvg::LottieAnimation> slot9;
unique_ptr<tvg::LottieAnimation> slot10;
unique_ptr<tvg::LottieAnimation> marker;
uint32_t w, h;
uint32_t size;
@ -127,6 +128,12 @@ struct UserExample : tvgexam::Example
slot9->frame(slot9->totalFrame() * progress);
}
//expression slot
{
auto progress = tvgexam::progress(elapsed, slot10->duration());
slot10->frame(slot10->totalFrame() * progress);
}
//marker
{
auto progress = tvgexam::progress(elapsed, marker->duration());
@ -286,6 +293,20 @@ struct UserExample : tvgexam::Example
canvas->push(picture);
}
//slot (expression)
{
slot10 = std::unique_ptr<tvg::LottieAnimation>(tvg::LottieAnimation::gen());
auto picture = slot10->picture();
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/lottie/extensions/slotsample10.json"))) return false;
const char* slotJson = R"({"rect_rotation":{"p":{"x":"var $bm_rt = time * 360;"}},"rect_scale":{"p":{"x":"var $bm_rt = [];$bm_rt[0] = value[0] + Math.cos(2 * Math.PI * time) * 100;$bm_rt[1] = value[1];"}},"rect_position":{"p":{"x":"var $bm_rt = [];$bm_rt[0] = value[0] + Math.cos(2 * Math.PI * time) * 100;$bm_rt[1] = value[1];"}}})";
if (!tvgexam::verify(slot10->override(slotJson))) return false;
sizing(picture, 10);
canvas->push(picture);
}
//marker
{
marker = std::unique_ptr<tvg::LottieAnimation>(tvg::LottieAnimation::gen());
@ -293,7 +314,7 @@ struct UserExample : tvgexam::Example
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/lottie/extensions/marker_sample.json"))) return false;
if (!tvgexam::verify(marker->segment("sectionC"))) return false;
sizing(picture, 10);
sizing(picture, 11);
canvas->push(picture);
}
@ -309,5 +330,5 @@ struct UserExample : tvgexam::Example
int main(int argc, char **argv)
{
return tvgexam::main(new UserExample, argc, argv, 1024, 1024);
return tvgexam::main(new UserExample, argc, argv, false, 1024, 1024, 1);
}

View file

@ -0,0 +1 @@
{"v":"5.5.7","ip":0,"op":180,"nm":"Animation","mn":"{8f1618e3-6f83-4531-8f65-07dd4b68ee2e}","fr":60,"w":512,"h":512,"assets":[],"slots":{},"layers":[{"ddd":0,"ty":4,"ind":0,"st":0,"ip":0,"op":180,"nm":"Layer","mn":"{85f37d8b-1792-4a4f-82d2-1b3b6d829c07}","ks":{"a":{"a":0,"k":[256,256]},"p":{"a":0,"k":[256,256]},"s":{"a":0,"k":[100,100]},"r":{"a":0,"k":0},"o":{"a":0,"k":100}},"shapes":[{"ty":"gr","nm":"Group","it":[{"ty":"rc","nm":"Rectangle","p":{"a":0,"k":[250,227]},"s":{"a":0,"k":[334,239]},"r":{"a":0,"k":0}},{"ty":"st","nm":"Stroke","mn":"{0930ce27-c8f9-4371-b0cf-111a859abfaf}","o":{"a":0,"k":100},"c":{"a":0,"k":[1,0.9803921568627451,0.2823529411764706]},"lc":2,"lj":2,"ml":0,"w":{"a":0,"k":30}},{"ty":"tr","a":{"a":0,"k":[249.3134328358209,254.47164179104476],"sid":"rect_anchor_point"},"p":{"a":0,"k":[249.3134328358209,254.47164179104476],"sid":"rect_position"},"s":{"a":0,"k":[100,100],"sid":"rect_scale"},"r":{"a":0,"k":0,"sid":"rect_rotation"},"o":{"a":0,"k":100,"sid":"rect_opacity"},"sk":{"a":0,"k":180,"sid":"rect_skew"},"sa":{"a":0,"k":0,"sid":"rect_skew_angle"}}]}]}],"meta":{"g":"Glaxnimate0.4.6-26-g7b05e75c"}}