elementary/transit - added wrn/err messages.
[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 Eina_List *
696 elm_transit_chain_transits_get(const Elm_Transit * transit)
697 {
698    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
699    return transit->next_chain_transits;
700 }
701
702 ///////////////////////////////////////////////////////////////////////////////
703 //Resizing Effect
704 ///////////////////////////////////////////////////////////////////////////////
705 typedef struct _Elm_Transit_Effect_Resizing Elm_Transit_Effect_Resizing;
706
707 struct _Elm_Transit_Effect_Resizing
708 {
709    struct _size {
710       Evas_Coord w, h;
711    } from, to;
712 };
713
714 static void
715 _transit_effect_resizing_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
716 {
717    Elm_Transit_Effect_Resizing *resizing = effect;
718    free(resizing);
719 }
720
721 static void
722 _transit_effect_resizing_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
723 {
724    EINA_SAFETY_ON_NULL_RETURN(effect);
725    EINA_SAFETY_ON_NULL_RETURN(transit);
726    Evas_Coord w, h;
727    Evas_Object *obj;
728    Eina_List *elist;
729    Elm_Transit_Effect_Resizing *resizing = effect;
730
731    w = resizing->from.w + (resizing->to.w * progress);
732    h = resizing->from.h + (resizing->to.h * progress);
733
734    EINA_LIST_FOREACH(transit->objs, elist, obj)
735      evas_object_resize(obj, w, h);
736 }
737
738 static Elm_Transit_Effect *
739 _transit_effect_resizing_context_new(Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
740 {
741    Elm_Transit_Effect_Resizing *resizing;
742
743    resizing = ELM_NEW(Elm_Transit_Effect_Resizing);
744    if (!resizing) return NULL;
745
746    resizing->from.w = from_w;
747    resizing->from.h = from_h;
748    resizing->to.w = to_w - from_w;
749    resizing->to.h = to_h - from_h;
750
751    return resizing;
752 }
753
754 EAPI Elm_Transit_Effect *
755 elm_transit_effect_resizing_add(Elm_Transit *transit, Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
756 {
757    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
758    Elm_Transit_Effect *effect = _transit_effect_resizing_context_new(from_w, from_h, to_w, to_h);
759
760    if (!effect)
761      {
762         ERR("Failed to allocate resizing effect! : transit=%p", transit);
763         return NULL;
764      }
765    elm_transit_effect_add(transit,
766                           _transit_effect_resizing_op, effect,
767                           _transit_effect_resizing_context_free);
768    return effect;
769 }
770
771 ///////////////////////////////////////////////////////////////////////////////
772 //Translation Effect
773 ///////////////////////////////////////////////////////////////////////////////
774 typedef struct _Elm_Transit_Effect_Translation Elm_Transit_Effect_Translation;
775 typedef struct _Elm_Transit_Effect_Translation_Node Elm_Transit_Effect_Translation_Node;
776
777 struct _Elm_Transit_Effect_Translation_Node
778 {
779    Evas_Object *obj;
780    Evas_Coord x, y;
781 };
782
783 struct _Elm_Transit_Effect_Translation
784 {
785    struct _position_variation {
786       Evas_Coord dx, dy;
787    } from, to;
788    Eina_List *nodes;
789 };
790
791 static void
792 _translation_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
793 {
794    Elm_Transit_Effect_Translation *translation = data;
795    Eina_List *elist;
796    Elm_Transit_Effect_Translation_Node *translation_node;
797
798    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
799      {
800         if (translation_node->obj != obj) continue;
801         translation->nodes = eina_list_remove_list(translation->nodes, elist);
802         free(translation_node);
803         break;
804      }
805 }
806
807 static Eina_List *
808 _translation_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Translation *translation)
809 {
810    Elm_Transit_Effect_Translation_Node *translation_node;
811    const Eina_List *elist;
812    Evas_Object *obj;
813    Eina_List *data_list = NULL;
814    const Eina_List *objs = elm_transit_objects_get(transit);
815
816    EINA_LIST_FOREACH(objs, elist, obj)
817      {
818         translation_node = ELM_NEW(Elm_Transit_Effect_Translation_Node);
819         if (!translation_node)
820           {
821              eina_list_free(data_list);
822              return NULL;
823           }
824         translation_node->obj = obj;
825         evas_object_geometry_get(obj, &(translation_node->x),
826                                  &(translation_node->y), NULL, NULL);
827         data_list = eina_list_append(data_list, translation_node);
828         evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
829                                        _translation_object_del_cb, translation);
830      }
831    return data_list;
832 }
833
834 void
835 _transit_effect_translation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
836 {
837    EINA_SAFETY_ON_NULL_RETURN(effect);
838    Elm_Transit_Effect_Translation *translation = effect;
839    Eina_List *elist, *elist_next;
840    Elm_Transit_Effect_Translation_Node *translation_node;
841
842    EINA_LIST_FOREACH_SAFE(translation->nodes,
843                           elist, elist_next, translation_node)
844      {
845         evas_object_event_callback_del(translation_node->obj,
846                                        EVAS_CALLBACK_DEL, _translation_object_del_cb);
847         translation->nodes = eina_list_remove_list(translation->nodes, elist);
848         free(translation_node);
849      }
850    free(translation);
851 }
852
853 void
854 _transit_effect_translation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress __UNUSED__)
855 {
856    EINA_SAFETY_ON_NULL_RETURN(effect);
857    EINA_SAFETY_ON_NULL_RETURN(transit);
858    Evas_Coord x, y;
859    Elm_Transit_Effect_Translation *translation = effect;
860    Elm_Transit_Effect_Translation_Node *translation_node;
861    Eina_List *elist;
862
863    if (!translation->nodes)
864      translation->nodes = _translation_nodes_build(transit, translation);
865
866    EINA_LIST_FOREACH(translation->nodes, elist, translation_node)
867      {
868         x = translation_node->x + translation->from.dx
869            + (translation->to.dx * progress);
870         y = translation_node->y + translation->from.dy
871            + (translation->to.dy * progress);
872         evas_object_move(translation_node->obj, x, y);
873      }
874 }
875
876 static Elm_Transit_Effect *
877 _transit_effect_translation_context_new(Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
878 {
879    Elm_Transit_Effect_Translation *translation;
880
881    translation = ELM_NEW(Elm_Transit_Effect_Translation);
882    if (!translation) return NULL;
883
884    translation->from.dx = from_dx;
885    translation->from.dy = from_dy;
886    translation->to.dx = to_dx - from_dx;
887    translation->to.dy = to_dy - from_dy;
888
889    return translation;
890 }
891
892 EAPI Elm_Transit_Effect *
893 elm_transit_effect_translation_add(Elm_Transit *transit, Evas_Coord from_dx, Evas_Coord from_dy, Evas_Coord to_dx, Evas_Coord to_dy)
894 {
895    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
896    Elm_Transit_Effect *effect_context = _transit_effect_translation_context_new(from_dx, from_dy, to_dx, to_dy);
897
898    if (!effect_context)
899      {
900         ERR("Failed to allocate translation effect! : transit=%p", transit);
901         return NULL;
902      }
903    elm_transit_effect_add(transit,
904                           _transit_effect_translation_op, effect_context,
905                           _transit_effect_translation_context_free);
906    return effect_context;
907 }
908
909
910 ///////////////////////////////////////////////////////////////////////////////
911 //Zoom Effect
912 ///////////////////////////////////////////////////////////////////////////////
913 typedef struct _Elm_Transit_Effect_Zoom Elm_Transit_Effect_Zoom;
914
915 struct _Elm_Transit_Effect_Zoom
916 {
917    float from, to;
918 };
919
920 void
921 _transit_effect_zoom_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
922 {
923    Elm_Transit_Effect_Zoom *zoom = effect;
924    free(zoom);
925 }
926
927 static void
928 _transit_effect_zoom_op(Elm_Transit_Effect *effect, Elm_Transit *transit , double progress)
929 {
930    EINA_SAFETY_ON_NULL_RETURN(effect);
931    EINA_SAFETY_ON_NULL_RETURN(transit);
932    Evas_Object *obj;
933    Eina_List *elist;
934    Elm_Transit_Effect_Zoom *zoom = effect;
935    Evas_Map *map;
936    Evas_Coord x, y, w, h;
937
938    map = evas_map_new(4);
939    if (!map) return;
940
941    EINA_LIST_FOREACH(transit->objs, elist, obj)
942      {
943         evas_object_geometry_get(obj, &x, &y, &w, &h);
944         evas_map_util_points_populate_from_object_full(map, obj, zoom->from +
945                                                        (progress * zoom->to));
946         evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
947         evas_object_map_set(obj, map);
948         evas_object_map_enable_set(obj, EINA_TRUE);
949      }
950    evas_map_free(map);
951 }
952
953 static Elm_Transit_Effect *
954 _transit_effect_zoom_context_new(float from_rate, float to_rate)
955 {
956    Elm_Transit_Effect_Zoom *zoom;
957
958    zoom = ELM_NEW(Elm_Transit_Effect_Zoom);
959    if (!zoom) return NULL;
960
961    zoom->from = (_TRANSIT_FOCAL - (from_rate * _TRANSIT_FOCAL)) * (1 / from_rate);
962    zoom->to = ((_TRANSIT_FOCAL - (to_rate * _TRANSIT_FOCAL)) * (1 / to_rate)) - zoom->from;
963
964    return zoom;
965 }
966
967 EAPI Elm_Transit_Effect *
968 elm_transit_effect_zoom_add(Elm_Transit *transit, float from_rate, float to_rate)
969 {
970    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
971    Elm_Transit_Effect *effect_context = _transit_effect_zoom_context_new(from_rate, to_rate);
972
973    if (!effect_context)
974      {
975         ERR("Failed to allocate zoom effect! : transit=%p", transit);
976         return NULL;
977      }
978    elm_transit_effect_add(transit,
979                           _transit_effect_zoom_op, effect_context,
980                           _transit_effect_zoom_context_free);
981    return effect_context;
982 }
983
984
985 ///////////////////////////////////////////////////////////////////////////////
986 //Flip Effect
987 ///////////////////////////////////////////////////////////////////////////////
988 typedef struct _Elm_Transit_Effect_Flip Elm_Transit_Effect_Flip;
989
990 struct _Elm_Transit_Effect_Flip
991 {
992    Elm_Transit_Effect_Flip_Axis axis;
993    Eina_Bool cw : 1;
994 };
995
996 static void
997 _transit_effect_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
998 {
999    EINA_SAFETY_ON_NULL_RETURN(effect);
1000    EINA_SAFETY_ON_NULL_RETURN(transit);
1001    Elm_Transit_Effect_Flip *flip = effect;
1002    Evas_Object *front, *back;
1003    int i;
1004    int count = eina_list_count(transit->objs);
1005
1006    for (i = 0; i < (count - 1); i += 2)
1007      {
1008         front = eina_list_nth(transit->objs, i);
1009         back = eina_list_nth(transit->objs, i+1);
1010         evas_object_map_enable_set(front, EINA_FALSE);
1011         evas_object_map_enable_set(back, EINA_FALSE);
1012      }
1013    free(flip);
1014 }
1015
1016 static void
1017 _transit_effect_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1018 {
1019    EINA_SAFETY_ON_NULL_RETURN(effect);
1020    EINA_SAFETY_ON_NULL_RETURN(transit);
1021    Evas_Object *obj, *front, *back;
1022    int count, i;
1023    Elm_Transit_Effect_Flip *flip = effect;
1024    Evas_Map *map;
1025    float degree;
1026    Evas_Coord x, y, w, h;
1027
1028    map = evas_map_new(4);
1029    if (!map) return;
1030
1031    if (flip->cw) degree = (float)(progress * 180);
1032    else degree = (float)(progress * -180);
1033
1034    count = eina_list_count(transit->objs);
1035
1036    for (i = 0; i < (count - 1); i += 2)
1037      {
1038         Evas_Coord half_w, half_h;
1039
1040         front = eina_list_nth(transit->objs, i);
1041         back = eina_list_nth(transit->objs, i+1);
1042
1043         if ((degree < 90) && (degree > -90))
1044           {
1045              obj = front;
1046              if (front != back)
1047                {
1048                   evas_object_hide(back);
1049                   evas_object_show(front);
1050                }
1051           }
1052         else
1053           {
1054              obj = back;
1055              if (front != back)
1056                {
1057                   evas_object_hide(front);
1058                   evas_object_show(back);
1059                }
1060           }
1061
1062         evas_map_util_points_populate_from_object_full(map, obj, 0);
1063         evas_object_geometry_get(obj, &x, &y, &w, &h);
1064         half_w = (w / 2);
1065         half_h = (h / 2);
1066
1067         if (flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1068           {
1069              if ((degree >= 90) || (degree <= -90))
1070                {
1071                   evas_map_point_image_uv_set(map, 0, w, 0);
1072                   evas_map_point_image_uv_set(map, 1, 0, 0);
1073                   evas_map_point_image_uv_set(map, 2, 0, h);
1074                   evas_map_point_image_uv_set(map, 3, w, h);
1075                }
1076              evas_map_util_3d_rotate(map, 0, degree,
1077                                      0, x + half_w, y + half_h, 0);
1078           }
1079         else
1080           {
1081              if ((degree >= 90) || (degree <= -90))
1082                {
1083                   evas_map_point_image_uv_set(map, 0, 0, h);
1084                   evas_map_point_image_uv_set(map, 1, w, h);
1085                   evas_map_point_image_uv_set(map, 2, w, 0);
1086                   evas_map_point_image_uv_set(map, 3, 0, 0);
1087                }
1088              evas_map_util_3d_rotate(map, degree,
1089                                      0, 0, x + half_w, y + half_h, 0);
1090           }
1091         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1092         evas_object_map_enable_set(front, EINA_TRUE);
1093         evas_object_map_enable_set(back, EINA_TRUE);
1094         evas_object_map_set(obj, map);
1095      }
1096    evas_map_free(map);
1097 }
1098
1099 static Elm_Transit_Effect *
1100 _transit_effect_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1101 {
1102    Elm_Transit_Effect_Flip *flip;
1103
1104    flip = ELM_NEW(Elm_Transit_Effect_Flip);
1105    if (!flip) return NULL;
1106
1107    flip->cw = cw;
1108    flip->axis = axis;
1109
1110    return flip;
1111 }
1112
1113 EAPI Elm_Transit_Effect *
1114 elm_transit_effect_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1115 {
1116    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1117    Elm_Transit_Effect *effect_context = _transit_effect_flip_context_new(axis, cw);
1118
1119    if (!effect_context)
1120      {
1121         ERR("Failed to allocate flip effect! : transit=%p", transit);
1122         return NULL;
1123      }
1124    elm_transit_effect_add(transit,
1125                           _transit_effect_flip_op, effect_context,
1126                           _transit_effect_flip_context_free);
1127    return effect_context;
1128 }
1129
1130 ///////////////////////////////////////////////////////////////////////////////
1131 //ResizableFlip Effect
1132 ///////////////////////////////////////////////////////////////////////////////
1133 typedef struct _Elm_Transit_Effect_Resizable_Flip Elm_Transit_Effect_ResizableFlip;
1134 typedef struct _Elm_Transit_Effect_Resizable_Flip_Node Elm_Transit_Effect_ResizableFlip_Node;
1135
1136 struct _Elm_Transit_Effect_Resizable_Flip_Node
1137 {
1138    Evas_Object *front;
1139    Evas_Object *back;
1140    struct _vector2d {
1141       float x, y;
1142    } from_pos, from_size, to_pos, to_size;
1143 };
1144
1145 struct _Elm_Transit_Effect_Resizable_Flip
1146 {
1147    Eina_List *nodes;
1148    Eina_Bool cw : 1;
1149    Elm_Transit_Effect_Flip_Axis axis;
1150 };
1151
1152 static void
1153 _resizable_flip_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1154 {
1155    Elm_Transit_Effect_ResizableFlip *resizable_flip = data;
1156    Eina_List *elist;
1157    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1158
1159    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1160      {
1161         if (resizable_flip_node->front == obj)
1162           evas_object_event_callback_del(resizable_flip_node->back,
1163                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1164         else if (resizable_flip_node->back == obj)
1165           evas_object_event_callback_del(resizable_flip_node->front,
1166                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1167         else continue;
1168
1169         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1170                                                       elist);
1171         free(resizable_flip_node);
1172         break;
1173      }
1174 }
1175
1176 static Eina_List *
1177 _resizable_flip_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_ResizableFlip *resizable_flip)
1178 {
1179    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1180    Eina_List *data_list = NULL;
1181    Evas_Coord front_x, front_y, front_w, front_h;
1182    Evas_Coord back_x, back_y, back_w, back_h;
1183    int i, count;
1184
1185    count = eina_list_count(transit->objs);
1186    for (i = 0; i < (count - 1); i += 2)
1187      {
1188         resizable_flip_node = ELM_NEW(Elm_Transit_Effect_ResizableFlip_Node);
1189         if (!resizable_flip_node)
1190           {
1191              eina_list_free(data_list);
1192              return NULL;
1193           }
1194
1195         resizable_flip_node->front = eina_list_nth(transit->objs, i);
1196         resizable_flip_node->back = eina_list_nth(transit->objs, i+1);
1197
1198         evas_object_geometry_get(resizable_flip_node->front,
1199                                  &front_x, &front_y, &front_w, &front_h);
1200         evas_object_geometry_get(resizable_flip_node->back,
1201                                  &back_x, &back_y, &back_w, &back_h);
1202
1203         resizable_flip_node->from_pos.x = front_x;
1204         resizable_flip_node->from_pos.y = front_y;
1205         resizable_flip_node->to_pos.x = back_x - front_x;
1206         resizable_flip_node->to_pos.y = back_y - front_y;
1207
1208         resizable_flip_node->from_size.x = front_w;
1209         resizable_flip_node->from_size.y = front_h;
1210         resizable_flip_node->to_size.x = back_w - front_w;
1211         resizable_flip_node->to_size.y = back_h - front_h;
1212
1213         data_list = eina_list_append(data_list, resizable_flip_node);
1214
1215         evas_object_event_callback_add(resizable_flip_node->back,
1216                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1217         evas_object_event_callback_add(resizable_flip_node->front,
1218                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1219      }
1220
1221    return data_list;
1222 }
1223
1224 static void
1225 _set_image_uv_by_axis_y(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1226 {
1227    if ((degree >= 90) || (degree <= -90))
1228      {
1229         evas_map_point_image_uv_set(map, 0,
1230                                     (flip->from_size.x * 2) + flip->to_size.x,
1231                                     0);
1232         evas_map_point_image_uv_set(map, 1, 0, 0);
1233         evas_map_point_image_uv_set(map, 2, 0,
1234                                     (flip->from_size.y * 2) + flip->to_size.y);
1235         evas_map_point_image_uv_set(map, 3,
1236                                     (flip->from_size.x * 2) + flip->to_size.x,
1237                                     (flip->from_size.y * 2) + flip->to_size.y);
1238      }
1239    else
1240      {
1241         evas_map_point_image_uv_set(map, 0, 0, 0);
1242         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1243         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1244                                     flip->from_size.y);
1245         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1246      }
1247 }
1248
1249 static void
1250 _set_image_uv_by_axis_x(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1251 {
1252    if ((degree >= 90) || (degree <= -90))
1253      {
1254         evas_map_point_image_uv_set(map, 0, 0,
1255                                     (flip->from_size.y * 2) + flip->to_size.y);
1256         evas_map_point_image_uv_set(map, 1,
1257                                     (flip->from_size.x * 2) + flip->to_size.x,
1258                                     (flip->from_size.y * 2) + flip->to_size.y);
1259         evas_map_point_image_uv_set(map, 2,
1260                                     (flip->from_size.x * 2) + flip->to_size.x,
1261                                     0);
1262         evas_map_point_image_uv_set(map, 3, 0, 0);
1263      }
1264    else
1265      {
1266         evas_map_point_image_uv_set(map, 0, 0, 0);
1267         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1268         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1269                                     flip->from_size.y);
1270         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1271      }
1272 }
1273
1274 void
1275 _transit_effect_resizable_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1276 {
1277    EINA_SAFETY_ON_NULL_RETURN(effect);
1278
1279    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1280    Eina_List *elist, *elist_next;
1281    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1282
1283    EINA_LIST_FOREACH_SAFE(resizable_flip->nodes,
1284                           elist, elist_next, resizable_flip_node)
1285      {
1286         evas_object_map_enable_set(resizable_flip_node->front, EINA_FALSE);
1287         evas_object_map_enable_set(resizable_flip_node->back, EINA_FALSE);
1288
1289         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1290                                                       elist);
1291
1292         evas_object_event_callback_del(resizable_flip_node->back,
1293                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1294         evas_object_event_callback_del(resizable_flip_node->front,
1295                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1296         free(resizable_flip_node);
1297      }
1298    free(resizable_flip);
1299 }
1300
1301 void
1302 _transit_effect_resizable_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1303 {
1304    EINA_SAFETY_ON_NULL_RETURN(effect);
1305    Evas_Map *map;
1306    Evas_Object *obj;
1307    float x, y, w, h;
1308    float degree;
1309    Evas_Coord half_w, half_h;
1310    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1311    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1312    Eina_List *elist;
1313
1314    map = evas_map_new(4);
1315    if (!map) return;
1316
1317    if (resizable_flip->cw) degree = (float)(progress * 180);
1318    else degree = (float)(progress * -180);
1319
1320    if (!resizable_flip->nodes)
1321      resizable_flip->nodes = _resizable_flip_nodes_build(transit,
1322                                                          resizable_flip);
1323
1324    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1325      {
1326         if ((degree < 90) && (degree > -90))
1327           {
1328              obj = resizable_flip_node->front;
1329              if (resizable_flip_node->front != resizable_flip_node->back)
1330                {
1331                   evas_object_hide(resizable_flip_node->back);
1332                   evas_object_show(resizable_flip_node->front);
1333                }
1334           }
1335         else
1336           {
1337              obj = resizable_flip_node->back;
1338              if (resizable_flip_node->front != resizable_flip_node->back)
1339                {
1340                   evas_object_hide(resizable_flip_node->front);
1341                   evas_object_show(resizable_flip_node->back);
1342                }
1343           }
1344
1345         x = resizable_flip_node->from_pos.x +
1346            (resizable_flip_node->to_pos.x * progress);
1347         y = resizable_flip_node->from_pos.y +
1348            (resizable_flip_node->to_pos.y * progress);
1349         w = resizable_flip_node->from_size.x +
1350            (resizable_flip_node->to_size.x * progress);
1351         h = resizable_flip_node->from_size.y +
1352            (resizable_flip_node->to_size.y * progress);
1353         evas_map_point_coord_set(map, 0, x, y, 0);
1354         evas_map_point_coord_set(map, 1, x + w, y, 0);
1355         evas_map_point_coord_set(map, 2, x + w, y + h, 0);
1356         evas_map_point_coord_set(map, 3, x, y + h, 0);
1357
1358         half_w = (Evas_Coord)(w / 2);
1359         half_h = (Evas_Coord)(h / 2);
1360
1361         if (resizable_flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1362           {
1363              _set_image_uv_by_axis_y(map, resizable_flip_node, degree);
1364              evas_map_util_3d_rotate(map, 0, degree,
1365                                      0, x + half_w, y + half_h, 0);
1366           }
1367         else
1368           {
1369              _set_image_uv_by_axis_x(map, resizable_flip_node, degree);
1370              evas_map_util_3d_rotate(map, degree, 0,
1371                                      0, x + half_w, y + half_h, 0);
1372           }
1373
1374         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1375         evas_object_map_enable_set(resizable_flip_node->front, EINA_TRUE);
1376         evas_object_map_enable_set(resizable_flip_node->back, EINA_TRUE);
1377         evas_object_map_set(obj, map);
1378      }
1379    evas_map_free(map);
1380 }
1381
1382 static Elm_Transit_Effect *
1383 _transit_effect_resizable_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1384 {
1385    Elm_Transit_Effect_ResizableFlip *resizable_flip;
1386
1387    resizable_flip = ELM_NEW(Elm_Transit_Effect_ResizableFlip);
1388    if (!resizable_flip) return NULL;
1389
1390    resizable_flip->cw = cw;
1391    resizable_flip->axis = axis;
1392
1393    return resizable_flip;
1394 }
1395
1396 EAPI Elm_Transit_Effect *
1397 elm_transit_effect_resizable_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1398 {
1399    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1400    Elm_Transit_Effect *effect_context = _transit_effect_resizable_flip_context_new(axis, cw);
1401
1402    if (!effect_context)
1403      {
1404         ERR("Failed to allocate resizable_flip effect! : transit=%p", transit);
1405         return NULL;
1406      }
1407    elm_transit_effect_add(transit,
1408                           _transit_effect_resizable_flip_op, effect_context,
1409                           _transit_effect_resizable_flip_context_free);
1410    return effect_context;
1411 }
1412
1413
1414 ///////////////////////////////////////////////////////////////////////////////
1415 //Wipe Effect
1416 ///////////////////////////////////////////////////////////////////////////////
1417 typedef struct _Elm_Transit_Effect_Wipe Elm_Transit_Effect_Wipe;
1418
1419 struct _Elm_Transit_Effect_Wipe
1420 {
1421    Elm_Transit_Effect_Wipe_Type type;
1422    Elm_Transit_Effect_Wipe_Dir dir;
1423 };
1424
1425 static void
1426 _elm_fx_wipe_hide(Evas_Map * map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1427 {
1428    float w2, h2;
1429
1430    switch (dir)
1431      {
1432       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1433          w2 = w - (w * progress);
1434          h2 = (y + h);
1435          evas_map_point_image_uv_set(map, 0, 0, 0);
1436          evas_map_point_image_uv_set(map, 1, w2, 0);
1437          evas_map_point_image_uv_set(map, 2, w2, h);
1438          evas_map_point_image_uv_set(map, 3, 0, h);
1439          evas_map_point_coord_set(map, 0, x, y, 0);
1440          evas_map_point_coord_set(map, 1, x + w2, y, 0);
1441          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
1442          evas_map_point_coord_set(map, 3, x, h2, 0);
1443          break;
1444       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
1445          w2 = (w * progress);
1446          h2 = (y + h);
1447          evas_map_point_image_uv_set(map, 0, w2, 0);
1448          evas_map_point_image_uv_set(map, 1, w, 0);
1449          evas_map_point_image_uv_set(map, 2, w, h);
1450          evas_map_point_image_uv_set(map, 3, w2, h);
1451          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1452          evas_map_point_coord_set(map, 1, x + w, y, 0);
1453          evas_map_point_coord_set(map, 2, x + w, h2, 0);
1454          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1455          break;
1456       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
1457          w2 = (x + w);
1458          h2 = h - (h * progress);
1459          evas_map_point_image_uv_set(map, 0, 0, 0);
1460          evas_map_point_image_uv_set(map, 1, w, 0);
1461          evas_map_point_image_uv_set(map, 2, w, h2);
1462          evas_map_point_image_uv_set(map, 3, 0, h2);
1463          evas_map_point_coord_set(map, 0, x, y, 0);
1464          evas_map_point_coord_set(map, 1, w2, y, 0);
1465          evas_map_point_coord_set(map, 2, w2, y+h2, 0);
1466          evas_map_point_coord_set(map, 3, x, y+h2, 0);
1467          break;
1468       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
1469          w2 = (x + w);
1470          h2 = (h * progress);
1471          evas_map_point_image_uv_set(map, 0, 0, h2);
1472          evas_map_point_image_uv_set(map, 1, w, h2);
1473          evas_map_point_image_uv_set(map, 2, w, h);
1474          evas_map_point_image_uv_set(map, 3, 0, h);
1475          evas_map_point_coord_set(map, 0, x, y + h2, 0);
1476          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
1477          evas_map_point_coord_set(map, 2, w2, y + h, 0);
1478          evas_map_point_coord_set(map, 3, x, y + h, 0);
1479          break;
1480       default:
1481          break;
1482      }
1483    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1484 }
1485
1486 static void
1487 _elm_fx_wipe_show(Evas_Map *map, Elm_Transit_Effect_Wipe_Dir dir, float x, float y, float w, float h, float progress)
1488 {
1489    float w2, h2;
1490
1491    switch (dir)
1492      {
1493       case ELM_TRANSIT_EFFECT_WIPE_DIR_LEFT:
1494          w2 = (w - (w * progress));
1495          h2 = (y + h);
1496          evas_map_point_image_uv_set(map, 0, w2, 0);
1497          evas_map_point_image_uv_set(map, 1, w, 0);
1498          evas_map_point_image_uv_set(map, 2, w, h);
1499          evas_map_point_image_uv_set(map, 3, w2, h);
1500          evas_map_point_coord_set(map, 0, x + w2, y, 0);
1501          evas_map_point_coord_set(map, 1, w, y, 0);
1502          evas_map_point_coord_set(map, 2, w, h2, 0);
1503          evas_map_point_coord_set(map, 3, x + w2, h2, 0);
1504          break;
1505       case ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT:
1506          w2 = (w * progress);
1507          h2 = (y + h);
1508          evas_map_point_image_uv_set(map, 0, 0, 0);
1509          evas_map_point_image_uv_set(map, 1, w2, 0);
1510          evas_map_point_image_uv_set(map, 2, w2, h);
1511          evas_map_point_image_uv_set(map, 3, 0, h);
1512          evas_map_point_coord_set(map, 0, x, y, 0);
1513          evas_map_point_coord_set(map, 1, x + w2, y, 0);
1514          evas_map_point_coord_set(map, 2, x + w2, h2, 0);
1515          evas_map_point_coord_set(map, 3, x, h2, 0);
1516          break;
1517       case ELM_TRANSIT_EFFECT_WIPE_DIR_UP:
1518          w2 = (x + w);
1519          h2 = (h - (h * progress));
1520          evas_map_point_image_uv_set(map, 0, 0, h2);
1521          evas_map_point_image_uv_set(map, 1, w, h2);
1522          evas_map_point_image_uv_set(map, 2, w, h);
1523          evas_map_point_image_uv_set(map, 3, 0, h);
1524          evas_map_point_coord_set(map, 0, x, y + h2, 0);
1525          evas_map_point_coord_set(map, 1, w2, y + h2, 0);
1526          evas_map_point_coord_set(map, 2, w2, y + h, 0);
1527          evas_map_point_coord_set(map, 3, x, y + h, 0);
1528          break;
1529       case ELM_TRANSIT_EFFECT_WIPE_DIR_DOWN:
1530          w2 = (x + w);
1531          h2 = (h * progress);
1532          evas_map_point_image_uv_set(map, 0, 0, 0);
1533          evas_map_point_image_uv_set(map, 1, w, 0);
1534          evas_map_point_image_uv_set(map, 2, w, h2);
1535          evas_map_point_image_uv_set(map, 3, 0, h2);
1536          evas_map_point_coord_set(map, 0, x, y, 0);
1537          evas_map_point_coord_set(map, 1, w2, y, 0);
1538          evas_map_point_coord_set(map, 2, w2, y + h2, 0);
1539          evas_map_point_coord_set(map, 3, x, y + h2, 0);
1540          break;
1541       default:
1542          break;
1543      }
1544    evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
1545 }
1546
1547 static void
1548 _transit_effect_wipe_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
1549 {
1550    EINA_SAFETY_ON_NULL_RETURN(effect);
1551    EINA_SAFETY_ON_NULL_RETURN(transit);
1552    Eina_List *elist;
1553    Evas_Object *obj;
1554    Elm_Transit_Effect_Wipe *wipe = effect;
1555    Eina_Bool reverse = elm_transit_auto_reverse_get(transit);
1556
1557    EINA_LIST_FOREACH(transit->objs, elist, obj)
1558      {
1559         if ((wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW && !reverse)
1560             || (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE && reverse))
1561           evas_object_show(obj);
1562         else evas_object_hide(obj);
1563         evas_object_map_enable_set(obj, EINA_FALSE);
1564      }
1565
1566    free(wipe);
1567 }
1568
1569 static void
1570 _transit_effect_wipe_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1571 {
1572    EINA_SAFETY_ON_NULL_RETURN(effect);
1573    EINA_SAFETY_ON_NULL_RETURN(transit);
1574    Elm_Transit_Effect_Wipe *wipe = effect;
1575    Evas_Map *map;
1576    Evas_Coord _x, _y, _w, _h;
1577    Eina_List *elist;
1578    Evas_Object *obj;
1579
1580    map = evas_map_new(4);
1581    if (!map) return;
1582
1583    EINA_LIST_FOREACH(transit->objs, elist, obj)
1584      {
1585         evas_object_geometry_get(obj, &_x, &_y, &_w, &_h);
1586
1587         if (wipe->type == ELM_TRANSIT_EFFECT_WIPE_TYPE_SHOW)
1588           _elm_fx_wipe_show(map, wipe->dir, _x, _y, _w, _h, (float)progress);
1589         else
1590           _elm_fx_wipe_hide(map, wipe->dir, _x, _y, _w, _h, (float)progress);
1591
1592         evas_object_map_enable_set(obj, EINA_TRUE);
1593         evas_object_map_set(obj, map);
1594      }
1595    evas_map_free(map);
1596 }
1597
1598 static Elm_Transit_Effect *
1599 _transit_effect_wipe_context_new(Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
1600 {
1601    Elm_Transit_Effect_Wipe *wipe;
1602
1603    wipe = ELM_NEW(Elm_Transit_Effect_Wipe);
1604    if (!wipe) return NULL;
1605
1606    wipe->type = type;
1607    wipe->dir = dir;
1608
1609    return wipe;
1610 }
1611
1612 EAPI void *
1613 elm_transit_effect_wipe_add(Elm_Transit *transit, Elm_Transit_Effect_Wipe_Type type, Elm_Transit_Effect_Wipe_Dir dir)
1614 {
1615    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1616    void *effect_context = _transit_effect_wipe_context_new(type, dir);
1617
1618    if (!effect_context)
1619      {
1620         ERR("Failed to allocate wipe effect! : transit=%p", transit);
1621         return NULL;
1622      }
1623    elm_transit_effect_add(transit,
1624                           _transit_effect_wipe_op, effect_context,
1625                           _transit_effect_wipe_context_free);
1626    return effect_context;
1627 }
1628
1629
1630 ///////////////////////////////////////////////////////////////////////////////
1631 //Color Effect
1632 ///////////////////////////////////////////////////////////////////////////////
1633 typedef struct _Elm_Transit_Effect_Color Elm_Transit_Effect_Color;
1634
1635 struct _Elm_Transit_Effect_Color
1636 {
1637    struct _unsigned_color {
1638       unsigned int r, g, b, a;
1639    } from;
1640    struct _signed_color {
1641       int r, g, b, a;
1642    } to;
1643 };
1644
1645 static void
1646 _transit_effect_color_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1647 {
1648    Elm_Transit_Effect_Color *color = effect;
1649    free(color);
1650 }
1651
1652 static void
1653 _transit_effect_color_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1654 {
1655    EINA_SAFETY_ON_NULL_RETURN(effect);
1656    EINA_SAFETY_ON_NULL_RETURN(transit);
1657    Elm_Transit_Effect_Color *color = effect;
1658    Evas_Object *obj;
1659    Eina_List *elist;
1660    unsigned int r, g, b, a;
1661
1662    r = (color->from.r + (int)((float)color->to.r * progress));
1663    g = (color->from.g + (int)((float)color->to.g * progress));
1664    b = (color->from.b + (int)((float)color->to.b * progress));
1665    a = (color->from.a + (int)((float)color->to.a * progress));
1666
1667    EINA_LIST_FOREACH(transit->objs, elist, obj)
1668      evas_object_color_set(obj, r, g, b, a);
1669 }
1670
1671 static Elm_Transit_Effect *
1672 _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)
1673 {
1674    Elm_Transit_Effect_Color *color;
1675
1676    color = ELM_NEW(Elm_Transit_Effect_Color);
1677    if (!color) return NULL;
1678
1679    color->from.r = from_r;
1680    color->from.g = from_g;
1681    color->from.b = from_b;
1682    color->from.a = from_a;
1683    color->to.r = to_r - from_r;
1684    color->to.g = to_g - from_g;
1685    color->to.b = to_b - from_b;
1686    color->to.a = to_a - from_a;
1687
1688    return color;
1689 }
1690
1691 EAPI Elm_Transit_Effect *
1692 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)
1693 {
1694    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1695    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);
1696
1697    if (!effect_context)
1698      {
1699         ERR("Failed to allocate color effect! : transit=%p", transit);
1700         return NULL;
1701      }
1702    elm_transit_effect_add(transit,
1703                           _transit_effect_color_op, effect_context,
1704                           _transit_effect_color_context_free);
1705    return effect_context;
1706 }
1707
1708 ///////////////////////////////////////////////////////////////////////////////
1709 //Fade Effect
1710 ///////////////////////////////////////////////////////////////////////////////
1711 typedef struct _Elm_Transit_Effect_Fade Elm_Transit_Effect_Fade;
1712 typedef struct _Elm_Transit_Effect_Fade_Node Elm_Transit_Effect_Fade_Node;
1713
1714 struct _Elm_Transit_Effect_Fade_Node
1715 {
1716    Evas_Object *before;
1717    Evas_Object *after;
1718    struct _signed_color before_color, after_color;
1719    int before_alpha;
1720    int after_alpha;
1721    Eina_Bool inversed : 1;
1722 };
1723
1724 struct _Elm_Transit_Effect_Fade
1725 {
1726    Eina_List *nodes;
1727 };
1728
1729 static void
1730 _fade_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1731 {
1732    Elm_Transit_Effect_Fade *fade = data;
1733    Eina_List *elist;
1734    Elm_Transit_Effect_Fade_Node *fade_node;
1735
1736    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1737      {
1738         if (fade_node->before == obj)
1739           evas_object_event_callback_del(fade_node->after,
1740                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1741         else if (fade_node->after == obj)
1742           evas_object_event_callback_del(fade_node->before,
1743                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1744         else continue;
1745
1746         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1747         free(fade_node);
1748         break;
1749      }
1750 }
1751
1752 static Eina_List *
1753 _fade_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Fade *fade_data)
1754 {
1755    Elm_Transit_Effect_Fade_Node *fade;
1756    Eina_List *data_list = NULL;
1757    int i, count;
1758
1759    count = eina_list_count(transit->objs);
1760    for (i = 0; i < count; i += 2)
1761      {
1762         fade = ELM_NEW(Elm_Transit_Effect_Fade_Node);
1763         if (!fade)
1764           {
1765              eina_list_free(data_list);
1766              return NULL;
1767           }
1768
1769         fade->before = eina_list_nth(transit->objs, i);
1770         fade->after = eina_list_nth(transit->objs, i+1);
1771
1772         evas_object_color_get(fade->before,
1773                               &fade->before_color.r, &fade->before_color.g,
1774                               &fade->before_color.b, &fade->before_color.a);
1775         evas_object_color_get(fade->after,
1776                               &fade->after_color.r, &fade->after_color.g,
1777                               &fade->after_color.b, &fade->after_color.a);
1778
1779         fade->before_alpha = (255 - fade->before_color.a);
1780         fade->after_alpha = (255 - fade->after_color.a);
1781
1782         data_list = eina_list_append(data_list, fade);
1783
1784         evas_object_event_callback_add(fade->before,
1785                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1786         evas_object_event_callback_add(fade->after,
1787                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1788      }
1789    return data_list;
1790 }
1791
1792 static void
1793 _transit_effect_fade_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1794 {
1795    EINA_SAFETY_ON_NULL_RETURN(effect);
1796    Elm_Transit_Effect_Fade *fade = effect;
1797    Elm_Transit_Effect_Fade_Node *fade_node;
1798    Eina_List *elist, *elist_next;
1799
1800    EINA_LIST_FOREACH_SAFE(fade->nodes, elist, elist_next, fade_node)
1801      {
1802         evas_object_color_set(fade_node->before, fade_node->before_color.r,
1803                               fade_node->before_color.g,
1804                               fade_node->before_color.b,
1805                               fade_node->before_color.a);
1806         evas_object_color_set(fade_node->after, fade_node->after_color.r,
1807                               fade_node->after_color.g,
1808                               fade_node->after_color.b,
1809                               fade_node->after_color.a);
1810
1811         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1812         evas_object_event_callback_del(fade_node->before,
1813                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1814         evas_object_event_callback_del(fade_node->after,
1815                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1816         free(fade_node);
1817      }
1818
1819    free(fade);
1820 }
1821
1822 static void
1823 _transit_effect_fade_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1824 {
1825    EINA_SAFETY_ON_NULL_RETURN(effect);
1826    Elm_Transit_Effect_Fade *fade = effect;
1827    Eina_List *elist;
1828    Elm_Transit_Effect_Fade_Node *fade_node;
1829    float _progress;
1830
1831    if (!fade->nodes)
1832      fade->nodes = _fade_nodes_build(transit, fade);
1833
1834    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1835      {
1836         if (progress < 0.5)
1837           {
1838              if (!fade_node->inversed)
1839                {
1840                   evas_object_hide(fade_node->after);
1841                   evas_object_show(fade_node->before);
1842                   fade_node->inversed = EINA_TRUE;
1843                }
1844
1845              _progress = (1 - (progress * 2));
1846
1847              evas_object_color_set(fade_node->before,
1848                                    fade_node->before_color.r * _progress,
1849                                    fade_node->before_color.g * _progress,
1850                                    fade_node->before_color.b * _progress,
1851                                    fade_node->before_color.a +
1852                                    fade_node->before_alpha * (1 - _progress));
1853           }
1854         else
1855           {
1856              if (fade_node->inversed)
1857                {
1858                   evas_object_hide(fade_node->before);
1859                   evas_object_show(fade_node->after);
1860                   fade_node->inversed = EINA_FALSE;
1861                }
1862
1863              _progress = ((progress - 0.5) * 2);
1864
1865              evas_object_color_set(fade_node->after,
1866                                    fade_node->after_color.r * _progress,
1867                                    fade_node->after_color.g * _progress,
1868                                    fade_node->after_color.b * _progress,
1869                                    fade_node->after_color.a +
1870                                    fade_node->after_alpha * (1 - _progress));
1871           }
1872      }
1873 }
1874
1875 static Elm_Transit_Effect *
1876 _transit_effect_fade_context_new(void)
1877 {
1878    Elm_Transit_Effect_Fade *fade;
1879    fade = ELM_NEW(Elm_Transit_Effect_Fade);
1880    if (!fade) return NULL;
1881    return fade;
1882 }
1883
1884 EAPI Elm_Transit_Effect *
1885 elm_transit_effect_fade_add(Elm_Transit *transit)
1886 {
1887    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1888
1889    Elm_Transit_Effect *effect_context = _transit_effect_fade_context_new();
1890
1891    if (!effect_context)
1892      {
1893         ERR("Failed to allocate fade effect! : transit=%p", transit);
1894         return NULL;
1895      }
1896    elm_transit_effect_add(transit,
1897                           _transit_effect_fade_op, effect_context,
1898                           _transit_effect_fade_context_free);
1899    return effect_context;
1900 }
1901
1902
1903 ///////////////////////////////////////////////////////////////////////////////
1904 //Blend Effect
1905 ///////////////////////////////////////////////////////////////////////////////
1906 typedef struct _Elm_Transit_Effect_Blend Elm_Transit_Effect_Blend;
1907 typedef struct _Elm_Transit_Effect_Blend_Node Elm_Transit_Effect_Blend_Node;
1908
1909 struct _Elm_Transit_Effect_Blend_Node
1910 {
1911    Evas_Object *before;
1912    Evas_Object *after;
1913    struct _signed_color from, to;
1914 };
1915
1916 struct _Elm_Transit_Effect_Blend
1917 {
1918    Eina_List *nodes;
1919 };
1920
1921 static void
1922 _blend_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1923 {
1924    Elm_Transit_Effect_Blend *blend = data;
1925    Eina_List *elist;
1926    Elm_Transit_Effect_Blend_Node *blend_node;
1927
1928    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
1929      {
1930         if (blend_node->after == obj)
1931           evas_object_event_callback_del(blend_node->before,
1932                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1933         else if (blend_node->before == obj)
1934           evas_object_event_callback_del(blend_node->after,
1935                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1936         else continue;
1937
1938         blend->nodes = eina_list_remove_list(blend->nodes, elist);
1939         free(blend_node);
1940         break;
1941      }
1942 }
1943
1944 static Eina_List *
1945 _blend_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Blend *blend)
1946 {
1947    Elm_Transit_Effect_Blend_Node *blend_node;
1948    Eina_List *data_list = NULL;
1949    int i, count;
1950
1951    count = eina_list_count(transit->objs);
1952    for (i = 0; i < (count - 1); i += 2)
1953      {
1954         blend_node = ELM_NEW(Elm_Transit_Effect_Blend_Node);
1955         if (!blend_node)
1956           {
1957              eina_list_free(data_list);
1958              return NULL;
1959           }
1960
1961         blend_node->before = eina_list_nth(transit->objs, i);
1962         blend_node->after = eina_list_nth(transit->objs, i + 1);
1963         evas_object_show(blend_node->before);
1964         evas_object_show(blend_node->after);
1965
1966         evas_object_color_get(blend_node->before, &blend_node->from.r,
1967                               &blend_node->from.g, &blend_node->from.b,
1968                               &blend_node->from.a);
1969         evas_object_color_get(blend_node->after, &blend_node->to.r,
1970                               &blend_node->to.g, &blend_node->to.b,
1971                               &blend_node->to.a);
1972
1973         data_list = eina_list_append(data_list, blend_node);
1974
1975         evas_object_event_callback_add(blend_node->before,
1976                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1977         evas_object_event_callback_add(blend_node->after,
1978                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1979      }
1980    return data_list;
1981 }
1982
1983 void
1984 _transit_effect_blend_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1985 {
1986    EINA_SAFETY_ON_NULL_RETURN(effect);
1987    Elm_Transit_Effect_Blend *blend = effect;
1988    Elm_Transit_Effect_Blend_Node *blend_node;
1989    Eina_List *elist, *elist_next;
1990
1991    EINA_LIST_FOREACH_SAFE(blend->nodes, elist, elist_next, blend_node)
1992      {
1993         evas_object_color_set(blend_node->before,
1994                               blend_node->from.r, blend_node->from.g,
1995                               blend_node->from.b, blend_node->from.a);
1996         evas_object_color_set(blend_node->after, blend_node->to.r,
1997                               blend_node->to.g, blend_node->to.b,
1998                               blend_node->to.a);
1999
2000         if (elm_transit_auto_reverse_get(transit))
2001           evas_object_hide(blend_node->after);
2002         else
2003           evas_object_hide(blend_node->before);
2004
2005         blend->nodes = eina_list_remove_list(blend->nodes, elist);
2006
2007         evas_object_event_callback_del(blend_node->before,
2008                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2009         evas_object_event_callback_del(blend_node->after,
2010                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
2011         free(blend_node);
2012      }
2013    free(blend);
2014 }
2015
2016 void
2017 _transit_effect_blend_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2018 {
2019    EINA_SAFETY_ON_NULL_RETURN(effect);
2020    EINA_SAFETY_ON_NULL_RETURN(transit);
2021    Elm_Transit_Effect_Blend *blend = effect;
2022    Elm_Transit_Effect_Blend_Node *blend_node;
2023    Eina_List *elist;
2024
2025    if (!blend->nodes) blend->nodes = _blend_nodes_build(transit, blend);
2026
2027    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
2028      {
2029         evas_object_color_set(blend_node->before,
2030                               (int)(blend_node->from.r * (1 - progress)),
2031                               (int)(blend_node->from.g * (1 - progress)),
2032                               (int)(blend_node->from.b * (1 - progress)),
2033                               (int)(blend_node->from.a * (1 - progress)));
2034         evas_object_color_set(blend_node->after,
2035                               (int)(blend_node->to.r * progress),
2036                               (int)(blend_node->to.g * progress),
2037                               (int)(blend_node->to.b * progress),
2038                               (int)(blend_node->to.a * progress));
2039      }
2040 }
2041
2042 static Elm_Transit_Effect *
2043 _transit_effect_blend_context_new(void)
2044 {
2045    Elm_Transit_Effect_Blend *blend;
2046
2047    blend = ELM_NEW(Elm_Transit_Effect_Blend);
2048    if (!blend) return NULL;
2049    return blend;
2050 }
2051
2052 EAPI Elm_Transit_Effect *
2053 elm_transit_effect_blend_add(Elm_Transit *transit)
2054 {
2055    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2056    Elm_Transit_Effect *effect_context = _transit_effect_blend_context_new();
2057
2058    if (!effect_context) return NULL;
2059    elm_transit_effect_add(transit,
2060                           _transit_effect_blend_op, effect_context,
2061                           _transit_effect_blend_context_free);
2062    return effect_context;
2063 }
2064
2065
2066 ///////////////////////////////////////////////////////////////////////////////
2067 //Rotation Effect
2068 ///////////////////////////////////////////////////////////////////////////////
2069 typedef struct _Elm_Transit_Effect_Rotation Elm_Transit_Effect_Rotation;
2070
2071 struct _Elm_Transit_Effect_Rotation
2072 {
2073    float from, to;
2074 };
2075
2076 static void
2077 _transit_effect_rotation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2078 {
2079    Elm_Transit_Effect_Rotation *rotation = effect;
2080    free(rotation);
2081 }
2082
2083 static void
2084 _transit_effect_rotation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2085 {
2086    EINA_SAFETY_ON_NULL_RETURN(effect);
2087    EINA_SAFETY_ON_NULL_RETURN(transit);
2088    Elm_Transit_Effect_Rotation *rotation = effect;
2089    Evas_Map *map;
2090    Evas_Coord x, y, w, h;
2091    float degree;
2092    float half_w, half_h;
2093    Eina_List *elist;
2094    Evas_Object *obj;
2095
2096    map = evas_map_new(4);
2097    if (!map) return;
2098
2099    EINA_LIST_FOREACH(transit->objs, elist, obj)
2100      {
2101         evas_map_util_points_populate_from_object_full(map, obj, 0);
2102         degree = rotation->from + (float)(progress * rotation->to);
2103
2104         evas_object_geometry_get(obj, &x, &y, &w, &h);
2105
2106         half_w = (float)w * 0.5;
2107         half_h = (float)h * 0.5;
2108
2109         evas_map_util_rotate(map, degree, x + half_w, y + half_h);
2110         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
2111         evas_object_map_enable_set(obj, EINA_TRUE);
2112         evas_object_map_set(obj, map);
2113      }
2114    evas_map_free(map);
2115 }
2116
2117 static Elm_Transit_Effect *
2118 _transit_effect_rotation_context_new(float from_degree, float to_degree)
2119 {
2120    Elm_Transit_Effect_Rotation *rotation;
2121
2122    rotation = ELM_NEW(Elm_Transit_Effect_Rotation);
2123    if (!rotation) return NULL;
2124
2125    rotation->from = from_degree;
2126    rotation->to = to_degree - from_degree;
2127
2128    return rotation;
2129 }
2130
2131 EAPI Elm_Transit_Effect *
2132 elm_transit_effect_rotation_add(Elm_Transit *transit, float from_degree, float to_degree)
2133 {
2134    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2135    Elm_Transit_Effect *effect_context = _transit_effect_rotation_context_new(from_degree, to_degree);
2136
2137    if (!effect_context) return NULL;
2138    elm_transit_effect_add(transit,
2139                           _transit_effect_rotation_op, effect_context,
2140                           _transit_effect_rotation_context_free);
2141    return effect_context;
2142 }
2143
2144
2145 ///////////////////////////////////////////////////////////////////////////////
2146 //ImageAnimation Effect
2147 ///////////////////////////////////////////////////////////////////////////////
2148 typedef struct _Elm_Transit_Effect_Image_Animation Elm_Transit_Effect_Image_Animation;
2149
2150 struct _Elm_Transit_Effect_Image_Animation
2151 {
2152    Eina_List *images;
2153 };
2154
2155 static void
2156 _transit_effect_image_animation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2157 {
2158    EINA_SAFETY_ON_NULL_RETURN(effect);
2159    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2160    const char *image;
2161    Eina_List *elist, *elist_next;
2162
2163    EINA_LIST_FOREACH_SAFE(image_animation->images, elist, elist_next, image)
2164      {
2165         image_animation->images =
2166            eina_list_remove_list(image_animation->images, elist);
2167         eina_stringshare_del(image);
2168      }
2169
2170    free(image_animation);
2171 }
2172
2173 static void
2174 _transit_effect_image_animation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2175 {
2176    EINA_SAFETY_ON_NULL_RETURN(effect);
2177    EINA_SAFETY_ON_NULL_RETURN(transit);
2178    Eina_List *elist;
2179    Evas_Object *obj;
2180    const char *type;
2181    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2182    unsigned int count = 0;
2183    int len;
2184
2185    type = eina_stringshare_add("icon");
2186    len = eina_list_count(image_animation->images);
2187
2188    if (!len) count = floor(progress * len);
2189    else count = floor(progress * (len - 1));
2190
2191    EINA_LIST_FOREACH(transit->objs, elist, obj)
2192      {
2193         if (elm_widget_type_check(obj, type))
2194           elm_icon_file_set(obj,
2195                             eina_list_nth(image_animation->images, count), NULL);
2196      }
2197
2198    eina_stringshare_del(type);
2199 }
2200
2201 static Elm_Transit_Effect *
2202 _transit_effect_image_animation_context_new(Eina_List *images)
2203 {
2204    Elm_Transit_Effect_Image_Animation *image_animation;
2205    image_animation = ELM_NEW(Elm_Transit_Effect_Image_Animation);
2206
2207    if (!image_animation) return NULL;
2208    image_animation->images = images;
2209    return image_animation;
2210 }
2211
2212 EAPI Elm_Transit_Effect *
2213 elm_transit_effect_image_animation_add(Elm_Transit *transit, Eina_List *images)
2214 {
2215    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2216    Elm_Transit_Effect *effect = _transit_effect_image_animation_context_new(images);
2217
2218    if (!effect)
2219      {
2220         ERR("Failed to allocate image_animation effect! : transit=%p", transit);
2221         return NULL;
2222      }
2223    elm_transit_effect_add(transit,
2224                           _transit_effect_image_animation_op, effect,
2225                           _transit_effect_image_animation_context_free);
2226    return effect;
2227 }