From 7cca3e053f9a5c645356bd6eff8c3eb39b4e34d0 Mon Sep 17 00:00:00 2001 From: Chae Lin Shin Date: Tue, 20 Oct 2020 15:30:58 +0900 Subject: [PATCH] wasm: Add extra functions for lottie animation to use them in rlottie viewer Added following functions for lottie animation - FillColor, FillOpacity, StrokeColor, StrokeOpacity, StrokeWidth, TrPosition, TrRotation, TrAnchor, TrScale, TrOpacity --- src/wasm/rlottiewasm.cpp | 87 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/src/wasm/rlottiewasm.cpp b/src/wasm/rlottiewasm.cpp index 4c759cc..af16379 100644 --- a/src/wasm/rlottiewasm.cpp +++ b/src/wasm/rlottiewasm.cpp @@ -27,6 +27,81 @@ public: return mPlayer ? true : false; } + void setFillColor(std::string keypath, float r, float g, float b) + { + if (!mPlayer) return; + + mPlayer->setValue(keypath, + rlottie::Color(r, g, b)); + } + + void setStrokeColor(std::string keypath, float r, float g, float b) + { + if (!mPlayer) return; + + mPlayer->setValue(keypath, + rlottie::Color(r, g, b)); + } + + void setFillOpacity(std::string keypath, float opacity) + { + if (!mPlayer || opacity > 100 || opacity < 0) return; + + mPlayer->setValue(keypath, opacity); + } + + void setStrokeOpacity(std::string keypath, float opacity) + { + if (!mPlayer || opacity > 100 || opacity < 0) return; + + mPlayer->setValue(keypath, opacity); + } + + void setStrokeWidth(std::string keypath, float width) + { + if (!mPlayer || width < 0) return; + + mPlayer->setValue(keypath, width); + } + + void setAnchor(std::string keypath, float x, float y) + { + if (!mPlayer) return; + + mPlayer->setValue(keypath, + rlottie::Point(x, y)); + } + + void setPosition(std::string keypath, float x, float y) + { + if (!mPlayer) return; + + mPlayer->setValue(keypath, + rlottie::Point(x, y)); + } + + void setScale(std::string keypath, float width, float height) + { + if (!mPlayer) return; + + mPlayer->setValue(keypath, + rlottie::Size(width, height)); + } + + void setRotation(std::string keypath, float degree) + { + if (!mPlayer || degree > 360 || degree < 0) return; + + mPlayer->setValue(keypath, degree); + } + + void setOpacity(std::string keypath, float opacity) + { + if (!mPlayer || opacity > 100 || opacity < 0) return; + + mPlayer->setValue(keypath, opacity); + } + // canvas pixel pix[0] pix[1] pix[2] pix[3] {B G R A} // lottie pixel pix[0] pix[1] pix[2] pix[3] {R G B A} val render(int frame, int width, int height) @@ -105,5 +180,15 @@ EMSCRIPTEN_BINDINGS(rlottie_bindings) .constructor(&RlottieWasm::create) .function("load", &RlottieWasm::load, allow_raw_pointers()) .function("frames", &RlottieWasm::frames) - .function("render", &RlottieWasm::render); + .function("render", &RlottieWasm::render) + .function("setFillColor", &RlottieWasm::setFillColor) + .function("setStrokeColor", &RlottieWasm::setStrokeColor) + .function("setFillOpacity", &RlottieWasm::setFillOpacity) + .function("setStrokeOpacity", &RlottieWasm::setStrokeOpacity) + .function("setStrokeWidth", &RlottieWasm::setStrokeWidth) + .function("setAnchor", &RlottieWasm::setAnchor) + .function("setPosition", &RlottieWasm::setPosition) + .function("setScale", &RlottieWasm::setScale) + .function("setRotation", &RlottieWasm::setRotation) + .function("setOpacity", &RlottieWasm::setOpacity); } -- 2.34.1