From 8f037082b08fca03f4cd019945e02e3a487676a1 Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Thu, 15 Apr 2021 09:55:09 +0200 Subject: [PATCH] evas vg: evas-vg-svg.c example The example for testing .svg files loading Change-Id: Iba993d04a8ad089d2e52b0fb0836eb3f53d32ec5 --- src/examples/evas/evas-vg-svg.c | 107 ++++ src/examples/evas/meson.build | 1 + src/examples/evas/resources/vg/tiger.svg | 829 +++++++++++++++++++++++++++++++ 3 files changed, 937 insertions(+) create mode 100644 src/examples/evas/evas-vg-svg.c create mode 100644 src/examples/evas/resources/vg/tiger.svg diff --git a/src/examples/evas/evas-vg-svg.c b/src/examples/evas/evas-vg-svg.c new file mode 100644 index 0000000..cbe2893 --- /dev/null +++ b/src/examples/evas/evas-vg-svg.c @@ -0,0 +1,107 @@ +/** + * Example of SVG using Evas_VG. + * + * This example show load SVG files. + * + * @verbatim + * gcc -o evas_vg_svg evas-vg-svg.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 400 +#define HEIGHT 600 + +static Eo *vg; + +static void +_on_keydown(void *data EINA_UNUSED, + Evas *evas EINA_UNUSED, + Evas_Object *o EINA_UNUSED, + void *einfo) +{ + Evas_Event_Key_Down *ev = einfo; + + if (strcmp(ev->key, "Right") == 0) + { + Eina_Position2D pos = efl_gfx_entity_position_get(vg); + pos.x += 50; + efl_gfx_entity_position_set(vg, pos); + printf("Moved right\n"); + } + + if (strcmp(ev->key, "Left") == 0) + { + Eina_Position2D pos = efl_gfx_entity_position_get(vg); + pos.x -= 50; + efl_gfx_entity_position_set(vg, pos); + printf("Moved left\n"); + } +} + +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); + evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); + + char filename[PATH_MAX]; + snprintf(filename, sizeof(filename), "%s/tiger.svg", PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER); + + vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas); + efl_file_simple_load(vg, filename, NULL); + efl_gfx_entity_size_set(vg, EINA_SIZE2D(WIDTH, HEIGHT)); + efl_gfx_entity_visible_set(vg, EINA_TRUE); + + 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 f021ac6..4e1c797 100644 --- a/src/examples/evas/meson.build +++ b/src/examples/evas/meson.build @@ -40,6 +40,7 @@ examples = [ 'evas-vg-simple', 'evas-vg-json', 'evas-vg-node', + 'evas-vg-svg', 'efl-canvas-animation', 'efl-canvas-vg-simple', 'evas-vg-circles', diff --git a/src/examples/evas/resources/vg/tiger.svg b/src/examples/evas/resources/vg/tiger.svg new file mode 100644 index 0000000..a59da8d --- /dev/null +++ b/src/examples/evas/resources/vg/tiger.svg @@ -0,0 +1,829 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.7.4