2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
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.
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.
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
20 #include "lottieview.h"
28 UxSampleTest(EvasApp *app, bool renderMode) {
30 mRenderMode = renderMode;
31 mResourceList = EvasApp::jsonFiles(std::string(DEMO_DIR) + "UXSample_1920x1080/");
32 mRepeatMode = LottieView::RepeatMode::Restart;
36 if (mResourceList.empty()) return;
39 mCurIndex = mResourceList.size() - 1;
44 if (mResourceList.empty()) return;
47 if (mCurIndex >= int(mResourceList.size()))
54 mView->setSize(mApp->width(), mApp->height());
60 mView = std::make_unique<LottieView>(mApp->evas(), mRenderMode);
61 mView->setFilePath(mResourceList[mCurIndex].c_str());
63 mView->setSize(mApp->width(), mApp->height());
67 mView->setRepeatMode(mRepeatMode);
72 bool mRenderMode = false;
74 std::vector<std::string> mResourceList;
75 std::unique_ptr<LottieView> mView;
76 LottieView::RepeatMode mRepeatMode;
80 onExitCb(void *data, void *extra)
82 UxSampleTest *view = (UxSampleTest *)data;
87 onKeyCb(void *data, void *extra)
89 UxSampleTest *view = (UxSampleTest *)data;
90 char *keyname = (char *)extra;
92 if (!strcmp(keyname, "Right") || !strcmp(keyname, "n")) {
94 } else if (!strcmp(keyname, "Left") || !strcmp(keyname, "p")) {
96 } else if (!strcmp(keyname,"r")) {
97 if (view->mRepeatMode == LottieView::RepeatMode::Restart) {
98 view->mRepeatMode = LottieView::RepeatMode::Reverse;
100 view->mRepeatMode = LottieView::RepeatMode::Restart;
102 view->mView->setRepeatMode(view->mRepeatMode);
107 onRenderPreCb(void *data, void *extra)
109 UxSampleTest *view = (UxSampleTest *)data;
111 view->mView->render();
115 onResizeCb(void *data, void *extra)
117 UxSampleTest *view = (UxSampleTest *)data;
122 main(int argc, char **argv)
124 EvasApp *app = new EvasApp(800, 800);
127 bool renderMode = true;
129 if (!strcmp(argv[1],"--disable-render"))
132 UxSampleTest *view = new UxSampleTest(app, renderMode);
135 app->addExitCb(onExitCb, view);
136 app->addKeyCb(onKeyCb, view);
137 app->addRenderPreCb(onRenderPreCb, view);
138 app->addResizeCb(onResizeCb, view);