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