2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include"lottieview.h"
21 using namespace rlottie;
24 animator(void *data , double pos)
26 LottieView *view = static_cast<LottieView *>(data);
30 view->mAnimator = NULL;
37 LottieView::LottieView(Evas *evas, Strategy s) {
41 mRepeatMode = LottieView::RepeatMode::Restart;
46 case Strategy::renderCpp: {
47 mRenderDelegate = std::make_unique<RlottieRenderStrategy_CPP>(evas);
50 case Strategy::renderCppAsync: {
51 mRenderDelegate = std::make_unique<RlottieRenderStrategy_CPP_ASYNC>(evas);
54 case Strategy::renderC: {
55 mRenderDelegate = std::make_unique<RlottieRenderStrategy_C>(evas);
58 case Strategy::renderCAsync: {
59 mRenderDelegate = std::make_unique<RlottieRenderStrategy_C_ASYNC>(evas);
62 case Strategy::eflVg: {
63 mRenderDelegate = std::make_unique<EflVgRenderStrategy>(evas);
67 mRenderDelegate = std::make_unique<RlottieRenderStrategy_CPP>(evas);
72 LottieView::~LottieView()
74 if (mAnimator) ecore_animator_del(mAnimator);
77 Evas_Object *LottieView::getImage() {
78 return mRenderDelegate->renderObject();
81 void LottieView::show()
83 mRenderDelegate->show();
87 void LottieView::hide()
89 mRenderDelegate->hide();
92 void LottieView::seek(float pos)
94 if (!mRenderDelegate) return;
97 mPos = mapProgress(pos);
99 // check if the pos maps to the current frame
100 if (mCurFrame == mRenderDelegate->frameAtPos(mPos)) return;
102 mCurFrame = mRenderDelegate->frameAtPos(mPos);
104 mRenderDelegate->renderRequest(mCurFrame);
107 float LottieView::getPos()
112 void LottieView::render()
114 mRenderDelegate->renderFlush();
117 void LottieView::setFilePath(const char *filePath)
119 mRenderDelegate->loadFromFile(filePath);
122 void LottieView::loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath)
124 mRenderDelegate->loadFromData(jsonData, key, resourcePath);
127 void LottieView::setSize(int w, int h)
129 mRenderDelegate->resize(w, h);
132 void LottieView::setPos(int x, int y)
134 mRenderDelegate->setPos(x, y);
137 void LottieView::finished()
142 void LottieView::loop(bool loop)
147 void LottieView::setRepeatCount(int count)
149 mRepeatCount = count;
152 void LottieView::setRepeatMode(LottieView::RepeatMode mode)
157 void LottieView::play()
159 if (mAnimator) ecore_animator_del(mAnimator);
160 mAnimator = ecore_animator_timeline_add(duration()/mSpeed, animator, this);
162 mCurCount = mRepeatCount;
166 void LottieView::pause()
171 void LottieView::stop()
175 ecore_animator_del(mAnimator);
180 void LottieView::restart()
183 if (mLoop || mRepeatCount) {
184 if (mRepeatMode == LottieView::RepeatMode::Reverse)
185 mReverse = !mReverse;
189 if (mAnimator) ecore_animator_del(mAnimator);
190 mAnimator = ecore_animator_timeline_add(duration()/mSpeed, animator, this);