#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);
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
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();