Added evas-lines example 81/241381/9
authorMichal Maciola <m.maciola@samsung.com>
Wed, 8 Jul 2020 10:40:26 +0000 (12:40 +0200)
committerHermet Park <chuneon.park@samsung.com>
Fri, 21 Aug 2020 01:14:38 +0000 (01:14 +0000)
Added welcome message with commands list

Ranamed to evas-vg-line

Change-Id: I730f8da9aaa5a54029a072c379463bce36ed1012

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

diff --git a/src/examples/evas/evas-vg-line.c b/src/examples/evas/evas-vg-line.c
new file mode 100644 (file)
index 0000000..fcb6209
--- /dev/null
@@ -0,0 +1,139 @@
+/**
+ * gcc -o evas-vg-line evas-vg-line.c `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;
+   Efl_VG *shape;
+};
+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,
+            void        *einfo)
+{
+   Evas_Event_Key_Down *ei = einfo;
+   Eina_Bool k = evas_object_key_grab(o, "q", 0, 0, EINA_TRUE);
+
+   if ( *ei->key == 'q' )
+     {
+       _on_delete(cnt.ee);
+     }
+
+   if ( *ei->key == 's' )
+     {
+        uint8_t x = rand() & 0xff;
+        uint8_t y = rand() & 0xff;
+        evas_vg_node_origin_set(cnt.shape, x, y);
+        printf("Evas object's origins was set to: %d, %d\n", x, y);
+     }
+
+   if ( *ei->key == 'a' )
+     {
+        uint32_t r = rand();
+        evas_vg_shape_stroke_color_set(cnt.shape, (r >> 16) & 0xff, (r >> 8) & 0xff, (r) & 0xff, 255);
+        printf("Evas object's random color was set\n");
+     }
+
+   if ( *ei->key == 'd' )
+     {
+        uint32_t w = rand() & (31);
+        evas_vg_shape_stroke_width_set(cnt.shape, w);
+        printf("Evas object's random stroke width set\n");
+     }
+}
+
+
+int
+main(void)
+{
+   Efl_VG *shape = NULL;
+   Efl_VG *container = NULL;
+
+   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);
+
+   cnt.shape = evas_vg_shape_add(container);
+   evas_vg_shape_append_move_to(cnt.shape, 20, 20);
+   evas_vg_shape_append_line_to(cnt.shape, 100, 20);
+   evas_vg_shape_stroke_color_set(cnt.shape, 255, 0, 0, 255);
+   evas_vg_shape_stroke_width_set(cnt.shape, 5);
+   evas_vg_shape_stroke_cap_set(cnt.shape, EFL_GFX_CAP_ROUND);
+
+   printf("Evas lines example\n");
+   printf("'a' to set random opaque color\n");
+   printf("'s' to set random origin\n");
+   printf("'d' to set random stroke width\n");
+   printf("'q' to quit\n");
+
+   evas_object_vg_root_node_set(cnt.vg, container);
+   ecore_main_loop_begin();
+   ecore_evas_shutdown();
+
+   return 0;
+}
index 157655e..a793be4 100644 (file)
@@ -44,6 +44,7 @@ examples = [
   'evas-vg-circles',
   'evas-vg-dash',
   'evas-vg-dup',
+  'evas-vg-line',
   'evas-vg-reset'
   'evas-vg-cubic'
   'evas-vg-gradient'