lottie/example: move resourcelist generation to evasapp class for reuse.
[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   void show() {
26     auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
27
28     if (resource.empty()) return;
29
30     int count = resource.size();
31     int colums = (int) ceil(sqrt(count));
32     int offset = 3;
33     int vw = (mApp->width() - (2 * offset * colums))/colums;
34     int vh = vw;
35     int posx = offset;
36     int posy = offset;
37     for(auto filePath : resource) {
38
39         std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
40        view->setFilePath(filePath.c_str());
41        view->setPos(posx, posy);
42        view->setSize(vw, vh);
43        view->show();
44        view->play();
45        view->loop(true);
46        //view->setRepeatMode(LottieView::RepeatMode::Reverse);
47
48        posx += vw+offset;
49        if ((mApp->width() - posx) < vw) {
50           posx = offset;
51           posy = posy + vh + offset;
52        }
53        mViews.push_back(std::move(view));
54     }
55
56   }
57
58 public:
59   EvasApp     *mApp;
60   bool         mRenderMode = false;
61   std::vector<std::unique_ptr<LottieView>>   mViews;
62 };
63
64 static void
65 onExitCb(void *data, void *extra)
66 {
67     LottieViewTest *view = (LottieViewTest *)data;
68     delete view;
69 }
70
71 int
72 main(int argc, char **argv)
73 {
74    EvasApp *app = new EvasApp(800, 800);
75    app->setup();
76
77    bool renderMode = true;
78    if (argc > 1) {
79        if (!strcmp(argv[1],"--disable-render"))
80            renderMode = false;
81    }
82    LottieViewTest *view = new LottieViewTest(app, renderMode);
83    view->show();
84
85    app->addExitCb(onExitCb, view);
86
87    app->run();
88    delete app;
89    return 0;
90 }
91
92
93
94
95