evas/canvas/vg: added dash example 63/240763/3
authorMateusz Palkowski <m.palkowski@AMDN2309VM01.digital.local>
Thu, 23 Jul 2020 08:59:27 +0000 (10:59 +0200)
committerHermet Park <chuneon.park@samsung.com>
Fri, 14 Aug 2020 02:52:35 +0000 (02:52 +0000)
Change-Id: Id2d2267629bf1c69ce847fa811b8e6dc9de45114

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

diff --git a/src/examples/evas/evas-vg-dash.c b/src/examples/evas/evas-vg-dash.c
new file mode 100644 (file)
index 0000000..652ce72
--- /dev/null
@@ -0,0 +1,136 @@
+/**
+ * gcc evas-dash.c -o evas-dash `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 *container = NULL;
+
+   unsigned int i;
+   unsigned int len = 1;
+   unsigned int len1 = 2;
+   unsigned int len2 = 3;
+   unsigned int len3;
+
+   Evas_Vg_Dash dash[len], dash1[len1], dash2[len2];
+   const Evas_Vg_Dash *dash3;
+
+   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, 4, 4);
+   evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
+   evas_vg_shape_stroke_width_set(shape, 6);
+   dash[0].length = 5;
+   dash[0].gap = 20;
+   evas_vg_shape_stroke_dash_set(shape, dash, len);
+
+   shape = evas_vg_shape_add(container);
+   evas_vg_shape_append_move_to(shape, 300, 300);
+   evas_vg_shape_append_line_to(shape, 350, 400);
+   evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
+   evas_vg_shape_stroke_width_set(shape, 5);
+   dash1[0].length = 5;
+   dash1[0].gap = 10;
+   dash1[1].length = 6;
+   dash1[1].gap = 12;
+   evas_vg_shape_stroke_cap_set(shape, EFL_GFX_CAP_ROUND);
+   evas_vg_shape_stroke_dash_set(shape, dash1, len1);
+
+   shape = evas_vg_shape_add(container);
+   evas_vg_shape_append_circle(shape, 300, 100, 50);
+   evas_vg_shape_stroke_color_set(shape, 0, 0, 255, 255);
+   evas_vg_shape_stroke_width_set(shape, 2);
+   dash2[0].length = 5;
+   dash2[0].gap = 10;
+   dash2[1].length = 50;
+   dash2[1].gap = 40;
+   dash2[2].length = 10;
+   dash2[2].gap = 15;
+   evas_vg_shape_stroke_dash_set(shape, dash2, len2);
+
+   evas_vg_shape_stroke_dash_get(shape, &dash3, &len3);
+   for (i = 0; i < len3; i++)
+      printf("%f %f ", dash3[i].length, dash3[i].gap);
+   printf("\n");
+
+   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 30bbd91..34ea87a 100644 (file)
@@ -33,7 +33,8 @@ examples = [
   'evas-vg-json',
   'efl-canvas-animation',
   'efl-canvas-vg-simple',
-  'evas-vg-circles'
+  'evas-vg-circles',
+  'evas-vg-dash'
 ]
 
 foreach example : examples