67edf8beba4aa63e5440f8ddae4e46cec560e08b
[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 _elm_transit_obj_data_update(Elm_Transit *transit, Evas_Object *obj);
88 static void _elm_transit_obj_data_recover(Elm_Transit *transit, Evas_Object *obj);
89 static void _elm_transit_obj_states_save(Evas_Object *obj, Elm_Transit_Obj_Data *obj_data);
90 static void _elm_transit_obj_remove_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
91 static void _obj_damage_area_set(Evas_Object *obj);
92 static void _elm_transit_obj_remove(Elm_Transit *transit, Evas_Object *obj);
93 static void _elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Module *effect_module);
94 static void _remove_dead_effects(Elm_Transit *transit);
95 static void _elm_transit_del(Elm_Transit *transit);
96 static void _chain_transits_go(Elm_Transit *transit);
97 static void _transit_animate_op(Elm_Transit *transit, double progress);
98 static Eina_Bool _animator_animate_cb(void *data);
99
100 static char *_transit_key= "_elm_transit_key";
101
102 static void
103 _elm_transit_obj_data_update(Elm_Transit *transit, Evas_Object *obj)
104 {
105    Elm_Transit_Obj_Data *obj_data = evas_object_data_get(obj, _transit_key);
106
107    if (!obj_data)
108      obj_data = ELM_NEW(Elm_Transit_Obj_Data);
109
110    obj_data->pass_events = evas_object_pass_events_get(obj);
111
112    if ((!transit->state_keep) && (obj_data->state))
113      {
114         free(obj_data->state);
115         obj_data->state = NULL;
116      }
117    else
118      {
119        _elm_transit_obj_states_save(obj, obj_data);
120      }
121
122    evas_object_data_set(obj, _transit_key, obj_data);
123 }
124
125 static void
126 _elm_transit_obj_states_save(Evas_Object *obj, Elm_Transit_Obj_Data *obj_data)
127 {
128    Elm_Transit_Obj_State *state = obj_data->state;
129
130    if (!state)
131      state = calloc(1, sizeof(Elm_Transit_Obj_State));
132    if (!state) return;
133
134    evas_object_geometry_get(obj, &state->x, &state->y, &state->w, &state->h);
135    evas_object_color_get(obj, &state->r, &state->g, &state->b, &state->a);
136    state->visible = evas_object_visible_get(obj);
137    state->map_enabled = evas_object_map_enable_get(obj);
138    if (evas_object_map_get(obj))
139      state->map = evas_map_dup(evas_object_map_get(obj));
140    obj_data->state = state;
141 }
142
143 static void
144 _remove_obj_from_list(Elm_Transit *transit, Evas_Object *obj)
145 {
146    //Remove duplicated objects
147    //TODO: Need to consider about optimizing here
148    while(1)
149      {
150         if (!eina_list_data_find_list(transit->objs, obj))
151           break;
152         transit->objs = eina_list_remove(transit->objs, obj);
153         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
154                                        _elm_transit_obj_remove_cb,
155                                        transit);
156      }
157 }
158
159 static void
160 _elm_transit_obj_remove_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
161 {
162    Elm_Transit *transit = data;
163    Elm_Transit_Obj_Data *obj_data = evas_object_data_get(obj, _transit_key);
164    if (obj_data)
165      {
166         if (obj_data->state)
167           free(obj_data->state);
168         free(obj_data);
169      }
170    _remove_obj_from_list(transit, obj);
171    if (!transit->objs) elm_transit_del(transit);
172 }
173
174 //TODO: Remove!
175 //Since evas map have a afterimage bug for this time.
176 //This function is added temporary.
177 static void
178 _obj_damage_area_set(Evas_Object *obj)
179 {
180    const Evas_Map *map;
181    Evas_Coord_Point coords;
182    Evas_Coord_Point min, max;
183    int i;
184
185    map  = evas_object_map_get(obj);
186    if (!map) return;
187
188    evas_map_point_coord_get(map, 0, &coords.x, &coords.y, NULL);
189
190    max = min = coords;
191
192    for (i = 1; i < 4; ++i)
193      {
194         evas_map_point_coord_get(map, i, &coords.x, &coords.y, NULL);
195
196         if (coords.x < min.x)
197           min.x = coords.x;
198         else if (coords.x > max.x)
199           max.x = coords.x;
200
201         if (coords.y < min.y)
202           min.y = coords.y;
203         else if (coords.y > max.y)
204           max.y = coords.y;
205      }
206
207    evas_damage_rectangle_add(evas_object_evas_get(obj),
208                              min.x, min.y,
209                              max.x - min.x, max.y - min.y);
210 }
211
212 static void
213 _elm_transit_obj_data_recover(Elm_Transit *transit, Evas_Object *obj)
214 {
215    Elm_Transit_Obj_Data *obj_data;
216    Elm_Transit_Obj_State *state;
217
218    obj_data = evas_object_data_get(obj, _transit_key);
219    if (!obj_data) return;
220    evas_object_data_del(obj, _transit_key);
221    evas_object_pass_events_set(obj, obj_data->pass_events);
222    state = obj_data->state;
223    if (state)
224      {
225         //recover the states of the object.
226         if (!transit->state_keep)
227           {
228              evas_object_move(obj, state->x, state->y);
229              evas_object_resize(obj, state->w, state->h);
230              evas_object_color_set(obj, state->r, state->g, state->b, state->a);
231              if (state->visible) evas_object_show(obj);
232              else evas_object_hide(obj);
233              if (state->map_enabled)
234                evas_object_map_enable_set(obj, EINA_TRUE);
235              else
236                evas_object_map_enable_set(obj, EINA_FALSE);
237              if (state->map)
238                evas_object_map_set(obj, state->map);
239
240              //TODO: Remove!
241              //Since evas map have a afterimage bug for this time.
242              //This line is added temporary.
243              _obj_damage_area_set(obj);
244
245           }
246         free(state);
247      }
248    free(obj_data);
249 }
250
251 static void
252 _elm_transit_obj_remove(Elm_Transit *transit, Evas_Object *obj)
253 {
254    _remove_obj_from_list(transit, obj);
255    _elm_transit_obj_data_recover(transit, obj);
256 }
257
258 static void
259 _elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Module *effect_module)
260 {
261    if (effect_module->end_cb)
262      effect_module->end_cb(effect_module->effect, transit);
263    free(effect_module);
264 }
265
266 static void
267 _remove_dead_effects(Elm_Transit *transit)
268 {
269    Elm_Transit_Effect_Module *effect_module;
270
271    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
272      {
273         if (effect_module->deleted)
274           {
275              _elm_transit_effect_del(transit, effect_module);
276              transit->effects_pending_del--;
277              if (!transit->effects_pending_del) return;
278           }
279      }
280 }
281
282 static void
283 _elm_transit_del(Elm_Transit *transit)
284 {
285    Elm_Transit_Effect_Module *effect_module;
286    Elm_Transit *chain_transit;
287    Eina_List *elist, *elist_next;
288
289    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
290      {
291         if (transit->prev_chain_transit)
292           transit->prev_chain_transit->next_chain_transits = eina_list_remove(transit->prev_chain_transit->next_chain_transits, transit);
293         chain_transit->prev_chain_transit = NULL;
294      }
295
296    eina_list_free(transit->next_chain_transits);
297
298    if (transit->animator)
299      ecore_animator_del(transit->animator);
300
301    while (transit->effect_list)
302      {
303         effect_module = EINA_INLIST_CONTAINER_GET(transit->effect_list, Elm_Transit_Effect_Module);
304         transit->effect_list = eina_inlist_remove(transit->effect_list, transit->effect_list);
305         _elm_transit_effect_del(transit, effect_module);
306      }
307
308    while (transit->objs)
309      _elm_transit_obj_remove(transit, eina_list_data_get(transit->objs));
310
311    transit->deleted = EINA_TRUE;
312
313    if (transit->del_data.func)
314      transit->del_data.func(transit->del_data.arg, transit);
315
316    EINA_MAGIC_SET(transit, EINA_MAGIC_NONE);
317    free(transit);
318 }
319
320 static void
321 _chain_transits_go(Elm_Transit *transit)
322 {
323    Eina_List *elist, *elist_next;
324    Elm_Transit *chain_transit;
325    Evas_Object *obj;
326
327    EINA_LIST_FOREACH(transit->objs, elist, obj)
328     _elm_transit_obj_data_recover(transit, obj);
329
330    EINA_LIST_FOREACH_SAFE(transit->next_chain_transits, elist, elist_next, chain_transit)
331      elm_transit_go(chain_transit);
332 }
333
334 static void
335 _transit_animate_op(Elm_Transit *transit, double progress)
336 {
337    Elm_Transit_Effect_Module *effect_module;
338
339    transit->walking++;
340    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
341      {
342         if (transit->deleted) break;
343         if (!effect_module->deleted)
344           effect_module->transition_cb(effect_module->effect, transit, progress);
345      }
346    transit->walking--;
347
348    if (transit->walking) return;
349
350    if (transit->deleted) _elm_transit_del(transit);
351    else if (transit->effects_pending_del) _remove_dead_effects(transit);
352 }
353
354 static Eina_Bool
355 _animator_animate_cb(void *data)
356 {
357    Elm_Transit *transit = data;
358    double elapsed_time, duration;
359
360    transit->time.current = ecore_loop_time_get();
361    elapsed_time = transit->time.current - transit->time.begin;
362    duration = transit->time.duration + transit->time.delayed;
363
364    if (elapsed_time > duration)
365      elapsed_time = duration;
366
367    transit->progress = elapsed_time / duration;
368    switch (transit->tween_mode)
369      {
370       case ELM_TRANSIT_TWEEN_MODE_ACCELERATE:
371         transit->progress = 1.0 - sin((ELM_PI / 2.0) + (transit->progress * ELM_PI / 2.0));
372         break;
373       case ELM_TRANSIT_TWEEN_MODE_DECELERATE:
374         transit->progress = sin(transit->progress * ELM_PI / 2.0);
375         break;
376       case ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL:
377         transit->progress = (1.0 - cos(transit->progress * ELM_PI)) / 2.0;
378         break;
379       default:
380         break;
381      }
382
383    /* Reverse? */
384    if (transit->repeat.reverse) transit->progress = 1 - transit->progress;
385
386    if (transit->time.duration > 0) _transit_animate_op(transit, transit->progress);
387
388    /* Not end. Keep going. */
389    if (elapsed_time < duration) return ECORE_CALLBACK_RENEW;
390
391    /* Repeat and reverse and time done! */
392    if ((transit->repeat.count >= 0) &&
393        (transit->repeat.current == transit->repeat.count) &&
394        ((!transit->auto_reverse) || transit->repeat.reverse))
395      {
396         /* run chain transit */
397         if (transit->next_chain_transits)
398           _chain_transits_go(transit);
399
400         elm_transit_del(transit);
401         return ECORE_CALLBACK_CANCEL;
402      }
403
404    /* Repeat Case */
405    if (!transit->auto_reverse || transit->repeat.reverse)
406      {
407         transit->repeat.current++;
408         transit->repeat.reverse = EINA_FALSE;
409      }
410    else transit->repeat.reverse = EINA_TRUE;
411
412    transit->time.begin = ecore_loop_time_get();
413
414    return ECORE_CALLBACK_RENEW;
415 }
416
417 EAPI Elm_Transit *
418 elm_transit_add(void)
419 {
420    Elm_Transit *transit = ELM_NEW(Elm_Transit);
421    if (!transit) return NULL;
422
423    EINA_MAGIC_SET(transit, ELM_TRANSIT_MAGIC);
424
425    elm_transit_tween_mode_set(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
426
427    return transit;
428 }
429
430 EAPI void
431 elm_transit_del(Elm_Transit *transit)
432 {
433    ELM_TRANSIT_CHECK_OR_RETURN(transit);
434
435    if (transit->walking) transit->deleted = EINA_TRUE;
436    else _elm_transit_del(transit);
437 }
438
439 EAPI void
440 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)
441 {
442    ELM_TRANSIT_CHECK_OR_RETURN(transit);
443    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
444    Elm_Transit_Effect_Module *effect_module;
445
446    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
447      if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect)) return;
448
449    effect_module = ELM_NEW(Elm_Transit_Effect_Module);
450    if (!effect_module) return;
451
452    effect_module->end_cb = end_cb;
453    effect_module->transition_cb = transition_cb;
454    effect_module->effect = effect;
455
456    transit->effect_list = eina_inlist_append(transit->effect_list, (Eina_Inlist*) effect_module);
457 }
458
459 EAPI void
460 elm_transit_effect_del(Elm_Transit *transit, Elm_Transit_Effect_Transition_Cb transition_cb, Elm_Transit_Effect *effect)
461 {
462    ELM_TRANSIT_CHECK_OR_RETURN(transit);
463    EINA_SAFETY_ON_NULL_RETURN(transition_cb);
464    Elm_Transit_Effect_Module *effect_module;
465
466    EINA_INLIST_FOREACH(transit->effect_list, effect_module)
467      {
468         if ((effect_module->transition_cb == transition_cb) && (effect_module->effect == effect))
469           {
470              if (transit->walking)
471                {
472                   effect_module->deleted = EINA_TRUE;
473                   transit->effects_pending_del++;
474                }
475              else
476                {
477                   _elm_transit_effect_del(transit, effect_module);
478                   if (!transit->effect_list) elm_transit_del(transit);
479                }
480              return;
481           }
482      }
483 }
484
485 EAPI void
486 elm_transit_object_add(Elm_Transit *transit, Evas_Object *obj)
487 {
488    ELM_TRANSIT_CHECK_OR_RETURN(transit);
489    EINA_SAFETY_ON_NULL_RETURN(obj);
490
491    if (transit->animator)
492      {
493         if (!evas_object_data_get(obj, _transit_key))
494           {
495              _elm_transit_obj_data_update(transit, obj);
496              evas_object_pass_events_set(obj, EINA_TRUE);
497           }
498      }
499
500    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
501                                   _elm_transit_obj_remove_cb,
502                                   transit);
503
504    transit->objs = eina_list_append(transit->objs, obj);
505 }
506
507 EAPI void
508 elm_transit_object_remove(Elm_Transit *transit, Evas_Object *obj)
509 {
510    ELM_TRANSIT_CHECK_OR_RETURN(transit);
511    EINA_SAFETY_ON_NULL_RETURN(obj);
512
513    _elm_transit_obj_remove(transit, obj);
514    if (!transit->objs) elm_transit_del(transit);
515 }
516
517 EAPI const Eina_List *
518 elm_transit_objects_get(const Elm_Transit *transit)
519 {
520    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
521    return transit->objs;
522 }
523
524 EAPI void
525 elm_transit_event_enabled_set(Elm_Transit *transit, Eina_Bool enabled)
526 {
527    ELM_TRANSIT_CHECK_OR_RETURN(transit);
528
529    Eina_List *list;
530    Evas_Object *obj;
531
532    if (transit->event_enabled == enabled) return;
533    transit->event_enabled = !!enabled;
534    if (!transit->animator) return;
535
536    EINA_LIST_FOREACH(transit->objs, list, obj)
537      evas_object_pass_events_set(obj, enabled);
538 }
539
540 EAPI Eina_Bool
541 elm_transit_event_enabled_get(const Elm_Transit *transit)
542 {
543    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
544    return transit->event_enabled;
545 }
546
547 EAPI void
548 elm_transit_del_cb_set(Elm_Transit *transit, void (*cb) (void *data, Elm_Transit *transit), void *data)
549 {
550    ELM_TRANSIT_CHECK_OR_RETURN(transit);
551    transit->del_data.func = cb;
552    transit->del_data.arg = data;
553 }
554
555 EAPI void
556 elm_transit_auto_reverse_set(Elm_Transit *transit, Eina_Bool reverse)
557 {
558    ELM_TRANSIT_CHECK_OR_RETURN(transit);
559    transit->auto_reverse = reverse;
560 }
561
562 EAPI Eina_Bool
563 elm_transit_auto_reverse_get(const Elm_Transit *transit)
564 {
565    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
566    return transit->auto_reverse;
567 }
568
569 EAPI void
570 elm_transit_repeat_times_set(Elm_Transit *transit, int repeat)
571 {
572    ELM_TRANSIT_CHECK_OR_RETURN(transit);
573    transit->repeat.count = repeat;
574    transit->repeat.current = 0;
575 }
576
577 EAPI int
578 elm_transit_repeat_times_get(const Elm_Transit *transit)
579 {
580    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
581    return transit->repeat.count;
582 }
583
584 EAPI void
585 elm_transit_tween_mode_set(Elm_Transit *transit, Elm_Transit_Tween_Mode tween_mode)
586 {
587    ELM_TRANSIT_CHECK_OR_RETURN(transit);
588    transit->tween_mode = tween_mode;
589 }
590
591 EAPI Elm_Transit_Tween_Mode
592 elm_transit_tween_mode_get(const Elm_Transit *transit)
593 {
594    ELM_TRANSIT_CHECK_OR_RETURN(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
595    return transit->tween_mode;
596 }
597
598 EAPI void
599 elm_transit_duration_set(Elm_Transit *transit, double duration)
600 {
601    ELM_TRANSIT_CHECK_OR_RETURN(transit);
602    if (transit->animator) return;
603    transit->time.duration = duration;
604 }
605
606 EAPI double
607 elm_transit_duration_get(const Elm_Transit *transit)
608 {
609    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0.0);
610    return transit->time.duration;
611 }
612
613 EAPI void
614 elm_transit_go(Elm_Transit *transit)
615 {
616    ELM_TRANSIT_CHECK_OR_RETURN(transit);
617
618    Eina_List *elist;
619    Evas_Object *obj;
620
621    if (transit->animator)
622      ecore_animator_del(transit->animator);
623
624    EINA_LIST_FOREACH(transit->objs, elist, obj)
625      _elm_transit_obj_data_update(transit, obj);
626
627    if (!transit->event_enabled)
628      {
629         EINA_LIST_FOREACH(transit->objs, elist, obj)
630           evas_object_pass_events_set(obj, EINA_TRUE);
631      }
632
633    transit->time.paused = 0;
634    transit->time.delayed = 0;
635    transit->time.begin = ecore_loop_time_get();
636    transit->animator = ecore_animator_add(_animator_animate_cb, transit);
637 }
638
639 EAPI void
640 elm_transit_paused_set(Elm_Transit *transit, Eina_Bool paused)
641 {
642    ELM_TRANSIT_CHECK_OR_RETURN(transit);
643
644    if (!transit->animator) return;
645
646    if (paused)
647      {
648         if (transit->time.paused > 0)
649           return;
650         ecore_animator_freeze(transit->animator);
651         transit->time.paused = ecore_loop_time_get();
652      }
653    else
654      {
655         if (transit->time.paused == 0)
656           return;
657         ecore_animator_thaw(transit->animator);
658         transit->time.delayed += (ecore_loop_time_get() - transit->time.paused);
659         transit->time.paused = 0;
660      }
661 }
662
663 EAPI Eina_Bool
664 elm_transit_paused_get(const Elm_Transit *transit)
665 {
666    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
667
668    if (transit->time.paused == 0)
669      return EINA_FALSE;
670
671    return EINA_TRUE;
672 }
673
674 EAPI double
675 elm_transit_progress_value_get(const Elm_Transit *transit)
676 {
677    ELM_TRANSIT_CHECK_OR_RETURN(transit, 0);
678
679    return transit->progress;
680 }
681
682 EAPI void
683 elm_transit_objects_final_state_keep_set(Elm_Transit *transit, Eina_Bool state_keep)
684 {
685    ELM_TRANSIT_CHECK_OR_RETURN(transit);
686
687    if (transit->state_keep == state_keep) return;
688    if (transit->animator) return;
689    transit->state_keep = !!state_keep;
690 }
691
692 EAPI Eina_Bool
693 elm_transit_objects_final_state_keep_get(const Elm_Transit *transit)
694 {
695    ELM_TRANSIT_CHECK_OR_RETURN(transit, EINA_FALSE);
696    return transit->state_keep;
697 }
698
699 EAPI void
700 elm_transit_chain_transit_add(Elm_Transit *transit, Elm_Transit *chain_transit)
701 {
702    ELM_TRANSIT_CHECK_OR_RETURN(transit);
703    ELM_TRANSIT_CHECK_OR_RETURN(chain_transit);
704
705    if (transit == chain_transit) return;
706    if (transit == chain_transit->prev_chain_transit) return;
707
708    if (chain_transit->prev_chain_transit)
709      chain_transit->prev_chain_transit->next_chain_transits = eina_list_remove(chain_transit->prev_chain_transit->next_chain_transits, chain_transit);
710
711    chain_transit->prev_chain_transit = transit;
712    transit->next_chain_transits = eina_list_append(transit->next_chain_transits, chain_transit);
713 }
714
715 EAPI Eina_List *
716 elm_transit_chain_transits_get(const Elm_Transit * transit)
717 {
718    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
719    return transit->next_chain_transits;
720 }
721
722 ///////////////////////////////////////////////////////////////////////////////
723 //Resizing Effect
724 ///////////////////////////////////////////////////////////////////////////////
725 typedef struct _Elm_Transit_Effect_Resizing Elm_Transit_Effect_Resizing;
726
727 struct _Elm_Transit_Effect_Resizing
728 {
729    struct _size {
730       Evas_Coord w, h;
731    } from, to;
732 };
733
734 static void
735 _transit_effect_resizing_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
736 {
737    Elm_Transit_Effect_Resizing *resizing = effect;
738    free(resizing);
739 }
740
741 static void
742 _transit_effect_resizing_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
743 {
744    EINA_SAFETY_ON_NULL_RETURN(effect);
745    EINA_SAFETY_ON_NULL_RETURN(transit);
746    Evas_Coord w, h;
747    Evas_Object *obj;
748    Eina_List *elist;
749    Elm_Transit_Effect_Resizing *resizing = effect;
750
751    w = resizing->from.w + (resizing->to.w * progress);
752    h = resizing->from.h + (resizing->to.h * progress);
753
754    EINA_LIST_FOREACH(transit->objs, elist, obj)
755      evas_object_resize(obj, w, h);
756 }
757
758 static Elm_Transit_Effect *
759 _transit_effect_resizing_context_new(Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
760 {
761    Elm_Transit_Effect_Resizing *resizing;
762
763    resizing = ELM_NEW(Elm_Transit_Effect_Resizing);
764    if (!resizing) return NULL;
765
766    resizing->from.w = from_w;
767    resizing->from.h = from_h;
768    resizing->to.w = to_w - from_w;
769    resizing->to.h = to_h - from_h;
770
771    return resizing;
772 }
773
774 EAPI Elm_Transit_Effect *
775 elm_transit_effect_resizing_add(Elm_Transit *transit, Evas_Coord from_w, Evas_Coord from_h, Evas_Coord to_w, Evas_Coord to_h)
776 {
777    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
778    Elm_Transit_Effect *effect = _transit_effect_resizing_context_new(from_w, from_h, to_w, to_h);
779
780    if (!effect) return NULL;
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_context = _transit_effect_translation_context_new(from_dx, from_dy, to_dx, to_dy);
913
914    if (!effect_context) return NULL;
915    elm_transit_effect_add(transit,
916                           _transit_effect_translation_op, effect_context,
917                           _transit_effect_translation_context_free);
918    return effect_context;
919 }
920
921
922 ///////////////////////////////////////////////////////////////////////////////
923 //Zoom Effect
924 ///////////////////////////////////////////////////////////////////////////////
925 typedef struct _Elm_Transit_Effect_Zoom Elm_Transit_Effect_Zoom;
926
927 struct _Elm_Transit_Effect_Zoom
928 {
929    float from, to;
930 };
931
932 void
933 _transit_effect_zoom_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
934 {
935    Elm_Transit_Effect_Zoom *zoom = effect;
936    free(zoom);
937 }
938
939 static void
940 _transit_effect_zoom_op(Elm_Transit_Effect *effect, Elm_Transit *transit , double progress)
941 {
942    EINA_SAFETY_ON_NULL_RETURN(effect);
943    EINA_SAFETY_ON_NULL_RETURN(transit);
944    Evas_Object *obj;
945    Eina_List *elist;
946    Elm_Transit_Effect_Zoom *zoom = effect;
947    Evas_Map *map;
948    Evas_Coord x, y, w, h;
949
950    map = evas_map_new(4);
951    if (!map) return;
952
953    EINA_LIST_FOREACH(transit->objs, elist, obj)
954      {
955         evas_object_geometry_get(obj, &x, &y, &w, &h);
956         evas_map_util_points_populate_from_object_full(map, obj, zoom->from +
957                                                        (progress * zoom->to));
958         evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, _TRANSIT_FOCAL);
959         evas_object_map_set(obj, map);
960         evas_object_map_enable_set(obj, EINA_TRUE);
961      }
962    evas_map_free(map);
963 }
964
965 static Elm_Transit_Effect *
966 _transit_effect_zoom_context_new(float from_rate, float to_rate)
967 {
968    Elm_Transit_Effect_Zoom *zoom;
969
970    zoom = ELM_NEW(Elm_Transit_Effect_Zoom);
971    if (!zoom) return NULL;
972
973    zoom->from = (_TRANSIT_FOCAL - (from_rate * _TRANSIT_FOCAL)) * (1 / from_rate);
974    zoom->to = ((_TRANSIT_FOCAL - (to_rate * _TRANSIT_FOCAL)) * (1 / to_rate)) - zoom->from;
975
976    return zoom;
977 }
978
979 EAPI Elm_Transit_Effect *
980 elm_transit_effect_zoom_add(Elm_Transit *transit, float from_rate, float to_rate)
981 {
982    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
983    Elm_Transit_Effect *effect_context = _transit_effect_zoom_context_new(from_rate, to_rate);
984
985    if (!effect_context) return NULL;
986    elm_transit_effect_add(transit,
987                           _transit_effect_zoom_op, effect_context,
988                           _transit_effect_zoom_context_free);
989    return effect_context;
990 }
991
992
993 ///////////////////////////////////////////////////////////////////////////////
994 //Flip Effect
995 ///////////////////////////////////////////////////////////////////////////////
996 typedef struct _Elm_Transit_Effect_Flip Elm_Transit_Effect_Flip;
997
998 struct _Elm_Transit_Effect_Flip
999 {
1000    Elm_Transit_Effect_Flip_Axis axis;
1001    Eina_Bool cw : 1;
1002 };
1003
1004 static void
1005 _transit_effect_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit)
1006 {
1007    EINA_SAFETY_ON_NULL_RETURN(effect);
1008    EINA_SAFETY_ON_NULL_RETURN(transit);
1009    Elm_Transit_Effect_Flip *flip = effect;
1010    Evas_Object *front, *back;
1011    int i;
1012    int count = eina_list_count(transit->objs);
1013
1014    for (i = 0; i < (count - 1); i += 2)
1015      {
1016         front = eina_list_nth(transit->objs, i);
1017         back = eina_list_nth(transit->objs, i+1);
1018         evas_object_map_enable_set(front, EINA_FALSE);
1019         evas_object_map_enable_set(back, EINA_FALSE);
1020      }
1021    free(flip);
1022 }
1023
1024 static void
1025 _transit_effect_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1026 {
1027    EINA_SAFETY_ON_NULL_RETURN(effect);
1028    EINA_SAFETY_ON_NULL_RETURN(transit);
1029    Evas_Object *obj, *front, *back;
1030    int count, i;
1031    Elm_Transit_Effect_Flip *flip = effect;
1032    Evas_Map *map;
1033    float degree;
1034    Evas_Coord x, y, w, h;
1035
1036    map = evas_map_new(4);
1037    if (!map) return;
1038
1039    if (flip->cw) degree = (float)(progress * 180);
1040    else degree = (float)(progress * -180);
1041
1042    count = eina_list_count(transit->objs);
1043
1044    for (i = 0; i < (count - 1); i += 2)
1045      {
1046         Evas_Coord half_w, half_h;
1047
1048         front = eina_list_nth(transit->objs, i);
1049         back = eina_list_nth(transit->objs, i+1);
1050
1051         if ((degree < 90) && (degree > -90))
1052           {
1053              obj = front;
1054              if (front != back)
1055                {
1056                   evas_object_hide(back);
1057                   evas_object_show(front);
1058                }
1059           }
1060         else
1061           {
1062              obj = back;
1063              if (front != back)
1064                {
1065                   evas_object_hide(front);
1066                   evas_object_show(back);
1067                }
1068           }
1069
1070         evas_map_util_points_populate_from_object_full(map, obj, 0);
1071         evas_object_geometry_get(obj, &x, &y, &w, &h);
1072         half_w = (w / 2);
1073         half_h = (h / 2);
1074
1075         if (flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1076           {
1077              if ((degree >= 90) || (degree <= -90))
1078                {
1079                   evas_map_point_image_uv_set(map, 0, w, 0);
1080                   evas_map_point_image_uv_set(map, 1, 0, 0);
1081                   evas_map_point_image_uv_set(map, 2, 0, h);
1082                   evas_map_point_image_uv_set(map, 3, w, h);
1083                }
1084              evas_map_util_3d_rotate(map, 0, degree,
1085                                      0, x + half_w, y + half_h, 0);
1086           }
1087         else
1088           {
1089              if ((degree >= 90) || (degree <= -90))
1090                {
1091                   evas_map_point_image_uv_set(map, 0, 0, h);
1092                   evas_map_point_image_uv_set(map, 1, w, h);
1093                   evas_map_point_image_uv_set(map, 2, w, 0);
1094                   evas_map_point_image_uv_set(map, 3, 0, 0);
1095                }
1096              evas_map_util_3d_rotate(map, degree,
1097                                      0, 0, x + half_w, y + half_h, 0);
1098           }
1099         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1100         evas_object_map_enable_set(front, EINA_TRUE);
1101         evas_object_map_enable_set(back, EINA_TRUE);
1102         evas_object_map_set(obj, map);
1103      }
1104    evas_map_free(map);
1105 }
1106
1107 static Elm_Transit_Effect *
1108 _transit_effect_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1109 {
1110    Elm_Transit_Effect_Flip *flip;
1111
1112    flip = ELM_NEW(Elm_Transit_Effect_Flip);
1113    if (!flip) return NULL;
1114
1115    flip->cw = cw;
1116    flip->axis = axis;
1117
1118    return flip;
1119 }
1120
1121 EAPI Elm_Transit_Effect *
1122 elm_transit_effect_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1123 {
1124    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1125    Elm_Transit_Effect *effect_context = _transit_effect_flip_context_new(axis, cw);
1126
1127    if (!effect_context) return NULL;
1128    elm_transit_effect_add(transit,
1129                           _transit_effect_flip_op, effect_context,
1130                           _transit_effect_flip_context_free);
1131    return effect_context;
1132 }
1133
1134 ///////////////////////////////////////////////////////////////////////////////
1135 //ResizableFlip Effect
1136 ///////////////////////////////////////////////////////////////////////////////
1137 typedef struct _Elm_Transit_Effect_Resizable_Flip Elm_Transit_Effect_ResizableFlip;
1138 typedef struct _Elm_Transit_Effect_Resizable_Flip_Node Elm_Transit_Effect_ResizableFlip_Node;
1139
1140 struct _Elm_Transit_Effect_Resizable_Flip_Node
1141 {
1142    Evas_Object *front;
1143    Evas_Object *back;
1144    struct _vector2d {
1145       float x, y;
1146    } from_pos, from_size, to_pos, to_size;
1147 };
1148
1149 struct _Elm_Transit_Effect_Resizable_Flip
1150 {
1151    Eina_List *nodes;
1152    Eina_Bool cw : 1;
1153    Elm_Transit_Effect_Flip_Axis axis;
1154 };
1155
1156 static void
1157 _resizable_flip_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1158 {
1159    Elm_Transit_Effect_ResizableFlip *resizable_flip = data;
1160    Eina_List *elist;
1161    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1162
1163    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1164      {
1165         if (resizable_flip_node->front == obj)
1166           evas_object_event_callback_del(resizable_flip_node->back,
1167                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1168         else if (resizable_flip_node->back == obj)
1169           evas_object_event_callback_del(resizable_flip_node->front,
1170                                          EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1171         else continue;
1172
1173         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1174                                                       elist);
1175         free(resizable_flip_node);
1176         break;
1177      }
1178 }
1179
1180 static Eina_List *
1181 _resizable_flip_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_ResizableFlip *resizable_flip)
1182 {
1183    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1184    Eina_List *data_list = NULL;
1185    Evas_Coord front_x, front_y, front_w, front_h;
1186    Evas_Coord back_x, back_y, back_w, back_h;
1187    int i, count;
1188
1189    count = eina_list_count(transit->objs);
1190    for (i = 0; i < (count - 1); i += 2)
1191      {
1192         resizable_flip_node = ELM_NEW(Elm_Transit_Effect_ResizableFlip_Node);
1193         if (!resizable_flip_node)
1194           {
1195              eina_list_free(data_list);
1196              return NULL;
1197           }
1198
1199         resizable_flip_node->front = eina_list_nth(transit->objs, i);
1200         resizable_flip_node->back = eina_list_nth(transit->objs, i+1);
1201
1202         evas_object_geometry_get(resizable_flip_node->front,
1203                                  &front_x, &front_y, &front_w, &front_h);
1204         evas_object_geometry_get(resizable_flip_node->back,
1205                                  &back_x, &back_y, &back_w, &back_h);
1206
1207         resizable_flip_node->from_pos.x = front_x;
1208         resizable_flip_node->from_pos.y = front_y;
1209         resizable_flip_node->to_pos.x = back_x - front_x;
1210         resizable_flip_node->to_pos.y = back_y - front_y;
1211
1212         resizable_flip_node->from_size.x = front_w;
1213         resizable_flip_node->from_size.y = front_h;
1214         resizable_flip_node->to_size.x = back_w - front_w;
1215         resizable_flip_node->to_size.y = back_h - front_h;
1216
1217         data_list = eina_list_append(data_list, resizable_flip_node);
1218
1219         evas_object_event_callback_add(resizable_flip_node->back,
1220                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1221         evas_object_event_callback_add(resizable_flip_node->front,
1222                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb, resizable_flip);
1223      }
1224
1225    return data_list;
1226 }
1227
1228 static void
1229 _set_image_uv_by_axis_y(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1230 {
1231    if ((degree >= 90) || (degree <= -90))
1232      {
1233         evas_map_point_image_uv_set(map, 0,
1234                                     (flip->from_size.x * 2) + flip->to_size.x,
1235                                     0);
1236         evas_map_point_image_uv_set(map, 1, 0, 0);
1237         evas_map_point_image_uv_set(map, 2, 0,
1238                                     (flip->from_size.y * 2) + flip->to_size.y);
1239         evas_map_point_image_uv_set(map, 3,
1240                                     (flip->from_size.x * 2) + flip->to_size.x,
1241                                     (flip->from_size.y * 2) + flip->to_size.y);
1242      }
1243    else
1244      {
1245         evas_map_point_image_uv_set(map, 0, 0, 0);
1246         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1247         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1248                                     flip->from_size.y);
1249         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1250      }
1251 }
1252
1253 static void
1254 _set_image_uv_by_axis_x(Evas_Map *map, Elm_Transit_Effect_ResizableFlip_Node *flip, float degree)
1255 {
1256    if ((degree >= 90) || (degree <= -90))
1257      {
1258         evas_map_point_image_uv_set(map, 0, 0,
1259                                     (flip->from_size.y * 2) + flip->to_size.y);
1260         evas_map_point_image_uv_set(map, 1,
1261                                     (flip->from_size.x * 2) + flip->to_size.x,
1262                                     (flip->from_size.y * 2) + flip->to_size.y);
1263         evas_map_point_image_uv_set(map, 2,
1264                                     (flip->from_size.x * 2) + flip->to_size.x,
1265                                     0);
1266         evas_map_point_image_uv_set(map, 3, 0, 0);
1267      }
1268    else
1269      {
1270         evas_map_point_image_uv_set(map, 0, 0, 0);
1271         evas_map_point_image_uv_set(map, 1, flip->from_size.x, 0);
1272         evas_map_point_image_uv_set(map, 2, flip->from_size.x,
1273                                     flip->from_size.y);
1274         evas_map_point_image_uv_set(map, 3, 0, flip->from_size.y);
1275      }
1276 }
1277
1278 void
1279 _transit_effect_resizable_flip_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1280 {
1281    EINA_SAFETY_ON_NULL_RETURN(effect);
1282
1283    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1284    Eina_List *elist, *elist_next;
1285    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1286
1287    EINA_LIST_FOREACH_SAFE(resizable_flip->nodes,
1288                           elist, elist_next, resizable_flip_node)
1289      {
1290         evas_object_map_enable_set(resizable_flip_node->front, EINA_FALSE);
1291         evas_object_map_enable_set(resizable_flip_node->back, EINA_FALSE);
1292
1293         resizable_flip->nodes = eina_list_remove_list(resizable_flip->nodes,
1294                                                       elist);
1295
1296         evas_object_event_callback_del(resizable_flip_node->back,
1297                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1298         evas_object_event_callback_del(resizable_flip_node->front,
1299                                        EVAS_CALLBACK_DEL, _resizable_flip_object_del_cb);
1300         free(resizable_flip_node);
1301      }
1302    free(resizable_flip);
1303 }
1304
1305 void
1306 _transit_effect_resizable_flip_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1307 {
1308    EINA_SAFETY_ON_NULL_RETURN(effect);
1309    Evas_Map *map;
1310    Evas_Object *obj;
1311    float x, y, w, h;
1312    float degree;
1313    Evas_Coord half_w, half_h;
1314    Elm_Transit_Effect_ResizableFlip *resizable_flip = effect;
1315    Elm_Transit_Effect_ResizableFlip_Node *resizable_flip_node;
1316    Eina_List *elist;
1317
1318    map = evas_map_new(4);
1319    if (!map) return;
1320
1321    if (resizable_flip->cw) degree = (float)(progress * 180);
1322    else degree = (float)(progress * -180);
1323
1324    if (!resizable_flip->nodes)
1325      resizable_flip->nodes = _resizable_flip_nodes_build(transit,
1326                                                          resizable_flip);
1327
1328    EINA_LIST_FOREACH(resizable_flip->nodes, elist, resizable_flip_node)
1329      {
1330         if ((degree < 90) && (degree > -90))
1331           {
1332              obj = resizable_flip_node->front;
1333              if (resizable_flip_node->front != resizable_flip_node->back)
1334                {
1335                   evas_object_hide(resizable_flip_node->back);
1336                   evas_object_show(resizable_flip_node->front);
1337                }
1338           }
1339         else
1340           {
1341              obj = resizable_flip_node->back;
1342              if (resizable_flip_node->front != resizable_flip_node->back)
1343                {
1344                   evas_object_hide(resizable_flip_node->front);
1345                   evas_object_show(resizable_flip_node->back);
1346                }
1347           }
1348
1349         x = resizable_flip_node->from_pos.x +
1350            (resizable_flip_node->to_pos.x * progress);
1351         y = resizable_flip_node->from_pos.y +
1352            (resizable_flip_node->to_pos.y * progress);
1353         w = resizable_flip_node->from_size.x +
1354            (resizable_flip_node->to_size.x * progress);
1355         h = resizable_flip_node->from_size.y +
1356            (resizable_flip_node->to_size.y * progress);
1357         evas_map_point_coord_set(map, 0, x, y, 0);
1358         evas_map_point_coord_set(map, 1, x + w, y, 0);
1359         evas_map_point_coord_set(map, 2, x + w, y + h, 0);
1360         evas_map_point_coord_set(map, 3, x, y + h, 0);
1361
1362         half_w = (Evas_Coord)(w / 2);
1363         half_h = (Evas_Coord)(h / 2);
1364
1365         if (resizable_flip->axis == ELM_TRANSIT_EFFECT_FLIP_AXIS_Y)
1366           {
1367              _set_image_uv_by_axis_y(map, resizable_flip_node, degree);
1368              evas_map_util_3d_rotate(map, 0, degree,
1369                                      0, x + half_w, y + half_h, 0);
1370           }
1371         else
1372           {
1373              _set_image_uv_by_axis_x(map, resizable_flip_node, degree);
1374              evas_map_util_3d_rotate(map, degree, 0,
1375                                      0, x + half_w, y + half_h, 0);
1376           }
1377
1378         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
1379         evas_object_map_enable_set(resizable_flip_node->front, EINA_TRUE);
1380         evas_object_map_enable_set(resizable_flip_node->back, EINA_TRUE);
1381         evas_object_map_set(obj, map);
1382      }
1383    evas_map_free(map);
1384 }
1385
1386 static Elm_Transit_Effect *
1387 _transit_effect_resizable_flip_context_new(Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1388 {
1389    Elm_Transit_Effect_ResizableFlip *resizable_flip;
1390
1391    resizable_flip = ELM_NEW(Elm_Transit_Effect_ResizableFlip);
1392    if (!resizable_flip) return NULL;
1393
1394    resizable_flip->cw = cw;
1395    resizable_flip->axis = axis;
1396
1397    return resizable_flip;
1398 }
1399
1400 EAPI Elm_Transit_Effect *
1401 elm_transit_effect_resizable_flip_add(Elm_Transit *transit, Elm_Transit_Effect_Flip_Axis axis, Eina_Bool cw)
1402 {
1403    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1404    Elm_Transit_Effect *effect_context = _transit_effect_resizable_flip_context_new(axis, cw);
1405
1406    if (!effect_context) return NULL;
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) return NULL;
1619    elm_transit_effect_add(transit,
1620                           _transit_effect_wipe_op, effect_context,
1621                           _transit_effect_wipe_context_free);
1622    return effect_context;
1623 }
1624
1625
1626 ///////////////////////////////////////////////////////////////////////////////
1627 //Color Effect
1628 ///////////////////////////////////////////////////////////////////////////////
1629 typedef struct _Elm_Transit_Effect_Color Elm_Transit_Effect_Color;
1630
1631 struct _Elm_Transit_Effect_Color
1632 {
1633    struct _unsigned_color {
1634       unsigned int r, g, b, a;
1635    } from;
1636    struct _signed_color {
1637       int r, g, b, a;
1638    } to;
1639 };
1640
1641 static void
1642 _transit_effect_color_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1643 {
1644    Elm_Transit_Effect_Color *color = effect;
1645    free(color);
1646 }
1647
1648 static void
1649 _transit_effect_color_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
1650 {
1651    EINA_SAFETY_ON_NULL_RETURN(effect);
1652    EINA_SAFETY_ON_NULL_RETURN(transit);
1653    Elm_Transit_Effect_Color *color = effect;
1654    Evas_Object *obj;
1655    Eina_List *elist;
1656    unsigned int r, g, b, a;
1657
1658    r = (color->from.r + (int)((float)color->to.r * progress));
1659    g = (color->from.g + (int)((float)color->to.g * progress));
1660    b = (color->from.b + (int)((float)color->to.b * progress));
1661    a = (color->from.a + (int)((float)color->to.a * progress));
1662
1663    EINA_LIST_FOREACH(transit->objs, elist, obj)
1664      evas_object_color_set(obj, r, g, b, a);
1665 }
1666
1667 static Elm_Transit_Effect *
1668 _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)
1669 {
1670    Elm_Transit_Effect_Color *color;
1671
1672    color = ELM_NEW(Elm_Transit_Effect_Color);
1673    if (!color) return NULL;
1674
1675    color->from.r = from_r;
1676    color->from.g = from_g;
1677    color->from.b = from_b;
1678    color->from.a = from_a;
1679    color->to.r = to_r - from_r;
1680    color->to.g = to_g - from_g;
1681    color->to.b = to_b - from_b;
1682    color->to.a = to_a - from_a;
1683
1684    return color;
1685 }
1686
1687 EAPI Elm_Transit_Effect *
1688 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)
1689 {
1690    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1691    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);
1692
1693    if (!effect_context) return NULL;
1694    elm_transit_effect_add(transit,
1695                           _transit_effect_color_op, effect_context,
1696                           _transit_effect_color_context_free);
1697    return effect_context;
1698 }
1699
1700 ///////////////////////////////////////////////////////////////////////////////
1701 //Fade Effect
1702 ///////////////////////////////////////////////////////////////////////////////
1703 typedef struct _Elm_Transit_Effect_Fade Elm_Transit_Effect_Fade;
1704 typedef struct _Elm_Transit_Effect_Fade_Node Elm_Transit_Effect_Fade_Node;
1705
1706 struct _Elm_Transit_Effect_Fade_Node
1707 {
1708    Evas_Object *before;
1709    Evas_Object *after;
1710    struct _signed_color before_color, after_color;
1711    int before_alpha;
1712    int after_alpha;
1713    Eina_Bool inversed : 1;
1714 };
1715
1716 struct _Elm_Transit_Effect_Fade
1717 {
1718    Eina_List *nodes;
1719 };
1720
1721 static void
1722 _fade_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1723 {
1724    Elm_Transit_Effect_Fade *fade = data;
1725    Eina_List *elist;
1726    Elm_Transit_Effect_Fade_Node *fade_node;
1727
1728    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1729      {
1730         if (fade_node->before == obj)
1731           evas_object_event_callback_del(fade_node->after,
1732                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1733         else if (fade_node->after == obj)
1734           evas_object_event_callback_del(fade_node->before,
1735                                          EVAS_CALLBACK_DEL, _fade_object_del_cb);
1736         else continue;
1737
1738         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1739         free(fade_node);
1740         break;
1741      }
1742 }
1743
1744 static Eina_List *
1745 _fade_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Fade *fade_data)
1746 {
1747    Elm_Transit_Effect_Fade_Node *fade;
1748    Eina_List *data_list = NULL;
1749    int i, count;
1750
1751    count = eina_list_count(transit->objs);
1752    for (i = 0; i < count; i += 2)
1753      {
1754         fade = ELM_NEW(Elm_Transit_Effect_Fade_Node);
1755         if (!fade)
1756           {
1757              eina_list_free(data_list);
1758              return NULL;
1759           }
1760
1761         fade->before = eina_list_nth(transit->objs, i);
1762         fade->after = eina_list_nth(transit->objs, i+1);
1763
1764         evas_object_color_get(fade->before,
1765                               &fade->before_color.r, &fade->before_color.g,
1766                               &fade->before_color.b, &fade->before_color.a);
1767         evas_object_color_get(fade->after,
1768                               &fade->after_color.r, &fade->after_color.g,
1769                               &fade->after_color.b, &fade->after_color.a);
1770
1771         fade->before_alpha = (255 - fade->before_color.a);
1772         fade->after_alpha = (255 - fade->after_color.a);
1773
1774         data_list = eina_list_append(data_list, fade);
1775
1776         evas_object_event_callback_add(fade->before,
1777                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1778         evas_object_event_callback_add(fade->after,
1779                                        EVAS_CALLBACK_DEL, _fade_object_del_cb, fade_data);
1780      }
1781    return data_list;
1782 }
1783
1784 static void
1785 _transit_effect_fade_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1786 {
1787    EINA_SAFETY_ON_NULL_RETURN(effect);
1788    Elm_Transit_Effect_Fade *fade = effect;
1789    Elm_Transit_Effect_Fade_Node *fade_node;
1790    Eina_List *elist, *elist_next;
1791
1792    EINA_LIST_FOREACH_SAFE(fade->nodes, elist, elist_next, fade_node)
1793      {
1794         evas_object_color_set(fade_node->before, fade_node->before_color.r,
1795                               fade_node->before_color.g,
1796                               fade_node->before_color.b,
1797                               fade_node->before_color.a);
1798         evas_object_color_set(fade_node->after, fade_node->after_color.r,
1799                               fade_node->after_color.g,
1800                               fade_node->after_color.b,
1801                               fade_node->after_color.a);
1802
1803         fade->nodes = eina_list_remove_list(fade->nodes, elist);
1804         evas_object_event_callback_del(fade_node->before,
1805                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1806         evas_object_event_callback_del(fade_node->after,
1807                                        EVAS_CALLBACK_DEL, _fade_object_del_cb);
1808         free(fade_node);
1809      }
1810
1811    free(fade);
1812 }
1813
1814 static void
1815 _transit_effect_fade_op(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__, double progress)
1816 {
1817    EINA_SAFETY_ON_NULL_RETURN(effect);
1818    Elm_Transit_Effect_Fade *fade = effect;
1819    Eina_List *elist;
1820    Elm_Transit_Effect_Fade_Node *fade_node;
1821    float _progress;
1822
1823    if (!fade->nodes)
1824      fade->nodes = _fade_nodes_build(transit, fade);
1825
1826    EINA_LIST_FOREACH(fade->nodes, elist, fade_node)
1827      {
1828         if (progress < 0.5)
1829           {
1830              if (!fade_node->inversed)
1831                {
1832                   evas_object_hide(fade_node->after);
1833                   evas_object_show(fade_node->before);
1834                   fade_node->inversed = EINA_TRUE;
1835                }
1836
1837              _progress = (1 - (progress * 2));
1838
1839              evas_object_color_set(fade_node->before,
1840                                    fade_node->before_color.r * _progress,
1841                                    fade_node->before_color.g * _progress,
1842                                    fade_node->before_color.b * _progress,
1843                                    fade_node->before_color.a +
1844                                    fade_node->before_alpha * (1 - _progress));
1845           }
1846         else
1847           {
1848              if (fade_node->inversed)
1849                {
1850                   evas_object_hide(fade_node->before);
1851                   evas_object_show(fade_node->after);
1852                   fade_node->inversed = EINA_FALSE;
1853                }
1854
1855              _progress = ((progress - 0.5) * 2);
1856
1857              evas_object_color_set(fade_node->after,
1858                                    fade_node->after_color.r * _progress,
1859                                    fade_node->after_color.g * _progress,
1860                                    fade_node->after_color.b * _progress,
1861                                    fade_node->after_color.a +
1862                                    fade_node->after_alpha * (1 - _progress));
1863           }
1864      }
1865 }
1866
1867 static Elm_Transit_Effect *
1868 _transit_effect_fade_context_new(void)
1869 {
1870    Elm_Transit_Effect_Fade *fade;
1871    fade = ELM_NEW(Elm_Transit_Effect_Fade);
1872    if (!fade) return NULL;
1873    return fade;
1874 }
1875
1876 EAPI Elm_Transit_Effect *
1877 elm_transit_effect_fade_add(Elm_Transit *transit)
1878 {
1879    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
1880
1881    Elm_Transit_Effect *effect_context = _transit_effect_fade_context_new();
1882    if (!effect_context) return NULL;
1883    elm_transit_effect_add(transit,
1884                           _transit_effect_fade_op, effect_context,
1885                           _transit_effect_fade_context_free);
1886    return effect_context;
1887 }
1888
1889
1890 ///////////////////////////////////////////////////////////////////////////////
1891 //Blend Effect
1892 ///////////////////////////////////////////////////////////////////////////////
1893 typedef struct _Elm_Transit_Effect_Blend Elm_Transit_Effect_Blend;
1894 typedef struct _Elm_Transit_Effect_Blend_Node Elm_Transit_Effect_Blend_Node;
1895
1896 struct _Elm_Transit_Effect_Blend_Node
1897 {
1898    Evas_Object *before;
1899    Evas_Object *after;
1900    struct _signed_color from, to;
1901 };
1902
1903 struct _Elm_Transit_Effect_Blend
1904 {
1905    Eina_List *nodes;
1906 };
1907
1908 static void
1909 _blend_object_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1910 {
1911    Elm_Transit_Effect_Blend *blend = data;
1912    Eina_List *elist;
1913    Elm_Transit_Effect_Blend_Node *blend_node;
1914
1915    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
1916      {
1917         if (blend_node->after == obj)
1918           evas_object_event_callback_del(blend_node->before,
1919                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1920         else if (blend_node->before == obj)
1921           evas_object_event_callback_del(blend_node->after,
1922                                          EVAS_CALLBACK_DEL, _blend_object_del_cb);
1923         else continue;
1924
1925         blend->nodes = eina_list_remove_list(blend->nodes, elist);
1926         free(blend_node);
1927         break;
1928      }
1929 }
1930
1931 static Eina_List *
1932 _blend_nodes_build(Elm_Transit *transit, Elm_Transit_Effect_Blend *blend)
1933 {
1934    Elm_Transit_Effect_Blend_Node *blend_node;
1935    Eina_List *data_list = NULL;
1936    int i, count;
1937
1938    count = eina_list_count(transit->objs);
1939    for (i = 0; i < (count - 1); i += 2)
1940      {
1941         blend_node = ELM_NEW(Elm_Transit_Effect_Blend_Node);
1942         if (!blend_node)
1943           {
1944              eina_list_free(data_list);
1945              return NULL;
1946           }
1947
1948         blend_node->before = eina_list_nth(transit->objs, i);
1949         blend_node->after = eina_list_nth(transit->objs, i + 1);
1950         evas_object_show(blend_node->before);
1951         evas_object_show(blend_node->after);
1952
1953         evas_object_color_get(blend_node->before, &blend_node->from.r,
1954                               &blend_node->from.g, &blend_node->from.b,
1955                               &blend_node->from.a);
1956         evas_object_color_get(blend_node->after, &blend_node->to.r,
1957                               &blend_node->to.g, &blend_node->to.b,
1958                               &blend_node->to.a);
1959
1960         data_list = eina_list_append(data_list, blend_node);
1961
1962         evas_object_event_callback_add(blend_node->before,
1963                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1964         evas_object_event_callback_add(blend_node->after,
1965                                        EVAS_CALLBACK_DEL, _blend_object_del_cb, blend);
1966      }
1967    return data_list;
1968 }
1969
1970 void
1971 _transit_effect_blend_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
1972 {
1973    EINA_SAFETY_ON_NULL_RETURN(effect);
1974    Elm_Transit_Effect_Blend *blend = effect;
1975    Elm_Transit_Effect_Blend_Node *blend_node;
1976    Eina_List *elist, *elist_next;
1977
1978    EINA_LIST_FOREACH_SAFE(blend->nodes, elist, elist_next, blend_node)
1979      {
1980         evas_object_color_set(blend_node->before,
1981                               blend_node->from.r, blend_node->from.g,
1982                               blend_node->from.b, blend_node->from.a);
1983         evas_object_color_set(blend_node->after, blend_node->to.r,
1984                               blend_node->to.g, blend_node->to.b,
1985                               blend_node->to.a);
1986
1987         if (elm_transit_auto_reverse_get(transit))
1988           evas_object_hide(blend_node->after);
1989         else
1990           evas_object_hide(blend_node->before);
1991
1992         blend->nodes = eina_list_remove_list(blend->nodes, elist);
1993
1994         evas_object_event_callback_del(blend_node->before,
1995                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
1996         evas_object_event_callback_del(blend_node->after,
1997                                        EVAS_CALLBACK_DEL, _blend_object_del_cb);
1998         free(blend_node);
1999      }
2000    free(blend);
2001 }
2002
2003 void
2004 _transit_effect_blend_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2005 {
2006    EINA_SAFETY_ON_NULL_RETURN(effect);
2007    EINA_SAFETY_ON_NULL_RETURN(transit);
2008    Elm_Transit_Effect_Blend *blend = effect;
2009    Elm_Transit_Effect_Blend_Node *blend_node;
2010    Eina_List *elist;
2011
2012    if (!blend->nodes) blend->nodes = _blend_nodes_build(transit, blend);
2013
2014    EINA_LIST_FOREACH(blend->nodes, elist, blend_node)
2015      {
2016         evas_object_color_set(blend_node->before,
2017                               (int)(blend_node->from.r * (1 - progress)),
2018                               (int)(blend_node->from.g * (1 - progress)),
2019                               (int)(blend_node->from.b * (1 - progress)),
2020                               (int)(blend_node->from.a * (1 - progress)));
2021         evas_object_color_set(blend_node->after,
2022                               (int)(blend_node->to.r * progress),
2023                               (int)(blend_node->to.g * progress),
2024                               (int)(blend_node->to.b * progress),
2025                               (int)(blend_node->to.a * progress));
2026      }
2027 }
2028
2029 static Elm_Transit_Effect *
2030 _transit_effect_blend_context_new(void)
2031 {
2032    Elm_Transit_Effect_Blend *blend;
2033
2034    blend = ELM_NEW(Elm_Transit_Effect_Blend);
2035    if (!blend) return NULL;
2036    return blend;
2037 }
2038
2039 EAPI Elm_Transit_Effect *
2040 elm_transit_effect_blend_add(Elm_Transit *transit)
2041 {
2042    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2043    Elm_Transit_Effect *effect_context = _transit_effect_blend_context_new();
2044
2045    if (!effect_context) return NULL;
2046    elm_transit_effect_add(transit,
2047                           _transit_effect_blend_op, effect_context,
2048                           _transit_effect_blend_context_free);
2049    return effect_context;
2050 }
2051
2052
2053 ///////////////////////////////////////////////////////////////////////////////
2054 //Rotation Effect
2055 ///////////////////////////////////////////////////////////////////////////////
2056 typedef struct _Elm_Transit_Effect_Rotation Elm_Transit_Effect_Rotation;
2057
2058 struct _Elm_Transit_Effect_Rotation
2059 {
2060    float from, to;
2061 };
2062
2063 static void
2064 _transit_effect_rotation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2065 {
2066    Elm_Transit_Effect_Rotation *rotation = effect;
2067    free(rotation);
2068 }
2069
2070 static void
2071 _transit_effect_rotation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2072 {
2073    EINA_SAFETY_ON_NULL_RETURN(effect);
2074    EINA_SAFETY_ON_NULL_RETURN(transit);
2075    Elm_Transit_Effect_Rotation *rotation = effect;
2076    Evas_Map *map;
2077    Evas_Coord x, y, w, h;
2078    float degree;
2079    float half_w, half_h;
2080    Eina_List *elist;
2081    Evas_Object *obj;
2082
2083    map = evas_map_new(4);
2084    if (!map) return;
2085
2086    EINA_LIST_FOREACH(transit->objs, elist, obj)
2087      {
2088         evas_map_util_points_populate_from_object_full(map, obj, 0);
2089         degree = rotation->from + (float)(progress * rotation->to);
2090
2091         evas_object_geometry_get(obj, &x, &y, &w, &h);
2092
2093         half_w = (float)w * 0.5;
2094         half_h = (float)h * 0.5;
2095
2096         evas_map_util_rotate(map, degree, x + half_w, y + half_h);
2097         evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, _TRANSIT_FOCAL);
2098         evas_object_map_enable_set(obj, EINA_TRUE);
2099         evas_object_map_set(obj, map);
2100      }
2101    evas_map_free(map);
2102 }
2103
2104 static Elm_Transit_Effect *
2105 _transit_effect_rotation_context_new(float from_degree, float to_degree)
2106 {
2107    Elm_Transit_Effect_Rotation *rotation;
2108
2109    rotation = ELM_NEW(Elm_Transit_Effect_Rotation);
2110    if (!rotation) return NULL;
2111
2112    rotation->from = from_degree;
2113    rotation->to = to_degree - from_degree;
2114
2115    return rotation;
2116 }
2117
2118 EAPI Elm_Transit_Effect *
2119 elm_transit_effect_rotation_add(Elm_Transit *transit, float from_degree, float to_degree)
2120 {
2121    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2122    Elm_Transit_Effect *effect_context = _transit_effect_rotation_context_new(from_degree, to_degree);
2123
2124    if (!effect_context) return NULL;
2125    elm_transit_effect_add(transit,
2126                           _transit_effect_rotation_op, effect_context,
2127                           _transit_effect_rotation_context_free);
2128    return effect_context;
2129 }
2130
2131
2132 ///////////////////////////////////////////////////////////////////////////////
2133 //ImageAnimation Effect
2134 ///////////////////////////////////////////////////////////////////////////////
2135 typedef struct _Elm_Transit_Effect_Image_Animation Elm_Transit_Effect_Image_Animation;
2136
2137 struct _Elm_Transit_Effect_Image_Animation
2138 {
2139    Eina_List *images;
2140 };
2141
2142 static void
2143 _transit_effect_image_animation_context_free(Elm_Transit_Effect *effect, Elm_Transit *transit __UNUSED__)
2144 {
2145    EINA_SAFETY_ON_NULL_RETURN(effect);
2146    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2147    const char *image;
2148    Eina_List *elist, *elist_next;
2149
2150    EINA_LIST_FOREACH_SAFE(image_animation->images, elist, elist_next, image)
2151      {
2152         image_animation->images =
2153            eina_list_remove_list(image_animation->images, elist);
2154         eina_stringshare_del(image);
2155      }
2156
2157    free(image_animation);
2158 }
2159
2160 static void
2161 _transit_effect_image_animation_op(Elm_Transit_Effect *effect, Elm_Transit *transit, double progress)
2162 {
2163    EINA_SAFETY_ON_NULL_RETURN(effect);
2164    EINA_SAFETY_ON_NULL_RETURN(transit);
2165    Eina_List *elist;
2166    Evas_Object *obj;
2167    const char *type;
2168    Elm_Transit_Effect_Image_Animation *image_animation = effect;
2169    unsigned int count = 0;
2170    int len;
2171
2172    type = eina_stringshare_add("icon");
2173    len = eina_list_count(image_animation->images);
2174
2175    if (!len) count = floor(progress * len);
2176    else count = floor(progress * (len - 1));
2177
2178    EINA_LIST_FOREACH(transit->objs, elist, obj)
2179      {
2180         if (elm_widget_type_check(obj, type))
2181           elm_icon_file_set(obj,
2182                             eina_list_nth(image_animation->images, count), NULL);
2183      }
2184
2185    eina_stringshare_del(type);
2186 }
2187
2188 static Elm_Transit_Effect *
2189 _transit_effect_image_animation_context_new(Eina_List *images)
2190 {
2191    Elm_Transit_Effect_Image_Animation *image_animation;
2192    image_animation = ELM_NEW(Elm_Transit_Effect_Image_Animation);
2193
2194    if (!image_animation) return NULL;
2195    image_animation->images = images;
2196    return image_animation;
2197 }
2198
2199 EAPI Elm_Transit_Effect *
2200 elm_transit_effect_image_animation_add(Elm_Transit *transit, Eina_List *images)
2201 {
2202    ELM_TRANSIT_CHECK_OR_RETURN(transit, NULL);
2203    Elm_Transit_Effect *effect = _transit_effect_image_animation_context_new(images);
2204
2205    if (!effect) return NULL;
2206    elm_transit_effect_add(transit,
2207                           _transit_effect_image_animation_op, effect,
2208                           _transit_effect_image_animation_context_free);
2209    return effect;
2210 }