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