evas/canvas/vg: added shape duplication example 68/240768/3
authorMateusz Palkowski <m.palkowski@AMDN2309VM01.digital.local>
Fri, 24 Jul 2020 08:19:51 +0000 (10:19 +0200)
committerHermet Park <chuneon.park@samsung.com>
Fri, 14 Aug 2020 02:54:09 +0000 (02:54 +0000)
Change-Id: I932d6e21631779cf182bdb47f4fbb35788a5bd08

src/examples/evas/evas-vg-dup.c [new file with mode: 0644]
src/examples/evas/meson.build

diff --git a/src/examples/evas/evas-vg-dup.c b/src/examples/evas/evas-vg-dup.c
new file mode 100644 (file)
index 0000000..797aa0e
--- /dev/null
@@ -0,0 +1,124 @@
+/**
+ * gcc evas-dup.c -o evas-dup `pkg-config --libs --cflags ecore ecore-evas`
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#define PACKAGE_EXAMPLES_DIR "."
+#endif
+
+#define WIDTH  400
+#define HEIGHT 400
+
+#include <Ecore.h>
+#include <Ecore_Evas.h>
+
+struct content
+{
+   Ecore_Evas  *ee;
+   Evas        *ev;
+   Evas_Object *bg;
+   Evas_Object *vg;
+};
+
+static struct  content cnt;
+
+static void
+_on_delete(Ecore_Evas *ee EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+}
+
+static void
+_canvas_resize_cb(Ecore_Evas *ee)
+{
+   int w, h;
+
+   ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
+   evas_object_resize(cnt.bg, w, h);
+   evas_object_resize(cnt.vg, w, h);
+}
+
+static void
+_on_keydown(void *data EINA_UNUSED,
+            Evas *evas EINA_UNUSED,
+            Evas_Object *o EINA_UNUSED,
+            void *event_info)
+{
+    Evas_Event_Key_Down *ei = event_info;
+
+    if (!strcmp(ei->key, "q"))
+      _on_delete(cnt.ee);
+}
+
+int
+main(void)
+{
+   Efl_VG *shape = NULL;
+   Efl_VG *new_shape = NULL;
+   Efl_VG *container = NULL;
+   unsigned int len = 2;
+   unsigned int len1 = 1;
+   Evas_Vg_Dash dash[len], dash1[len1];
+
+   if (!ecore_evas_init())
+      return EXIT_FAILURE;
+
+   cnt.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
+   if (!cnt.ee)
+     {
+        ecore_evas_shutdown();
+        return -1;
+     }
+
+   ecore_evas_callback_delete_request_set(cnt.ee, _on_delete);
+   ecore_evas_callback_resize_set(cnt.ee, _canvas_resize_cb);
+   ecore_evas_show(cnt.ee);
+
+   cnt.ev = ecore_evas_get(cnt.ee);
+   cnt.bg = evas_object_rectangle_add(cnt.ev);
+   evas_object_color_set(cnt.bg, 255, 255, 255, 255);
+   evas_object_focus_set(cnt.bg, EINA_TRUE);
+   evas_object_show(cnt.bg);
+   evas_object_event_callback_add(cnt.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
+   cnt.vg = evas_object_vg_add(cnt.ev);
+   evas_object_show(cnt.vg);
+   _canvas_resize_cb(cnt.ee);
+   container = evas_vg_container_add(cnt.vg);
+
+   shape = evas_vg_shape_add(container);
+   evas_vg_shape_append_rect(shape, 50, 50, 100 , 100, 10, 10);
+   evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
+   evas_vg_shape_stroke_width_set(shape, 5);
+   dash[0].length = 5;
+   dash[0].gap = 20;
+   dash[1].length = 6;
+   dash[1].gap = 12;
+   evas_vg_shape_stroke_dash_set(shape, dash, len);
+
+   new_shape = evas_vg_shape_add(container);
+   evas_vg_shape_dup(new_shape, shape);
+   evas_vg_shape_stroke_color_set(new_shape, 0, 0, 0, 0);
+   evas_vg_node_color_set(new_shape, 0, 0, 100, 100);
+   evas_vg_node_origin_set(new_shape, 200, 150);
+
+   shape = evas_vg_shape_add(container);
+   evas_vg_shape_append_circle(shape, 300, 300, 50);
+   evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
+   evas_vg_node_color_set(shape, 0, 100, 100, 100);
+   evas_vg_shape_stroke_width_set(shape, 6);
+   dash1[0].length = 2;
+   dash1[0].gap = 5;
+   evas_vg_shape_stroke_dash_set(shape, dash1, len1);
+
+   new_shape = evas_vg_shape_add(container);
+   evas_vg_shape_dup(new_shape, shape);
+   evas_vg_shape_stroke_color_set(new_shape, 50, 50, 50, 255);
+   evas_vg_shape_stroke_width_set(new_shape, 10);
+
+   evas_object_vg_root_node_set(cnt.vg, container);
+   ecore_main_loop_begin();
+   ecore_evas_shutdown();
+   return 0;
+}
\ No newline at end of file
index 34ea87a..6127394 100644 (file)
@@ -34,7 +34,8 @@ examples = [
   'efl-canvas-animation',
   'efl-canvas-vg-simple',
   'evas-vg-circles',
-  'evas-vg-dash'
+  'evas-vg-dash',
+  'evas-vg-dup'
 ]
 
 foreach example : examples