Swiftgram/example/lottieviewtest.cpp
subhransu mohanty a798a8429f lottie/example: fixed layout issue.
Change-Id: Id8795b63d13cca081d383f4e1303b990bdb723be
2018-07-16 12:20:30 +00:00

123 lines
2.6 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;
}
bool isJsonFile(const char *filename) {
const char *dot = strrchr(filename, '.');
if(!dot || dot == filename) return false;
return !strcmp(dot + 1, "json");
}
void buildResourceList() {
DIR *d;
struct dirent *dir;
d = opendir(DEMO_DIR);
if (d) {
while ((dir = readdir(d)) != NULL) {
if (isJsonFile(dir->d_name))
mResource.push_back(dir->d_name);
}
closedir(d);
}
}
void displayResourceList() {
for(auto i : mResource) {
std::string filePath = DEMO_DIR;
filePath +=i;
}
}
void show() {
if (mResource.empty()) return;
int count = mResource.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 i : mResource) {
std::string filePath = DEMO_DIR;
filePath +=i;
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;
std::vector<std::string> mResource;
};
static void
onExitCb(void *data)
{
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->buildResourceList();
view->show();
app->addExitCb(onExitCb, view);
app->run();
delete app;
return 0;
}