Swiftgram/example/lottieviewtest.cpp
subhransu mohanty ad76a433c7 lottie/example: move resourcelist generation to evasapp class for reuse.
Change-Id: If96683fe079a6484195b87c2fdd96c385114af12
2018-07-17 17:17:43 +09:00

96 lines
1.9 KiB
C++

#include "evasapp.h"
#include "lottieview.h"
#include<iostream>
#include <dirent.h>
#include <stdio.h>
using namespace std;
/*
* To check the frame rate with rendermode off run
* ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render
*
* To check the frame rate with render backend
* ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest
*
*/
class LottieViewTest
{
public:
LottieViewTest(EvasApp *app, bool renderMode) {
mApp = app;
mRenderMode = renderMode;
}
void show() {
auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
if (resource.empty()) return;
int count = resource.size();
int colums = (int) ceil(sqrt(count));
int offset = 3;
int vw = (mApp->width() - (2 * offset * colums))/colums;
int vh = vw;
int posx = offset;
int posy = offset;
for(auto filePath : resource) {
std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
view->setFilePath(filePath.c_str());
view->setPos(posx, posy);
view->setSize(vw, vh);
view->show();
view->play();
view->loop(true);
//view->setRepeatMode(LottieView::RepeatMode::Reverse);
posx += vw+offset;
if ((mApp->width() - posx) < vw) {
posx = offset;
posy = posy + vh + offset;
}
mViews.push_back(std::move(view));
}
}
public:
EvasApp *mApp;
bool mRenderMode = false;
std::vector<std::unique_ptr<LottieView>> mViews;
};
static void
onExitCb(void *data, void *extra)
{
LottieViewTest *view = (LottieViewTest *)data;
delete view;
}
int
main(int argc, char **argv)
{
EvasApp *app = new EvasApp(800, 800);
app->setup();
bool renderMode = true;
if (argc > 1) {
if (!strcmp(argv[1],"--disable-render"))
renderMode = false;
}
LottieViewTest *view = new LottieViewTest(app, renderMode);
view->show();
app->addExitCb(onExitCb, view);
app->run();
delete app;
return 0;
}