summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaehyun Cho <jae_hyun.cho@samsung.com>2018-04-10 22:09:39 +0900
committerJaehyun Cho <jae_hyun.cho@samsung.com>2018-04-12 22:02:29 +0900
commit348bae4b24f216dbfa5118f92b7ebbc455e7018f (patch)
tree9ed1ed61d80e6e0ba683fc6f622b870ba72e725b
parent3d6fa02540e8b56f85d285309268db5c6d793636 (diff)
efl_canvas_object: Add events for state changes of object's animation
Add events to notice the state changes of canvas object's animation. anim_started, anim_running, and anim_ended events are added.
-rw-r--r--src/lib/evas/Evas_Eo.h5
-rw-r--r--src/lib/evas/canvas/efl_canvas_object.eo5
-rw-r--r--src/lib/evas/canvas/evas_object_main.c133
3 files changed, 118 insertions, 25 deletions
diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h
index 7a44a0985d..c6a6a935bb 100644
--- a/src/lib/evas/Evas_Eo.h
+++ b/src/lib/evas/Evas_Eo.h
@@ -136,6 +136,11 @@ struct _Efl_Canvas_Animation_Player_Event_Running
136 double progress; 136 double progress;
137}; 137};
138 138
139typedef struct Efl_Canvas_Object_Animation_Event_Info
140{
141 const Efl_Event_Description *event_type;
142} Efl_Canvas_Object_Animation_Event_Info;
143
139/** 144/**
140 * @ingroup Evas_Object_Rectangle 145 * @ingroup Evas_Object_Rectangle
141 * 146 *
diff --git a/src/lib/evas/canvas/efl_canvas_object.eo b/src/lib/evas/canvas/efl_canvas_object.eo
index d6a97acf49..5ec948af2f 100644
--- a/src/lib/evas/canvas/efl_canvas_object.eo
+++ b/src/lib/evas/canvas/efl_canvas_object.eo
@@ -622,4 +622,9 @@ abstract Efl.Canvas.Object (Efl.Object, Efl.Gfx, Efl.Gfx.Color, Efl.Gfx.Stack, E
622 Efl.Loop.Consumer.loop { get; } 622 Efl.Loop.Consumer.loop { get; }
623 Efl.Canvas.Pointer.pointer_inside { get; } 623 Efl.Canvas.Pointer.pointer_inside { get; }
624 } 624 }
625 events {
626 anim_started; [[Animation is started.]]
627 anim_running; [[Animation is running.]]
628 anim_ended; [[Animation is ended.]]
629 }
625} 630}
diff --git a/src/lib/evas/canvas/evas_object_main.c b/src/lib/evas/canvas/evas_object_main.c
index 350db6bb8d..43d2b33574 100644
--- a/src/lib/evas/canvas/evas_object_main.c
+++ b/src/lib/evas/canvas/evas_object_main.c
@@ -44,8 +44,7 @@ typedef struct _Event_Animation
44 EINA_INLIST; 44 EINA_INLIST;
45 45
46 const Efl_Event_Description *desc; 46 const Efl_Event_Description *desc;
47 47 Efl_Canvas_Animation *anim;
48 Efl_Canvas_Animation *anim;
49} Event_Animation; 48} Event_Animation;
50 49
51static Eina_Bool 50static Eina_Bool
@@ -166,22 +165,63 @@ _evas_object_pointer_data_get(Evas_Pointer_Data *evas_pdata,
166 return pdata; 165 return pdata;
167} 166}
168 167
169static void _animation_intercept_hide(void *data, Evas_Object *eo_obj);
170static void _hide(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj); 168static void _hide(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj);
171 169
172static void 170static void
173_animation_end_cb(void *data, const Efl_Event *event) 171_anim_started_cb(void *data, const Efl_Event *ev)
174{ 172{
175 Evas_Object_Protected_Data *obj; 173 const Efl_Event_Description *desc = data;
176 Event_Animation *event_anim = data;
177 174
178 obj = EVAS_OBJECT_DATA_SAFE_GET(efl_animation_player_target_get(event->object)); 175 Efl_Canvas_Object_Animation_Event_Info event;
179 if (!obj) return; 176 event.event_type = desc;
180 177
181 if (efl_animation_player_animation_get(event->object) != event_anim->anim) 178 Eo *eo_obj = efl_animation_player_target_get(ev->object);
182 return; 179
180 efl_event_callback_call(eo_obj, EFL_CANVAS_OBJECT_EVENT_ANIM_STARTED,
181 &event);
182}
183
184static void
185_anim_running_cb(void *data, const Efl_Event *ev)
186{
187 const Efl_Event_Description *desc = data;
188
189 Efl_Canvas_Object_Animation_Event_Info event;
190 event.event_type = desc;
183 191
184 _hide(obj->object, obj); 192 Eo *eo_obj = efl_animation_player_target_get(ev->object);
193
194 efl_event_callback_call(eo_obj, EFL_CANVAS_OBJECT_EVENT_ANIM_RUNNING,
195 &event);
196}
197
198static void
199_anim_ended_cb(void *data, const Efl_Event *ev)
200{
201 const Efl_Event_Description *desc = data;
202
203 efl_event_callback_del(ev->object, EFL_ANIMATION_PLAYER_EVENT_STARTED,
204 _anim_started_cb, desc);
205 efl_event_callback_del(ev->object, EFL_ANIMATION_PLAYER_EVENT_RUNNING,
206 _anim_running_cb, desc);
207 efl_event_callback_del(ev->object, EFL_ANIMATION_PLAYER_EVENT_ENDED,
208 _anim_ended_cb, desc);
209
210 Efl_Canvas_Object_Animation_Event_Info event;
211 event.event_type = desc;
212
213 Eo *eo_obj = efl_animation_player_target_get(ev->object);
214
215 efl_event_callback_call(eo_obj, EFL_CANVAS_OBJECT_EVENT_ANIM_ENDED,
216 &event);
217
218 if (desc == EFL_GFX_EVENT_HIDE)
219 {
220 Evas_Object_Protected_Data *obj = EVAS_OBJECT_DATA_SAFE_GET(eo_obj);
221 if (!obj) return;
222
223 _hide(eo_obj, obj);
224 }
185} 225}
186 226
187static void 227static void
@@ -192,9 +232,20 @@ _animation_intercept_hide(void *data, Evas_Object *eo_obj)
192 if (!obj) return; 232 if (!obj) return;
193 233
194 if (event_anim->anim && obj->anim_player && 234 if (event_anim->anim && obj->anim_player &&
195 (event_anim->anim != efl_animation_player_animation_get(obj->anim_player))) 235 (event_anim->anim != efl_animation_player_animation_get(obj->anim_player)))
196 { 236 {
197 efl_animation_player_animation_set(obj->anim_player, event_anim->anim); 237 efl_animation_player_animation_set(obj->anim_player, event_anim->anim);
238
239 efl_event_callback_add(obj->anim_player,
240 EFL_ANIMATION_PLAYER_EVENT_STARTED,
241 _anim_started_cb, EFL_GFX_EVENT_HIDE);
242 efl_event_callback_add(obj->anim_player,
243 EFL_ANIMATION_PLAYER_EVENT_RUNNING,
244 _anim_running_cb, EFL_GFX_EVENT_HIDE);
245 efl_event_callback_add(obj->anim_player,
246 EFL_ANIMATION_PLAYER_EVENT_ENDED,
247 _anim_ended_cb, EFL_GFX_EVENT_HIDE);
248
198 //Start animation 249 //Start animation
199 efl_player_start(obj->anim_player); 250 efl_player_start(obj->anim_player);
200 } 251 }
@@ -205,17 +256,18 @@ _event_anim_free(Event_Animation *event_anim, Evas_Object_Protected_Data *obj)
205{ 256{
206 if (event_anim->anim) 257 if (event_anim->anim)
207 { 258 {
208 //Deallocate memory and Unset callbacks for Hide event 259 //Unset callbacks for Hide event
209 if (event_anim->desc == EFL_GFX_EVENT_HIDE) 260 if (event_anim->desc == EFL_GFX_EVENT_HIDE)
261 evas_object_intercept_hide_callback_del(obj->object,
262 _animation_intercept_hide);
263
264 if (efl_player_play_get(obj->anim_player))
210 { 265 {
211 evas_object_intercept_hide_callback_del(obj->object, 266 Efl_Animation *running_anim =
212 _animation_intercept_hide); 267 efl_animation_player_animation_get(obj->anim_player);
213 efl_event_callback_del(obj->anim_player, 268
214 EFL_ANIMATION_PLAYER_EVENT_ENDED, 269 if (running_anim == event_anim->anim)
215 _animation_end_cb, 270 efl_player_stop(obj->anim_player);
216 event_anim);
217 if (efl_player_play_get(obj->anim_player))
218 efl_gfx_visible_set(obj->object, EINA_FALSE);
219 } 271 }
220 } 272 }
221 273
@@ -972,6 +1024,11 @@ _efl_canvas_object_efl_object_del(const Eo *eo_obj, Evas_Object_Protected_Data *
972 obj->del_ref = EINA_TRUE; 1024 obj->del_ref = EINA_TRUE;
973 return; 1025 return;
974 } 1026 }
1027
1028 //Unset callbacks for Hide event before hiding
1029 evas_object_intercept_hide_callback_del((Eo *)eo_obj,
1030 _animation_intercept_hide);
1031
975 efl_gfx_visible_set((Eo *) eo_obj, EINA_FALSE); 1032 efl_gfx_visible_set((Eo *) eo_obj, EINA_FALSE);
976 obj->efl_del_called = EINA_TRUE; 1033 obj->efl_del_called = EINA_TRUE;
977 efl_del(efl_super(eo_obj, MY_CLASS)); 1034 efl_del(efl_super(eo_obj, MY_CLASS));
@@ -1120,6 +1177,16 @@ _efl_canvas_object_efl_object_event_callback_call(Eo *eo_obj,
1120 //Create animation object to start animation 1177 //Create animation object to start animation
1121 efl_animation_player_animation_set(obj->anim_player, event_anim->anim); 1178 efl_animation_player_animation_set(obj->anim_player, event_anim->anim);
1122 1179
1180 efl_event_callback_add(obj->anim_player,
1181 EFL_ANIMATION_PLAYER_EVENT_STARTED,
1182 _anim_started_cb, desc);
1183 efl_event_callback_add(obj->anim_player,
1184 EFL_ANIMATION_PLAYER_EVENT_RUNNING,
1185 _anim_running_cb, desc);
1186 efl_event_callback_add(obj->anim_player,
1187 EFL_ANIMATION_PLAYER_EVENT_ENDED,
1188 _anim_ended_cb, desc);
1189
1123 //Start animation 1190 //Start animation
1124 efl_player_start(obj->anim_player); 1191 efl_player_start(obj->anim_player);
1125 } 1192 }
@@ -1149,6 +1216,16 @@ _efl_canvas_object_efl_object_event_callback_legacy_call(Eo *eo_obj,
1149 //Create animation object to start animation 1216 //Create animation object to start animation
1150 efl_animation_player_animation_set(obj->anim_player, event_anim->anim); 1217 efl_animation_player_animation_set(obj->anim_player, event_anim->anim);
1151 1218
1219 efl_event_callback_add(obj->anim_player,
1220 EFL_ANIMATION_PLAYER_EVENT_STARTED,
1221 _anim_started_cb, desc);
1222 efl_event_callback_add(obj->anim_player,
1223 EFL_ANIMATION_PLAYER_EVENT_RUNNING,
1224 _anim_running_cb, desc);
1225 efl_event_callback_add(obj->anim_player,
1226 EFL_ANIMATION_PLAYER_EVENT_ENDED,
1227 _anim_ended_cb, desc);
1228
1152 //Start animation 1229 //Start animation
1153 efl_player_start(obj->anim_player); 1230 efl_player_start(obj->anim_player);
1154 } 1231 }
@@ -1873,6 +1950,16 @@ _show(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj)
1873 //Create animation object to start animation 1950 //Create animation object to start animation
1874 efl_animation_player_animation_set(obj->anim_player, event_anim->anim); 1951 efl_animation_player_animation_set(obj->anim_player, event_anim->anim);
1875 1952
1953 efl_event_callback_add(obj->anim_player,
1954 EFL_ANIMATION_PLAYER_EVENT_STARTED,
1955 _anim_started_cb, EFL_GFX_EVENT_SHOW);
1956 efl_event_callback_add(obj->anim_player,
1957 EFL_ANIMATION_PLAYER_EVENT_RUNNING,
1958 _anim_running_cb, EFL_GFX_EVENT_SHOW);
1959 efl_event_callback_add(obj->anim_player,
1960 EFL_ANIMATION_PLAYER_EVENT_ENDED,
1961 _anim_ended_cb, EFL_GFX_EVENT_SHOW);
1962
1876 //Start animation 1963 //Start animation
1877 efl_player_start(obj->anim_player); 1964 efl_player_start(obj->anim_player);
1878 } 1965 }
@@ -2492,10 +2579,6 @@ _efl_canvas_object_event_animation_set(Eo *eo_obj,
2492 evas_object_intercept_hide_callback_add(eo_obj, 2579 evas_object_intercept_hide_callback_add(eo_obj,
2493 _animation_intercept_hide, 2580 _animation_intercept_hide,
2494 event_anim); 2581 event_anim);
2495 efl_event_callback_add(pd->anim_player,
2496 EFL_ANIMATION_PLAYER_EVENT_ENDED,
2497 _animation_end_cb,
2498 event_anim);
2499 } 2582 }
2500 2583
2501 event_anim->desc = desc; 2584 event_anim->desc = desc;