tasn pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=edc3ba59a5b1fcf1405b3a0badaa48c0e837903e

commit edc3ba59a5b1fcf1405b3a0badaa48c0e837903e
Author: Tom Hacohen <t...@stosb.com>
Date:   Thu Apr 30 13:58:26 2015 +0100

    Win: Make animator,tick signal actually work.
    
    This commit also updated one of the elementary test to show
    the new one of doing it.
    
    This lets users of the API just add a callback and automatically
    get animation ticks. It's done per window, because update rate
    may be different for different windows (think different screens).
---
 src/bin/test_anim.c | 18 ++--------------
 src/lib/elm_win.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/src/bin/test_anim.c b/src/bin/test_anim.c
index 820851c..2eb07d6 100644
--- a/src/bin/test_anim.c
+++ b/src/bin/test_anim.c
@@ -10,19 +10,9 @@ static const char *names[] =
      "bub3", "sh3",
 };
 
-static void
-_del(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void 
*event_info EINA_UNUSED)
-{
-   Evas_Object *win = data;
-   Ecore_Animator *ani = evas_object_data_get(win, "animator");
-
-   ecore_animator_del(ani);
-}
-
 static Eina_Bool
-anim(void *data)
+_anim_tick(void *data EINA_UNUSED, Eo *win, const Eo_Event_Description *desc 
EINA_UNUSED, void *event_info EINA_UNUSED)
 {
-   Evas_Object *win = data;
    Evas_Object *bub, *sh;
    Evas_Coord x, y, w, h, vw, vh;
    double t, xx, yy, zz, r, fac;
@@ -66,7 +56,6 @@ void
 test_anim(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void 
*event_info EINA_UNUSED)
 {
    Evas_Object *win, *bg, *bub, *sh;
-   Ecore_Animator *ani;
    char buf[PATH_MAX];
    unsigned int i;
 
@@ -104,8 +93,5 @@ test_anim(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_info
    evas_object_resize(win, 480, 800);
    evas_object_show(win);
 
-   ani = ecore_animator_add(anim, win);
-   evas_object_data_set(win, "animator", ani);
-
-   evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _del, win);
+   eo_do(win, eo_event_callback_add(ELM_WIN_EVENT_ANIMATOR_TICK, _anim_tick, 
NULL));
 }
diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c
index 494db21..32bbd09 100644
--- a/src/lib/elm_win.c
+++ b/src/lib/elm_win.c
@@ -196,6 +196,12 @@ struct _Elm_Win_Data
 
    void *trap_data;
 
+   struct
+     {
+        Ecore_Animator *obj;
+        unsigned short wants;
+     } animator;
+
    double       aspect;
    int          size_base_w, size_base_h;
    int          size_step_w, size_step_h;
@@ -3059,6 +3065,59 @@ _accel_is_gl(void)
    return EINA_FALSE;
 }
 
+static Eina_Bool
+_animator_tick_cb(void *_obj)
+{
+   Elm_Win *obj = _obj;
+   eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_ANIMATOR_TICK, NULL));
+
+   return ECORE_CALLBACK_RENEW;
+}
+
+static Eina_Bool
+_cb_added(void *_data,
+          Eo *obj,
+          const Eo_Event_Description *desc EINA_UNUSED,
+          void *event_info)
+{
+   const Eo_Callback_Array_Item *event = event_info;
+   Elm_Win_Data *data = _data;
+
+   if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
+     {
+        data->animator.wants++;
+        if (data->animator.wants == 1)
+          {
+             data->animator.obj = eo_add(ECORE_ANIMATOR_CLASS, obj,
+                   ecore_animator_constructor(_animator_tick_cb, obj));
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+static Eina_Bool
+_cb_deled(void *_data,
+          Eo *obj EINA_UNUSED,
+          const Eo_Event_Description *desc EINA_UNUSED,
+          void *event_info)
+{
+   const Eo_Callback_Array_Item *event = event_info;
+   Elm_Win_Data *data = _data;
+
+   if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
+     {
+        data->animator.wants--;
+        if (data->animator.wants == 0)
+          {
+             eo_del(data->animator.obj);
+             data->animator.obj = NULL;
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
 EOLIAN static void
 _elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type 
type)
 {
@@ -3635,6 +3694,9 @@ _elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const 
char *name, Elm_Win_Type t
      }
 
    evas_object_show(sd->edje);
+
+   eo_do(obj, eo_event_callback_add(EO_EV_CALLBACK_ADD, _cb_added, sd),
+         eo_event_callback_add(EO_EV_CALLBACK_DEL, _cb_deled, sd));
 }
 
 EOLIAN static void

-- 


Reply via email to