summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-04-30 13:58:26 +0100
committerTom Hacohen <tom@stosb.com>2015-05-06 15:46:46 +0100
commitedc3ba59a5b1fcf1405b3a0badaa48c0e837903e (patch)
treef4d5b74e91498754b7e0419cd341c3d55d7cf434
parent7d19def2139a6e2ce9ff72a00b5e49a2497cee20 (diff)
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).
-rw-r--r--src/bin/test_anim.c18
-rw-r--r--src/lib/elm_win.c62
2 files changed, 64 insertions, 16 deletions
diff --git a/src/bin/test_anim.c b/src/bin/test_anim.c
index 820851cc3..2eb07d6b3 100644
--- a/src/bin/test_anim.c
+++ b/src/bin/test_anim.c
@@ -10,19 +10,9 @@ static const char *names[] =
10 "bub3", "sh3", 10 "bub3", "sh3",
11}; 11};
12 12
13static void
14_del(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
15{
16 Evas_Object *win = data;
17 Ecore_Animator *ani = evas_object_data_get(win, "animator");
18
19 ecore_animator_del(ani);
20}
21
22static Eina_Bool 13static Eina_Bool
23anim(void *data) 14_anim_tick(void *data EINA_UNUSED, Eo *win, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
24{ 15{
25 Evas_Object *win = data;
26 Evas_Object *bub, *sh; 16 Evas_Object *bub, *sh;
27 Evas_Coord x, y, w, h, vw, vh; 17 Evas_Coord x, y, w, h, vw, vh;
28 double t, xx, yy, zz, r, fac; 18 double t, xx, yy, zz, r, fac;
@@ -66,7 +56,6 @@ void
66test_anim(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 56test_anim(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
67{ 57{
68 Evas_Object *win, *bg, *bub, *sh; 58 Evas_Object *win, *bg, *bub, *sh;
69 Ecore_Animator *ani;
70 char buf[PATH_MAX]; 59 char buf[PATH_MAX];
71 unsigned int i; 60 unsigned int i;
72 61
@@ -104,8 +93,5 @@ test_anim(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info
104 evas_object_resize(win, 480, 800); 93 evas_object_resize(win, 480, 800);
105 evas_object_show(win); 94 evas_object_show(win);
106 95
107 ani = ecore_animator_add(anim, win); 96 eo_do(win, eo_event_callback_add(ELM_WIN_EVENT_ANIMATOR_TICK, _anim_tick, NULL));
108 evas_object_data_set(win, "animator", ani);
109
110 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _del, win);
111} 97}
diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c
index 494db21f0..32bbd09c2 100644
--- a/src/lib/elm_win.c
+++ b/src/lib/elm_win.c
@@ -196,6 +196,12 @@ struct _Elm_Win_Data
196 196
197 void *trap_data; 197 void *trap_data;
198 198
199 struct
200 {
201 Ecore_Animator *obj;
202 unsigned short wants;
203 } animator;
204
199 double aspect; 205 double aspect;
200 int size_base_w, size_base_h; 206 int size_base_w, size_base_h;
201 int size_step_w, size_step_h; 207 int size_step_w, size_step_h;
@@ -3059,6 +3065,59 @@ _accel_is_gl(void)
3059 return EINA_FALSE; 3065 return EINA_FALSE;
3060} 3066}
3061 3067
3068static Eina_Bool
3069_animator_tick_cb(void *_obj)
3070{
3071 Elm_Win *obj = _obj;
3072 eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_ANIMATOR_TICK, NULL));
3073
3074 return ECORE_CALLBACK_RENEW;
3075}
3076
3077static Eina_Bool
3078_cb_added(void *_data,
3079 Eo *obj,
3080 const Eo_Event_Description *desc EINA_UNUSED,
3081 void *event_info)
3082{
3083 const Eo_Callback_Array_Item *event = event_info;
3084 Elm_Win_Data *data = _data;
3085
3086 if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
3087 {
3088 data->animator.wants++;
3089 if (data->animator.wants == 1)
3090 {
3091 data->animator.obj = eo_add(ECORE_ANIMATOR_CLASS, obj,
3092 ecore_animator_constructor(_animator_tick_cb, obj));
3093 }
3094 }
3095
3096 return EO_CALLBACK_CONTINUE;
3097}
3098
3099static Eina_Bool
3100_cb_deled(void *_data,
3101 Eo *obj EINA_UNUSED,
3102 const Eo_Event_Description *desc EINA_UNUSED,
3103 void *event_info)
3104{
3105 const Eo_Callback_Array_Item *event = event_info;
3106 Elm_Win_Data *data = _data;
3107
3108 if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
3109 {
3110 data->animator.wants--;
3111 if (data->animator.wants == 0)
3112 {
3113 eo_del(data->animator.obj);
3114 data->animator.obj = NULL;
3115 }
3116 }
3117
3118 return EO_CALLBACK_CONTINUE;
3119}
3120
3062EOLIAN static void 3121EOLIAN static void
3063_elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type type) 3122_elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type type)
3064{ 3123{
@@ -3635,6 +3694,9 @@ _elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type t
3635 } 3694 }
3636 3695
3637 evas_object_show(sd->edje); 3696 evas_object_show(sd->edje);
3697
3698 eo_do(obj, eo_event_callback_add(EO_EV_CALLBACK_ADD, _cb_added, sd),
3699 eo_event_callback_add(EO_EV_CALLBACK_DEL, _cb_deled, sd));
3638} 3700}
3639 3701
3640EOLIAN static void 3702EOLIAN static void