deae8e549474b533ddf80d008d830714ff04ab42
[platform/core/uifw/lottie-player.git] / example / lottieview.h
1 #ifndef LOTTIEVIEW_H
2 #define LOTTIEVIEW_H
3
4 #ifndef EFL_BETA_API_SUPPORT
5 #define EFL_BETA_API_SUPPORT
6 #endif
7
8 #ifndef EFL_EO_API_SUPPORT
9 #define EFL_EO_API_SUPPORT
10 #endif
11
12 #include <Eo.h>
13 #include <Efl.h>
14 #include <Evas.h>
15 #include <Ecore.h>
16 #include <Ecore_Evas.h>
17 #include "lottieanimation.h"
18 #include "lottieanimation_capi.h"
19 #include<future>
20 class LottieView
21 {
22 public:
23     enum class RepeatMode {
24         Restart,
25         Reverse
26     };
27     LottieView(Evas *evas, bool renderMode = true, bool asyncRender = true);
28     ~LottieView();
29     Evas_Object *getImage();
30     void setSize(int w, int h);
31     void setPos(int x, int y);
32     void setFilePath(const char *filePath);
33     void loadFromData(const std::string &jsonData, const std::string &key);
34     void show();
35     void hide();
36     void loop(bool loop);
37     void setSpeed(float speed) { mSpeed = speed;}
38     void setRepeatCount(int count);
39     void setRepeatMode(LottieView::RepeatMode mode);
40     float getFrameRate() const { return mFrameRate; }
41     long getTotalFrame() const { return mTotalFrame; }
42 public:
43     void seek(float pos);
44     float getPos();
45     void finished();
46     void play();
47     void pause();
48     void stop();
49     void render();
50     void initializeBufferObject(Evas *evas);
51 private:
52     void createVgNode(LOTNode *node, Efl_VG *parent);
53     void update(const std::vector<LOTNode *> &);
54     void restart();
55 public:
56     int                      mw;
57     int                      mh;
58     Evas                    *mEvas;
59     Efl_VG                  *mRoot;
60     Evas_Object             *mVg;
61     int                      mRepeatCount;
62     LottieView::RepeatMode   mRepeatMode;
63     std::unique_ptr<lottie::Animation>       mPlayer;
64     size_t                   mCurFrame{UINT_MAX};
65     Ecore_Animator          *mAnimator{nullptr};
66     bool                     mLoop;
67     int                      mCurCount;
68     bool                     mReverse;
69     bool                     mPalying;
70     Evas_Object             *mImage;
71     float                    mSpeed;
72     bool                     mRenderMode;
73     bool                     mAsyncRender;
74     bool                     mDirty;
75     float                    mStartPos;
76     float                    mPos;
77     float                    mFrameRate;
78     long                     mTotalFrame;
79     std::future<lottie::Surface>        mRenderTask;
80 };
81
82 class LottieViewCApi
83 {
84 public:
85 private:
86     Evas                    *mEvas;
87     Lottie_Animation        *mAnimation;
88 };
89
90 #endif //LOTTIEVIEW_H