This commit is contained in:
Jinny You 2025-02-20 22:53:04 +08:00
parent df58466ce7
commit acdec3d294
2 changed files with 85 additions and 4 deletions

View file

@ -20,6 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <thorvg_lottie.h>
#include "Example.h" #include "Example.h"
/************************************************************************/ /************************************************************************/
@ -28,12 +29,12 @@
struct UserExample : tvgexam::Example struct UserExample : tvgexam::Example
{ {
unique_ptr<tvg::Animation> animation; unique_ptr<tvg::LottieAnimation> animation;
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
{ {
//Animation Controller //Animation Controller
animation = unique_ptr<tvg::Animation>(tvg::Animation::gen()); animation = unique_ptr<tvg::LottieAnimation>(tvg::LottieAnimation::gen());
auto picture = animation->picture(); auto picture = animation->picture();
//Background //Background
@ -45,6 +46,9 @@ struct UserExample : tvgexam::Example
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/lottie/sample.json"))) return false; if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/lottie/sample.json"))) return false;
const char* slotJson = R"({"rect_position":{"p":{"x": "var $bm_rt = [];\n$bm_rt[0] = value[0] + Math.cos(2 * Math.PI * time) * 100;\n$bm_rt[1] = value[1];"}}})";
if (!tvgexam::verify(animation->override(slotJson))) return false;
//image scaling preserving its aspect ratio //image scaling preserving its aspect ratio
float scale; float scale;
float shiftX = 0.0f, shiftY = 0.0f; float shiftX = 0.0f, shiftY = 0.0f;
@ -90,5 +94,6 @@ struct UserExample : tvgexam::Example
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return tvgexam::main(new UserExample, argc, argv, false, 1024, 1024); // Ensure thread is 1 for expression support
return tvgexam::main(new UserExample, argc, argv, false, 1024, 1024, 1);
} }

File diff suppressed because one or more lines are too long