lottie-player : Initial draft for lottie-player library
[platform/core/uifw/lottie-player.git] / example / lottieviewtest.cpp
1 #include "evasapp.h"
2 #include "lottieview.h"
3 #include<iostream>
4 #include <dirent.h>
5 #include <stdio.h>
6 using namespace std;
7
8 /*
9  * To check the frame rate with rendermode off run
10  * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render
11  *
12  * To check the frame rate with  render backend
13  * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest
14  *
15  */
16
17 class LottieViewTest
18 {
19 public:
20   LottieViewTest(EvasApp *app, bool renderMode) {
21       mApp = app;
22       mRenderMode = renderMode;
23   }
24
25   bool isJsonFile(const char *filename) {
26     const char *dot = strrchr(filename, '.');
27     if(!dot || dot == filename) return false;
28     return !strcmp(dot + 1, "json");
29   }
30
31   void buildResourceList() {
32       DIR *d;
33       struct dirent *dir;
34       d = opendir(DEMO_DIR);
35       if (d) {
36         while ((dir = readdir(d)) != NULL) {
37           if (isJsonFile(dir->d_name))
38             mResource.push_back(dir->d_name);
39         }
40         closedir(d);
41       }
42   }
43   void displayResourceList() {
44     for(auto i : mResource) {
45        std::string filePath = DEMO_DIR;
46        filePath +=i;
47     }
48   }
49
50   void show() {
51     if (mResource.empty()) return;
52
53     int count = mResource.size();
54     int colums = sqrt(count);
55     int rows = (count % colums) ? colums+1 : colums;
56     int offset = 3;
57     int vw = (mApp->width() - (2 * offset * colums))/colums;
58     int vh = (mApp->height() - (2 * offset * rows))/rows;
59     int posx = offset;
60     int posy = offset;
61     for(auto i : mResource) {
62        std::string filePath = DEMO_DIR;
63        filePath +=i;
64
65        std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
66        view->setFilePath(filePath.c_str());
67        view->setPos(posx, posy);
68        view->setSize(vw, vh);
69        view->show();
70        view->play();
71        view->loop(true);
72        //view->setRepeatMode(LottieView::RepeatMode::Reverse);
73
74        posx += vw+offset;
75        if ((mApp->width() - posx) < vw) {
76           posx = offset;
77           posy = posy + vh + offset;
78        }
79        mViews.push_back(std::move(view));
80     }
81
82   }
83
84 public:
85   EvasApp     *mApp;
86   bool         mRenderMode = false;
87   std::vector<std::unique_ptr<LottieView>>   mViews;
88   std::vector<std::string>                   mResource;
89 };
90
91 static void
92 onExitCb(void *data)
93 {
94     LottieViewTest *view = (LottieViewTest *)data;
95     delete view;
96 }
97
98 int
99 main(int argc, char **argv)
100 {
101    EvasApp *app = new EvasApp(800, 800);
102    app->setup();
103
104    bool renderMode = true;
105    if (argc > 1) {
106        if (!strcmp(argv[1],"--disable-render"))
107            renderMode = false;
108    }
109    LottieViewTest *view = new LottieViewTest(app, renderMode);
110    view->buildResourceList();
111    view->show();
112
113    app->addExitCb(onExitCb, view);
114
115    app->run();
116    delete app;
117    return 0;
118 }
119
120
121
122
123