mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 05:26:48 +00:00
lottie/example: move resourcelist generation to evasapp class for reuse.
Change-Id: If96683fe079a6484195b87c2fdd96c385114af12
This commit is contained in:
parent
0347a9677f
commit
ad76a433c7
@ -1,4 +1,5 @@
|
|||||||
#include "evasapp.h"
|
#include "evasapp.h"
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_on_resize(Ecore_Evas *ee)
|
_on_resize(Ecore_Evas *ee)
|
||||||
@ -81,3 +82,27 @@ void EvasApp::run()
|
|||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
ecore_evas_shutdown();
|
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<std::string>
|
||||||
|
EvasApp::jsonFiles(const std::string &dirName, bool recurse)
|
||||||
|
{
|
||||||
|
DIR *d;
|
||||||
|
struct dirent *dir;
|
||||||
|
std::vector<std::string> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,9 @@
|
|||||||
#include <Ecore.h>
|
#include <Ecore.h>
|
||||||
#include <Ecore_Evas.h>
|
#include <Ecore_Evas.h>
|
||||||
#include <Ecore_Input.h>
|
#include <Ecore_Input.h>
|
||||||
|
#include<vector>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
|
||||||
typedef void (*appCb)(void *userData, void *extra);
|
typedef void (*appCb)(void *userData, void *extra);
|
||||||
class EvasApp
|
class EvasApp
|
||||||
@ -32,6 +35,7 @@ public:
|
|||||||
void addExitCb(appCb exitcb, void *data) {mExitCb = exitcb; mExitData = data;}
|
void addExitCb(appCb exitcb, void *data) {mExitCb = exitcb; mExitData = data;}
|
||||||
void addResizeCb(appCb resizecb, void *data) {mResizeCb = resizecb; mResizeData = data;}
|
void addResizeCb(appCb resizecb, void *data) {mResizeCb = resizecb; mResizeData = data;}
|
||||||
void addKeyCb(appCb keycb, void *data) {mKeyCb = keycb; mKeyData = data;}
|
void addKeyCb(appCb keycb, void *data) {mKeyCb = keycb; mKeyData = data;}
|
||||||
|
static std::vector<std::string> jsonFiles(const std::string &dir, bool recurse=false);
|
||||||
public:
|
public:
|
||||||
int mw;
|
int mw;
|
||||||
int mh;
|
int mh;
|
||||||
|
|||||||
@ -22,46 +22,21 @@ public:
|
|||||||
mRenderMode = renderMode;
|
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() {
|
void show() {
|
||||||
if (mResource.empty()) return;
|
auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
|
||||||
|
|
||||||
int count = mResource.size();
|
if (resource.empty()) return;
|
||||||
|
|
||||||
|
int count = resource.size();
|
||||||
int colums = (int) ceil(sqrt(count));
|
int colums = (int) ceil(sqrt(count));
|
||||||
int offset = 3;
|
int offset = 3;
|
||||||
int vw = (mApp->width() - (2 * offset * colums))/colums;
|
int vw = (mApp->width() - (2 * offset * colums))/colums;
|
||||||
int vh = vw;
|
int vh = vw;
|
||||||
int posx = offset;
|
int posx = offset;
|
||||||
int posy = offset;
|
int posy = offset;
|
||||||
for(auto i : mResource) {
|
for(auto filePath : resource) {
|
||||||
std::string filePath = DEMO_DIR;
|
|
||||||
filePath +=i;
|
|
||||||
|
|
||||||
std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
|
std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
|
||||||
view->setFilePath(filePath.c_str());
|
view->setFilePath(filePath.c_str());
|
||||||
view->setPos(posx, posy);
|
view->setPos(posx, posy);
|
||||||
view->setSize(vw, vh);
|
view->setSize(vw, vh);
|
||||||
@ -84,7 +59,6 @@ public:
|
|||||||
EvasApp *mApp;
|
EvasApp *mApp;
|
||||||
bool mRenderMode = false;
|
bool mRenderMode = false;
|
||||||
std::vector<std::unique_ptr<LottieView>> mViews;
|
std::vector<std::unique_ptr<LottieView>> mViews;
|
||||||
std::vector<std::string> mResource;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -106,7 +80,6 @@ main(int argc, char **argv)
|
|||||||
renderMode = false;
|
renderMode = false;
|
||||||
}
|
}
|
||||||
LottieViewTest *view = new LottieViewTest(app, renderMode);
|
LottieViewTest *view = new LottieViewTest(app, renderMode);
|
||||||
view->buildResourceList();
|
|
||||||
view->show();
|
view->show();
|
||||||
|
|
||||||
app->addExitCb(onExitCb, view);
|
app->addExitCb(onExitCb, view);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user