From adddac6180b8b476cf10e5bd27de2fbfa75872e3 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 13 Aug 2018 19:29:38 +0900 Subject: [PATCH] lottieplayer: merge setPos() with renderList() renderList() build render tree based on current Position. merge both api helps user to avoid mistake. Change-Id: Ia158f28b5ab66ec6e20665726a21d7f1c4e4cc13 --- example/lottieview.cpp | 6 ++---- inc/lottieplayer.h | 3 +-- src/lottie/lottieplayer.cpp | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/example/lottieview.cpp b/example/lottieview.cpp index a59468d..6970191 100644 --- a/example/lottieview.cpp +++ b/example/lottieview.cpp @@ -162,8 +162,7 @@ void LottieView::seek(float pos) } } } else { - mPlayer->setPos(pos); - const std::vector &renderList = mPlayer->renderList(); + const std::vector &renderList = mPlayer->renderList(pos); update(renderList); } } @@ -186,8 +185,7 @@ void LottieView::render() } mBuffer.buffer = nullptr; } else { - mPlayer->setPos(mPendingPos); - const std::vector &renderList = mPlayer->renderList(); + const std::vector &renderList = mPlayer->renderList(mPendingPos); update(renderList); } } diff --git a/inc/lottieplayer.h b/inc/lottieplayer.h index 1fcdb77..9115977 100644 --- a/inc/lottieplayer.h +++ b/inc/lottieplayer.h @@ -46,10 +46,9 @@ public: float playTime() const; - void setPos(float pos); float pos(); - const std::vector &renderList() const; + const std::vector &renderList(float pos) const; // TODO: Consider correct position... void setSize(int width, int height); diff --git a/src/lottie/lottieplayer.cpp b/src/lottie/lottieplayer.cpp index 7c97398..95368af 100644 --- a/src/lottie/lottieplayer.cpp +++ b/src/lottie/lottieplayer.cpp @@ -7,15 +7,18 @@ #include class LOTPlayerPrivate { + +private: + bool setPos(float pos); + public: LOTPlayerPrivate(); bool setFilePath(std::string path); void setSize(const VSize &sz); VSize size() const; float playTime() const; - bool setPos(float pos); float pos(); - const std::vector &renderList() const; + const std::vector &renderList(float pos); bool render(float pos, const LOTBuffer &buffer); public: @@ -48,13 +51,13 @@ VSize LOTPlayerPrivate::size() const } } -const std::vector &LOTPlayerPrivate::renderList() const +const std::vector &LOTPlayerPrivate::renderList(float pos) { if (!mCompItem) { static std::vector empty; return empty; } - + this->setPos(pos); return mCompItem->renderList(); } @@ -66,7 +69,10 @@ float LOTPlayerPrivate::playTime() const bool LOTPlayerPrivate::setPos(float pos) { - if (!mModel || !mCompItem) return false; + if (!mModel || !mCompItem) { + vWarning << "Invalid data, mModel(?), mCompItem(?)"; + return false; + } if (pos > 1.0) pos = 1.0; if (pos < 0) pos = 0; @@ -244,19 +250,14 @@ float LOTPlayer::playTime() const return d->playTime(); } -void LOTPlayer::setPos(float pos) -{ - d->setPos(pos); -} - float LOTPlayer::pos() { return d->pos(); } -const std::vector &LOTPlayer::renderList() const +const std::vector &LOTPlayer::renderList(float pos) const { - return d->renderList(); + return d->renderList(pos); } std::future LOTPlayer::render(float pos, LOTBuffer buffer) -- 2.34.1