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