elementary/transit - fixed blocking problem when two objects are added.
[framework/uifw/elementary.git] / src / lib / elm_transit.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 #define ELM_TRANSIT_CHECK_OR_RETURN(transit, ...) \
5    do { \
6       if (!transit) { \
7          CRITICAL("Elm_Transit " # transit " is NULL!"); \
8          return __VA_ARGS__; \
9       } \
10       if (!EINA_MAGIC_CHECK(transit, ELM_TRANSIT_MAGIC)) { \
11          EINA_MAGIC_FAIL(transit, ELM_TRANSIT_MAGIC); \
12          return __VA_ARGS__; \
13       } \
14       if (transit->deleted){ \
15          ERR("Elm_Transit " # transit " has already been deleted!"); \
16          return __VA_ARGS__; \
17       } \
18    } while (0)
19
20 /**
21  *
22  * @defgroup Transit Transit
23  * @ingroup Elementary
24  *
25  * Transit (see Warning below) is designed to set the various effects for the
26  * Evas_Object such like translation, rotation, etc. For using Effects, Create
27  * transit and insert effects which are interesting.
28  * Once effects are inserted into transit, transit will manage those effects.
29  * (ex deleting).
30  *
31  * Example:
32  * @code
33  * Elm_Transit *trans = elm_transit_add();
34  * elm_transit_object_add(trans, obj);
35  * void *effect_context = elm_transit_effect_translation_context_new(0.0, 0.0,
36  *                                                               280.0, 280.0);
37  * elm_transit_effect_add(transit,
38  *                        elm_transit_effect_translation_op, effect_context,
39  *                        elm_transit_effect_translation_context_free);
40  * elm_transit_duration_set(transit, 1);
41  * elm_transit_auto_reverse_set(transit, EINA_TRUE);
42  * elm_transit_tween_mode_set(transit, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
43  * elm_transit_repeat_times_set(transit, 3);
44  * @endcode
45  *
46  * @warning We strongly recomend to use elm_transit just when edje can not do
47  * the trick. Edje has more advantage than Elm_Transit, it has more flexibility and
48  * animations can be manipulated inside the theme.
49  */
50
51 #define _TRANSIT_FOCAL 2000
52
53 struct _Elm_Transit
54 {
55 #define ELM_TRANSIT_MAGIC 0xd27f190a
56    EINA_MAGIC;
57
58    Ecore_Animator *animator;
59    Eina_Inlist *effect_list;
60    Eina_List *objs;
61    Eina_Hash *objs_data_hash;
62    Elm_Transit *prev_chain_transit;
63    Eina_List *next_chain_transits;
64    Elm_Transit_Tween_Mode tween_mode;
65    struct {
66       Elm_Transit_Effect_End_Cb func;
67       void *arg;
68    } del_data;
69    struct {
70       double delayed;
71       double paused;
72       double duration;
73       double begin;
74       double current;
75    } time;
76    struct {
77       int count;
78       int current;
79       Eina_Bool reverse;
80    } repeat;
81    double progress;
82    unsigned int effects_pending_del;
83    int walking;
84    Eina_Bool auto_reverse : 1;
85    Eina_Bool event_enabled : 1;
86    Eina_Bool deleted : 1;
87    Eina_Bool state_keep : 1;
88 };
89
90 struct _Elm_Transit_Effect_Module
91 {
92    EINA_INLIST;
93    Elm_Transit_Effect_Transition_Cb transition_cb;
94    Elm_Transit_Effect_End_Cb end_cb;
95    Elm_Transit_Effect *effect;
96    Eina_Bool deleted : 1;
97 };
98
99 struct _Elm_Obj_State
100 {
101    Evas_Coord x, y, w, h;
102    int r,g,b,a;
103    Evas_Map *map;
104    Eina_Bool map_enabled : 1;
105    Eina_Bool visible : 1;
106 };
107
108 struct _Elm_Obj_Data
109 {
110    struct _Elm_Obj_State *state;
111    Eina_Bool pass_events : 1;
112 };
113
114 typedef struct _Elm_Transit_Effect_Module Elm_Transit_Effect_Module;
115 typedef struct _Elm_Obj_Data Elm_Obj_Data;
116 typedef struct _Elm_Obj_State Elm_Obj_State;
117
118 static void
119 _elm_transit_obj_states_save(Evas_Object *obj, Elm_Obj_Data *obj_data)
120 {
121    Elm_Obj_State *state;
122
123    if (obj_data->state) return;
124    state = calloc(1, sizeof(Elm_Obj_State));
125    if (!state) return;
126    evas_object_geometry_get(obj, &state->x, &state->y, &state->w, &state->h);
127    evas_object_color_get(obj, &state->r, &state->g, &state->b, &state->a);
128    state->visible = evas_object_visible_get(obj);
129    state->map_enabled = evas_object_map_enable_get(obj);
130    if (evas_object_map_get(obj))
131      state->map = evas_map_dup(evas_object_map_get(obj));
132    obj_data->state = state;
133 }
134
135 static Eina_Bool
136 _hash_foreach_pass_events_set(const Eina_Hash *hash __UNUSED__, const void *key, void *data __UNUSED__, void *fdata)
137 {
138    Elm_Transit *transit = fdata;
139    evas_object_pass_events_set((Evas_Object*) key, transit->event_enabled);
140    return EINA_TRUE;
141 }
142
143 static Eina_Bool
144 _hash_foreach_obj_states_save(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata __UNUSED__)
145 {
146    _elm_transit_obj_states_save((Evas_Object *) key, (Elm_Obj_Data *) data);
147    return EINA_TRUE;
148 }
149
150 static void
151 _elm_transit_object_remove_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
152 {
153    Elm_Transit *transit;
154    Elm_Obj_Data *obj_data;
155    Eina_List *list;
156
157    transit = data;
158    list = eina_list_data_find_list(transit->objs, obj);
159    obj_data = eina_hash_find(transit->objs_data_hash, list);
160    if (!obj_data) return;
161    eina_hash_del_by_key(transit->objs_data_hash, list);
162    evas_object_pass_events_set(obj, obj_data->pass_events);
163    if (obj_data->state)
164      free(obj_data->state);
165    free(obj_data);
166    transit->objs = eina_list_remove(transit->objs, obj);
167    if (!transit->objs) elm_transit_del(transit);
168 }
169
170 //TODO: Remove!
171 //Since evas map have a afterimage bug for this time.
172 //This function is added temporary.
173 static void
174 _obj_damage_area_set(Evas_Object *obj)
175 {
176    const Evas_Map *map;
177    Evas_Coord_Point coords;
178    Evas_Coord_Point min, max;
179    int i;
180
181    map  = evas_object_map_get(obj);
182    if (!map) return;
183
184    evas_map_point_coord_get(map, 0, &coords.x, &coords.y, NULL);
185
186    max = min = coords;
187
188    for (i = 1; i < 4; ++i)
189      {
190         evas_map_point_coord_get(map, i, &coords.x, &coords.y, NULL);
191
192         if (coords.x < min.x)
193           min.x = coords.x;
194         else if (coords.x > max.x)
195           max.x = coords.x;
196
197         if (coords.y < min.y)
198           min.y = coords.y;
199         else if (coords.y > max.y)
200           max.y = coords.y;
201      }
202
203    evas_damage_rectangle_add(evas_object_evas_get(obj),
204                              min.x, min.y,
205                              max.x - min.x, max.y - min.y);
206 }
207
208 static void
209 _remove_obj_from_list(Elm_Transit *transit, Evas_Object *obj)
210 {
211    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
212                                        _elm_transit_object_remove_cb,
213                                        transit);
214
215    //Remove duplicated objects
216    //TODO: Need to consider about optimizing here
217    while(1)
218      {
219         if (!eina_list_data_find_list(transit->objs, obj))
220           break;
221         transit->objs = eina_list_remove(transit->objs, obj);
222      }
223 }
224
225 static void
226 _elm_transit_object_remove(Elm_Transit *transit, Evas_Object *obj)
227 {
228    Elm_Obj_Data *obj_data;
229    Elm_Obj_State *state;
230    Eina_List *list;
231
232    list = eina_list_data_find_list(transit->objs, obj);
233    obj_data = eina_hash_find(transit->objs_data_hash, list);
234    if (!obj_data)
235      {
236         _remove_obj_from_list(transit, obj);
237         return;
238      }
239    eina_hash_del_by_key(transit->objs_data_hash, list);
240    _remove_obj_from_list(transit, obj);
241    evas_object_pass_events_set(obj, obj_data->pass_events);
242    state = obj_data->state;
243    if (state)
244      {
245         //recover the states of the object.
246         if (!transit->state_keep)
247           {
248              evas_object_move(obj, state->x, state->y);
249              evas_object_resize(obj, state->w, state->h);
250              evas_object_color_set(obj, state->r, state->g, state->b, state->a);
251              if (state->visible) evas_object_show(obj);
252              else evas_object_hide(obj);
253              if (state->map_enabled)
254                evas_object_map_enable_set(obj, EINA_TRUE);
255              else
256                evas_object_map_enable_set(obj, EINA_FALSE);
257              if (state->map)
258                evas_object_map_set(obj, state->map);
259
260              //TODO: Remove!
261              //Since evas map have a afterimage bug for this time.
262              //This line is added temporary.
263              _obj_damage_area_set(obj);
264
265           }
266         free(state);
267      }
268    free(obj_data);
269
270 }
271
272 static void
273 _elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Module *effect_module)
274 {
275    if (effect_module->end_cb)
276      effect_module->end_cb(effect_module->effect, transit);
277    free(effect_module);
278 }
279
280 static void
281 _remove_dead_effects(Elm_Transit *transit)
282 {
283    Elm_Transit_Effect_Module *effect_module;
284
285    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
286      {
287         if (effect_module->deleted)
288           {
289              _elm_transit_effect_del(transit, effect_module);
290              transit->effects_pending_del--;
291              if (!transit->effects_pending_del) return;
292           }
293      }
294 }
295
296 static void
297 _elm_transit_del(Elm_Transit *transit)
298 {
299    Elm_Transit_Effect_Module *effect_module;
300    Elm_Transit *chain_transit;
301    Eina_List *elist, *elist_next;
302
303    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
304      {
305         if (transit->prev_chain_transit)
306           transit->prev_chain_transit->next_chain_transits = eina_list_remove(transit->prev_chain_transit->next_chain_transits, transit);
307         chain_transit->prev_chain_transit = NULL;
308      }
309
310    eina_list_free(transit->next_chain_transits);
311
312    if (transit->animator)
313      ecore_animator_del(transit->animator);
314
315    while (transit->effect_list)
316      {
317         effect_module = EINA_INLIST_CONTAINER_GET(transit->effect_list, Elm_Transit_Effect_Module);
318         transit->effect_list = eina_inlist_remove(transit->effect_list, transit->effect_list);
319      }
320
321    while (transit->objs)
322      _elm_transit_object_remove(transit, eina_list_data_get(transit->objs));
323
324    transit->deleted = EINA_TRUE;
325
326    if (transit->del_data.func)
327      transit->del_data.func(transit->del_data.arg, transit);
328
329    eina_hash_free(transit->objs_data_hash);
330
331    EINA_MAGIC_SET(transit, EINA_MAGIC_NONE);
332    free(transit);
333 }
334
335 static void
336 _chain_transits_go(Elm_Transit *transit)
337 {
338    Eina_List *elist, *elist_next;
339    Elm_Transit *chain_transit;
340
341    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
342      elm_transit_go(chain_transit);
343 }
344
345 static void
346 _transit_animate_op(Elm_Transit *transit, double progress)
347 {
348    Elm_Transit_Effect_Module *effect_module;
349
350    transit->walking++;
351    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
352      {
353         if (transit->deleted) break;
354         if (!effect_module->deleted)
355           effect_module->transition_cb(effect_module->effect, transit, progress);
356      }
357    transit->walking--;
358
359    if (transit->walking) return;
360
361    if (transit->deleted) _elm_transit_del(transit);
362    else if (transit->effects_pending_del) _remove_dead_effects(transit);
363 }
364
365 static Eina_Bool
366 _animator_animate_cb(void *data)
367 {
368    Elm_Transit *transit = data;
369    double elapsed_time, duration;
370
371    transit->time.current = ecore_loop_time_get();
372    elapsed_time = transit->time.current - transit->time.begin;
373    duration = transit->time.duration + transit->time.delayed;
374
375    if (elapsed_time > duration)
376      elapsed_time = duration;
377
378    transit->progress = elapsed_time / duration;
379    switch (transit->tween_mode)
380      {
381       case ELM_TRANSIT_TWEEN_MODE_ACCELERATE:
382         transit->progress = 1.0 - sin((ELM_PI / 2.0) + (transit->progress * ELM_PI / 2.0));
383         break;
384       case ELM_TRANSIT_TWEEN_MODE_DECELERATE:
385         transit->progress = sin(transit->progress * ELM_PI / 2.0);
386         break;
387       case ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL:
388         transit->progress = (1.0 - cos(transit->progress * ELM_PI)) / 2.0;
389         break;
390       default:
391         break;
392      }
393
394    /* Reverse? */
395    if (transit->repeat.reverse) transit->progress = 1 - transit->progress;
396
397    if (transit->time.duration > 0) _transit_animate_op(transit, transit->progress);
398
399    /* Not end. Keep going. */
400    if (elapsed_time < duration) return ECORE_CALLBACK_RENEW;
401
402    /* Repeat and reverse and time done! */
403    if ((transit->repeat.count >= 0) &&
404        (transit->repeat.current == transit->repeat.count) &&
405        ((!transit->auto_reverse) || transit->repeat.reverse))
406      {
407         /* run chain transit */
408         if (transit->next_chain_transits)
409           _chain_transits_go(transit);
410
411         elm_transit_del(transit);
412         return ECORE_CALLBACK_CANCEL;
413      }
414
415    /* Repeat Case */
416    if (!transit->auto_reverse || transit->repeat.reverse)
417      {
418         transit->repeat.current++;
419         transit->repeat.reverse = EINA_FALSE;
420      }
421    else transit->repeat.reverse = EINA_TRUE;
422
423    transit->time.begin = ecore_loop_time_get();
424
425    return ECORE_CALLBACK_RENEW;
426 }
427
428 /**
429  * Add new transit.
430  *
431  * @note Is not necessary to delete the transit object, it will be deleted at
432  * the end of its operation.
433  * @note The transit will start playing when the program enter in the main loop, is not
434  * necessary to give a start to the transit.
435  *
436  * @param duration The duration of the transit in seconds. When transit starts
437  * to run, it will last a @p duration time.
438  * @return The transit object.
439  *
440  * @ingroup Transit
441  */
442 EAPI Elm_Transit *
443 elm_transit_add(void)
444 {
445    Elm_Transit *transit = ELM_NEW(Elm_Transit);
446    if (!transit) return NULL;
447
448    EINA_MAGIC_SET(transit, ELM_TRANSIT_MAGIC);
449
450    elm_transit_tween_mode_set(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
451
452    transit->objs_data_hash = eina_hash_int32_new(NULL);
453
454    return transit;
455 }
456 /**
457  * Stops the animation and delete the @p transit object.
458  *
459  * Call this function if you wants to stop the animation before the duration
460  * time. Make sure the @p transit object is still alive with
461  * elm_transit_del_cb_set() function.
462  * All added effects will be deleted, calling its repective data_free_cb
463  * functions. The function setted by elm_transit_del_cb_set() will be called.
464  *
465  * @see elm_transit_del_cb_set()
466  *
467  * @param transit The transit object to be deleted.
468  *
469  * @ingroup Transit
470  * @warning Just call this function if you are sure the transit is alive.
471  */
472 EAPI void
473 elm_transit_del(Elm_Transit *transit)
474 {
475    ELM_TRANSIT_CHECK_OR_RETURN(transit);
476
477    if (transit->walking) transit->deleted = EINA_TRUE;
478    else _elm_transit_del(transit);
479 }
480
481 /**
482  * Add a new effect to the transit.
483  *
484  * @note The cb function and the data are the key to the effect. If you try to
485  * add an already added effect, nothing is done.
486  * @note After the first addition of an effect in @p transit, if its
487  * effect list become empty again, the @p transit will be killed by
488  * elm_transit_del(transit) function.
489  *
490  * Exemple:
491  * @code
492  * Elm_Transit *transit = elm_transit_add();
493  * elm_transit_effect_add(transit,
494  *                        elm_transit_effect_blend_op,
495  *                        elm_transit_effect_blend_context_new(),
496  *                        elm_transit_effect_blend_context_free);
497  * @endcode
498  *
499  * @param transit The transit object.
500  * @param cb The operation function. It is called when the animation begins,
501  * it is the function that actually performs the animation. It is called with
502  * the @p data, @p transit and the time progression of the animation (a double
503  * value between 0.0 and 1.0).
504  * @param data The context data of the effect.
505  * @param data_free_cb The function to free the context data, it will be called
506  * at the end of the effect, it must finalize the animation and free the
507  * @p data.
508  *
509  * @ingroup Transit
510  * @warning The transit free the context data at the and of the transition with
511  * the data_free_cb function, do not use the context data in another transit.
512  */
513 EAPI void
514 elm_transit_effect_add(Elm_Transit *transit, Elm_Transit_Effect_Transition_Cb transition_cb, Elm_Transit_Effect *effect, Elm_Transit_Effect_End_Cb end_cb)
515 {
516    ELM_TRANSIT_CHECK_OR_RETURN(transit);
517    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
518    Elm_Transit_Effect_Module *effect_module;
519
520    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
521      if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect)) return;
522
523    effect_module = ELM_NEW(Elm_Transit_Effect_Module);
524    if (!effect_module) return;
525
526    effect_module->end_cb = end_cb;
527    effect_module->transition_cb = transition_cb;
528    effect_module->effect = effect;
529
530    transit->effect_list = eina_inlist_append(transit->effect_list, (Eina_Inlist*) effect_module);
531 }
532
533 /**
534  * Delete an added effect.
535  *
536  * This function will remove the effect from the @p transit, calling the
537  * data_free_cb to free the @p data.
538  *
539  * @see elm_transit_effect_add()
540  *
541  * @note If the effect is not found, nothing is done.
542  * @note If the effect list become empty, this function will call
543  * elm_transit_del(transit), that is, it will kill the @p transit.
544  *
545  * @param transit The transit object.
546  * @param cb The operation function.
547  * @param data The context data of the effect.
548  *
549  * @ingroup Transit
550  */
551 EAPI void
552 elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Transition_Cb transition_cb, Elm_Transit_Effect *effect)
553 {
554    ELM_TRANSIT_CHECK_OR_RETURN(transit);
555    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
556    Elm_Transit_Effect_Module *effect_module;
557
558    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
559      {
560         if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect))
561           {
562              if (transit->walking)
563                {
564                   effect_module->deleted = EINA_TRUE;
565                   transit->effects_pending_del++;
566                }
567              else
568                {
569                   _elm_transit_effect_del(transit, effect_module);
570                   if (!transit->effect_list) elm_transit_del(transit);
571                }
572              return;
573           }
574      }
575 }
576
577 /**
578  * Add new object to apply the effects.
579  *
580  * @note After the first addition of an object in @p transit, if its
581  * object list become empty again, the @p transit will be killed by
582  * elm_transit_del(transit) function.
583  * @note If the @p obj belongs to another transit, the @p obj will be
584  * removed from it and it will only belong to the @p transit. If the old
585  * transit stays without objects, it will die.
586  * @note When you add an object into the @p transit, its state from
587  * evas_object_pass_events_get(obj) is saved, and it is applied when the
588  * transit ends, if you change this state whith evas_object_pass_events_set()
589  * after add the object, this state will change again when @p transit stops to
590  * run.
591  *
592  * @param transit The transit object.
593  * @param obj Object to be animated.
594  *
595  * @ingroup Transit
596  * @warning It is not allowed to add a new object after transit begins to go.
597  */
598 EAPI void
599 elm_transit_object_add(Elm_Transit *transit, Evas_Object *obj)
600 {
601    ELM_TRANSIT_CHECK_OR_RETURN(transit);
602    EINA_SAFETY_ON_NULL_RETURN(obj);
603    Elm_Obj_Data *obj_data;
604    Eina_List * list;
605
606 //TODO: Check the remove case of the same objects in this transit. 
607    obj_data = ELM_NEW(Elm_Obj_Data);
608    obj_data->pass_events = evas_object_pass_events_get(obj);
609    if (!transit->event_enabled)
610      evas_object_pass_events_set(obj, EINA_TRUE);
611
612    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
613                                   _elm_transit_object_remove_cb,
614                                   transit);
615
616    transit->objs = eina_list_append(transit->objs, obj);
617    list = eina_list_last(transit->objs);
618    eina_hash_add(transit->objs_data_hash, list, obj_data);
619
620    if (!transit->state_keep)
621      _elm_transit_obj_states_save(obj, obj_data);
622 }
623
624 /**
625  * Removes an added object from the transit.
626  *
627  * @note If the @p obj is not in the @p transit, nothing is done.
628  * @note If the list become empty, this function will call
629  * elm_transit_del(transit), that is, it will kill the @p transit.
630  *
631  * @param transit The transit object.
632  * @param obj Object to be removed from @p transit.
633  *
634  * @ingroup Transit
635  * @warning It is not allowed to remove objects after transit begins to go.
636  */
637 EAPI void
638 elm_transit_object_remove(Elm_Transit *transit, Evas_Object *obj)
639 {
640    ELM_TRANSIT_CHECK_OR_RETURN(transit);
641    EINA_SAFETY_ON_NULL_RETURN(obj);
642
643    _elm_transit_object_remove(transit, obj);
644    if (!transit->objs) elm_transit_del(transit);
645 }
646
647 /**
648  * Get the objects of the transit.
649  *
650  * @param transit The transit object.
651  * @return a Eina_List with the objects from the transit.
652  *
653  * @ingroup Transit
654  */
655 EAPI const Eina_List *
656 elm_transit_objects_get(const Elm_Transit *transit)
657 {
658    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
659    return transit->objs;
660 }
661
662 /**
663  * Set the event enabled when transit is operating.
664  *
665  * If @p enabled is EINA_TRUE, the objects of the transit will receives
666  * events from mouse and keyboard during the animation.
667  * @note When you add an object with elm_transit_object_add(), its state from
668  * evas_object_pass_events_get(obj) is saved, and it is applied when the
669  * transit ends, if you change this state with evas_object_pass_events_set()
670  * after adding the object, this state will change again when @p transit stops
671  * to run.
672  *
673  * @param transit The transit object.
674  * @param enabled Disable or enable.
675  *
676  * @ingroup Transit
677  */
678 EAPI void
679 elm_transit_event_enabled_set(Elm_Transit *transit, Eina_Bool enabled)
680 {
681    ELM_TRANSIT_CHECK_OR_RETURN(transit);
682
683    if (transit->event_enabled == enabled) return;
684    transit->event_enabled = !!enabled;
685    eina_hash_foreach(transit->objs_data_hash, _hash_foreach_pass_events_set, transit);
686 }
687
688 /**
689  * Get the value of event enabled status.
690  *
691  * @see elm_transit_event_enabled_set()
692  *
693  * @param transit The Transit object
694  * @return EINA_TRUE, when event is enabled. If @p transit is NULL
695  * EINA_FALSE is returned
696  *
697  * @ingroup Transit
698  */
699 EAPI Eina_Bool
700 elm_transit_event_enabled_get(const Elm_Transit *transit)
701 {
702    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
703    return transit->event_enabled;
704 }
705
706
707 /**
708  * Set the event enabled when transit is operating.
709  *
710  * If @p disabled is EINA_TRUE, the objects of the transit will receives
711  * events from mouse and keyboard during the animation.
712  * @note When you add an object with elm_transit_object_add(), its state from
713  * evas_object_pass_events_get(obj) is saved, and it is applied when the
714  * transit ends, if you change this state with evas_object_pass_events_set()
715  * after add the object, this state will change again when @p transit stops to
716  * run.
717  *
718  * @see elm_transit_event_enabled_set()
719  *
720  * @param transit The transit object.
721  * @param disabled Disable or enable.
722  *
723  * @ingroup Transit
724  */
725 EINA_DEPRECATED EAPI void
726 elm_transit_event_block_set(Elm_Transit *transit, Eina_Bool disabled)
727 {
728    elm_transit_event_enabled_set(transit, disabled);
729 }
730
731
732 /**
733  * Get the value of event block enabled  status.
734  *
735  * @see elm_transit_event_enabled_set(), elm_transit_event_enabled_get()
736  *
737  * @param transit The Transit object
738  * @return EINA_TRUE, when event is enabled. If @p transit is NULL
739  * EINA_FALSE is returned
740  *
741  * @ingroup Transit
742  */
743 EINA_DEPRECATED EAPI Eina_Bool
744 elm_transit_event_block_get(const Elm_Transit *transit)
745 {
746    return !elm_transit_event_enabled_get(transit);
747 }
748
749 /**
750  * Set the user-callback function when the transit is deleted.
751  *
752  * @note Using this function twice will overwrite the first function setted.
753  * @note the @p transit object will be deleted after call @p cb function.
754  *
755  * @param transit The transit object.
756  * @param cb Callback function pointer. This function will be called before
757  * the deletion of the transit.
758  * @param data Callback funtion user data. It is the @p op parameter.
759  *
760  * @ingroup Transit
761  */
762 EAPI void
763 elm_transit_del_cb_set(Elm_Transit *transit, void (*cb) (void *data, Elm_Transit *transit), void *data)
764 {
765    ELM_TRANSIT_CHECK_OR_RETURN(transit);
766    transit->del_data.func = cb;
767    transit->del_data.arg = data;
768 }
769
770 /**
771  * Set reverse effect automatically.
772  *
773  * If auto reverse is setted, after running the effects with the progress
774  * parameter from 0 to 1, it will call the effecs again with the progress
775  * from 1 to 0. The transit will last for a time iqual to (2 * duration * repeat),
776  * where the duration was setted with the function elm_transit_add and
777  * the repeat with the function elm_transit_repeat_times_set().
778  *
779  * @param transit The transit object.
780  * @param reverse EINA_TRUE means the auto_reverse is on.
781  *
782  * @ingroup Transit
783  */
784 EAPI void
785 elm_transit_auto_reverse_set(Elm_Transit *transit, Eina_Bool reverse)
786 {
787    ELM_TRANSIT_CHECK_OR_RETURN(transit);
788    transit->auto_reverse = reverse;
789 }
790
791 /**
792  * Get if the auto reverse is on.
793  *
794  * @see elm_transit_auto_reverse_set()
795  *
796  * @param transit The transit object.
797  * @return EINA_TRUE means auto reverse is on. If @p transit is NULL
798  * EINA_FALSE is returned
799  *
800  * @ingroup Transit
801  */
802 EAPI Eina_Bool
803 elm_transit_auto_reverse_get(const Elm_Transit *transit)
804 {
805    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
806    return transit->auto_reverse;
807 }
808
809 /**
810  * Set the transit repeat count. Effect will be repeated by repeat count.
811  *
812  * This function sets the number of repetition the transit will run after
813  * the first one, that is, if @p repeat is 1, the transit will run 2 times.
814  * If the @p repeat is a negative number, it will repeat infinite times.
815  *
816  * @note If this function is called during the transit execution, the transit
817  * will run @p repeat times, ignoring the times it already performed.
818  *
819  * @param transit The transit object
820  * @param repeat Repeat count
821  *
822  * @ingroup Transit
823  */
824 EAPI void
825 elm_transit_repeat_times_set(Elm_Transit *transit, int repeat)
826 {
827    ELM_TRANSIT_CHECK_OR_RETURN(transit);
828    transit->repeat.count = repeat;
829    transit->repeat.current = 0;
830 }
831
832 /**
833  * Get the transit repeat count.
834  *
835  * @see elm_transit_repeat_times_set()
836  *
837  * @param transit The Transit object.
838  * @return The repeat count. If @p transit is NULL
839  * 0 is returned
840  *
841  * @ingroup Transit
842  */
843 EAPI int
844 elm_transit_repeat_times_get(const Elm_Transit *transit)
845 {
846    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
847    return transit->repeat.count;
848 }
849
850 /**
851  * Set the transit animation acceleration type.
852  *
853  * This function sets the tween mode of the transit that can be:
854  * ELM_TRANSIT_TWEEN_MODE_LINEAR - The default mode.
855  * ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL - Starts in accelerate mode and ends decelerating.
856  * ELM_TRANSIT_TWEEN_MODE_DECELERATE - The animation will be slowed over time.
857  * ELM_TRANSIT_TWEEN_MODE_ACCELERATE - The animation will accelerate over time.
858  *
859  * @param transit The transit object.
860  * @param tween_mode The tween type.
861  *
862  * @ingroup Transit
863  */
864 EAPI void
865 elm_transit_tween_mode_set(Elm_Transit *transit, Elm_Transit_Tween_Mode tween_mode)
866 {
867    ELM_TRANSIT_CHECK_OR_RETURN(transit);
868    transit->tween_mode = tween_mode;
869 }
870
871 /**
872  * Get the transit animation acceleration type.
873  *
874  * @note @p transit can not be NULL
875  *
876  * @param transit The transit object.
877  * @return The tween type. If @p transit is NULL
878  * ELM_TRANSIT_TWEEN_MODE_LINEAR is returned.
879  *
880  * @ingroup Transit
881  */
882 EAPI Elm_Transit_Tween_Mode
883 elm_transit_tween_mode_get(const Elm_Transit *transit)
884 {
885    ELM_TRANSIT_CHECK_OR_RETURN(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
886    return transit->tween_mode;
887 }
888
889 /**
890  * Set the transit animation time
891  *
892  * @note @p transit can not be NULL
893  *
894  * @param transit The transit object.
895  * @param duration The animation time.
896  *
897  * @ingroup Transit
898  */
899 EAPI void
900 elm_transit_duration_set(Elm_Transit *transit, double duration)
901 {
902    ELM_TRANSIT_CHECK_OR_RETURN(transit);
903    if (transit->animator) return;
904    transit->time.duration = duration;
905 }
906
907 /**
908  * Get the transit animation time
909  *
910  * @note @p transit can not be NULL
911  *
912  * @param transit The transit object.
913  *
914  * @return The transit animation time.
915  *
916  * @ingroup Transit
917  */
918 EAPI double
919 elm_transit_duration_get(const Elm_Transit *transit)
920 {
921    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0.0);
922    return transit->time.duration;
923 }
924
925 /**
926  * Starts the transition.
927  * Once this API is called, the transit begins to measure the time.
928  *
929  * @note @p transit can not be NULL
930  *
931  * @param transit The transit object.
932  *
933  * @ingroup Transit
934  */
935 EAPI void
936 elm_transit_go(Elm_Transit *transit)
937 {
938    ELM_TRANSIT_CHECK_OR_RETURN(transit);
939
940    if (transit->animator)
941      ecore_animator_del(transit->animator);
942
943    transit->time.paused = 0;
944    transit->time.delayed = 0;
945    transit->time.begin = ecore_loop_time_get();
946    transit->animator = ecore_animator_add(_animator_animate_cb, transit);
947 }
948
949 /**
950  * Pause/Resume the transition.
951  * If you call elm_transit_go again, paused states will affect no anymore.
952  *
953  * @note @p transit can not be NULL
954  *
955  * @param transit The transit object.
956  *
957  * @ingroup Transit
958  */
959 EAPI void
960 elm_transit_paused_set(Elm_Transit *transit, Eina_Bool paused)
961 {
962    ELM_TRANSIT_CHECK_OR_RETURN(transit);
963
964    if (!transit->animator) return;
965
966    if (paused)
967      {
968         if (transit->time.paused > 0)
969           return;
970         ecore_animator_freeze(transit->animator);
971         transit->time.paused = ecore_loop_time_get();
972      }
973    else
974      {
975         if (transit->time.paused == 0)
976           return;
977         ecore_animator_thaw(transit->animator);
978         transit->time.delayed += (ecore_loop_time_get() - transit->time.paused);
979         transit->time.paused = 0;
980      }
981 }
982
983 /**
984  * Get the value of paused status.
985  *
986  * @see elm_transit_paused_set()
987  *
988  * @note @p transit can not be NULL
989  *
990  * @param transit The transit object.
991  * @return EINA_TRUE means transition is paused. If @p transit is NULL
992  * EINA_FALSE is returned
993  *
994  * @ingroup Transit
995  */
996 EAPI Eina_Bool
997 elm_transit_paused_get(const Elm_Transit *transit)
998 {
999    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
1000
1001    if (transit->time.paused == 0)
1002      return EINA_FALSE;
1003
1004    return EINA_TRUE;
1005 }
1006
1007 /**
1008  * Get the time progression of the animation (a double value between 0.0 and 1.0).
1009  *
1010  * @note @p transit can not be NULL
1011  *
1012  * @param transit The transit object.
1013  *
1014  * @return The time progression value. If @p transit is NULL
1015  * 0 is returned
1016  *
1017  * @ingroup Transit
1018  */
1019 EAPI double
1020 elm_transit_progress_value_get(const Elm_Transit *transit)
1021 {
1022    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
1023    return transit->progress;
1024 }
1025
1026
1027
1028 /**
1029  * Enable/disable keeping up the objects states.
1030  * If it is not kept, the objects states will be reset when transition ends.
1031  *
1032  * @note @p transit can not be NULL.
1033  * @note One state includes geometry, color, map data.
1034  *
1035  * @param transit The transit object.
1036  * @param state_keep Keeping or Non Keeping.
1037  *
1038  * @ingroup Transit
1039  */
1040 EAPI void
1041 elm_transit_objects_final_state_keep_set(Elm_Transit *transit, Eina_Bool state_keep)
1042 {
1043    ELM_TRANSIT_CHECK_OR_RETURN(transit);
1044    if (transit->state_keep == state_keep) return;
1045    if (transit->animator) return;
1046    transit->state_keep = !!state_keep;
1047    if (state_keep) return;
1048    eina_hash_foreach(transit->objs_data_hash, _hash_foreach_obj_states_save, NULL);
1049 }
1050
1051 /**
1052  * Get a value whether the objects states will be reset or not.
1053  *
1054  * @note @p transit can not be NULL
1055  *
1056  * @see elm_transit_objects_final_state_keep_set()
1057  *
1058  * @param transit The transit object.
1059  * @return EINA_TRUE means the states of the objects will be reset.
1060  * If @p transit is NULL, EINA_FALSE is returned
1061  *
1062  * @ingroup Transit
1063  */
1064 EAPI Eina_Bool
1065 elm_transit_objects_final_state_keep_get(const Elm_Transit *transit)
1066 {
1067    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
1068    return transit->state_keep;
1069 }
1070
1071 /**
1072  * Makes the chain relationship between two transits.
1073  *
1074  * @note @p transit can not be NULL. Transit would have multiple chain transits.
1075  * @note @p chain_transit can not be NULL. Chain transits could be chained to the only one transit.
1076  *
1077  * @param transit The transit object.
1078  * @param chain_transit The chain transit object. This transit will be operated  
1079  *        after transit is done.
1080  *
1081  * @ingroup Transit
1082  */
1083 EAPI void
1084 elm_transit_chain_transit_add(Elm_Transit *transit, Elm_Transit *chain_transit)
1085 {
1086    ELM_TRANSIT_CHECK_OR_RETURN(transit);
1087    ELM_TRANSIT_CHECK_OR_RETURN(chain_transit);
1088
1089    if (transit == chain_transit) return;
1090    if (transit == chain_transit->prev_chain_transit) return;
1091
1092    if (chain_transit->prev_chain_transit)
1093      chain_transit->prev_chain_transit->next_chain_transits = eina_list_remove(chain_transit->prev_chain_transit->next_chain_transits, chain_transit);
1094
1095    chain_transit->prev_chain_transit = transit;
1096    transit->next_chain_transits = eina_list_append(transit->next_chain_transits, chain_transit);
1097 }
1098
1099 /**
1100  * Get the current chain transit list.
1101  *
1102  * @note @p transit can not be NULL.
1103  *
1104  * @param transit The transit object.
1105  * @return chain transit list.
1106  *
1107  * @ingroup Transit
1108  */
1109 EAPI Eina_List *
1110 elm_transit_chain_transits_get(const Elm_Transit * transit)
1111 {
1112    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1113    return transit->next_chain_transits;
1114 }
1115
1116 ///////////////////////////////////////////////////////////////////////////////
1117 //Resizing Effect
1118 ///////////////////////////////////////////////////////////////////////////////
1119 typedef struct _Elm_Transit_Effect_Resizing Elm_Transit_Effect_Resizing;
1120
1121 struct _Elm_Transit_Effect_Resizing
1122 {
1123    struct _size {
1124       Evas_Coord w, h;
1125    } from, to;
1126 };
1127
1128 static void
1129 _transit_effect_resizing_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1130 {
1131    Elm_Transit_Effect_Resizing *resizing = effect;
1132    free(resizing);
1133 }
1134
1135 static void
1136 _transit_effect_resizing_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1137 {
1138    EINA_SAFETY_ON_NULL_RETURN(effect);
1139    EINA_SAFETY_ON_NULL_RETURN(transit);
1140    Evas_Coord w, h;
1141    Evas_Object *obj;
1142    Eina_List *elist;
1143    Elm_Transit_Effect_Resizing *resizing = effect;
1144
1145    w = resizing->from.w + (resizing->to.w * progress);
1146    h = resizing->from.h + (resizing->to.h * progress);
1147
1148    EINA_LIST_FOREACH(transit->objs, elist, obj)
1149      evas_object_resize(obj, w, h);
1150 }
1151
1152 static Elm_Transit_Effect *
1153 _transit_effect_resizing_context_new(Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
1154 {
1155    Elm_Transit_Effect_Resizing *resizing;
1156
1157    resizing = ELM_NEW(Elm_Transit_Effect_Resizing);
1158    if (!resizing) return NULL;
1159
1160    resizing->from.w = from_w;
1161    resizing->from.h = from_h;
1162    resizing->to.w = to_w - from_w;
1163    resizing->to.h = to_h - from_h;
1164
1165    return resizing;
1166 }
1167
1168 /**
1169  * Add the Resizing Effect to Elm_Transit.
1170  *
1171  * @note This API is one of the facades. It creates resizing effect context
1172  * and add it's required APIs to elm_transit_effect_add.
1173  *
1174  * @see elm_transit_effect_add()
1175  *
1176  * @param transit Transit object.
1177  * @param from_w Object width size when effect begins.
1178  * @param from_h Object height size when effect begins.
1179  * @param to_w Object width size when effect ends.
1180  * @param to_h Object height size when effect ends.
1181  * @return Resizing effect context data.
1182  *
1183  * @ingroup Transit
1184  */
1185 EAPI Elm_Transit_Effect *
1186 elm_transit_effect_resizing_add(Elm_Transit *transit, Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
1187 {
1188    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1189    Elm_Transit_Effect *effect = _transit_effect_resizing_context_new(from_w, from_h, to_w, to_h);
1190
1191    if (!effect) return NULL;
1192    elm_transit_effect_add(transit,
1193                           _transit_effect_resizing_op, effect,
1194                           _transit_effect_resizing_context_free);
1195    return effect;
1196 }
1197
1198 ///////////////////////////////////////////////////////////////////////////////
1199 //Translation Effect
1200 ///////////////////////////////////////////////////////////////////////////////
1201 typedef struct _Elm_Transit_Effect_Translation Elm_Transit_Effect_Translation;
1202 typedef struct _Elm_Transit_Effect_Translation_Node Elm_Transit_Effect_Translation_Node;
1203
1204 struct _Elm_Transit_Effect_Translation_Node
1205 {
1206    Evas_Object *obj;
1207    Evas_Coord x, y;
1208 };
1209
1210 struct _Elm_Transit_Effect_Translation
1211 {
1212    struct _position_variation {
1213       Evas_Coord dx, dy;
1214    } from, to;
1215    Eina_List *nodes;
1216 };
1217
1218 static void
1219 _translation_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1220 {
1221    Elm_Transit_Effect_Translation *translation = data;
1222    Eina_List *elist;
1223    Elm_Transit_Effect_Translation_Node *translation_node;
1224
1225    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
1226      {
1227         if (translation_node->obj != obj) continue;
1228         translation->nodes = eina_list_remove_list(translation->nodes, elist);
1229         free(translation_node);
1230         break;
1231      }
1232 }
1233
1234 static Eina_List *
1235 _translation_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Translation *translation)
1236 {
1237    Elm_Transit_Effect_Translation_Node *translation_node;
1238    const Eina_List *elist;
1239    Evas_Object *obj;
1240    Eina_List *data_list = NULL;
1241    const Eina_List *objs = elm_transit_objects_get(transit);
1242
1243    EINA_LIST_FOREACH(objs, elist, obj)
1244      {
1245         translation_node = ELM_NEW(Elm_Transit_Effect_Translation_Node);
1246         if (!translation_node)
1247           {
1248              eina_list_free(data_list);
1249              return NULL;
1250           }
1251         translation_node->obj = obj;
1252         evas_object_geometry_get(obj, &(translation_node->x),
1253                                  &(translation_node->y), NULL, NULL);
1254         data_list = eina_list_append(data_list, translation_node);
1255         evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
1256                                        _translation_object_del_cb, translation);
1257      }
1258    return data_list;
1259 }
1260
1261 void
1262 _transit_effect_translation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1263 {
1264    EINA_SAFETY_ON_NULL_RETURN(effect);
1265    Elm_Transit_Effect_Translation *translation = effect;
1266    Eina_List *elist, *elist_next;
1267    Elm_Transit_Effect_Translation_Node *translation_node;
1268
1269    EINA_LIST_FOREACH_SAFE(translation->nodes,
1270                           elist, elist_next, translation_node)
1271      {
1272         evas_object_event_callback_del(translation_node->obj,
1273                                        EVAS_CALLBACK_DEL, _translation_object_del_cb);
1274         translation->nodes = eina_list_remove_list(translation->nodes, elist);
1275         free(translation_node);
1276      }
1277    free(translation);
1278 }
1279
1280 void
1281 _transit_effect_translation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress __UNUSED__)
1282 {
1283    EINA_SAFETY_ON_NULL_RETURN(effect);
1284    EINA_SAFETY_ON_NULL_RETURN(transit);
1285    Evas_Coord x, y;
1286    Elm_Transit_Effect_Translation *translation = effect;
1287    Elm_Transit_Effect_Translation_Node *translation_node;
1288    Eina_List *elist;
1289
1290    if (!translation->nodes)
1291      translation->nodes = _translation_nodes_build(transit, translation);
1292
1293    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
1294      {
1295         x = translation_node->x + translation->from.dx
1296            + (translation->to.dx * progress);
1297         y = translation_node->y + translation->from.dy
1298            + (translation->to.dy * progress);
1299         evas_object_move(translation_node->obj, x, y);
1300      }
1301 }
1302
1303 static Elm_Transit_Effect *
1304 _transit_effect_translation_context_new(Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
1305 {
1306    Elm_Transit_Effect_Translation *translation;
1307
1308    translation = ELM_NEW(Elm_Transit_Effect_Translation);
1309    if (!translation) return NULL;
1310
1311    translation->from.dx = from_dx;
1312    translation->from.dy = from_dy;
1313    translation->to.dx = to_dx - from_dx;
1314    translation->to.dy = to_dy - from_dy;
1315
1316    return translation;
1317 }
1318
1319 /**
1320  * Add the Translation Effect to Elm_Transit.
1321  *
1322  * @note This API is one of the facades. It creates translation effect context
1323  * and add it's required APIs to elm_transit_effect_add.
1324  *
1325  * @see elm_transit_effect_add()
1326  *
1327  * @param transit Transit object.
1328  * @param from_dx X Position variation when effect begins.
1329  * @param from_dy Y Position variation when effect begins.
1330  * @param to_dx X Position variation when effect ends.
1331  * @param to_dy Y Position variation when effect ends.
1332  * @return Translation effect context data.
1333  *
1334  * @ingroup Transit
1335  * @warning Is higher recommended just create a transit with this effect when
1336  * the window that the objects of the transit belongs has already been created.
1337  * This is because this effect needs the geometry information about the objects,
1338  * and if the window was not created yet, it can get a wrong information.
1339  */
1340 EAPI Elm_Transit_Effect *
1341 elm_transit_effect_translation_add(Elm_Transit *transit, Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
1342 {
1343    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1344    Elm_Transit_Effect *effect_context = _transit_effect_translation_context_new(from_dx, from_dy, to_dx, to_dy);
1345
1346    if (!effect_context) return NULL;
1347    elm_transit_effect_add(transit,
1348                           _transit_effect_translation_op, effect_context,
1349                           _transit_effect_translation_context_free);
1350    return effect_context;
1351 }
1352
1353
1354 ///////////////////////////////////////////////////////////////////////////////
1355 //Zoom Effect
1356 ///////////////////////////////////////////////////////////////////////////////
1357 typedef struct _Elm_Transit_Effect_Zoom Elm_Transit_Effect_Zoom;
1358
1359 struct _Elm_Transit_Effect_Zoom
1360 {
1361    float from, to;
1362 };
1363
1364 void
1365 _transit_effect_zoom_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1366 {
1367    Elm_Transit_Effect_Zoom *zoom = effect;
1368    free(zoom);
1369 }
1370
1371 static void
1372 _transit_effect_zoom_op(Elm_Transit_Effect *effect, Elm_Transit *transit , double progress)
1373 {
1374    EINA_SAFETY_ON_NULL_RETURN(effect);
1375    EINA_SAFETY_ON_NULL_RETURN(transit);
1376    Evas_Object *obj;
1377    Eina_List *elist;
1378    Elm_Transit_Effect_Zoom *zoom = effect;
1379    Evas_Map *map;
1380    Evas_Coord x, y, w, h;
1381
1382    map = evas_map_new(4);
1383    if (!map) return;
1384
1385    EINA_LIST_FOREACH(transit->objs, elist, obj)
1386      {
1387         evas_object_geometry_get(obj, &x, &y, &w, &h);
1388         evas_map_util_points_populate_from_object_full(map, obj, zoom->from +
1389                                                        (progress * zoom->to));
1390         evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1391         evas_object_map_set(obj, map);
1392         evas_object_map_enable_set(obj, EINA_TRUE);
1393      }
1394    evas_map_free(map);
1395 }
1396
1397 static Elm_Transit_Effect *
1398 _transit_effect_zoom_context_new(float from_rate, float to_rate)
1399 {
1400    Elm_Transit_Effect_Zoom *zoom;
1401
1402    zoom = ELM_NEW(Elm_Transit_Effect_Zoom);
1403    if (!zoom) return NULL;
1404
1405    zoom->from = (_TRANSIT_FOCAL - (from_rate * _TRANSIT_FOCAL)) * (1 / from_rate);
1406    zoom->to = ((_TRANSIT_FOCAL - (to_rate * _TRANSIT_FOCAL)) * (1 / to_rate)) - zoom->from;
1407
1408    return zoom;
1409 }
1410
1411 /**
1412  * Add the Zoom Effect to Elm_Transit.
1413  *
1414  * @note This API is one of the facades. It creates zoom effect context
1415  * and add it's required APIs to elm_transit_effect_add.
1416  *
1417  * @see elm_transit_effect_add()
1418  *
1419  * @param transit Transit object.
1420  * @param from_rate Scale rate when effect begins (1 is current rate).
1421  * @param to_rate Scale rate when effect ends.
1422  * @return Zoom effect context data.
1423  *
1424  * @ingroup Transit
1425  * @warning Is higher recommended just create a transit with this effect when
1426  * the window that the objects of the transit belongs has already been created.
1427  * This is because this effect needs the geometry information about the objects,
1428  * and if the window was not created yet, it can get a wrong information.
1429  */
1430 EAPI Elm_Transit_Effect *
1431 elm_transit_effect_zoom_add(Elm_Transit *transit, float from_rate, float to_rate)
1432 {
1433    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1434    Elm_Transit_Effect *effect_context = _transit_effect_zoom_context_new(from_rate, to_rate);
1435
1436    if (!effect_context) return NULL;
1437    elm_transit_effect_add(transit,
1438                           _transit_effect_zoom_op, effect_context,
1439                           _transit_effect_zoom_context_free);
1440    return effect_context;
1441 }
1442
1443
1444 ///////////////////////////////////////////////////////////////////////////////
1445 //Flip Effect
1446 ///////////////////////////////////////////////////////////////////////////////
1447 typedef struct _Elm_Transit_Effect_Flip Elm_Transit_Effect_Flip;
1448
1449 struct _Elm_Transit_Effect_Flip
1450 {
1451    Elm_Transit_Effect_Flip_Axis axis;
1452    Eina_Bool cw : 1;
1453 };
1454
1455 static void
1456 _transit_effect_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
1457 {
1458    EINA_SAFETY_ON_NULL_RETURN(effect);
1459    EINA_SAFETY_ON_NULL_RETURN(transit);
1460    Elm_Transit_Effect_Flip *flip = effect;
1461    Evas_Object *front, *back;
1462    int i;
1463    int count = eina_list_count(transit->objs);
1464
1465    for (i = 0; i < (count - 1); i += 2)
1466      {
1467         front = eina_list_nth(transit->objs, i);
1468         back = eina_list_nth(transit->objs, i+1);
1469         evas_object_map_enable_set(front, EINA_FALSE);
1470         evas_object_map_enable_set(back, EINA_FALSE);
1471      }
1472    free(flip);
1473 }
1474
1475 static void
1476 _transit_effect_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1477 {
1478    EINA_SAFETY_ON_NULL_RETURN(effect);
1479    EINA_SAFETY_ON_NULL_RETURN(transit);
1480    Evas_Object *obj, *front, *back;
1481    int count, i;
1482    Elm_Transit_Effect_Flip *flip = effect;
1483    Evas_Map *map;
1484    float degree;
1485    Evas_Coord x, y, w, h;
1486
1487    map = evas_map_new(4);
1488    if (!map) return;
1489
1490    if (flip->cw) degree = (float)(progress * 180);
1491    else degree = (float)(progress * -180);
1492
1493    count = eina_list_count(transit->objs);
1494
1495    for (i = 0; i < (count - 1); i += 2)
1496      {
1497         Evas_Coord half_w, half_h;
1498
1499         front = eina_list_nth(transit->objs, i);
1500         back = eina_list_nth(transit->objs, i+1);
1501
1502         if ((degree < 90) && (degree > -90))
1503           {
1504              obj = front;
1505              if (front != back)
1506                {
1507                   evas_object_hide(back);
1508                   evas_object_show(front);
1509                }
1510           }
1511         else
1512           {
1513              obj = back;
1514              if (front != back)
1515                {
1516                   evas_object_hide(front);
1517                   evas_object_show(back);
1518                }
1519           }
1520
1521         evas_map_util_points_populate_from_object_full(map, obj, 0);
1522         evas_object_geometry_get(obj, &x, &y, &w, &h);
1523         half_w = (w / 2);
1524         half_h = (h / 2);
1525
1526         if (flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1527           {
1528              if ((degree >= 90) || (degree <= -90))
1529                {
1530                   evas_map_point_image_uv_set(map, 0, w, 0);
1531                   evas_map_point_image_uv_set(map, 1, 0, 0);
1532                   evas_map_point_image_uv_set(map, 2, 0, h);
1533                   evas_map_point_image_uv_set(map, 3, w, h);
1534                }
1535              evas_map_util_3d_rotate(map, 0, degree,
1536                                      0, x + half_w, y + half_h, 0);
1537           }
1538         else
1539           {
1540              if ((degree >= 90) || (degree <= -90))
1541                {
1542                   evas_map_point_image_uv_set(map, 0, 0, h);
1543                   evas_map_point_image_uv_set(map, 1, w, h);
1544                   evas_map_point_image_uv_set(map, 2, w, 0);
1545                   evas_map_point_image_uv_set(map, 3, 0, 0);
1546                }
1547              evas_map_util_3d_rotate(map, degree,
1548                                      0, 0, x + half_w, y + half_h, 0);
1549           }
1550         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1551         evas_object_map_enable_set(front, EINA_TRUE);
1552         evas_object_map_enable_set(back, EINA_TRUE);
1553         evas_object_map_set(obj, map);
1554      }
1555    evas_map_free(map);
1556 }
1557
1558 static Elm_Transit_Effect *
1559 _transit_effect_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1560 {
1561    Elm_Transit_Effect_Flip *flip;
1562
1563    flip = ELM_NEW(Elm_Transit_Effect_Flip);
1564    if (!flip) return NULL;
1565
1566    flip->cw = cw;
1567    flip->axis = axis;
1568
1569    return flip;
1570 }
1571
1572 /**
1573  * Add the Flip Effect to Elm_Transit.
1574  *
1575  * @note This API is one of the facades. It creates flip effect context
1576  * and add it's required APIs to elm_transit_effect_add.
1577  * @note This effect is applied to each pair of objects in the order they are listed
1578  * in the transit list of objects. The first object in the pair will be the
1579  * "front" object and the second will be the "back" object.
1580  *
1581  * @see elm_transit_effect_add()
1582  *
1583  * @param transit Transit object.
1584  * @param axis Flipping Axis(X or Y).
1585  * @param cw Flipping Direction. EINA_TRUE is clock-wise.
1586  * @return Flip effect context data.
1587  *
1588  * @ingroup Transit
1589  * @warning Is higher recommended just create a transit with this effect when
1590  * the window that the objects of the transit belongs has already been created.
1591  * This is because this effect needs the geometry information about the objects,
1592  * and if the window was not created yet, it can get a wrong information.
1593  */
1594 EAPI Elm_Transit_Effect *
1595 elm_transit_effect_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1596 {
1597    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1598    Elm_Transit_Effect *effect_context = _transit_effect_flip_context_new(axis, cw);
1599
1600    if (!effect_context) return NULL;
1601    elm_transit_effect_add(transit,
1602                           _transit_effect_flip_op, effect_context,
1603                           _transit_effect_flip_context_free);
1604    return effect_context;
1605 }
1606
1607 ///////////////////////////////////////////////////////////////////////////////
1608 //ResizableFlip Effect
1609 ///////////////////////////////////////////////////////////////////////////////
1610 typedef struct _Elm_Transit_Effect_Resizable_Flip Elm_Transit_Effect_ResizableFlip;
1611 typedef struct _Elm_Transit_Effect_Resizable_Flip_Node Elm_Transit_Effect_ResizableFlip_Node;
1612
1613 struct _Elm_Transit_Effect_Resizable_Flip_Node
1614 {
1615    Evas_Object *front;
1616    Evas_Object *back;
1617    struct _vector2d {
1618       float x, y;
1619    } from_pos, from_size, to_pos, to_size;
1620 };
1621
1622 struct _Elm_Transit_Effect_Resizable_Flip
1623 {
1624    Eina_List *nodes;
1625    Eina_Bool cw : 1;
1626    Elm_Transit_Effect_Flip_Axis axis;
1627 };
1628
1629 static void
1630 _resizable_flip_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1631 {
1632    Elm_Transit_Effect_ResizableFlip *resizable_flip = data;
1633    Eina_List *elist;
1634    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1635
1636    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1637      {
1638         if (resizable_flip_node->front == obj)
1639           evas_object_event_callback_del(resizable_flip_node->back,
1640                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1641         else if (resizable_flip_node->back == obj)
1642           evas_object_event_callback_del(resizable_flip_node->front,
1643                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1644         else continue;
1645
1646         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1647                                                       elist);
1648         free(resizable_flip_node);
1649         break;
1650      }
1651 }
1652
1653 static Eina_List *
1654 _resizable_flip_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_ResizableFlip *resizable_flip)
1655 {
1656    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1657    Eina_List *data_list = NULL;
1658    Evas_Coord front_x, front_y, front_w, front_h;
1659    Evas_Coord back_x, back_y, back_w, back_h;
1660    int i, count;
1661
1662    count = eina_list_count(transit->objs);
1663    for (i = 0; i < (count - 1); i += 2)
1664      {
1665         resizable_flip_node = ELM_NEW(Elm_Transit_Effect_ResizableFlip_Node);
1666         if (!resizable_flip_node)
1667           {
1668              eina_list_free(data_list);
1669              return NULL;
1670           }
1671
1672         resizable_flip_node->front = eina_list_nth(transit->objs, i);
1673         resizable_flip_node->back = eina_list_nth(transit->objs, i+1);
1674
1675         evas_object_geometry_get(resizable_flip_node->front,
1676                                  &front_x, &front_y, &front_w, &front_h);
1677         evas_object_geometry_get(resizable_flip_node->back,
1678                                  &back_x, &back_y, &back_w, &back_h);
1679
1680         resizable_flip_node->from_pos.x = front_x;
1681         resizable_flip_node->from_pos.y = front_y;
1682         resizable_flip_node->to_pos.x = back_x - front_x;
1683         resizable_flip_node->to_pos.y = back_y - front_y;
1684
1685         resizable_flip_node->from_size.x = front_w;
1686         resizable_flip_node->from_size.y = front_h;
1687         resizable_flip_node->to_size.x = back_w - front_w;
1688         resizable_flip_node->to_size.y = back_h - front_h;
1689
1690         data_list = eina_list_append(data_list, resizable_flip_node);
1691
1692         evas_object_event_callback_add(resizable_flip_node->back,
1693                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1694         evas_object_event_callback_add(resizable_flip_node->front,
1695                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1696      }
1697
1698    return data_list;
1699 }
1700
1701 static void
1702 _set_image_uv_by_axis_y(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1703 {
1704    if ((degree >= 90) || (degree <= -90))
1705      {
1706         evas_map_point_image_uv_set(map, 0,
1707                                     (flip->from_size.x * 2) + flip->to_size.x,
1708                                     0);
1709         evas_map_point_image_uv_set(map, 1, 0, 0);
1710         evas_map_point_image_uv_set(map, 2, 0,
1711                                     (flip->from_size.y * 2) + flip->to_size.y);
1712         evas_map_point_image_uv_set(map, 3,
1713                                     (flip->from_size.x * 2) + flip->to_size.x,
1714                                     (flip->from_size.y * 2) + flip->to_size.y);
1715      }
1716    else
1717      {
1718         evas_map_point_image_uv_set(map, 0, 0, 0);
1719         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1720         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1721                                     flip->from_size.y);
1722         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1723      }
1724 }
1725
1726 static void
1727 _set_image_uv_by_axis_x(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1728 {
1729    if ((degree >= 90) || (degree <= -90))
1730      {
1731         evas_map_point_image_uv_set(map, 0, 0,
1732                                     (flip->from_size.y * 2) + flip->to_size.y);
1733         evas_map_point_image_uv_set(map, 1,
1734                                     (flip->from_size.x * 2) + flip->to_size.x,
1735                                     (flip->from_size.y * 2) + flip->to_size.y);
1736         evas_map_point_image_uv_set(map, 2,
1737                                     (flip->from_size.x * 2) + flip->to_size.x,
1738                                     0);
1739         evas_map_point_image_uv_set(map, 3, 0, 0);
1740      }
1741    else
1742      {
1743         evas_map_point_image_uv_set(map, 0, 0, 0);
1744         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1745         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1746                                     flip->from_size.y);
1747         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1748      }
1749 }
1750
1751 void
1752 _transit_effect_resizable_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1753 {
1754    EINA_SAFETY_ON_NULL_RETURN(effect);
1755
1756    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1757    Eina_List *elist, *elist_next;
1758    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1759
1760    EINA_LIST_FOREACH_SAFE(resizable_flip->nodes,
1761                           elist, elist_next, resizable_flip_node)
1762      {
1763         evas_object_map_enable_set(resizable_flip_node->front, EINA_FALSE);
1764         evas_object_map_enable_set(resizable_flip_node->back, EINA_FALSE);
1765
1766         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1767                                                       elist);
1768
1769         evas_object_event_callback_del(resizable_flip_node->back,
1770                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1771         evas_object_event_callback_del(resizable_flip_node->front,
1772                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1773         free(resizable_flip_node);
1774      }
1775    free(resizable_flip);
1776 }
1777
1778 void
1779 _transit_effect_resizable_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1780 {
1781    EINA_SAFETY_ON_NULL_RETURN(effect);
1782    Evas_Map *map;
1783    Evas_Object *obj;
1784    float x, y, w, h;
1785    float degree;
1786    Evas_Coord half_w, half_h;
1787    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1788    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1789    Eina_List *elist;
1790
1791    map = evas_map_new(4);
1792    if (!map) return;
1793
1794    if (resizable_flip->cw) degree = (float)(progress * 180);
1795    else degree = (float)(progress * -180);
1796
1797    if (!resizable_flip->nodes)
1798      resizable_flip->nodes = _resizable_flip_nodes_build(transit,
1799                                                          resizable_flip);
1800
1801    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1802      {
1803         if ((degree < 90) && (degree > -90))
1804           {
1805              obj = resizable_flip_node->front;
1806              if (resizable_flip_node->front != resizable_flip_node->back)
1807                {
1808                   evas_object_hide(resizable_flip_node->back);
1809                   evas_object_show(resizable_flip_node->front);
1810                }
1811           }
1812         else
1813           {
1814              obj = resizable_flip_node->back;
1815              if (resizable_flip_node->front != resizable_flip_node->back)
1816                {
1817                   evas_object_hide(resizable_flip_node->front);
1818                   evas_object_show(resizable_flip_node->back);
1819                }
1820           }
1821
1822         x = resizable_flip_node->from_pos.x +
1823            (resizable_flip_node->to_pos.x * progress);
1824         y = resizable_flip_node->from_pos.y +
1825            (resizable_flip_node->to_pos.y * progress);
1826         w = resizable_flip_node->from_size.x +
1827            (resizable_flip_node->to_size.x * progress);
1828         h = resizable_flip_node->from_size.y +
1829            (resizable_flip_node->to_size.y * progress);
1830         evas_map_point_coord_set(map, 0, x, y, 0);
1831         evas_map_point_coord_set(map, 1, x + w, y, 0);
1832         evas_map_point_coord_set(map, 2, x + w, y + h, 0);
1833         evas_map_point_coord_set(map, 3, x, y + h, 0);
1834
1835         half_w = (Evas_Coord)(w / 2);
1836         half_h = (Evas_Coord)(h / 2);
1837
1838         if (resizable_flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1839           {
1840              _set_image_uv_by_axis_y(map, resizable_flip_node, degree);
1841              evas_map_util_3d_rotate(map, 0, degree,
1842                                      0, x + half_w, y + half_h, 0);
1843           }
1844         else
1845           {
1846              _set_image_uv_by_axis_x(map, resizable_flip_node, degree);
1847              evas_map_util_3d_rotate(map, degree, 0,
1848                                      0, x + half_w, y + half_h, 0);
1849           }
1850
1851         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1852         evas_object_map_enable_set(resizable_flip_node->front, EINA_TRUE);
1853         evas_object_map_enable_set(resizable_flip_node->back, EINA_TRUE);
1854         evas_object_map_set(obj, map);
1855      }
1856    evas_map_free(map);
1857 }
1858
1859 static Elm_Transit_Effect *
1860 _transit_effect_resizable_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1861 {
1862    Elm_Transit_Effect_ResizableFlip *resizable_flip;
1863
1864    resizable_flip = ELM_NEW(Elm_Transit_Effect_ResizableFlip);
1865    if (!resizable_flip) return NULL;
1866
1867    resizable_flip->cw = cw;
1868    resizable_flip->axis = axis;
1869
1870    return resizable_flip;
1871 }
1872
1873 /**
1874  * Add the Resizable Flip Effect to Elm_Transit.
1875  *
1876  * @note This API is one of the facades. It creates resizable flip effect context
1877  * and add it's required APIs to elm_transit_effect_add.
1878  * @note This effect is applied to each pair of objects in the order they are listed
1879  * in the transit list of objects. The first object in the pair will be the
1880  * "front" object and the second will be the "back" object.
1881  *
1882  * @see elm_transit_effect_add()
1883  *
1884  * @param transit Transit object.
1885  * @param axis Flipping Axis(X or Y).
1886  * @param cw Flipping Direction. EINA_TRUE is clock-wise.
1887  * @return Resizable flip effect context data.
1888  *
1889  * @ingroup Transit
1890  * @warning Is higher recommended just create a transit with this effect when
1891  * the window that the objects of the transit belongs has already been created.
1892  * This is because this effect needs the geometry information about the objects,
1893  * and if the window was not created yet, it can get a wrong information.
1894  */
1895 EAPI Elm_Transit_Effect *
1896 elm_transit_effect_resizable_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1897 {
1898    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1899    Elm_Transit_Effect *effect_context = _transit_effect_resizable_flip_context_new(axis, cw);
1900
1901    if (!effect_context) return NULL;
1902    elm_transit_effect_add(transit,
1903                           _transit_effect_resizable_flip_op, effect_context,
1904                           _transit_effect_resizable_flip_context_free);
1905    return effect_context;
1906 }
1907
1908
1909 ///////////////////////////////////////////////////////////////////////////////
1910 //Wipe Effect
1911 ///////////////////////////////////////////////////////////////////////////////
1912 typedef struct _Elm_Transit_Effect_Wipe Elm_Transit_Effect_Wipe;
1913
1914 struct _Elm_Transit_Effect_Wipe
1915 {
1916    Elm_Transit_Effect_Wipe_Type type;
1917    Elm_Transit_Effect_Wipe_Dir dir;
1918 };
1919
1920 static void
1921 _elm_fx_wipe_hide(Evas_Map * map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1922 {
1923    float w2, h2;
1924
1925    switch (dir)
1926      {
1927       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1928          w2 = w - (w * progress);
1929          h2 = (y + h);
1930          evas_map_point_image_uv_set(map, 0, 0, 0);
1931          evas_map_point_image_uv_set(map, 1, w2, 0);
1932          evas_map_point_image_uv_set(map, 2, w2, h);
1933          evas_map_point_image_uv_set(map, 3, 0, h);
1934          evas_map_point_coord_set(map, 0, x, y, 0);
1935          evas_map_point_coord_set(map, 1, x + w2, y, 0);
1936          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
1937          evas_map_point_coord_set(map, 3, x, h2, 0);
1938          break;
1939       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
1940          w2 = (w * progress);
1941          h2 = (y + h);
1942          evas_map_point_image_uv_set(map, 0, w2, 0);
1943          evas_map_point_image_uv_set(map, 1, w, 0);
1944          evas_map_point_image_uv_set(map, 2, w, h);
1945          evas_map_point_image_uv_set(map, 3, w2, h);
1946          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1947          evas_map_point_coord_set(map, 1, x + w, y, 0);
1948          evas_map_point_coord_set(map, 2, x + w, h2, 0);
1949          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1950          break;
1951       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
1952          w2 = (x + w);
1953          h2 = h - (h * progress);
1954          evas_map_point_image_uv_set(map, 0, 0, 0);
1955          evas_map_point_image_uv_set(map, 1, w, 0);
1956          evas_map_point_image_uv_set(map, 2, w, h2);
1957          evas_map_point_image_uv_set(map, 3, 0, h2);
1958          evas_map_point_coord_set(map, 0, x, y, 0);
1959          evas_map_point_coord_set(map, 1, w2, y, 0);
1960          evas_map_point_coord_set(map, 2, w2, y+h2, 0);
1961          evas_map_point_coord_set(map, 3, x, y+h2, 0);
1962          break;
1963       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
1964          w2 = (x + w);
1965          h2 = (h * progress);
1966          evas_map_point_image_uv_set(map, 0, 0, h2);
1967          evas_map_point_image_uv_set(map, 1, w, h2);
1968          evas_map_point_image_uv_set(map, 2, w, h);
1969          evas_map_point_image_uv_set(map, 3, 0, h);
1970          evas_map_point_coord_set(map, 0, x, y + h2, 0);
1971          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
1972          evas_map_point_coord_set(map, 2, w2, y + h, 0);
1973          evas_map_point_coord_set(map, 3, x, y + h, 0);
1974          break;
1975       default:
1976          break;
1977      }
1978    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1979 }
1980
1981 static void
1982 _elm_fx_wipe_show(Evas_Map *map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1983 {
1984    float w2, h2;
1985
1986    switch (dir)
1987      {
1988       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1989          w2 = (w - (w * progress));
1990          h2 = (y + h);
1991          evas_map_point_image_uv_set(map, 0, w2, 0);
1992          evas_map_point_image_uv_set(map, 1, w, 0);
1993          evas_map_point_image_uv_set(map, 2, w, h);
1994          evas_map_point_image_uv_set(map, 3, w2, h);
1995          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1996          evas_map_point_coord_set(map, 1, w, y, 0);
1997          evas_map_point_coord_set(map, 2, w, h2, 0);
1998          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1999          break;
2000       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
2001          w2 = (w * progress);
2002          h2 = (y + h);
2003          evas_map_point_image_uv_set(map, 0, 0, 0);
2004          evas_map_point_image_uv_set(map, 1, w2, 0);
2005          evas_map_point_image_uv_set(map, 2, w2, h);
2006          evas_map_point_image_uv_set(map, 3, 0, h);
2007          evas_map_point_coord_set(map, 0, x, y, 0);
2008          evas_map_point_coord_set(map, 1, x + w2, y, 0);
2009          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
2010          evas_map_point_coord_set(map, 3, x, h2, 0);
2011          break;
2012       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
2013          w2 = (x + w);
2014          h2 = (h - (h * progress));
2015          evas_map_point_image_uv_set(map, 0, 0, h2);
2016          evas_map_point_image_uv_set(map, 1, w, h2);
2017          evas_map_point_image_uv_set(map, 2, w, h);
2018          evas_map_point_image_uv_set(map, 3, 0, h);
2019          evas_map_point_coord_set(map, 0, x, y + h2, 0);
2020          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
2021          evas_map_point_coord_set(map, 2, w2, y + h, 0);
2022          evas_map_point_coord_set(map, 3, x, y + h, 0);
2023          break;
2024       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
2025          w2 = (x + w);
2026          h2 = (h * progress);
2027          evas_map_point_image_uv_set(map, 0, 0, 0);
2028          evas_map_point_image_uv_set(map, 1, w, 0);
2029          evas_map_point_image_uv_set(map, 2, w, h2);
2030          evas_map_point_image_uv_set(map, 3, 0, h2);
2031          evas_map_point_coord_set(map, 0, x, y, 0);
2032          evas_map_point_coord_set(map, 1, w2, y, 0);
2033          evas_map_point_coord_set(map, 2, w2, y + h2, 0);
2034          evas_map_point_coord_set(map, 3, x, y + h2, 0);
2035          break;
2036       default:
2037          break;
2038      }
2039    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
2040 }
2041
2042 static void
2043 _transit_effect_wipe_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
2044 {
2045    EINA_SAFETY_ON_NULL_RETURN(effect);
2046    EINA_SAFETY_ON_NULL_RETURN(transit);
2047    Eina_List *elist;
2048    Evas_Object *obj;
2049    Elm_Transit_Effect_Wipe *wipe = effect;
2050    Eina_Bool reverse = elm_transit_auto_reverse_get(transit);
2051
2052    EINA_LIST_FOREACH(transit->objs, elist, obj)
2053      {
2054         if ((wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW && !reverse)
2055             || (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE && reverse))
2056           evas_object_show(obj);
2057         else evas_object_hide(obj);
2058         evas_object_map_enable_set(obj, EINA_FALSE);
2059      }
2060
2061    free(wipe);
2062 }
2063
2064 static void
2065 _transit_effect_wipe_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2066 {
2067    EINA_SAFETY_ON_NULL_RETURN(effect);
2068    EINA_SAFETY_ON_NULL_RETURN(transit);
2069    Elm_Transit_Effect_Wipe *wipe = effect;
2070    Evas_Map *map;
2071    Evas_Coord _x, _y, _w, _h;
2072    Eina_List *elist;
2073    Evas_Object *obj;
2074
2075    map = evas_map_new(4);
2076    if (!map) return;
2077
2078    EINA_LIST_FOREACH(transit->objs, elist, obj)
2079      {
2080         evas_object_geometry_get(obj, &_x, &_y, &_w, &_h);
2081
2082         if (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW)
2083           _elm_fx_wipe_show(map, wipe->dir, _x, _y, _w, _h, (float)progress);
2084         else
2085           _elm_fx_wipe_hide(map, wipe->dir, _x, _y, _w, _h, (float)progress);
2086
2087         evas_object_map_enable_set(obj, EINA_TRUE);
2088         evas_object_map_set(obj, map);
2089      }
2090    evas_map_free(map);
2091 }
2092
2093 static Elm_Transit_Effect *
2094 _transit_effect_wipe_context_new(Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
2095 {
2096    Elm_Transit_Effect_Wipe *wipe;
2097
2098    wipe = ELM_NEW(Elm_Transit_Effect_Wipe);
2099    if (!wipe) return NULL;
2100
2101    wipe->type = type;
2102    wipe->dir = dir;
2103
2104    return wipe;
2105 }
2106
2107 /**
2108  * Add the Wipe Effect to Elm_Transit.
2109  *
2110  * @note This API is one of the facades. It creates wipe effect context
2111  * and add it's required APIs to elm_transit_effect_add.
2112  *
2113  * @see elm_transit_effect_add()
2114  *
2115  * @param transit Transit object.
2116  * @param type Wipe type. Hide or show.
2117  * @param dir Wipe Direction.
2118  * @return Wipe effect context data.
2119  *
2120  * @ingroup Transit
2121  * @warning Is higher recommended just create a transit with this effect when
2122  * the window that the objects of the transit belongs has already been created.
2123  * This is because this effect needs the geometry information about the objects,
2124  * and if the window was not created yet, it can get a wrong information.
2125  */
2126 EAPI void *
2127 elm_transit_effect_wipe_add(Elm_Transit *transit, Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
2128 {
2129    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2130    void *effect_context = _transit_effect_wipe_context_new(type, dir);
2131
2132    if (!effect_context) return NULL;
2133    elm_transit_effect_add(transit,
2134                           _transit_effect_wipe_op, effect_context,
2135                           _transit_effect_wipe_context_free);
2136    return effect_context;
2137 }
2138
2139
2140 ///////////////////////////////////////////////////////////////////////////////
2141 //Color Effect
2142 ///////////////////////////////////////////////////////////////////////////////
2143 typedef struct _Elm_Transit_Effect_Color Elm_Transit_Effect_Color;
2144
2145 struct _Elm_Transit_Effect_Color
2146 {
2147    struct _unsigned_color {
2148       unsigned int r, g, b, a;
2149    } from;
2150    struct _signed_color {
2151       int r, g, b, a;
2152    } to;
2153 };
2154
2155 static void
2156 _transit_effect_color_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2157 {
2158    Elm_Transit_Effect_Color *color = effect;
2159    free(color);
2160 }
2161
2162 static void
2163 _transit_effect_color_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2164 {
2165    EINA_SAFETY_ON_NULL_RETURN(effect);
2166    EINA_SAFETY_ON_NULL_RETURN(transit);
2167    Elm_Transit_Effect_Color *color = effect;
2168    Evas_Object *obj;
2169    Eina_List *elist;
2170    unsigned int r, g, b, a;
2171
2172    r = (color->from.r + (int)((float)color->to.r * progress));
2173    g = (color->from.g + (int)((float)color->to.g * progress));
2174    b = (color->from.b + (int)((float)color->to.b * progress));
2175    a = (color->from.a + (int)((float)color->to.a * progress));
2176
2177    EINA_LIST_FOREACH(transit->objs, elist, obj)
2178      evas_object_color_set(obj, r, g, b, a);
2179 }
2180
2181 static Elm_Transit_Effect *
2182 _transit_effect_color_context_new(unsigned int from_r, unsigned int from_g, unsigned int from_b, unsigned int from_a, unsigned int to_r, unsigned int to_g, unsigned int to_b, unsigned int to_a)
2183 {
2184    Elm_Transit_Effect_Color *color;
2185
2186    color = ELM_NEW(Elm_Transit_Effect_Color);
2187    if (!color) return NULL;
2188
2189    color->from.r = from_r;
2190    color->from.g = from_g;
2191    color->from.b = from_b;
2192    color->from.a = from_a;
2193    color->to.r = to_r - from_r;
2194    color->to.g = to_g - from_g;
2195    color->to.b = to_b - from_b;
2196    color->to.a = to_a - from_a;
2197
2198    return color;
2199 }
2200
2201 /**
2202  * Add the Color Effect to Elm_Transit.
2203  *
2204  * @note This API is one of the facades. It creates color effect context
2205  * and add it's required APIs to elm_transit_effect_add.
2206  *
2207  * @see elm_transit_effect_add()
2208  *
2209  * @param transit        Transit object.
2210  * @param  from_r        RGB R when effect begins.
2211  * @param  from_g        RGB G when effect begins.
2212  * @param  from_b        RGB B when effect begins.
2213  * @param  from_a        RGB A when effect begins.
2214  * @param  to_r          RGB R when effect ends.
2215  * @param  to_g          RGB G when effect ends.
2216  * @param  to_b          RGB B when effect ends.
2217  * @param  to_a          RGB A when effect ends.
2218  * @return               Color effect context data.
2219  *
2220  * @ingroup Transit
2221  */
2222 EAPI Elm_Transit_Effect *
2223 elm_transit_effect_color_add(Elm_Transit *transit, unsigned int from_r, unsigned int from_g, unsigned int from_b, unsigned int from_a, unsigned int to_r, unsigned int to_g, unsigned int to_b, unsigned int to_a)
2224 {
2225    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2226    Elm_Transit_Effect *effect_context = _transit_effect_color_context_new(from_r, from_g, from_b, from_a, to_r, to_g, to_b, to_a);
2227
2228    if (!effect_context) return NULL;
2229    elm_transit_effect_add(transit,
2230                           _transit_effect_color_op, effect_context,
2231                           _transit_effect_color_context_free);
2232    return effect_context;
2233 }
2234
2235 ///////////////////////////////////////////////////////////////////////////////
2236 //Fade Effect
2237 ///////////////////////////////////////////////////////////////////////////////
2238 typedef struct _Elm_Transit_Effect_Fade Elm_Transit_Effect_Fade;
2239 typedef struct _Elm_Transit_Effect_Fade_Node Elm_Transit_Effect_Fade_Node;
2240
2241 struct _Elm_Transit_Effect_Fade_Node
2242 {
2243    Evas_Object *before;
2244    Evas_Object *after;
2245    struct _signed_color before_color, after_color;
2246    int before_alpha;
2247    int after_alpha;
2248    Eina_Bool inversed : 1;
2249 };
2250
2251 struct _Elm_Transit_Effect_Fade
2252 {
2253    Eina_List *nodes;
2254 };
2255
2256 static void
2257 _fade_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2258 {
2259    Elm_Transit_Effect_Fade *fade = data;
2260    Eina_List *elist;
2261    Elm_Transit_Effect_Fade_Node *fade_node;
2262
2263    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
2264      {
2265         if (fade_node->before == obj)
2266           evas_object_event_callback_del(fade_node->after,
2267                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
2268         else if (fade_node->after == obj)
2269           evas_object_event_callback_del(fade_node->before,
2270                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
2271         else continue;
2272
2273         fade->nodes = eina_list_remove_list(fade->nodes, elist);
2274         free(fade_node);
2275         break;
2276      }
2277 }
2278
2279 static Eina_List *
2280 _fade_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Fade *fade_data)
2281 {
2282    Elm_Transit_Effect_Fade_Node *fade;
2283    Eina_List *data_list = NULL;
2284    int i, count;
2285
2286    count = eina_list_count(transit->objs);
2287    for (i = 0; i < count; i += 2)
2288      {
2289         fade = ELM_NEW(Elm_Transit_Effect_Fade_Node);
2290         if (!fade)
2291           {
2292              eina_list_free(data_list);
2293              return NULL;
2294           }
2295
2296         fade->before = eina_list_nth(transit->objs, i);
2297         fade->after = eina_list_nth(transit->objs, i+1);
2298
2299         evas_object_color_get(fade->before,
2300                               &fade->before_color.r, &fade->before_color.g,
2301                               &fade->before_color.b, &fade->before_color.a);
2302         evas_object_color_get(fade->after,
2303                               &fade->after_color.r, &fade->after_color.g,
2304                               &fade->after_color.b, &fade->after_color.a);
2305
2306         fade->before_alpha = (255 - fade->before_color.a);
2307         fade->after_alpha = (255 - fade->after_color.a);
2308
2309         data_list = eina_list_append(data_list, fade);
2310
2311         evas_object_event_callback_add(fade->before,
2312                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
2313         evas_object_event_callback_add(fade->after,
2314                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
2315      }
2316    return data_list;
2317 }
2318
2319 static void
2320 _transit_effect_fade_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2321 {
2322    EINA_SAFETY_ON_NULL_RETURN(effect);
2323    Elm_Transit_Effect_Fade *fade = effect;
2324    Elm_Transit_Effect_Fade_Node *fade_node;
2325    Eina_List *elist, *elist_next;
2326
2327    EINA_LIST_FOREACH_SAFE(fade->nodes, elist, elist_next, fade_node)
2328      {
2329         evas_object_color_set(fade_node->before, fade_node->before_color.r,
2330                               fade_node->before_color.g,
2331                               fade_node->before_color.b,
2332                               fade_node->before_color.a);
2333         evas_object_color_set(fade_node->after, fade_node->after_color.r,
2334                               fade_node->after_color.g,
2335                               fade_node->after_color.b,
2336                               fade_node->after_color.a);
2337
2338         fade->nodes = eina_list_remove_list(fade->nodes, elist);
2339         evas_object_event_callback_del(fade_node->before,
2340                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
2341         evas_object_event_callback_del(fade_node->after,
2342                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
2343         free(fade_node);
2344      }
2345
2346    free(fade);
2347 }
2348
2349 static void
2350 _transit_effect_fade_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
2351 {
2352    EINA_SAFETY_ON_NULL_RETURN(effect);
2353    Elm_Transit_Effect_Fade *fade = effect;
2354    Eina_List *elist;
2355    Elm_Transit_Effect_Fade_Node *fade_node;
2356    float _progress;
2357
2358    if (!fade->nodes)
2359      fade->nodes = _fade_nodes_build(transit, fade);
2360
2361    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
2362      {
2363         if (progress < 0.5)
2364           {
2365              if (!fade_node->inversed)
2366                {
2367                   evas_object_hide(fade_node->after);
2368                   evas_object_show(fade_node->before);
2369                   fade_node->inversed = EINA_TRUE;
2370                }
2371
2372              _progress = (1 - (progress * 2));
2373
2374              evas_object_color_set(fade_node->before,
2375                                    fade_node->before_color.r * _progress,
2376                                    fade_node->before_color.g * _progress,
2377                                    fade_node->before_color.b * _progress,
2378                                    fade_node->before_color.a +
2379                                    fade_node->before_alpha * (1 - _progress));
2380           }
2381         else
2382           {
2383              if (fade_node->inversed)
2384                {
2385                   evas_object_hide(fade_node->before);
2386                   evas_object_show(fade_node->after);
2387                   fade_node->inversed = EINA_FALSE;
2388                }
2389
2390              _progress = ((progress - 0.5) * 2);
2391
2392              evas_object_color_set(fade_node->after,
2393                                    fade_node->after_color.r * _progress,
2394                                    fade_node->after_color.g * _progress,
2395                                    fade_node->after_color.b * _progress,
2396                                    fade_node->after_color.a +
2397                                    fade_node->after_alpha * (1 - _progress));
2398           }
2399      }
2400 }
2401
2402 static Elm_Transit_Effect *
2403 _transit_effect_fade_context_new(void)
2404 {
2405    Elm_Transit_Effect_Fade *fade;
2406    fade = ELM_NEW(Elm_Transit_Effect_Fade);
2407    if (!fade) return NULL;
2408    return fade;
2409 }
2410
2411 /**
2412  * Add the Fade Effect to Elm_Transit.
2413  *
2414  * @note This API is one of the facades. It creates fade effect context
2415  * and add it's required APIs to elm_transit_effect_add.
2416  * @note This effect is applied to each pair of objects in the order they are listed
2417  * in the transit list of objects. The first object in the pair will be the
2418  * "before" object and the second will be the "after" object.
2419  *
2420  * @see elm_transit_effect_add()
2421  *
2422  * @param transit Transit object.
2423  * @return Fade effect context data.
2424  *
2425  * @ingroup Transit
2426  * @warning Is higher recommended just create a transit with this effect when
2427  * the window that the objects of the transit belongs has already been created.
2428  * This is because this effect needs the color information about the objects,
2429  * and if the window was not created yet, it can get a wrong information.
2430  */
2431 EAPI Elm_Transit_Effect *
2432 elm_transit_effect_fade_add(Elm_Transit *transit)
2433 {
2434    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2435
2436    Elm_Transit_Effect *effect_context = _transit_effect_fade_context_new();
2437    if (!effect_context) return NULL;
2438    elm_transit_effect_add(transit,
2439                           _transit_effect_fade_op, effect_context,
2440                           _transit_effect_fade_context_free);
2441    return effect_context;
2442 }
2443
2444
2445 ///////////////////////////////////////////////////////////////////////////////
2446 //Blend Effect
2447 ///////////////////////////////////////////////////////////////////////////////
2448 typedef struct _Elm_Transit_Effect_Blend Elm_Transit_Effect_Blend;
2449 typedef struct _Elm_Transit_Effect_Blend_Node Elm_Transit_Effect_Blend_Node;
2450
2451 struct _Elm_Transit_Effect_Blend_Node
2452 {
2453    Evas_Object *before;
2454    Evas_Object *after;
2455    struct _signed_color from, to;
2456 };
2457
2458 struct _Elm_Transit_Effect_Blend
2459 {
2460    Eina_List *nodes;
2461 };
2462
2463 static void
2464 _blend_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2465 {
2466    Elm_Transit_Effect_Blend *blend = data;
2467    Eina_List *elist;
2468    Elm_Transit_Effect_Blend_Node *blend_node;
2469
2470    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
2471      {
2472         if (blend_node->after == obj)
2473           evas_object_event_callback_del(blend_node->before,
2474                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
2475         else if (blend_node->before == obj)
2476           evas_object_event_callback_del(blend_node->after,
2477                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
2478         else continue;
2479
2480         blend->nodes = eina_list_remove_list(blend->nodes, elist);
2481         free(blend_node);
2482         break;
2483      }
2484 }
2485
2486 static Eina_List *
2487 _blend_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Blend *blend)
2488 {
2489    Elm_Transit_Effect_Blend_Node *blend_node;
2490    Eina_List *data_list = NULL;
2491    int i, count;
2492
2493    count = eina_list_count(transit->objs);
2494    for (i = 0; i < (count - 1); i += 2)
2495      {
2496         blend_node = ELM_NEW(Elm_Transit_Effect_Blend_Node);
2497         if (!blend_node)
2498           {
2499              eina_list_free(data_list);
2500              return NULL;
2501           }
2502
2503         blend_node->before = eina_list_nth(transit->objs, i);
2504         blend_node->after = eina_list_nth(transit->objs, i + 1);
2505         evas_object_show(blend_node->before);
2506         evas_object_show(blend_node->after);
2507
2508         evas_object_color_get(blend_node->before, &blend_node->from.r,
2509                               &blend_node->from.g, &blend_node->from.b,
2510                               &blend_node->from.a);
2511         evas_object_color_get(blend_node->after, &blend_node->to.r,
2512                               &blend_node->to.g, &blend_node->to.b,
2513                               &blend_node->to.a);
2514
2515         data_list = eina_list_append(data_list, blend_node);
2516
2517         evas_object_event_callback_add(blend_node->before,
2518                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
2519         evas_object_event_callback_add(blend_node->after,
2520                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
2521      }
2522    return data_list;
2523 }
2524
2525 void
2526 _transit_effect_blend_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2527 {
2528    EINA_SAFETY_ON_NULL_RETURN(effect);
2529    Elm_Transit_Effect_Blend *blend = effect;
2530    Elm_Transit_Effect_Blend_Node *blend_node;
2531    Eina_List *elist, *elist_next;
2532
2533    EINA_LIST_FOREACH_SAFE(blend->nodes, elist, elist_next, blend_node)
2534      {
2535         evas_object_color_set(blend_node->before,
2536                               blend_node->from.r, blend_node->from.g,
2537                               blend_node->from.b, blend_node->from.a);
2538         evas_object_color_set(blend_node->after, blend_node->to.r,
2539                               blend_node->to.g, blend_node->to.b,
2540                               blend_node->to.a);
2541
2542         if (elm_transit_auto_reverse_get(transit))
2543           evas_object_hide(blend_node->after);
2544         else
2545           evas_object_hide(blend_node->before);
2546
2547         blend->nodes = eina_list_remove_list(blend->nodes, elist);
2548
2549         evas_object_event_callback_del(blend_node->before,
2550                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2551         evas_object_event_callback_del(blend_node->after,
2552                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2553         free(blend_node);
2554      }
2555    free(blend);
2556 }
2557
2558 void
2559 _transit_effect_blend_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2560 {
2561    EINA_SAFETY_ON_NULL_RETURN(effect);
2562    EINA_SAFETY_ON_NULL_RETURN(transit);
2563    Elm_Transit_Effect_Blend *blend = effect;
2564    Elm_Transit_Effect_Blend_Node *blend_node;
2565    Eina_List *elist;
2566
2567    if (!blend->nodes) blend->nodes = _blend_nodes_build(transit, blend);
2568
2569    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
2570      {
2571         evas_object_color_set(blend_node->before,
2572                               (int)(blend_node->from.r * (1 - progress)),
2573                               (int)(blend_node->from.g * (1 - progress)),
2574                               (int)(blend_node->from.b * (1 - progress)),
2575                               (int)(blend_node->from.a * (1 - progress)));
2576         evas_object_color_set(blend_node->after,
2577                               (int)(blend_node->to.r * progress),
2578                               (int)(blend_node->to.g * progress),
2579                               (int)(blend_node->to.b * progress),
2580                               (int)(blend_node->to.a * progress));
2581      }
2582 }
2583
2584 static Elm_Transit_Effect *
2585 _transit_effect_blend_context_new(void)
2586 {
2587    Elm_Transit_Effect_Blend *blend;
2588
2589    blend = ELM_NEW(Elm_Transit_Effect_Blend);
2590    if (!blend) return NULL;
2591    return blend;
2592 }
2593
2594 /**
2595  * Add the Blend Effect to Elm_Transit.
2596  *
2597  * @note This API is one of the facades. It creates blend effect context
2598  * and add it's required APIs to elm_transit_effect_add.
2599  * @note This effect is applied to each pair of objects in the order they are listed
2600  * in the transit list of objects. The first object in the pair will be the
2601  * "before" object and the second will be the "after" object.
2602  *
2603  * @see elm_transit_effect_add()
2604  *
2605  * @param transit Transit object.
2606  * @return Blend effect context data.
2607  *
2608  * @ingroup Transit
2609  * @warning Is higher recommended just create a transit with this effect when
2610  * the window that the objects of the transit belongs has already been created.
2611  * This is because this effect needs the color information about the objects,
2612  * and if the window was not created yet, it can get a wrong information.
2613  */
2614 EAPI Elm_Transit_Effect *
2615 elm_transit_effect_blend_add(Elm_Transit *transit)
2616 {
2617    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2618    Elm_Transit_Effect *effect_context = _transit_effect_blend_context_new();
2619
2620    if (!effect_context) return NULL;
2621    elm_transit_effect_add(transit,
2622                           _transit_effect_blend_op, effect_context,
2623                           _transit_effect_blend_context_free);
2624    return effect_context;
2625 }
2626
2627
2628 ///////////////////////////////////////////////////////////////////////////////
2629 //Rotation Effect
2630 ///////////////////////////////////////////////////////////////////////////////
2631 typedef struct _Elm_Transit_Effect_Rotation Elm_Transit_Effect_Rotation;
2632
2633 struct _Elm_Transit_Effect_Rotation
2634 {
2635    float from, to;
2636 };
2637
2638 static void
2639 _transit_effect_rotation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2640 {
2641    Elm_Transit_Effect_Rotation *rotation = effect;
2642    free(rotation);
2643 }
2644
2645 static void
2646 _transit_effect_rotation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2647 {
2648    EINA_SAFETY_ON_NULL_RETURN(effect);
2649    EINA_SAFETY_ON_NULL_RETURN(transit);
2650    Elm_Transit_Effect_Rotation *rotation = effect;
2651    Evas_Map *map;
2652    Evas_Coord x, y, w, h;
2653    float degree;
2654    float half_w, half_h;
2655    Eina_List *elist;
2656    Evas_Object *obj;
2657
2658    map = evas_map_new(4);
2659    if (!map) return;
2660
2661    EINA_LIST_FOREACH(transit->objs, elist, obj)
2662      {
2663         evas_map_util_points_populate_from_object_full(map, obj, 0);
2664         degree = rotation->from + (float)(progress * rotation->to);
2665
2666         evas_object_geometry_get(obj, &x, &y, &w, &h);
2667
2668         half_w = (float)w * 0.5;
2669         half_h = (float)h * 0.5;
2670
2671         evas_map_util_3d_rotate(map, 0, 0, degree, x + half_w, y + half_h, 0);
2672         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
2673         evas_object_map_enable_set(obj, EINA_TRUE);
2674         evas_object_map_set(obj, map);
2675      }
2676    evas_map_free(map);
2677 }
2678
2679 static Elm_Transit_Effect *
2680 _transit_effect_rotation_context_new(float from_degree, float to_degree)
2681 {
2682    Elm_Transit_Effect_Rotation *rotation;
2683
2684    rotation = ELM_NEW(Elm_Transit_Effect_Rotation);
2685    if (!rotation) return NULL;
2686
2687    rotation->from = from_degree;
2688    rotation->to = to_degree - from_degree;
2689
2690    return rotation;
2691 }
2692
2693 /**
2694  * Add the Rotation Effect to Elm_Transit.
2695  *
2696  * @note This API is one of the facades. It creates rotation effect context
2697  * and add it's required APIs to elm_transit_effect_add.
2698  *
2699  * @see elm_transit_effect_add()
2700  *
2701  * @param transit Transit object.
2702  * @param from_degree Degree when effect begins.
2703  * @param to_degree Degree when effect is ends.
2704  * @return Rotation effect context data.
2705  *
2706  * @ingroup Transit
2707  * @warning Is higher recommended just create a transit with this effect when
2708  * the window that the objects of the transit belongs has already been created.
2709  * This is because this effect needs the geometry information about the objects,
2710  * and if the window was not created yet, it can get a wrong information.
2711  */
2712 EAPI Elm_Transit_Effect *
2713 elm_transit_effect_rotation_add(Elm_Transit *transit, float from_degree, float to_degree)
2714 {
2715    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2716    Elm_Transit_Effect *effect_context = _transit_effect_rotation_context_new(from_degree, to_degree);
2717
2718    if (!effect_context) return NULL;
2719    elm_transit_effect_add(transit,
2720                           _transit_effect_rotation_op, effect_context,
2721                           _transit_effect_rotation_context_free);
2722    return effect_context;
2723 }
2724
2725
2726 ///////////////////////////////////////////////////////////////////////////////
2727 //ImageAnimation Effect
2728 ///////////////////////////////////////////////////////////////////////////////
2729 typedef struct _Elm_Transit_Effect_Image_Animation Elm_Transit_Effect_Image_Animation;
2730
2731 struct _Elm_Transit_Effect_Image_Animation
2732 {
2733    Eina_List *images;
2734 };
2735
2736 static void
2737 _transit_effect_image_animation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2738 {
2739    EINA_SAFETY_ON_NULL_RETURN(effect);
2740    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2741    const char *image;
2742    Eina_List *elist, *elist_next;
2743
2744    EINA_LIST_FOREACH_SAFE(image_animation->images, elist, elist_next, image)
2745      {
2746         image_animation->images =
2747            eina_list_remove_list(image_animation->images, elist);
2748         eina_stringshare_del(image);
2749      }
2750
2751    free(image_animation);
2752 }
2753
2754 static void
2755 _transit_effect_image_animation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2756 {
2757    EINA_SAFETY_ON_NULL_RETURN(effect);
2758    EINA_SAFETY_ON_NULL_RETURN(transit);
2759    Eina_List *elist;
2760    Evas_Object *obj;
2761    const char *type;
2762    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2763    unsigned int count = 0;
2764    int len;
2765
2766    type = eina_stringshare_add("icon");
2767    len = eina_list_count(image_animation->images);
2768
2769    if (!len) count = floor(progress * len);
2770    else count = floor(progress * (len - 1));
2771
2772    EINA_LIST_FOREACH(transit->objs, elist, obj)
2773      {
2774         if (elm_widget_type_check(obj, type))
2775           elm_icon_file_set(obj,
2776                             eina_list_nth(image_animation->images, count), NULL);
2777      }
2778
2779    eina_stringshare_del(type);
2780 }
2781
2782 static Elm_Transit_Effect *
2783 _transit_effect_image_animation_context_new(Eina_List *images)
2784 {
2785    Elm_Transit_Effect_Image_Animation *image_animation;
2786    image_animation = ELM_NEW(Elm_Transit_Effect_Image_Animation);
2787
2788    if (!image_animation) return NULL;
2789    image_animation->images = images;
2790    return image_animation;
2791 }
2792
2793 /**
2794  * Add the ImageAnimation Effect to Elm_Transit.
2795  *
2796  * @note This API is one of the facades. It creates image animation effect context
2797  * and add it's required APIs to elm_transit_effect_add.
2798  * The @p images parameter is a list images paths. This list and
2799  * its contents will be deleted at the end of the effect by
2800  * elm_transit_effect_image_animation_context_free() function.
2801  *
2802  * Example:
2803  * @code
2804  * char buf[PATH_MAX];
2805  * Eina_List *images = NULL;
2806  * Elm_Transit *transi = elm_transit_add();
2807  *
2808  * snprintf(buf, sizeof(buf), "%s/images/icon_11.png", PACKAGE_DATA_DIR);
2809  * images = eina_list_append(images, eina_stringshare_add(buf));
2810  *
2811  * snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
2812  * images = eina_list_append(images, eina_stringshare_add(buf));
2813  * elm_transit_effect_image_animation_add(transi, images);
2814  *
2815  * @endcode
2816  *
2817  * @see elm_transit_effect_add()
2818  *
2819  * @param transit Transit object.
2820  * @param images Eina_List of images file paths. This list and
2821  * its contents will be deleted at the end of the effect by
2822  * elm_transit_effect_image_animation_context_free() function.
2823  * @return Image Animation effect context data.
2824  *
2825  * @ingroup Transit
2826  */
2827 EAPI Elm_Transit_Effect *
2828 elm_transit_effect_image_animation_add(Elm_Transit *transit, Eina_List *images)
2829 {
2830    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2831    Elm_Transit_Effect *effect = _transit_effect_image_animation_context_new(images);
2832
2833    if (!effect) return NULL;
2834    elm_transit_effect_add(transit,
2835                           _transit_effect_image_animation_op, effect,
2836                           _transit_effect_image_animation_context_free);
2837    return effect;
2838 }