From ad76a433c7c3ca313681bab1caa71422fe9a4242 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Tue, 17 Jul 2018 17:17:43 +0900 Subject: [PATCH] lottie/example: move resourcelist generation to evasapp class for reuse. Change-Id: If96683fe079a6484195b87c2fdd96c385114af12 --- example/evasapp.cpp | 25 +++++++++++++++++++++++++ example/evasapp.h | 4 ++++ example/lottieviewtest.cpp | 39 ++++++--------------------------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/example/evasapp.cpp b/example/evasapp.cpp index 1463a61..2a1552f 100644 --- a/example/evasapp.cpp +++ b/example/evasapp.cpp @@ -1,4 +1,5 @@ #include "evasapp.h" +#include static void _on_resize(Ecore_Evas *ee) @@ -81,3 +82,27 @@ void EvasApp::run() ecore_main_loop_begin(); ecore_evas_shutdown(); } + +static bool isJsonFile(const char *filename) { + const char *dot = strrchr(filename, '.'); + if(!dot || dot == filename) return false; + return !strcmp(dot + 1, "json"); +} + +std::vector +EvasApp::jsonFiles(const std::string &dirName, bool recurse) +{ + DIR *d; + struct dirent *dir; + std::vector result; + d = opendir(dirName.c_str()); + if (d) { + while ((dir = readdir(d)) != NULL) { + if (isJsonFile(dir->d_name)) + result.push_back(dirName + dir->d_name); + } + closedir(d); + } + return result; +} + diff --git a/example/evasapp.h b/example/evasapp.h index ddb9615..9ae027e 100644 --- a/example/evasapp.h +++ b/example/evasapp.h @@ -15,6 +15,9 @@ #include #include #include +#include +#include + typedef void (*appCb)(void *userData, void *extra); class EvasApp @@ -32,6 +35,7 @@ public: void addExitCb(appCb exitcb, void *data) {mExitCb = exitcb; mExitData = data;} void addResizeCb(appCb resizecb, void *data) {mResizeCb = resizecb; mResizeData = data;} void addKeyCb(appCb keycb, void *data) {mKeyCb = keycb; mKeyData = data;} + static std::vector jsonFiles(const std::string &dir, bool recurse=false); public: int mw; int mh; diff --git a/example/lottieviewtest.cpp b/example/lottieviewtest.cpp index 6fc6e94..6c27f40 100644 --- a/example/lottieviewtest.cpp +++ b/example/lottieviewtest.cpp @@ -22,46 +22,21 @@ public: 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; + auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR)); + + if (resource.empty()) return; - int count = mResource.size(); + 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 i : mResource) { - std::string filePath = DEMO_DIR; - filePath +=i; + for(auto filePath : resource) { - std::unique_ptr view(new LottieView(mApp->evas(), mRenderMode)); + std::unique_ptr view(new LottieView(mApp->evas(), mRenderMode)); view->setFilePath(filePath.c_str()); view->setPos(posx, posy); view->setSize(vw, vh); @@ -84,7 +59,6 @@ public: EvasApp *mApp; bool mRenderMode = false; std::vector> mViews; - std::vector mResource; }; static void @@ -106,7 +80,6 @@ main(int argc, char **argv) renderMode = false; } LottieViewTest *view = new LottieViewTest(app, renderMode); - view->buildResourceList(); view->show(); app->addExitCb(onExitCb, view); -- 2.7.4