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
24 _on_resize(Ecore_Evas *ee)
26 EvasApp *app = (EvasApp *)ecore_evas_data_get(ee, "app");
28 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
31 app->mResizeCb(app->mResizeData, nullptr);
35 _on_delete(Ecore_Evas *ee)
37 EvasApp *app = (EvasApp *)ecore_evas_data_get(ee, "app");
39 app->mExitCb(app->mExitData, nullptr);
41 ecore_main_loop_quit();
46 on_key_down(void *data, int type, void *event)
48 Ecore_Event_Key *keyData = (Ecore_Event_Key *)event;
50 EvasApp *app = (EvasApp *) data;
51 if (app && app->mKeyCb)
52 app->mKeyCb(app->mKeyData, (void *)keyData->key);
58 on_pre_render(Ecore_Evas *ee)
60 EvasApp *app = (EvasApp *)ecore_evas_data_get(ee, "app");
61 if (app->mRenderPreCb)
62 app->mRenderPreCb(app->mRenderPreData, nullptr);
66 on_post_render(Ecore_Evas *ee)
68 EvasApp *app = (EvasApp *)ecore_evas_data_get(ee, "app");
69 if (app && app->mRenderPostCb)
70 app->mRenderPostCb(app->mRenderPostData, nullptr);
73 EvasApp::EvasApp(int w, int h)
75 if (!ecore_evas_init())
79 //setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
80 mEcoreEvas = ecore_evas_new(NULL, 0, 0, mw, mh, NULL);
81 if (!mEcoreEvas) return;
87 ecore_evas_data_set(mEcoreEvas, "app", this);
88 ecore_evas_callback_resize_set(mEcoreEvas, _on_resize);
89 ecore_evas_callback_delete_request_set(mEcoreEvas, _on_delete);
90 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, on_key_down, this);
91 ecore_evas_callback_pre_render_set(mEcoreEvas, on_pre_render);
92 ecore_evas_callback_post_render_set(mEcoreEvas, on_post_render);
94 ecore_evas_show(mEcoreEvas);
95 mEvas = ecore_evas_get(mEcoreEvas);
96 mBackground = evas_object_rectangle_add(mEvas);
97 evas_object_color_set(mBackground, 70, 70, 70, 255);
98 evas_object_show(mBackground);
102 EvasApp::resize(int w, int h)
104 evas_object_resize(mBackground, w, h);
112 ecore_main_loop_begin();
113 ecore_evas_shutdown();
116 static bool isJsonFile(const char *filename) {
117 const char *dot = strrchr(filename, '.');
118 if(!dot || dot == filename) return false;
119 return !strcmp(dot + 1, "json");
122 std::vector<std::string>
123 EvasApp::jsonFiles(const std::string &dirName, bool recurse)
127 std::vector<std::string> result;
128 d = opendir(dirName.c_str());
130 while ((dir = readdir(d)) != NULL) {
131 if (isJsonFile(dir->d_name))
132 result.push_back(dirName + dir->d_name);
137 std::sort(result.begin(), result.end(), [](auto & a, auto &b){return a < b;});