From 871251479df3d8b6697a0334dc2420c435708a53 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Tue, 23 Oct 2018 08:55:39 +0900 Subject: [PATCH] lottie: Add duration() and frameAtPos() api to CompositionData model. Change-Id: I7ff968b8262270dcd7b47a16f1a9549f7ffdb7d5 --- src/lottie/lottieanimation.cpp | 10 ++-------- src/lottie/lottiemodel.h | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index f7a929f..a6ba779 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -40,12 +40,7 @@ size_t AnimationImpl::totalFrame() const size_t AnimationImpl::frameAtPos(double pos) const { - if (pos < 0) pos = 0; - if (pos > 1) pos = 1; - - if (mModel->isStatic()) return 0; - - return mModel->startFrame() + pos * mModel->frameDuration(); + return mModel->frameAtPos(pos); } VSize AnimationImpl::size() const @@ -63,8 +58,7 @@ const std::vector &AnimationImpl::renderList(size_t frameNo, const VS double AnimationImpl::duration() const { - if (mModel->isStatic()) return 0; - return double(mModel->frameDuration()) / double(mModel->frameRate()); + return mModel->duration(); } bool AnimationImpl::update(size_t frameNo, const VSize &size) diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 3d0183f..7d61ebf 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -324,6 +324,16 @@ class LOTCompositionData : public LOTData { public: LOTCompositionData():LOTData(LOTData::Type::Composition){} + double duration() const { + return isStatic() ? startFrame() : + frameDuration() / frameRate(); // in second + } + size_t frameAtPos(double pos) const { + if (pos < 0) pos = 0; + if (pos > 1) pos = 1; + return isStatic() ? startFrame() : + startFrame() + pos * frameDuration(); + } long frameDuration() const {return mEndFrame - mStartFrame -1;} float frameRate() const {return mFrameRate;} long startFrame() const {return mStartFrame;} @@ -624,10 +634,12 @@ public: class LOTModel { public: - bool isStatic() const{return mRoot->isStatic();} - size_t frameDuration() {return mRoot->frameDuration();} - size_t frameRate() {return mRoot->frameRate();} - size_t startFrame() {return mRoot->startFrame();} + bool isStatic() const {return mRoot->isStatic();} + double duration() const {return mRoot->duration();} + size_t frameDuration() const {return mRoot->frameDuration();} + size_t frameRate() const {return mRoot->frameRate();} + size_t startFrame() const {return mRoot->startFrame();} + size_t frameAtPos(double pos) const {return mRoot->frameAtPos(pos);} public: std::shared_ptr mRoot; }; -- 2.34.1