added example for evas_vg_shape_current_ctrl_get() 58/240758/6
authorp.kalota <p.kalota@samsung.com>
Mon, 27 Jul 2020 13:07:56 +0000 (15:07 +0200)
committerHermet Park <chuneon.park@samsung.com>
Tue, 18 Aug 2020 08:35:54 +0000 (08:35 +0000)
Change-Id: Ie6710a2ff58faea84d0686a26a5e41aa38b3692c

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

diff --git a/src/examples/evas/evas-vg-current.c b/src/examples/evas/evas-vg-current.c
new file mode 100644 (file)
index 0000000..fc17465
--- /dev/null
@@ -0,0 +1,140 @@
+/**
+ * gcc -o evas-vg-current evas-vg-current.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;
+};
+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;
+   if (!strcmp(ei->key, "q"))
+      _on_delete(cnt.ee);
+}
+
+static int
+_init_win()
+{
+   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, 0, 0, 0, 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);
+   return 0;
+}
+
+static void
+_print_points(Efl_VG *shape, const char *cmd_name)
+{
+   double curr_ctrl_x = 0, curr_ctlr_y = 0;
+   double curr_x = 0, curr_y = 0;
+   evas_vg_shape_current_ctrl_get(shape, &curr_ctrl_x, &curr_ctlr_y);
+   evas_vg_shape_current_get(shape, &curr_x, &curr_y);
+
+   printf("%-6s     (%6.1lf, %6.1lf)    (%6.1f, %6.1lf)\n", cmd_name, curr_x, curr_y,
+                                                             curr_ctrl_x, curr_ctlr_y);
+}
+
+static void
+_draw_commands(Efl_VG *container)
+{
+   Efl_VG *shape = evas_vg_shape_add(container);
+
+   printf("%-6s    %-16s    %s\n\n", "Command", "Current Point", "Current Control Point");
+
+   evas_vg_shape_append_rect(shape, 200, 200, 100, 100, 0, 0);
+   _print_points(shape, "Rect");
+   evas_vg_shape_append_circle(shape, 100, 100, 50);
+   _print_points(shape, "Circle");
+   evas_vg_shape_append_line_to(shape, 100, 300);
+   _print_points(shape, "Line");
+   evas_vg_shape_append_cubic_to(shape, 350,200, 100,400, 350,300);
+   _print_points(shape, "Cubic");
+   evas_vg_shape_append_close(shape);
+   _print_points(shape, "Close");
+
+   evas_vg_shape_stroke_width_set(shape, 5);
+   evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
+}
+
+static void
+_init_vg()
+{
+   Efl_VG *container;
+   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);
+   _draw_commands(container);
+   evas_object_vg_root_node_set(cnt.vg, container);
+}
+
+int
+main(void)
+{
+   int err = _init_win();
+   if (err==EXIT_FAILURE || err==-1)
+      return err;
+
+   _init_vg();
+
+   ecore_main_loop_begin();
+   ecore_evas_shutdown();
+
+   return err;
+}
\ No newline at end of file
index 1d9b95e..f78600d 100644 (file)
@@ -30,6 +30,7 @@ examples = [
   'evas-text',
   'evas-transparent',
   'evas-vg-cmd-equal',
+  'evas-vg-current',
   'evas-vg-interpolation',
   'evas-vg-star-path',
   'evas-vg-batman',