From 21c1a2d655dfef3e9de969d545604c0e5eb57060 Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Wed, 4 Aug 2021 11:57:42 +0200 Subject: [PATCH] evas vg: added evas-vg-json-multiple.c example Added evas-vg-json-multiple.c example for loading multiple lottie files Example shows the usage of efl_file_simple_load and eina_file_dir_list and is helpful testing json loader changes Change-Id: I11de3eb5ff774e1ab26d6db9cc7e0e1d809f793f --- src/examples/evas/evas-vg-json-multiple.c | 95 +++++++++++++++++++++++++++++++ src/examples/evas/meson.build | 1 + 2 files changed, 96 insertions(+) create mode 100644 src/examples/evas/evas-vg-json-multiple.c diff --git a/src/examples/evas/evas-vg-json-multiple.c b/src/examples/evas/evas-vg-json-multiple.c new file mode 100644 index 0000000..715782a --- /dev/null +++ b/src/examples/evas/evas-vg-json-multiple.c @@ -0,0 +1,95 @@ +/** + * Example of loading multiple lottie files using Evas_VG and eina_file_dir_list. + * + * @verbatim + * gcc -o evas_vg_json evas-vg-json-multiple.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl` + * @endverbatim + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef PACKAGE_EXAMPLES_DIR +#define PACKAGE_EXAMPLES_DIR "." +#endif + +#ifndef EFL_BETA_API_SUPPORT +#define EFL_BETA_API_SUPPORT +#endif + +#ifndef EFL_EO_API_SUPPORT +#define EFL_EO_API_SUPPORT +#endif + + +#include +#include +#include "evas-common.h" + +#define WIDTH 800 +#define HEIGHT 800 +#define NUM_PER_LINE 8 +#define SIZE (WIDTH/NUM_PER_LINE) + +static int count = 0; +void jsonDirCallback(const char* name, const char* path, void* data) +{ + //ignore if not json + const char *ext = name + strlen(name) - 4; + if (strcmp(ext, "json")) return; + + if (count >= WIDTH * HEIGHT / (SIZE * SIZE)) return; + + char buf[PATH_MAX]; + snprintf(buf, sizeof(buf), "%s/%s", path, name); + printf("file: %s\n", buf); + + Eo *evas = (Eo*) data; + Eo *vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas); + efl_file_simple_load(vg, buf, NULL); + efl_gfx_entity_size_set(vg, EINA_SIZE2D(100, 100)); + efl_gfx_entity_position_set(vg, EINA_POSITION2D((count % NUM_PER_LINE) * SIZE, (count / NUM_PER_LINE) * SIZE)); + efl_gfx_entity_visible_set(vg, EINA_TRUE); + count++; +} + +static void +_on_delete(Ecore_Evas *ee EINA_UNUSED) +{ + ecore_main_loop_quit(); +} + +int +main(void) +{ + if (!ecore_evas_init()) + return EXIT_FAILURE; + + Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); + if (!ee) + goto panic; + + ecore_evas_callback_delete_request_set(ee, _on_delete); + ecore_evas_show(ee); + + Eo *evas = ecore_evas_get(ee); + + Eo *bg = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas); + efl_gfx_entity_size_set(bg, EINA_SIZE2D(WIDTH, HEIGHT)); + efl_gfx_color_set(bg, 255, 255, 255, 255); + efl_gfx_entity_visible_set(bg, EINA_TRUE); + evas_object_focus_set(bg, EINA_TRUE); + + eina_file_dir_list(PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER, EINA_TRUE, jsonDirCallback, evas); + + ecore_main_loop_begin(); + ecore_evas_shutdown(); + + return 0; + +panic: + fprintf(stderr, "error: Requires at least one Evas engine built and linked" + " to ecore-evas for this example to run properly.\n"); + return -2; +} diff --git a/src/examples/evas/meson.build b/src/examples/evas/meson.build index 2b22676..8b0d67e 100644 --- a/src/examples/evas/meson.build +++ b/src/examples/evas/meson.build @@ -39,6 +39,7 @@ examples = [ 'evas-vg-batman', 'evas-vg-simple', 'evas-vg-json', + 'evas-vg-json-multiple', 'evas-vg-node', 'evas-vg-svg', 'efl-canvas-animation', -- 2.7.4