lottie/example : added segmented animation support in lottieview
[platform/core/uifw/lottie-player.git] / example / demo.cpp
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
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.
8  * 
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.
13  * 
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
17  */
18
19 #include "evasapp.h"
20 #include "lottieview.h"
21 #include<iostream>
22 #include <stdio.h>
23 #include <fstream>
24 #include <sstream>
25 using namespace std;
26
27 static void
28 onExitCb(void *data, void *extra)
29 {
30     LottieView *view = (LottieView *)data;
31     delete view;
32 }
33
34 static void
35 onRenderPreCb(void *data, void *extra)
36 {
37     LottieView *view = (LottieView *)data;
38     view->render();
39 }
40
41 int
42 main(void)
43 {
44    EvasApp *app = new EvasApp(800, 800);
45    app->setup();
46
47    std::string filePath = DEMO_DIR;
48    filePath +="mask.json";
49
50    std::ifstream f;
51    f.open(filePath);
52    std::stringstream buf;
53    buf << f.rdbuf();
54    f.close();
55
56    LottieView *view = new LottieView(app->evas());
57    view->loadFromData(buf.str().data(), "test_key");
58    view->setPos(0, 0);
59    view->setSize(800, 800);
60    view->show();
61    view->setMinProgress(0.5);
62    view->setMaxProgress(0.0);
63    view->play();
64    view->loop(true);
65    view->setRepeatMode(LottieView::RepeatMode::Reverse);
66
67    app->addExitCb(onExitCb, view);
68    app->addRenderPreCb(onRenderPreCb, view);
69    app->run();
70    delete app;
71    return 0;
72 }
73
74
75
76
77