elementary/transit - added a new APIs elm_transit_chain_transit_del
[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 #define _TRANSIT_FOCAL 2000
22
23 struct _Elm_Transit
24 {
25 #define ELM_TRANSIT_MAGIC 0xd27f190a
26    EINA_MAGIC;
27
28    Ecore_Animator *animator;
29    Eina_Inlist *effect_list;
30    Eina_List *objs;
31    Elm_Transit *prev_chain_transit;
32    Eina_List *next_chain_transits;
33    Elm_Transit_Tween_Mode tween_mode;
34    struct {
35       Elm_Transit_Effect_End_Cb func;
36       void *arg;
37    } del_data;
38    struct {
39       double delayed;
40       double paused;
41       double duration;
42       double begin;
43       double current;
44    } time;
45    struct {
46       int count;
47       int current;
48       Eina_Bool reverse;
49    } repeat;
50    double progress;
51    unsigned int effects_pending_del;
52    int walking;
53    Eina_Bool auto_reverse : 1;
54    Eina_Bool event_enabled : 1;
55    Eina_Bool deleted : 1;
56    Eina_Bool state_keep : 1;
57 };
58
59 struct _Elm_Transit_Effect_Module
60 {
61    EINA_INLIST;
62    Elm_Transit_Effect_Transition_Cb transition_cb;
63    Elm_Transit_Effect_End_Cb end_cb;
64    Elm_Transit_Effect *effect;
65    Eina_Bool deleted : 1;
66 };
67
68 struct _Elm_Transit_Obj_State
69 {
70    Evas_Coord x, y, w, h;
71    int r,g,b,a;
72    Evas_Map *map;
73    Eina_Bool map_enabled : 1;
74    Eina_Bool visible : 1;
75 };
76
77 struct _Elm_Transit_Obj_Data
78 {
79    struct _Elm_Transit_Obj_State *state;
80    Eina_Bool pass_events : 1;
81 };
82
83 typedef struct _Elm_Transit_Effect_Module Elm_Transit_Effect_Module;
84 typedef struct _Elm_Transit_Obj_Data Elm_Transit_Obj_Data;
85 typedef struct _Elm_Transit_Obj_State Elm_Transit_Obj_State;
86
87 static void _transit_obj_data_update(Elm_Transit *transit, Evas_Object *obj);
88 static void _transit_obj_data_recover(Elm_Transit *transit, Evas_Object *obj);
89 static void _transit_obj_states_save(Evas_Object *obj, Elm_Transit_Obj_Data *obj_data);
90 static void _transit_obj_remove_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
91 static void _transit_obj_remove(Elm_Transit *transit, Evas_Object *obj);
92 static void _transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Module *effect_module);
93 static void _transit_remove_dead_effects(Elm_Transit *transit);
94 static void _transit_del(Elm_Transit *transit);
95 static void _transit_chain_transits_go(Elm_Transit *transit);
96 static void _transit_animate_op(Elm_Transit *transit, double progress);
97 static Eina_Bool _transit_animate_cb(void *data);
98
99 static char *_transit_key= "_elm_transit_key";
100
101 static void
102 _transit_obj_data_update(Elm_Transit *transit, Evas_Object *obj)
103 {
104    Elm_Transit_Obj_Data *obj_data = evas_object_data_get(obj, _transit_key);
105
106    if (!obj_data)
107      obj_data = ELM_NEW(Elm_Transit_Obj_Data);
108
109    obj_data->pass_events = evas_object_pass_events_get(obj);
110
111    if ((!transit->state_keep) && (obj_data->state))
112      {
113         free(obj_data->state);
114         obj_data->state = NULL;
115      }
116    else
117      {
118        _transit_obj_states_save(obj, obj_data);
119      }
120
121    evas_object_data_set(obj, _transit_key, obj_data);
122 }
123
124 static void
125 _transit_obj_states_save(Evas_Object *obj, Elm_Transit_Obj_Data *obj_data)
126 {
127    Elm_Transit_Obj_State *state = obj_data->state;
128
129    if (!state)
130      state = calloc(1, sizeof(Elm_Transit_Obj_State));
131    if (!state) return;
132
133    evas_object_geometry_get(obj, &state->x, &state->y, &state->w, &state->h);
134    evas_object_color_get(obj, &state->r, &state->g, &state->b, &state->a);
135    state->visible = evas_object_visible_get(obj);
136    state->map_enabled = evas_object_map_enable_get(obj);
137    if (evas_object_map_get(obj))
138      state->map = evas_map_dup(evas_object_map_get(obj));
139    obj_data->state = state;
140 }
141
142 static void
143 _remove_obj_from_list(Elm_Transit *transit, Evas_Object *obj)
144 {
145    //Remove duplicated objects
146    //TODO: Need to consider about optimizing here
147    while(1)
148      {
149         if (!eina_list_data_find_list(transit->objs, obj))
150           break;
151         transit->objs = eina_list_remove(transit->objs, obj);
152         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
153                                        _transit_obj_remove_cb,
154                                        transit);
155      }
156 }
157
158 static void
159 _transit_obj_remove_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
160 {
161    Elm_Transit *transit = data;
162    Elm_Transit_Obj_Data *obj_data = evas_object_data_get(obj, _transit_key);
163    if (obj_data)
164      {
165         if (obj_data->state)
166           free(obj_data->state);
167         free(obj_data);
168      }
169    _remove_obj_from_list(transit, obj);
170    if (!transit->objs) elm_transit_del(transit);
171 }
172
173 static void
174 _transit_obj_data_recover(Elm_Transit *transit, Evas_Object *obj)
175 {
176    Elm_Transit_Obj_Data *obj_data;
177    Elm_Transit_Obj_State *state;
178
179    obj_data = evas_object_data_get(obj, _transit_key);
180    if (!obj_data) return;
181    evas_object_data_del(obj, _transit_key);
182    evas_object_pass_events_set(obj, obj_data->pass_events);
183    state = obj_data->state;
184    if (state)
185      {
186         //recover the states of the object.
187         if (!transit->state_keep)
188           {
189              evas_object_move(obj, state->x, state->y);
190              evas_object_resize(obj, state->w, state->h);
191              evas_object_color_set(obj, state->r, state->g, state->b, state->a);
192              if (state->visible) evas_object_show(obj);
193              else evas_object_hide(obj);
194              if (state->map_enabled)
195                evas_object_map_enable_set(obj, EINA_TRUE);
196              else
197                evas_object_map_enable_set(obj, EINA_FALSE);
198              if (state->map)
199                evas_object_map_set(obj, state->map);
200           }
201         free(state);
202      }
203    free(obj_data);
204 }
205
206 static void
207 _transit_obj_remove(Elm_Transit *transit, Evas_Object *obj)
208 {
209    _remove_obj_from_list(transit, obj);
210    _transit_obj_data_recover(transit, obj);
211 }
212
213 static void
214 _transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Module *effect_module)
215 {
216    if (effect_module->end_cb)
217      effect_module->end_cb(effect_module->effect, transit);
218    free(effect_module);
219 }
220
221 static void
222 _transit_remove_dead_effects(Elm_Transit *transit)
223 {
224    Elm_Transit_Effect_Module *effect_module;
225
226    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
227      {
228         if (effect_module->deleted)
229           {
230              _transit_effect_del(transit, effect_module);
231              transit->effects_pending_del--;
232              if (!transit->effects_pending_del) return;
233           }
234      }
235 }
236
237 static void
238 _transit_del(Elm_Transit *transit)
239 {
240    Elm_Transit_Effect_Module *effect_module;
241    Elm_Transit *chain_transit;
242    Eina_List *elist, *elist_next;
243
244    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
245      {
246         if (transit->prev_chain_transit)
247           transit->prev_chain_transit->next_chain_transits = eina_list_remove(transit->prev_chain_transit->next_chain_transits, transit);
248         chain_transit->prev_chain_transit = NULL;
249      }
250
251    eina_list_free(transit->next_chain_transits);
252
253    if (transit->animator)
254      ecore_animator_del(transit->animator);
255
256    while (transit->effect_list)
257      {
258         effect_module = EINA_INLIST_CONTAINER_GET(transit->effect_list, Elm_Transit_Effect_Module);
259         transit->effect_list = eina_inlist_remove(transit->effect_list, transit->effect_list);
260         _transit_effect_del(transit, effect_module);
261      }
262
263    while (transit->objs)
264      _transit_obj_remove(transit, eina_list_data_get(transit->objs));
265
266    transit->deleted = EINA_TRUE;
267
268    if (transit->del_data.func)
269      transit->del_data.func(transit->del_data.arg, transit);
270
271    EINA_MAGIC_SET(transit, EINA_MAGIC_NONE);
272    free(transit);
273 }
274
275 static void
276 _transit_chain_transits_go(Elm_Transit *transit)
277 {
278    Eina_List *elist, *elist_next;
279    Elm_Transit *chain_transit;
280    Evas_Object *obj;
281
282    EINA_LIST_FOREACH(transit->objs, elist, obj)
283     _transit_obj_data_recover(transit, obj);
284
285    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
286      elm_transit_go(chain_transit);
287 }
288
289 static void
290 _transit_animate_op(Elm_Transit *transit, double progress)
291 {
292    Elm_Transit_Effect_Module *effect_module;
293
294    transit->walking++;
295    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
296      {
297         if (transit->deleted) break;
298         if (!effect_module->deleted)
299           effect_module->transition_cb(effect_module->effect, transit, progress);
300      }
301    transit->walking--;
302
303    if (transit->walking) return;
304
305    if (transit->deleted) _transit_del(transit);
306    else if (transit->effects_pending_del) _transit_remove_dead_effects(transit);
307 }
308
309 static Eina_Bool
310 _transit_animate_cb(void *data)
311 {
312    Elm_Transit *transit = data;
313    double elapsed_time, duration;
314
315    transit->time.current = ecore_loop_time_get();
316    elapsed_time = transit->time.current - transit->time.begin;
317    duration = transit->time.duration + transit->time.delayed;
318
319    if (elapsed_time > duration)
320      elapsed_time = duration;
321
322    transit->progress = elapsed_time / duration;
323    switch (transit->tween_mode)
324      {
325       case ELM_TRANSIT_TWEEN_MODE_ACCELERATE:
326         transit->progress = 1.0 - sin((ELM_PI / 2.0) + (transit->progress * ELM_PI / 2.0));
327         break;
328       case ELM_TRANSIT_TWEEN_MODE_DECELERATE:
329         transit->progress = sin(transit->progress * ELM_PI / 2.0);
330         break;
331       case ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL:
332         transit->progress = (1.0 - cos(transit->progress * ELM_PI)) / 2.0;
333         break;
334       default:
335         break;
336      }
337
338    /* Reverse? */
339    if (transit->repeat.reverse) transit->progress = 1 - transit->progress;
340
341    if (transit->time.duration > 0) _transit_animate_op(transit, transit->progress);
342
343    /* Not end. Keep going. */
344    if (elapsed_time < duration) return ECORE_CALLBACK_RENEW;
345
346    /* Repeat and reverse and time done! */
347    if ((transit->repeat.count >= 0) &&
348        (transit->repeat.current == transit->repeat.count) &&
349        ((!transit->auto_reverse) || transit->repeat.reverse))
350      {
351         /* run chain transit */
352         if (transit->next_chain_transits)
353           _transit_chain_transits_go(transit);
354
355         elm_transit_del(transit);
356         return ECORE_CALLBACK_CANCEL;
357      }
358
359    /* Repeat Case */
360    if (!transit->auto_reverse || transit->repeat.reverse)
361      {
362         transit->repeat.current++;
363         transit->repeat.reverse = EINA_FALSE;
364      }
365    else transit->repeat.reverse = EINA_TRUE;
366
367    transit->time.begin = ecore_loop_time_get();
368
369    return ECORE_CALLBACK_RENEW;
370 }
371
372 EAPI Elm_Transit *
373 elm_transit_add(void)
374 {
375    Elm_Transit *transit = ELM_NEW(Elm_Transit);
376    if (!transit)
377      {
378         ERR("Failed to allocate a elm_transit object!");
379         return NULL;
380      }
381
382    EINA_MAGIC_SET(transit, ELM_TRANSIT_MAGIC);
383
384    elm_transit_tween_mode_set(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
385
386    return transit;
387 }
388
389 EAPI void
390 elm_transit_del(Elm_Transit *transit)
391 {
392    ELM_TRANSIT_CHECK_OR_RETURN(transit);
393
394    if (transit->walking) transit->deleted = EINA_TRUE;
395    else _transit_del(transit);
396 }
397
398 EAPI void
399 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)
400 {
401    ELM_TRANSIT_CHECK_OR_RETURN(transit);
402    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
403    Elm_Transit_Effect_Module *effect_module;
404
405    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
406      if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect))
407        {
408           WRN("elm_transit does not allow to add the duplicated effect! : transit=%p", transit);
409           return;
410        }
411
412    effect_module = ELM_NEW(Elm_Transit_Effect_Module);
413    if (!effect_module)
414      {
415         ERR("Failed to allocate a new effect!: transit=%p", transit);
416         return;
417      }
418
419    effect_module->end_cb = end_cb;
420    effect_module->transition_cb = transition_cb;
421    effect_module->effect = effect;
422
423    transit->effect_list = eina_inlist_append(transit->effect_list, (Eina_Inlist*) effect_module);
424 }
425
426 EAPI void
427 elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Transition_Cb transition_cb, Elm_Transit_Effect *effect)
428 {
429    ELM_TRANSIT_CHECK_OR_RETURN(transit);
430    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
431    Elm_Transit_Effect_Module *effect_module;
432
433    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
434      {
435         if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect))
436           {
437              if (transit->walking)
438                {
439                   effect_module->deleted = EINA_TRUE;
440                   transit->effects_pending_del++;
441                }
442              else
443                {
444                   _transit_effect_del(transit, effect_module);
445                   if (!transit->effect_list) elm_transit_del(transit);
446                }
447              return;
448           }
449      }
450 }
451
452 EAPI void
453 elm_transit_object_add(Elm_Transit *transit, Evas_Object *obj)
454 {
455    ELM_TRANSIT_CHECK_OR_RETURN(transit);
456    EINA_SAFETY_ON_NULL_RETURN(obj);
457
458    if (transit->animator)
459      {
460         if (!evas_object_data_get(obj, _transit_key))
461           {
462              _transit_obj_data_update(transit, obj);
463              evas_object_pass_events_set(obj, EINA_TRUE);
464           }
465      }
466
467    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
468                                   _transit_obj_remove_cb,
469                                   transit);
470
471    transit->objs = eina_list_append(transit->objs, obj);
472 }
473
474 EAPI void
475 elm_transit_object_remove(Elm_Transit *transit, Evas_Object *obj)
476 {
477    ELM_TRANSIT_CHECK_OR_RETURN(transit);
478    EINA_SAFETY_ON_NULL_RETURN(obj);
479
480    _transit_obj_remove(transit, obj);
481    if (!transit->objs) elm_transit_del(transit);
482 }
483
484 EAPI const Eina_List *
485 elm_transit_objects_get(const Elm_Transit *transit)
486 {
487    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
488    return transit->objs;
489 }
490
491 EAPI void
492 elm_transit_event_enabled_set(Elm_Transit *transit, Eina_Bool enabled)
493 {
494    ELM_TRANSIT_CHECK_OR_RETURN(transit);
495
496    Eina_List *list;
497    Evas_Object *obj;
498
499    if (transit->event_enabled == enabled) return;
500    transit->event_enabled = !!enabled;
501    if (!transit->animator) return;
502
503    EINA_LIST_FOREACH(transit->objs, list, obj)
504      evas_object_pass_events_set(obj, enabled);
505 }
506
507 EAPI Eina_Bool
508 elm_transit_event_enabled_get(const Elm_Transit *transit)
509 {
510    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
511    return transit->event_enabled;
512 }
513
514 EAPI void
515 elm_transit_del_cb_set(Elm_Transit *transit, void (*cb) (void *data, Elm_Transit *transit), void *data)
516 {
517    ELM_TRANSIT_CHECK_OR_RETURN(transit);
518    transit->del_data.func = cb;
519    transit->del_data.arg = data;
520 }
521
522 EAPI void
523 elm_transit_auto_reverse_set(Elm_Transit *transit, Eina_Bool reverse)
524 {
525    ELM_TRANSIT_CHECK_OR_RETURN(transit);
526    transit->auto_reverse = reverse;
527 }
528
529 EAPI Eina_Bool
530 elm_transit_auto_reverse_get(const Elm_Transit *transit)
531 {
532    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
533    return transit->auto_reverse;
534 }
535
536 EAPI void
537 elm_transit_repeat_times_set(Elm_Transit *transit, int repeat)
538 {
539    ELM_TRANSIT_CHECK_OR_RETURN(transit);
540    transit->repeat.count = repeat;
541    transit->repeat.current = 0;
542 }
543
544 EAPI int
545 elm_transit_repeat_times_get(const Elm_Transit *transit)
546 {
547    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
548    return transit->repeat.count;
549 }
550
551 EAPI void
552 elm_transit_tween_mode_set(Elm_Transit *transit, Elm_Transit_Tween_Mode tween_mode)
553 {
554    ELM_TRANSIT_CHECK_OR_RETURN(transit);
555    transit->tween_mode = tween_mode;
556 }
557
558 EAPI Elm_Transit_Tween_Mode
559 elm_transit_tween_mode_get(const Elm_Transit *transit)
560 {
561    ELM_TRANSIT_CHECK_OR_RETURN(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
562    return transit->tween_mode;
563 }
564
565 EAPI void
566 elm_transit_duration_set(Elm_Transit *transit, double duration)
567 {
568    ELM_TRANSIT_CHECK_OR_RETURN(transit);
569    if (transit->animator)
570      {
571         WRN("elm_transit does not allow to set the duration time in operating! : transit=%p", transit);
572         return;
573      }
574    transit->time.duration = duration;
575 }
576
577 EAPI double
578 elm_transit_duration_get(const Elm_Transit *transit)
579 {
580    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0.0);
581    return transit->time.duration;
582 }
583
584 EAPI void
585 elm_transit_go(Elm_Transit *transit)
586 {
587    ELM_TRANSIT_CHECK_OR_RETURN(transit);
588
589    Eina_List *elist;
590    Evas_Object *obj;
591
592    if (transit->animator)
593      ecore_animator_del(transit->animator);
594
595    EINA_LIST_FOREACH(transit->objs, elist, obj)
596      _transit_obj_data_update(transit, obj);
597
598    if (!transit->event_enabled)
599      {
600         EINA_LIST_FOREACH(transit->objs, elist, obj)
601           evas_object_pass_events_set(obj, EINA_TRUE);
602      }
603
604    transit->time.paused = 0;
605    transit->time.delayed = 0;
606    transit->time.begin = ecore_loop_time_get();
607    transit->animator = ecore_animator_add(_transit_animate_cb, transit);
608 }
609
610 EAPI void
611 elm_transit_paused_set(Elm_Transit *transit, Eina_Bool paused)
612 {
613    ELM_TRANSIT_CHECK_OR_RETURN(transit);
614
615    if (!transit->animator) return;
616
617    if (paused)
618      {
619         if (transit->time.paused > 0)
620           return;
621         ecore_animator_freeze(transit->animator);
622         transit->time.paused = ecore_loop_time_get();
623      }
624    else
625      {
626         if (transit->time.paused == 0)
627           return;
628         ecore_animator_thaw(transit->animator);
629         transit->time.delayed += (ecore_loop_time_get() - transit->time.paused);
630         transit->time.paused = 0;
631      }
632 }
633
634 EAPI Eina_Bool
635 elm_transit_paused_get(const Elm_Transit *transit)
636 {
637    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
638
639    if (transit->time.paused == 0)
640      return EINA_FALSE;
641
642    return EINA_TRUE;
643 }
644
645 EAPI double
646 elm_transit_progress_value_get(const Elm_Transit *transit)
647 {
648    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
649
650    return transit->progress;
651 }
652
653 EAPI void
654 elm_transit_objects_final_state_keep_set(Elm_Transit *transit, Eina_Bool state_keep)
655 {
656    ELM_TRANSIT_CHECK_OR_RETURN(transit);
657
658    if (transit->state_keep == state_keep) return;
659    if (transit->animator)
660      {
661         WRN("elm_transit does not allow to change final state keep mode in operating! : transit=%p", transit);
662         return;
663      }
664    transit->state_keep = !!state_keep;
665 }
666
667 EAPI Eina_Bool
668 elm_transit_objects_final_state_keep_get(const Elm_Transit *transit)
669 {
670    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
671    return transit->state_keep;
672 }
673
674 EAPI void
675 elm_transit_chain_transit_add(Elm_Transit *transit, Elm_Transit *chain_transit)
676 {
677    ELM_TRANSIT_CHECK_OR_RETURN(transit);
678    ELM_TRANSIT_CHECK_OR_RETURN(chain_transit);
679
680    if (transit == chain_transit)
681      {
682         WRN("You add a same transit as a chain transit! : transit=%p, chain_transit=%p", transit, chain_transit);
683         return;
684      }
685    if (transit == chain_transit->prev_chain_transit)
686      return;
687
688    if (chain_transit->prev_chain_transit)
689      chain_transit->prev_chain_transit->next_chain_transits = eina_list_remove(chain_transit->prev_chain_transit->next_chain_transits, chain_transit);
690
691    chain_transit->prev_chain_transit = transit;
692    transit->next_chain_transits = eina_list_append(transit->next_chain_transits, chain_transit);
693 }
694
695 EAPI void
696 elm_transit_chain_transit_del(Elm_Transit *transit, Elm_Transit *chain_transit)
697 {
698    ELM_TRANSIT_CHECK_OR_RETURN(transit);
699    ELM_TRANSIT_CHECK_OR_RETURN(chain_transit);
700
701    if (chain_transit->prev_chain_transit != transit)
702      {
703         WRN("These two transit does not have the chain relationship! : transit=%p, chain_transit=%p", transit, chain_transit);
704         return;
705      }
706
707    chain_transit->prev_chain_transit = NULL;
708    transit->next_chain_transits = eina_list_remove(transit->next_chain_transits, chain_transit);
709 }
710
711 EAPI Eina_List *
712 elm_transit_chain_transits_get(const Elm_Transit * transit)
713 {
714    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
715    return transit->next_chain_transits;
716 }
717
718 ///////////////////////////////////////////////////////////////////////////
719 //Resizing Effect
720 ///////////////////////////////////////////////////////////////////////////
721 typedef struct _Elm_Transit_Effect_Resizing Elm_Transit_Effect_Resizing;
722
723 struct _Elm_Transit_Effect_Resizing
724 {
725    struct _size {
726       Evas_Coord w, h;
727    } from, to;
728 };
729
730 static void
731 _transit_effect_resizing_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
732 {
733    Elm_Transit_Effect_Resizing *resizing = effect;
734    free(resizing);
735 }
736
737 static void
738 _transit_effect_resizing_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
739 {
740    EINA_SAFETY_ON_NULL_RETURN(effect);
741    EINA_SAFETY_ON_NULL_RETURN(transit);
742    Evas_Coord w, h;
743    Evas_Object *obj;
744    Eina_List *elist;
745    Elm_Transit_Effect_Resizing *resizing = effect;
746
747    w = resizing->from.w + (resizing->to.w * progress);
748    h = resizing->from.h + (resizing->to.h * progress);
749
750    EINA_LIST_FOREACH(transit->objs, elist, obj)
751      evas_object_resize(obj, w, h);
752 }
753
754 static Elm_Transit_Effect *
755 _transit_effect_resizing_context_new(Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
756 {
757    Elm_Transit_Effect_Resizing *resizing;
758
759    resizing = ELM_NEW(Elm_Transit_Effect_Resizing);
760    if (!resizing) return NULL;
761
762    resizing->from.w = from_w;
763    resizing->from.h = from_h;
764    resizing->to.w = to_w - from_w;
765    resizing->to.h = to_h - from_h;
766
767    return resizing;
768 }
769
770 EAPI Elm_Transit_Effect *
771 elm_transit_effect_resizing_add(Elm_Transit *transit, Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
772 {
773    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
774    Elm_Transit_Effect *effect = _transit_effect_resizing_context_new(from_w, from_h, to_w, to_h);
775
776    if (!effect)
777      {
778         ERR("Failed to allocate resizing effect! : transit=%p", transit);
779         return NULL;
780      }
781    elm_transit_effect_add(transit,
782                           _transit_effect_resizing_op, effect,
783                           _transit_effect_resizing_context_free);
784    return effect;
785 }
786
787 ///////////////////////////////////////////////////////////////////////////
788 //Translation Effect
789 ///////////////////////////////////////////////////////////////////////////
790 typedef struct _Elm_Transit_Effect_Translation Elm_Transit_Effect_Translation;
791 typedef struct _Elm_Transit_Effect_Translation_Node Elm_Transit_Effect_Translation_Node;
792
793 struct _Elm_Transit_Effect_Translation_Node
794 {
795    Evas_Object *obj;
796    Evas_Coord x, y;
797 };
798
799 struct _Elm_Transit_Effect_Translation
800 {
801    struct _position_variation {
802       Evas_Coord dx, dy;
803    } from, to;
804    Eina_List *nodes;
805 };
806
807 static void
808 _translation_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
809 {
810    Elm_Transit_Effect_Translation *translation = data;
811    Eina_List *elist;
812    Elm_Transit_Effect_Translation_Node *translation_node;
813
814    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
815      {
816         if (translation_node->obj != obj) continue;
817         translation->nodes = eina_list_remove_list(translation->nodes, elist);
818         free(translation_node);
819         break;
820      }
821 }
822
823 static Eina_List *
824 _translation_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Translation *translation)
825 {
826    Elm_Transit_Effect_Translation_Node *translation_node;
827    const Eina_List *elist;
828    Evas_Object *obj;
829    Eina_List *data_list = NULL;
830    const Eina_List *objs = elm_transit_objects_get(transit);
831
832    EINA_LIST_FOREACH(objs, elist, obj)
833      {
834         translation_node = ELM_NEW(Elm_Transit_Effect_Translation_Node);
835         if (!translation_node)
836           {
837              eina_list_free(data_list);
838              return NULL;
839           }
840         translation_node->obj = obj;
841         evas_object_geometry_get(obj, &(translation_node->x),
842                                  &(translation_node->y), NULL, NULL);
843         data_list = eina_list_append(data_list, translation_node);
844         evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
845                                        _translation_object_del_cb, translation);
846      }
847    return data_list;
848 }
849
850 void
851 _transit_effect_translation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
852 {
853    EINA_SAFETY_ON_NULL_RETURN(effect);
854    Elm_Transit_Effect_Translation *translation = effect;
855    Eina_List *elist, *elist_next;
856    Elm_Transit_Effect_Translation_Node *translation_node;
857
858    EINA_LIST_FOREACH_SAFE(translation->nodes,
859                           elist, elist_next, translation_node)
860      {
861         evas_object_event_callback_del(translation_node->obj,
862                                        EVAS_CALLBACK_DEL, _translation_object_del_cb);
863         translation->nodes = eina_list_remove_list(translation->nodes, elist);
864         free(translation_node);
865      }
866    free(translation);
867 }
868
869 void
870 _transit_effect_translation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress __UNUSED__)
871 {
872    EINA_SAFETY_ON_NULL_RETURN(effect);
873    EINA_SAFETY_ON_NULL_RETURN(transit);
874    Evas_Coord x, y;
875    Elm_Transit_Effect_Translation *translation = effect;
876    Elm_Transit_Effect_Translation_Node *translation_node;
877    Eina_List *elist;
878
879    if (!translation->nodes)
880      translation->nodes = _translation_nodes_build(transit, translation);
881
882    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
883      {
884         x = translation_node->x + translation->from.dx
885            + (translation->to.dx * progress);
886         y = translation_node->y + translation->from.dy
887            + (translation->to.dy * progress);
888         evas_object_move(translation_node->obj, x, y);
889      }
890 }
891
892 static Elm_Transit_Effect *
893 _transit_effect_translation_context_new(Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
894 {
895    Elm_Transit_Effect_Translation *translation;
896
897    translation = ELM_NEW(Elm_Transit_Effect_Translation);
898    if (!translation) return NULL;
899
900    translation->from.dx = from_dx;
901    translation->from.dy = from_dy;
902    translation->to.dx = to_dx - from_dx;
903    translation->to.dy = to_dy - from_dy;
904
905    return translation;
906 }
907
908 EAPI Elm_Transit_Effect *
909 elm_transit_effect_translation_add(Elm_Transit *transit, Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
910 {
911    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
912    Elm_Transit_Effect *effect = _transit_effect_translation_context_new(from_dx, from_dy, to_dx, to_dy);
913
914    if (!effect)
915      {
916         ERR("Failed to allocate translation effect! : transit=%p", transit);
917         return NULL;
918      }
919    elm_transit_effect_add(transit,
920                           _transit_effect_translation_op, effect,
921                           _transit_effect_translation_context_free);
922    return effect;
923 }
924
925 ///////////////////////////////////////////////////////////////////////////
926 //Zoom Effect
927 ///////////////////////////////////////////////////////////////////////////
928 typedef struct _Elm_Transit_Effect_Zoom Elm_Transit_Effect_Zoom;
929
930 struct _Elm_Transit_Effect_Zoom
931 {
932    float from, to;
933 };
934
935 void
936 _transit_effect_zoom_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
937 {
938    Elm_Transit_Effect_Zoom *zoom = effect;
939    free(zoom);
940 }
941
942 static void
943 _transit_effect_zoom_op(Elm_Transit_Effect *effect, Elm_Transit *transit , double progress)
944 {
945    EINA_SAFETY_ON_NULL_RETURN(effect);
946    EINA_SAFETY_ON_NULL_RETURN(transit);
947    Evas_Object *obj;
948    Eina_List *elist;
949    Elm_Transit_Effect_Zoom *zoom = effect;
950    Evas_Map *map;
951    Evas_Coord x, y, w, h;
952
953    map = evas_map_new(4);
954    if (!map) return;
955
956    EINA_LIST_FOREACH(transit->objs, elist, obj)
957      {
958         evas_object_geometry_get(obj, &x, &y, &w, &h);
959         evas_map_util_points_populate_from_object_full(map, obj, zoom->from +
960                                                        (progress * zoom->to));
961         evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
962         evas_object_map_set(obj, map);
963         evas_object_map_enable_set(obj, EINA_TRUE);
964      }
965    evas_map_free(map);
966 }
967
968 static Elm_Transit_Effect *
969 _transit_effect_zoom_context_new(float from_rate, float to_rate)
970 {
971    Elm_Transit_Effect_Zoom *zoom;
972
973    zoom = ELM_NEW(Elm_Transit_Effect_Zoom);
974    if (!zoom) return NULL;
975
976    zoom->from = (_TRANSIT_FOCAL - (from_rate * _TRANSIT_FOCAL)) * (1 / from_rate);
977    zoom->to = ((_TRANSIT_FOCAL - (to_rate * _TRANSIT_FOCAL)) * (1 / to_rate)) - zoom->from;
978
979    return zoom;
980 }
981
982 EAPI Elm_Transit_Effect *
983 elm_transit_effect_zoom_add(Elm_Transit *transit, float from_rate, float to_rate)
984 {
985    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
986    Elm_Transit_Effect *effect = _transit_effect_zoom_context_new(from_rate, to_rate);
987
988    if (!effect)
989      {
990         ERR("Failed to allocate zoom effect! : transit=%p", transit);
991         return NULL;
992      }
993    elm_transit_effect_add(transit,
994                           _transit_effect_zoom_op, effect,
995                           _transit_effect_zoom_context_free);
996    return effect;
997 }
998
999 ///////////////////////////////////////////////////////////////////////////
1000 //Flip Effect
1001 ///////////////////////////////////////////////////////////////////////////
1002 typedef struct _Elm_Transit_Effect_Flip Elm_Transit_Effect_Flip;
1003
1004 struct _Elm_Transit_Effect_Flip
1005 {
1006    Elm_Transit_Effect_Flip_Axis axis;
1007    Eina_Bool cw : 1;
1008 };
1009
1010 static void
1011 _transit_effect_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
1012 {
1013    EINA_SAFETY_ON_NULL_RETURN(effect);
1014    EINA_SAFETY_ON_NULL_RETURN(transit);
1015    Elm_Transit_Effect_Flip *flip = effect;
1016    Evas_Object *front, *back;
1017    int i;
1018    int count = eina_list_count(transit->objs);
1019
1020    for (i = 0; i < (count - 1); i += 2)
1021      {
1022         front = eina_list_nth(transit->objs, i);
1023         back = eina_list_nth(transit->objs, i+1);
1024         evas_object_map_enable_set(front, EINA_FALSE);
1025         evas_object_map_enable_set(back, EINA_FALSE);
1026      }
1027    free(flip);
1028 }
1029
1030 static void
1031 _transit_effect_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1032 {
1033    EINA_SAFETY_ON_NULL_RETURN(effect);
1034    EINA_SAFETY_ON_NULL_RETURN(transit);
1035    Evas_Object *obj, *front, *back;
1036    int count, i;
1037    Elm_Transit_Effect_Flip *flip = effect;
1038    Evas_Map *map;
1039    float degree;
1040    Evas_Coord x, y, w, h;
1041
1042    map = evas_map_new(4);
1043    if (!map) return;
1044
1045    if (flip->cw) degree = (float)(progress * 180);
1046    else degree = (float)(progress * -180);
1047
1048    count = eina_list_count(transit->objs);
1049
1050    for (i = 0; i < (count - 1); i += 2)
1051      {
1052         Evas_Coord half_w, half_h;
1053
1054         front = eina_list_nth(transit->objs, i);
1055         back = eina_list_nth(transit->objs, i+1);
1056
1057         if ((degree < 90) && (degree > -90))
1058           {
1059              obj = front;
1060              if (front != back)
1061                {
1062                   evas_object_hide(back);
1063                   evas_object_show(front);
1064                }
1065           }
1066         else
1067           {
1068              obj = back;
1069              if (front != back)
1070                {
1071                   evas_object_hide(front);
1072                   evas_object_show(back);
1073                }
1074           }
1075
1076         evas_map_util_points_populate_from_object_full(map, obj, 0);
1077         evas_object_geometry_get(obj, &x, &y, &w, &h);
1078         half_w = (w / 2);
1079         half_h = (h / 2);
1080
1081         if (flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1082           {
1083              if ((degree >= 90) || (degree <= -90))
1084                {
1085                   evas_map_point_image_uv_set(map, 0, w, 0);
1086                   evas_map_point_image_uv_set(map, 1, 0, 0);
1087                   evas_map_point_image_uv_set(map, 2, 0, h);
1088                   evas_map_point_image_uv_set(map, 3, w, h);
1089                }
1090              evas_map_util_3d_rotate(map, 0, degree,
1091                                      0, x + half_w, y + half_h, 0);
1092           }
1093         else
1094           {
1095              if ((degree >= 90) || (degree <= -90))
1096                {
1097                   evas_map_point_image_uv_set(map, 0, 0, h);
1098                   evas_map_point_image_uv_set(map, 1, w, h);
1099                   evas_map_point_image_uv_set(map, 2, w, 0);
1100                   evas_map_point_image_uv_set(map, 3, 0, 0);
1101                }
1102              evas_map_util_3d_rotate(map, degree,
1103                                      0, 0, x + half_w, y + half_h, 0);
1104           }
1105         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1106         evas_object_map_enable_set(front, EINA_TRUE);
1107         evas_object_map_enable_set(back, EINA_TRUE);
1108         evas_object_map_set(obj, map);
1109      }
1110    evas_map_free(map);
1111 }
1112
1113 static Elm_Transit_Effect *
1114 _transit_effect_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1115 {
1116    Elm_Transit_Effect_Flip *flip;
1117
1118    flip = ELM_NEW(Elm_Transit_Effect_Flip);
1119    if (!flip) return NULL;
1120
1121    flip->cw = cw;
1122    flip->axis = axis;
1123
1124    return flip;
1125 }
1126
1127 EAPI Elm_Transit_Effect *
1128 elm_transit_effect_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1129 {
1130    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1131    Elm_Transit_Effect *effect = _transit_effect_flip_context_new(axis, cw);
1132
1133    if (!effect)
1134      {
1135         ERR("Failed to allocate flip effect! : transit=%p", transit);
1136         return NULL;
1137      }
1138    elm_transit_effect_add(transit,
1139                           _transit_effect_flip_op, effect,
1140                           _transit_effect_flip_context_free);
1141    return effect;
1142 }
1143
1144 ///////////////////////////////////////////////////////////////////////////
1145 //ResizableFlip Effect
1146 ///////////////////////////////////////////////////////////////////////////
1147 typedef struct _Elm_Transit_Effect_Resizable_Flip Elm_Transit_Effect_ResizableFlip;
1148 typedef struct _Elm_Transit_Effect_Resizable_Flip_Node Elm_Transit_Effect_ResizableFlip_Node;
1149
1150 struct _Elm_Transit_Effect_Resizable_Flip_Node
1151 {
1152    Evas_Object *front;
1153    Evas_Object *back;
1154    struct _vector2d {
1155       float x, y;
1156    } from_pos, from_size, to_pos, to_size;
1157 };
1158
1159 struct _Elm_Transit_Effect_Resizable_Flip
1160 {
1161    Eina_List *nodes;
1162    Eina_Bool cw : 1;
1163    Elm_Transit_Effect_Flip_Axis axis;
1164 };
1165
1166 static void
1167 _resizable_flip_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1168 {
1169    Elm_Transit_Effect_ResizableFlip *resizable_flip = data;
1170    Eina_List *elist;
1171    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1172
1173    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1174      {
1175         if (resizable_flip_node->front == obj)
1176           evas_object_event_callback_del(resizable_flip_node->back,
1177                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1178         else if (resizable_flip_node->back == obj)
1179           evas_object_event_callback_del(resizable_flip_node->front,
1180                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1181         else continue;
1182
1183         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1184                                                       elist);
1185         free(resizable_flip_node);
1186         break;
1187      }
1188 }
1189
1190 static Eina_List *
1191 _resizable_flip_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_ResizableFlip *resizable_flip)
1192 {
1193    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1194    Eina_List *data_list = NULL;
1195    Evas_Coord front_x, front_y, front_w, front_h;
1196    Evas_Coord back_x, back_y, back_w, back_h;
1197    int i, count;
1198
1199    count = eina_list_count(transit->objs);
1200    for (i = 0; i < (count - 1); i += 2)
1201      {
1202         resizable_flip_node = ELM_NEW(Elm_Transit_Effect_ResizableFlip_Node);
1203         if (!resizable_flip_node)
1204           {
1205              eina_list_free(data_list);
1206              return NULL;
1207           }
1208
1209         resizable_flip_node->front = eina_list_nth(transit->objs, i);
1210         resizable_flip_node->back = eina_list_nth(transit->objs, i+1);
1211
1212         evas_object_geometry_get(resizable_flip_node->front,
1213                                  &front_x, &front_y, &front_w, &front_h);
1214         evas_object_geometry_get(resizable_flip_node->back,
1215                                  &back_x, &back_y, &back_w, &back_h);
1216
1217         resizable_flip_node->from_pos.x = front_x;
1218         resizable_flip_node->from_pos.y = front_y;
1219         resizable_flip_node->to_pos.x = back_x - front_x;
1220         resizable_flip_node->to_pos.y = back_y - front_y;
1221
1222         resizable_flip_node->from_size.x = front_w;
1223         resizable_flip_node->from_size.y = front_h;
1224         resizable_flip_node->to_size.x = back_w - front_w;
1225         resizable_flip_node->to_size.y = back_h - front_h;
1226
1227         data_list = eina_list_append(data_list, resizable_flip_node);
1228
1229         evas_object_event_callback_add(resizable_flip_node->back,
1230                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1231         evas_object_event_callback_add(resizable_flip_node->front,
1232                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1233      }
1234
1235    return data_list;
1236 }
1237
1238 static void
1239 _set_image_uv_by_axis_y(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1240 {
1241    if ((degree >= 90) || (degree <= -90))
1242      {
1243         evas_map_point_image_uv_set(map, 0,
1244                                     (flip->from_size.x * 2) + flip->to_size.x,
1245                                     0);
1246         evas_map_point_image_uv_set(map, 1, 0, 0);
1247         evas_map_point_image_uv_set(map, 2, 0,
1248                                     (flip->from_size.y * 2) + flip->to_size.y);
1249         evas_map_point_image_uv_set(map, 3,
1250                                     (flip->from_size.x * 2) + flip->to_size.x,
1251                                     (flip->from_size.y * 2) + flip->to_size.y);
1252      }
1253    else
1254      {
1255         evas_map_point_image_uv_set(map, 0, 0, 0);
1256         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1257         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1258                                     flip->from_size.y);
1259         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1260      }
1261 }
1262
1263 static void
1264 _set_image_uv_by_axis_x(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1265 {
1266    if ((degree >= 90) || (degree <= -90))
1267      {
1268         evas_map_point_image_uv_set(map, 0, 0,
1269                                     (flip->from_size.y * 2) + flip->to_size.y);
1270         evas_map_point_image_uv_set(map, 1,
1271                                     (flip->from_size.x * 2) + flip->to_size.x,
1272                                     (flip->from_size.y * 2) + flip->to_size.y);
1273         evas_map_point_image_uv_set(map, 2,
1274                                     (flip->from_size.x * 2) + flip->to_size.x,
1275                                     0);
1276         evas_map_point_image_uv_set(map, 3, 0, 0);
1277      }
1278    else
1279      {
1280         evas_map_point_image_uv_set(map, 0, 0, 0);
1281         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1282         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1283                                     flip->from_size.y);
1284         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1285      }
1286 }
1287
1288 void
1289 _transit_effect_resizable_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1290 {
1291    EINA_SAFETY_ON_NULL_RETURN(effect);
1292
1293    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1294    Eina_List *elist, *elist_next;
1295    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1296
1297    EINA_LIST_FOREACH_SAFE(resizable_flip->nodes,
1298                           elist, elist_next, resizable_flip_node)
1299      {
1300         evas_object_map_enable_set(resizable_flip_node->front, EINA_FALSE);
1301         evas_object_map_enable_set(resizable_flip_node->back, EINA_FALSE);
1302
1303         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1304                                                       elist);
1305
1306         evas_object_event_callback_del(resizable_flip_node->back,
1307                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1308         evas_object_event_callback_del(resizable_flip_node->front,
1309                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1310         free(resizable_flip_node);
1311      }
1312    free(resizable_flip);
1313 }
1314
1315 void
1316 _transit_effect_resizable_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1317 {
1318    EINA_SAFETY_ON_NULL_RETURN(effect);
1319    Evas_Map *map;
1320    Evas_Object *obj;
1321    float x, y, w, h;
1322    float degree;
1323    Evas_Coord half_w, half_h;
1324    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1325    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1326    Eina_List *elist;
1327
1328    map = evas_map_new(4);
1329    if (!map) return;
1330
1331    if (resizable_flip->cw) degree = (float)(progress * 180);
1332    else degree = (float)(progress * -180);
1333
1334    if (!resizable_flip->nodes)
1335      resizable_flip->nodes = _resizable_flip_nodes_build(transit,
1336                                                          resizable_flip);
1337
1338    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1339      {
1340         if ((degree < 90) && (degree > -90))
1341           {
1342              obj = resizable_flip_node->front;
1343              if (resizable_flip_node->front != resizable_flip_node->back)
1344                {
1345                   evas_object_hide(resizable_flip_node->back);
1346                   evas_object_show(resizable_flip_node->front);
1347                }
1348           }
1349         else
1350           {
1351              obj = resizable_flip_node->back;
1352              if (resizable_flip_node->front != resizable_flip_node->back)
1353                {
1354                   evas_object_hide(resizable_flip_node->front);
1355                   evas_object_show(resizable_flip_node->back);
1356                }
1357           }
1358
1359         x = resizable_flip_node->from_pos.x +
1360            (resizable_flip_node->to_pos.x * progress);
1361         y = resizable_flip_node->from_pos.y +
1362            (resizable_flip_node->to_pos.y * progress);
1363         w = resizable_flip_node->from_size.x +
1364            (resizable_flip_node->to_size.x * progress);
1365         h = resizable_flip_node->from_size.y +
1366            (resizable_flip_node->to_size.y * progress);
1367         evas_map_point_coord_set(map, 0, x, y, 0);
1368         evas_map_point_coord_set(map, 1, x + w, y, 0);
1369         evas_map_point_coord_set(map, 2, x + w, y + h, 0);
1370         evas_map_point_coord_set(map, 3, x, y + h, 0);
1371
1372         half_w = (Evas_Coord)(w / 2);
1373         half_h = (Evas_Coord)(h / 2);
1374
1375         if (resizable_flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1376           {
1377              _set_image_uv_by_axis_y(map, resizable_flip_node, degree);
1378              evas_map_util_3d_rotate(map, 0, degree,
1379                                      0, x + half_w, y + half_h, 0);
1380           }
1381         else
1382           {
1383              _set_image_uv_by_axis_x(map, resizable_flip_node, degree);
1384              evas_map_util_3d_rotate(map, degree, 0,
1385                                      0, x + half_w, y + half_h, 0);
1386           }
1387
1388         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1389         evas_object_map_enable_set(resizable_flip_node->front, EINA_TRUE);
1390         evas_object_map_enable_set(resizable_flip_node->back, EINA_TRUE);
1391         evas_object_map_set(obj, map);
1392      }
1393    evas_map_free(map);
1394 }
1395
1396 static Elm_Transit_Effect *
1397 _transit_effect_resizable_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1398 {
1399    Elm_Transit_Effect_ResizableFlip *resizable_flip;
1400
1401    resizable_flip = ELM_NEW(Elm_Transit_Effect_ResizableFlip);
1402    if (!resizable_flip) return NULL;
1403
1404    resizable_flip->cw = cw;
1405    resizable_flip->axis = axis;
1406
1407    return resizable_flip;
1408 }
1409
1410 EAPI Elm_Transit_Effect *
1411 elm_transit_effect_resizable_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1412 {
1413    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1414    Elm_Transit_Effect *effect = _transit_effect_resizable_flip_context_new(axis, cw);
1415
1416    if (!effect)
1417      {
1418         ERR("Failed to allocate resizable_flip effect! : transit=%p", transit);
1419         return NULL;
1420      }
1421    elm_transit_effect_add(transit,
1422                           _transit_effect_resizable_flip_op, effect,
1423                           _transit_effect_resizable_flip_context_free);
1424    return effect;
1425 }
1426
1427 ///////////////////////////////////////////////////////////////////////////
1428 //Wipe Effect
1429 ///////////////////////////////////////////////////////////////////////////
1430 typedef struct _Elm_Transit_Effect_Wipe Elm_Transit_Effect_Wipe;
1431
1432 struct _Elm_Transit_Effect_Wipe
1433 {
1434    Elm_Transit_Effect_Wipe_Type type;
1435    Elm_Transit_Effect_Wipe_Dir dir;
1436 };
1437
1438 static void
1439 _elm_fx_wipe_hide(Evas_Map * map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1440 {
1441    float w2, h2;
1442
1443    switch (dir)
1444      {
1445       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1446          w2 = w - (w * progress);
1447          h2 = (y + h);
1448          evas_map_point_image_uv_set(map, 0, 0, 0);
1449          evas_map_point_image_uv_set(map, 1, w2, 0);
1450          evas_map_point_image_uv_set(map, 2, w2, h);
1451          evas_map_point_image_uv_set(map, 3, 0, h);
1452          evas_map_point_coord_set(map, 0, x, y, 0);
1453          evas_map_point_coord_set(map, 1, x + w2, y, 0);
1454          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
1455          evas_map_point_coord_set(map, 3, x, h2, 0);
1456          break;
1457       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
1458          w2 = (w * progress);
1459          h2 = (y + h);
1460          evas_map_point_image_uv_set(map, 0, w2, 0);
1461          evas_map_point_image_uv_set(map, 1, w, 0);
1462          evas_map_point_image_uv_set(map, 2, w, h);
1463          evas_map_point_image_uv_set(map, 3, w2, h);
1464          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1465          evas_map_point_coord_set(map, 1, x + w, y, 0);
1466          evas_map_point_coord_set(map, 2, x + w, h2, 0);
1467          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1468          break;
1469       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
1470          w2 = (x + w);
1471          h2 = h - (h * progress);
1472          evas_map_point_image_uv_set(map, 0, 0, 0);
1473          evas_map_point_image_uv_set(map, 1, w, 0);
1474          evas_map_point_image_uv_set(map, 2, w, h2);
1475          evas_map_point_image_uv_set(map, 3, 0, h2);
1476          evas_map_point_coord_set(map, 0, x, y, 0);
1477          evas_map_point_coord_set(map, 1, w2, y, 0);
1478          evas_map_point_coord_set(map, 2, w2, y+h2, 0);
1479          evas_map_point_coord_set(map, 3, x, y+h2, 0);
1480          break;
1481       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
1482          w2 = (x + w);
1483          h2 = (h * progress);
1484          evas_map_point_image_uv_set(map, 0, 0, h2);
1485          evas_map_point_image_uv_set(map, 1, w, h2);
1486          evas_map_point_image_uv_set(map, 2, w, h);
1487          evas_map_point_image_uv_set(map, 3, 0, h);
1488          evas_map_point_coord_set(map, 0, x, y + h2, 0);
1489          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
1490          evas_map_point_coord_set(map, 2, w2, y + h, 0);
1491          evas_map_point_coord_set(map, 3, x, y + h, 0);
1492          break;
1493       default:
1494          break;
1495      }
1496    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1497 }
1498
1499 static void
1500 _elm_fx_wipe_show(Evas_Map *map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1501 {
1502    float w2, h2;
1503
1504    switch (dir)
1505      {
1506       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1507          w2 = (w - (w * progress));
1508          h2 = (y + h);
1509          evas_map_point_image_uv_set(map, 0, w2, 0);
1510          evas_map_point_image_uv_set(map, 1, w, 0);
1511          evas_map_point_image_uv_set(map, 2, w, h);
1512          evas_map_point_image_uv_set(map, 3, w2, h);
1513          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1514          evas_map_point_coord_set(map, 1, w, y, 0);
1515          evas_map_point_coord_set(map, 2, w, h2, 0);
1516          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1517          break;
1518       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
1519          w2 = (w * progress);
1520          h2 = (y + h);
1521          evas_map_point_image_uv_set(map, 0, 0, 0);
1522          evas_map_point_image_uv_set(map, 1, w2, 0);
1523          evas_map_point_image_uv_set(map, 2, w2, h);
1524          evas_map_point_image_uv_set(map, 3, 0, h);
1525          evas_map_point_coord_set(map, 0, x, y, 0);
1526          evas_map_point_coord_set(map, 1, x + w2, y, 0);
1527          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
1528          evas_map_point_coord_set(map, 3, x, h2, 0);
1529          break;
1530       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
1531          w2 = (x + w);
1532          h2 = (h - (h * progress));
1533          evas_map_point_image_uv_set(map, 0, 0, h2);
1534          evas_map_point_image_uv_set(map, 1, w, h2);
1535          evas_map_point_image_uv_set(map, 2, w, h);
1536          evas_map_point_image_uv_set(map, 3, 0, h);
1537          evas_map_point_coord_set(map, 0, x, y + h2, 0);
1538          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
1539          evas_map_point_coord_set(map, 2, w2, y + h, 0);
1540          evas_map_point_coord_set(map, 3, x, y + h, 0);
1541          break;
1542       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
1543          w2 = (x + w);
1544          h2 = (h * progress);
1545          evas_map_point_image_uv_set(map, 0, 0, 0);
1546          evas_map_point_image_uv_set(map, 1, w, 0);
1547          evas_map_point_image_uv_set(map, 2, w, h2);
1548          evas_map_point_image_uv_set(map, 3, 0, h2);
1549          evas_map_point_coord_set(map, 0, x, y, 0);
1550          evas_map_point_coord_set(map, 1, w2, y, 0);
1551          evas_map_point_coord_set(map, 2, w2, y + h2, 0);
1552          evas_map_point_coord_set(map, 3, x, y + h2, 0);
1553          break;
1554       default:
1555          break;
1556      }
1557    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1558 }
1559
1560 static void
1561 _transit_effect_wipe_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
1562 {
1563    EINA_SAFETY_ON_NULL_RETURN(effect);
1564    EINA_SAFETY_ON_NULL_RETURN(transit);
1565    Eina_List *elist;
1566    Evas_Object *obj;
1567    Elm_Transit_Effect_Wipe *wipe = effect;
1568    Eina_Bool reverse = elm_transit_auto_reverse_get(transit);
1569
1570    EINA_LIST_FOREACH(transit->objs, elist, obj)
1571      {
1572         if ((wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW && !reverse)
1573             || (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE && reverse))
1574           evas_object_show(obj);
1575         else evas_object_hide(obj);
1576         evas_object_map_enable_set(obj, EINA_FALSE);
1577      }
1578
1579    free(wipe);
1580 }
1581
1582 static void
1583 _transit_effect_wipe_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1584 {
1585    EINA_SAFETY_ON_NULL_RETURN(effect);
1586    EINA_SAFETY_ON_NULL_RETURN(transit);
1587    Elm_Transit_Effect_Wipe *wipe = effect;
1588    Evas_Map *map;
1589    Evas_Coord _x, _y, _w, _h;
1590    Eina_List *elist;
1591    Evas_Object *obj;
1592
1593    map = evas_map_new(4);
1594    if (!map) return;
1595
1596    EINA_LIST_FOREACH(transit->objs, elist, obj)
1597      {
1598         evas_object_geometry_get(obj, &_x, &_y, &_w, &_h);
1599
1600         if (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW)
1601           _elm_fx_wipe_show(map, wipe->dir, _x, _y, _w, _h, (float)progress);
1602         else
1603           _elm_fx_wipe_hide(map, wipe->dir, _x, _y, _w, _h, (float)progress);
1604
1605         evas_object_map_enable_set(obj, EINA_TRUE);
1606         evas_object_map_set(obj, map);
1607      }
1608    evas_map_free(map);
1609 }
1610
1611 static Elm_Transit_Effect *
1612 _transit_effect_wipe_context_new(Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
1613 {
1614    Elm_Transit_Effect_Wipe *wipe;
1615
1616    wipe = ELM_NEW(Elm_Transit_Effect_Wipe);
1617    if (!wipe) return NULL;
1618
1619    wipe->type = type;
1620    wipe->dir = dir;
1621
1622    return wipe;
1623 }
1624
1625 EAPI void *
1626 elm_transit_effect_wipe_add(Elm_Transit *transit, Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
1627 {
1628    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1629    void *effect = _transit_effect_wipe_context_new(type, dir);
1630
1631    if (!effect)
1632      {
1633         ERR("Failed to allocate wipe effect! : transit=%p", transit);
1634         return NULL;
1635      }
1636    elm_transit_effect_add(transit,
1637                           _transit_effect_wipe_op, effect,
1638                           _transit_effect_wipe_context_free);
1639    return effect;
1640 }
1641
1642 ///////////////////////////////////////////////////////////////////////////
1643 //Color Effect
1644 ///////////////////////////////////////////////////////////////////////////
1645 typedef struct _Elm_Transit_Effect_Color Elm_Transit_Effect_Color;
1646
1647 struct _Elm_Transit_Effect_Color
1648 {
1649    struct _unsigned_color {
1650       unsigned int r, g, b, a;
1651    } from;
1652    struct _signed_color {
1653       int r, g, b, a;
1654    } to;
1655 };
1656
1657 static void
1658 _transit_effect_color_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1659 {
1660    Elm_Transit_Effect_Color *color = effect;
1661    free(color);
1662 }
1663
1664 static void
1665 _transit_effect_color_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1666 {
1667    EINA_SAFETY_ON_NULL_RETURN(effect);
1668    EINA_SAFETY_ON_NULL_RETURN(transit);
1669    Elm_Transit_Effect_Color *color = effect;
1670    Evas_Object *obj;
1671    Eina_List *elist;
1672    unsigned int r, g, b, a;
1673
1674    r = (color->from.r + (int)((float)color->to.r * progress));
1675    g = (color->from.g + (int)((float)color->to.g * progress));
1676    b = (color->from.b + (int)((float)color->to.b * progress));
1677    a = (color->from.a + (int)((float)color->to.a * progress));
1678
1679    EINA_LIST_FOREACH(transit->objs, elist, obj)
1680      evas_object_color_set(obj, r, g, b, a);
1681 }
1682
1683 static Elm_Transit_Effect *
1684 _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)
1685 {
1686    Elm_Transit_Effect_Color *color;
1687
1688    color = ELM_NEW(Elm_Transit_Effect_Color);
1689    if (!color) return NULL;
1690
1691    color->from.r = from_r;
1692    color->from.g = from_g;
1693    color->from.b = from_b;
1694    color->from.a = from_a;
1695    color->to.r = to_r - from_r;
1696    color->to.g = to_g - from_g;
1697    color->to.b = to_b - from_b;
1698    color->to.a = to_a - from_a;
1699
1700    return color;
1701 }
1702
1703 EAPI Elm_Transit_Effect *
1704 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)
1705 {
1706    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1707    Elm_Transit_Effect *effect = _transit_effect_color_context_new(from_r, from_g, from_b, from_a, to_r, to_g, to_b, to_a);
1708
1709    if (!effect)
1710      {
1711         ERR("Failed to allocate color effect! : transit=%p", transit);
1712         return NULL;
1713      }
1714    elm_transit_effect_add(transit,
1715                           _transit_effect_color_op, effect,
1716                           _transit_effect_color_context_free);
1717    return effect;
1718 }
1719
1720 ///////////////////////////////////////////////////////////////////////////
1721 //Fade Effect
1722 ///////////////////////////////////////////////////////////////////////////
1723 typedef struct _Elm_Transit_Effect_Fade Elm_Transit_Effect_Fade;
1724 typedef struct _Elm_Transit_Effect_Fade_Node Elm_Transit_Effect_Fade_Node;
1725
1726 struct _Elm_Transit_Effect_Fade_Node
1727 {
1728    Evas_Object *before;
1729    Evas_Object *after;
1730    struct _signed_color before_color, after_color;
1731    int before_alpha;
1732    int after_alpha;
1733    Eina_Bool inversed : 1;
1734 };
1735
1736 struct _Elm_Transit_Effect_Fade
1737 {
1738    Eina_List *nodes;
1739 };
1740
1741 static void
1742 _fade_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1743 {
1744    Elm_Transit_Effect_Fade *fade = data;
1745    Eina_List *elist;
1746    Elm_Transit_Effect_Fade_Node *fade_node;
1747
1748    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1749      {
1750         if (fade_node->before == obj)
1751           evas_object_event_callback_del(fade_node->after,
1752                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1753         else if (fade_node->after == obj)
1754           evas_object_event_callback_del(fade_node->before,
1755                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1756         else continue;
1757
1758         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1759         free(fade_node);
1760         break;
1761      }
1762 }
1763
1764 static Eina_List *
1765 _fade_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Fade *fade_data)
1766 {
1767    Elm_Transit_Effect_Fade_Node *fade;
1768    Eina_List *data_list = NULL;
1769    int i, count;
1770
1771    count = eina_list_count(transit->objs);
1772    for (i = 0; i < count; i += 2)
1773      {
1774         fade = ELM_NEW(Elm_Transit_Effect_Fade_Node);
1775         if (!fade)
1776           {
1777              eina_list_free(data_list);
1778              return NULL;
1779           }
1780
1781         fade->before = eina_list_nth(transit->objs, i);
1782         fade->after = eina_list_nth(transit->objs, i+1);
1783
1784         evas_object_color_get(fade->before,
1785                               &fade->before_color.r, &fade->before_color.g,
1786                               &fade->before_color.b, &fade->before_color.a);
1787         evas_object_color_get(fade->after,
1788                               &fade->after_color.r, &fade->after_color.g,
1789                               &fade->after_color.b, &fade->after_color.a);
1790
1791         fade->before_alpha = (255 - fade->before_color.a);
1792         fade->after_alpha = (255 - fade->after_color.a);
1793
1794         data_list = eina_list_append(data_list, fade);
1795
1796         evas_object_event_callback_add(fade->before,
1797                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1798         evas_object_event_callback_add(fade->after,
1799                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1800      }
1801    return data_list;
1802 }
1803
1804 static void
1805 _transit_effect_fade_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1806 {
1807    EINA_SAFETY_ON_NULL_RETURN(effect);
1808    Elm_Transit_Effect_Fade *fade = effect;
1809    Elm_Transit_Effect_Fade_Node *fade_node;
1810    Eina_List *elist, *elist_next;
1811
1812    EINA_LIST_FOREACH_SAFE(fade->nodes, elist, elist_next, fade_node)
1813      {
1814         evas_object_color_set(fade_node->before, fade_node->before_color.r,
1815                               fade_node->before_color.g,
1816                               fade_node->before_color.b,
1817                               fade_node->before_color.a);
1818         evas_object_color_set(fade_node->after, fade_node->after_color.r,
1819                               fade_node->after_color.g,
1820                               fade_node->after_color.b,
1821                               fade_node->after_color.a);
1822
1823         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1824         evas_object_event_callback_del(fade_node->before,
1825                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1826         evas_object_event_callback_del(fade_node->after,
1827                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1828         free(fade_node);
1829      }
1830
1831    free(fade);
1832 }
1833
1834 static void
1835 _transit_effect_fade_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1836 {
1837    EINA_SAFETY_ON_NULL_RETURN(effect);
1838    Elm_Transit_Effect_Fade *fade = effect;
1839    Eina_List *elist;
1840    Elm_Transit_Effect_Fade_Node *fade_node;
1841    float _progress;
1842
1843    if (!fade->nodes)
1844      fade->nodes = _fade_nodes_build(transit, fade);
1845
1846    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1847      {
1848         if (progress < 0.5)
1849           {
1850              if (!fade_node->inversed)
1851                {
1852                   evas_object_hide(fade_node->after);
1853                   evas_object_show(fade_node->before);
1854                   fade_node->inversed = EINA_TRUE;
1855                }
1856
1857              _progress = (1 - (progress * 2));
1858
1859              evas_object_color_set(fade_node->before,
1860                                    fade_node->before_color.r * _progress,
1861                                    fade_node->before_color.g * _progress,
1862                                    fade_node->before_color.b * _progress,
1863                                    fade_node->before_color.a +
1864                                    fade_node->before_alpha * (1 - _progress));
1865           }
1866         else
1867           {
1868              if (fade_node->inversed)
1869                {
1870                   evas_object_hide(fade_node->before);
1871                   evas_object_show(fade_node->after);
1872                   fade_node->inversed = EINA_FALSE;
1873                }
1874
1875              _progress = ((progress - 0.5) * 2);
1876
1877              evas_object_color_set(fade_node->after,
1878                                    fade_node->after_color.r * _progress,
1879                                    fade_node->after_color.g * _progress,
1880                                    fade_node->after_color.b * _progress,
1881                                    fade_node->after_color.a +
1882                                    fade_node->after_alpha * (1 - _progress));
1883           }
1884      }
1885 }
1886
1887 static Elm_Transit_Effect *
1888 _transit_effect_fade_context_new(void)
1889 {
1890    Elm_Transit_Effect_Fade *fade;
1891    fade = ELM_NEW(Elm_Transit_Effect_Fade);
1892    if (!fade) return NULL;
1893    return fade;
1894 }
1895
1896 EAPI Elm_Transit_Effect *
1897 elm_transit_effect_fade_add(Elm_Transit *transit)
1898 {
1899    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1900
1901    Elm_Transit_Effect *effect = _transit_effect_fade_context_new();
1902
1903    if (!effect)
1904      {
1905         ERR("Failed to allocate fade effect! : transit=%p", transit);
1906         return NULL;
1907      }
1908    elm_transit_effect_add(transit,
1909                           _transit_effect_fade_op, effect,
1910                           _transit_effect_fade_context_free);
1911    return effect;
1912 }
1913
1914 ///////////////////////////////////////////////////////////////////////////
1915 //Blend Effect
1916 ///////////////////////////////////////////////////////////////////////////
1917 typedef struct _Elm_Transit_Effect_Blend Elm_Transit_Effect_Blend;
1918 typedef struct _Elm_Transit_Effect_Blend_Node Elm_Transit_Effect_Blend_Node;
1919
1920 struct _Elm_Transit_Effect_Blend_Node
1921 {
1922    Evas_Object *before;
1923    Evas_Object *after;
1924    struct _signed_color from, to;
1925 };
1926
1927 struct _Elm_Transit_Effect_Blend
1928 {
1929    Eina_List *nodes;
1930 };
1931
1932 static void
1933 _blend_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1934 {
1935    Elm_Transit_Effect_Blend *blend = data;
1936    Eina_List *elist;
1937    Elm_Transit_Effect_Blend_Node *blend_node;
1938
1939    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
1940      {
1941         if (blend_node->after == obj)
1942           evas_object_event_callback_del(blend_node->before,
1943                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1944         else if (blend_node->before == obj)
1945           evas_object_event_callback_del(blend_node->after,
1946                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1947         else continue;
1948
1949         blend->nodes = eina_list_remove_list(blend->nodes, elist);
1950         free(blend_node);
1951         break;
1952      }
1953 }
1954
1955 static Eina_List *
1956 _blend_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Blend *blend)
1957 {
1958    Elm_Transit_Effect_Blend_Node *blend_node;
1959    Eina_List *data_list = NULL;
1960    int i, count;
1961
1962    count = eina_list_count(transit->objs);
1963    for (i = 0; i < (count - 1); i += 2)
1964      {
1965         blend_node = ELM_NEW(Elm_Transit_Effect_Blend_Node);
1966         if (!blend_node)
1967           {
1968              eina_list_free(data_list);
1969              return NULL;
1970           }
1971
1972         blend_node->before = eina_list_nth(transit->objs, i);
1973         blend_node->after = eina_list_nth(transit->objs, i + 1);
1974         evas_object_show(blend_node->before);
1975         evas_object_show(blend_node->after);
1976
1977         evas_object_color_get(blend_node->before, &blend_node->from.r,
1978                               &blend_node->from.g, &blend_node->from.b,
1979                               &blend_node->from.a);
1980         evas_object_color_get(blend_node->after, &blend_node->to.r,
1981                               &blend_node->to.g, &blend_node->to.b,
1982                               &blend_node->to.a);
1983
1984         data_list = eina_list_append(data_list, blend_node);
1985
1986         evas_object_event_callback_add(blend_node->before,
1987                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1988         evas_object_event_callback_add(blend_node->after,
1989                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1990      }
1991    return data_list;
1992 }
1993
1994 void
1995 _transit_effect_blend_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1996 {
1997    EINA_SAFETY_ON_NULL_RETURN(effect);
1998    Elm_Transit_Effect_Blend *blend = effect;
1999    Elm_Transit_Effect_Blend_Node *blend_node;
2000    Eina_List *elist, *elist_next;
2001
2002    EINA_LIST_FOREACH_SAFE(blend->nodes, elist, elist_next, blend_node)
2003      {
2004         evas_object_color_set(blend_node->before,
2005                               blend_node->from.r, blend_node->from.g,
2006                               blend_node->from.b, blend_node->from.a);
2007         evas_object_color_set(blend_node->after, blend_node->to.r,
2008                               blend_node->to.g, blend_node->to.b,
2009                               blend_node->to.a);
2010
2011         if (elm_transit_auto_reverse_get(transit))
2012           evas_object_hide(blend_node->after);
2013         else
2014           evas_object_hide(blend_node->before);
2015
2016         blend->nodes = eina_list_remove_list(blend->nodes, elist);
2017
2018         evas_object_event_callback_del(blend_node->before,
2019                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2020         evas_object_event_callback_del(blend_node->after,
2021                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2022         free(blend_node);
2023      }
2024    free(blend);
2025 }
2026
2027 void
2028 _transit_effect_blend_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2029 {
2030    EINA_SAFETY_ON_NULL_RETURN(effect);
2031    EINA_SAFETY_ON_NULL_RETURN(transit);
2032    Elm_Transit_Effect_Blend *blend = effect;
2033    Elm_Transit_Effect_Blend_Node *blend_node;
2034    Eina_List *elist;
2035
2036    if (!blend->nodes) blend->nodes = _blend_nodes_build(transit, blend);
2037
2038    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
2039      {
2040         evas_object_color_set(blend_node->before,
2041                               (int)(blend_node->from.r * (1 - progress)),
2042                               (int)(blend_node->from.g * (1 - progress)),
2043                               (int)(blend_node->from.b * (1 - progress)),
2044                               (int)(blend_node->from.a * (1 - progress)));
2045         evas_object_color_set(blend_node->after,
2046                               (int)(blend_node->to.r * progress),
2047                               (int)(blend_node->to.g * progress),
2048                               (int)(blend_node->to.b * progress),
2049                               (int)(blend_node->to.a * progress));
2050      }
2051 }
2052
2053 static Elm_Transit_Effect *
2054 _transit_effect_blend_context_new(void)
2055 {
2056    Elm_Transit_Effect_Blend *blend;
2057
2058    blend = ELM_NEW(Elm_Transit_Effect_Blend);
2059    if (!blend) return NULL;
2060    return blend;
2061 }
2062
2063 EAPI Elm_Transit_Effect *
2064 elm_transit_effect_blend_add(Elm_Transit *transit)
2065 {
2066    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2067    Elm_Transit_Effect *effect = _transit_effect_blend_context_new();
2068
2069    if (!effect)
2070      {
2071         ERR("Failed to allocate blend effect! : transit=%p", transit);
2072         return NULL;
2073      }
2074    elm_transit_effect_add(transit,
2075                           _transit_effect_blend_op, effect,
2076                           _transit_effect_blend_context_free);
2077    return effect;
2078 }
2079
2080 ///////////////////////////////////////////////////////////////////////////
2081 //Rotation Effect
2082 ///////////////////////////////////////////////////////////////////////////
2083 typedef struct _Elm_Transit_Effect_Rotation Elm_Transit_Effect_Rotation;
2084
2085 struct _Elm_Transit_Effect_Rotation
2086 {
2087    float from, to;
2088 };
2089
2090 static void
2091 _transit_effect_rotation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2092 {
2093    Elm_Transit_Effect_Rotation *rotation = effect;
2094    free(rotation);
2095 }
2096
2097 static void
2098 _transit_effect_rotation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2099 {
2100    EINA_SAFETY_ON_NULL_RETURN(effect);
2101    EINA_SAFETY_ON_NULL_RETURN(transit);
2102    Elm_Transit_Effect_Rotation *rotation = effect;
2103    Evas_Map *map;
2104    Evas_Coord x, y, w, h;
2105    float degree;
2106    float half_w, half_h;
2107    Eina_List *elist;
2108    Evas_Object *obj;
2109
2110    map = evas_map_new(4);
2111    if (!map) return;
2112
2113    EINA_LIST_FOREACH(transit->objs, elist, obj)
2114      {
2115         evas_map_util_points_populate_from_object_full(map, obj, 0);
2116         degree = rotation->from + (float)(progress * rotation->to);
2117
2118         evas_object_geometry_get(obj, &x, &y, &w, &h);
2119
2120         half_w = (float)w * 0.5;
2121         half_h = (float)h * 0.5;
2122
2123         evas_map_util_rotate(map, degree, x + half_w, y + half_h);
2124         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
2125         evas_object_map_enable_set(obj, EINA_TRUE);
2126         evas_object_map_set(obj, map);
2127      }
2128    evas_map_free(map);
2129 }
2130
2131 static Elm_Transit_Effect *
2132 _transit_effect_rotation_context_new(float from_degree, float to_degree)
2133 {
2134    Elm_Transit_Effect_Rotation *rotation;
2135
2136    rotation = ELM_NEW(Elm_Transit_Effect_Rotation);
2137    if (!rotation) return NULL;
2138
2139    rotation->from = from_degree;
2140    rotation->to = to_degree - from_degree;
2141
2142    return rotation;
2143 }
2144
2145 EAPI Elm_Transit_Effect *
2146 elm_transit_effect_rotation_add(Elm_Transit *transit, float from_degree, float to_degree)
2147 {
2148    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2149    Elm_Transit_Effect *effect = _transit_effect_rotation_context_new(from_degree, to_degree);
2150
2151    if (!effect)
2152      {
2153         ERR("Failed to allocate rotation effect! : transit=%p", transit);
2154         return NULL;
2155      }
2156    elm_transit_effect_add(transit,
2157                           _transit_effect_rotation_op, effect,
2158                           _transit_effect_rotation_context_free);
2159    return effect;
2160 }
2161
2162 ///////////////////////////////////////////////////////////////////////////
2163 //ImageAnimation Effect
2164 ///////////////////////////////////////////////////////////////////////////
2165 typedef struct _Elm_Transit_Effect_Image_Animation Elm_Transit_Effect_Image_Animation;
2166
2167 struct _Elm_Transit_Effect_Image_Animation
2168 {
2169    Eina_List *images;
2170 };
2171
2172 static void
2173 _transit_effect_image_animation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2174 {
2175    EINA_SAFETY_ON_NULL_RETURN(effect);
2176    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2177    const char *image;
2178    Eina_List *elist, *elist_next;
2179
2180    EINA_LIST_FOREACH_SAFE(image_animation->images, elist, elist_next, image)
2181      {
2182         image_animation->images =
2183            eina_list_remove_list(image_animation->images, elist);
2184         eina_stringshare_del(image);
2185      }
2186
2187    free(image_animation);
2188 }
2189
2190 static void
2191 _transit_effect_image_animation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2192 {
2193    EINA_SAFETY_ON_NULL_RETURN(effect);
2194    EINA_SAFETY_ON_NULL_RETURN(transit);
2195    Eina_List *elist;
2196    Evas_Object *obj;
2197    const char *type;
2198    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2199    unsigned int count = 0;
2200    int len;
2201
2202    type = eina_stringshare_add("icon");
2203    len = eina_list_count(image_animation->images);
2204
2205    if (!len) count = floor(progress * len);
2206    else count = floor(progress * (len - 1));
2207
2208    EINA_LIST_FOREACH(transit->objs, elist, obj)
2209      {
2210         if (elm_widget_type_check(obj, type))
2211           elm_icon_file_set(obj,
2212                             eina_list_nth(image_animation->images, count), NULL);
2213      }
2214
2215    eina_stringshare_del(type);
2216 }
2217
2218 static Elm_Transit_Effect *
2219 _transit_effect_image_animation_context_new(Eina_List *images)
2220 {
2221    Elm_Transit_Effect_Image_Animation *image_animation;
2222    image_animation = ELM_NEW(Elm_Transit_Effect_Image_Animation);
2223
2224    if (!image_animation) return NULL;
2225    image_animation->images = images;
2226    return image_animation;
2227 }
2228
2229 EAPI Elm_Transit_Effect *
2230 elm_transit_effect_image_animation_add(Elm_Transit *transit, Eina_List *images)
2231 {
2232    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2233    Elm_Transit_Effect *effect = _transit_effect_image_animation_context_new(images);
2234
2235    if (!effect)
2236      {
2237         ERR("Failed to allocate image_animation effect! : transit=%p", transit);
2238         return NULL;
2239      }
2240    elm_transit_effect_add(transit,
2241                           _transit_effect_image_animation_op, effect,
2242                           _transit_effect_image_animation_context_free);
2243    return effect;
2244 }