lottie/example: updated evasapp to handle keyevent propagation.
[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 = (int) ceil(sqrt(count));
55     int offset = 3;
56     int vw = (mApp->width() - (2 * offset * colums))/colums;
57     int vh = vw;
58     int posx = offset;
59     int posy = offset;
60     for(auto i : mResource) {
61        std::string filePath = DEMO_DIR;
62        filePath +=i;
63
64        std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
65        view->setFilePath(filePath.c_str());
66        view->setPos(posx, posy);
67        view->setSize(vw, vh);
68        view->show();
69        view->play();
70        view->loop(true);
71        //view->setRepeatMode(LottieView::RepeatMode::Reverse);
72
73        posx += vw+offset;
74        if ((mApp->width() - posx) < vw) {
75           posx = offset;
76           posy = posy + vh + offset;
77        }
78        mViews.push_back(std::move(view));
79     }
80
81   }
82
83 public:
84   EvasApp     *mApp;
85   bool         mRenderMode = false;
86   std::vector<std::unique_ptr<LottieView>>   mViews;
87   std::vector<std::string>                   mResource;
88 };
89
90 static void
91 onExitCb(void *data, void *extra)
92 {
93     LottieViewTest *view = (LottieViewTest *)data;
94     delete view;
95 }
96
97 int
98 main(int argc, char **argv)
99 {
100    EvasApp *app = new EvasApp(800, 800);
101    app->setup();
102
103    bool renderMode = true;
104    if (argc > 1) {
105        if (!strcmp(argv[1],"--disable-render"))
106            renderMode = false;
107    }
108    LottieViewTest *view = new LottieViewTest(app, renderMode);
109    view->buildResourceList();
110    view->show();
111
112    app->addExitCb(onExitCb, view);
113
114    app->run();
115    delete app;
116    return 0;
117 }
118
119
120
121
122