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