evas examples: improved evas-vg-json-multiple.c example 65/267865/2
authorMichal Maciola <m.maciola@samsung.com>
Fri, 10 Dec 2021 15:47:28 +0000 (16:47 +0100)
committerChun <jykeon@samsung.com>
Mon, 17 Jan 2022 01:24:00 +0000 (01:24 +0000)
Change-Id: I6ebf64ca1b8609869db97d3a6053cc44ba70da18

src/examples/evas/evas-vg-json-multiple.c

index 715782a..3ac8403 100644 (file)
 #include <Ecore_Evas.h>
 #include "evas-common.h"
 
-#define WIDTH  800
-#define HEIGHT 800
-#define NUM_PER_LINE 8
-#define SIZE (WIDTH/NUM_PER_LINE)
+#define IMAGE_SIZE 100
+#define COLUMNS 8
+#define ROWS    8
+#define WIDTH  (COLUMNS * IMAGE_SIZE)
+#define HEIGHT (ROWS * IMAGE_SIZE)
+#define AUTOPLAY 1
+
+Eo *bg;
+Eo *anim;
+static Eo *gvg[COLUMNS * ROWS] = {};
+static unsigned int count = 0;
+
+static void
+_running_cb(void *data EINA_UNUSED, const Efl_Event *event)
+{
+   double progress = *((double*)event->info);
+   unsigned int i;
+
+   for (i = 0; i < count; i++)
+     {
+        if (!gvg[i]) continue;
+        double frameCnt = (double) (efl_gfx_frame_controller_frame_count_get(gvg[i]) - 1);
+        int frame = (int) (frameCnt * progress);
+        efl_gfx_frame_controller_frame_set(gvg[i], frame);
+     }
+}
+
+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, "space") == 0) {
+      double animation_progress = efl_canvas_object_animation_progress_get(bg);
+      if (animation_progress < 0)
+        {
+         printf("Animation started\n");
+         efl_canvas_object_animation_start(bg, anim, 1.0, 0.0);
+        }
+      else
+        {
+         printf("Animation stopped\n");
+         efl_canvas_object_animation_stop(bg);
+        }
+   }
+}
 
-static int count = 0;
 void jsonDirCallback(const char* name, const char* path, void* data)
 {
     //ignore if not json
     const char *ext = name + strlen(name) - 4;
     if (strcmp(ext, "json")) return;
 
-    if (count >= WIDTH * HEIGHT / (SIZE * SIZE)) return;
+    if (count >= COLUMNS * ROWS) return;
 
     char buf[PATH_MAX];
     snprintf(buf, sizeof(buf), "%s/%s", path, name);
@@ -48,10 +92,10 @@ void jsonDirCallback(const char* name, const char* path, void* data)
     Eo *evas = (Eo*) data;
     Eo *vg = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas);
     efl_file_simple_load(vg, buf, NULL);
-    efl_gfx_entity_size_set(vg, EINA_SIZE2D(100, 100));
-    efl_gfx_entity_position_set(vg, EINA_POSITION2D((count % NUM_PER_LINE) * SIZE, (count / NUM_PER_LINE) * SIZE));
+    efl_gfx_entity_size_set(vg, EINA_SIZE2D(IMAGE_SIZE, IMAGE_SIZE));
+    efl_gfx_entity_position_set(vg, EINA_POSITION2D((count % COLUMNS) * IMAGE_SIZE, (count / COLUMNS) * IMAGE_SIZE));
     efl_gfx_entity_visible_set(vg, EINA_TRUE);
-    count++;
+    gvg[count++] = vg;
 }
 
 static void
@@ -75,14 +119,22 @@ main(void)
 
    Eo *evas = ecore_evas_get(ee);
 
-   Eo *bg = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
+   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);
 
    eina_file_dir_list(PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER, EINA_TRUE, jsonDirCallback, evas);
 
+   anim = efl_add(EFL_CANVAS_ANIMATION_CLASS, evas);
+   efl_animation_duration_set(anim, 10.0);
+   efl_event_callback_add(bg, EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, _running_cb, NULL);
+#ifdef AUTOPLAY
+   efl_canvas_object_animation_start(bg, anim, 1.0, 0.0);
+#endif // AUTOPLAY
+
    ecore_main_loop_begin();
    ecore_evas_shutdown();