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
22 #ifndef EFL_BETA_API_SUPPORT
23 #define EFL_BETA_API_SUPPORT
26 #ifndef EFL_EO_API_SUPPORT
27 #define EFL_EO_API_SUPPORT
34 #include <Ecore_Evas.h>
35 #include "lottieanimation.h"
36 #include "lottieanimation_capi.h"
42 enum class RepeatMode {
46 LottieView(Evas *evas, bool renderMode = true, bool asyncRender = true);
48 Evas_Object *getImage();
49 void setSize(int w, int h);
50 void setPos(int x, int y);
51 void setFilePath(const char *filePath);
52 void loadFromData(const std::string &jsonData, const std::string &key);
56 void setSpeed(float speed) { mSpeed = speed;}
57 void setRepeatCount(int count);
58 void setRepeatMode(LottieView::RepeatMode mode);
59 float getFrameRate() const { return mFrameRate; }
60 long getTotalFrame() const { return mTotalFrame; }
69 void initializeBufferObject(Evas *evas);
70 void setMinProgress(float progress)
73 mMinProgress = progress;
75 void setMaxProgress(float progress)
78 mMaxprogress = progress;
81 float mapProgress(float progress) {
82 //clamp it to the segment
83 progress = (mMinProgress + (mMaxprogress - mMinProgress) * progress);
85 // currently playing and in reverse mode
86 if (mPalying && mReverse)
87 progress = mMaxprogress > mMinProgress ?
88 mMaxprogress - progress : mMinProgress - progress;
93 float duration() const {
94 // usually we run the animation for mPlayer->duration()
95 // but now run animation for segmented duration.
96 return mPlayer->duration() * fabs(mMaxprogress - mMinProgress);
98 void createVgNode(LOTNode *node, Efl_VG *root);
99 void update(const std::vector<LOTNode *> &);
100 void updateTree(const LOTLayerNode *);
101 void update(const LOTLayerNode *, Efl_VG *parent);
110 LottieView::RepeatMode mRepeatMode;
111 std::unique_ptr<lottie::Animation> mPlayer;
112 size_t mCurFrame{UINT_MAX};
113 Ecore_Animator *mAnimator{nullptr};
126 std::future<lottie::Surface> mRenderTask;
128 //keep a segment of the animation default is [0, 1]
129 float mMinProgress{0};
130 float mMaxprogress{1};
138 Lottie_Animation *mAnimation;
141 #endif //LOTTIEVIEW_H