diff options
author | Jaehyun Cho <jae_hyun.cho@samsung.com> | 2017-07-03 21:58:38 +0900 |
---|---|---|
committer | Jaehyun Cho <jae_hyun.cho@samsung.com> | 2017-08-18 12:06:01 +0900 |
commit | 9594cf4a0d32bc28b9c358aeab2b474d103910cd (patch) | |
tree | 89c3d70247da2768efef043705e9ce7430fa22e6 | |
parent | e597954263fd0ebc956c84d33c937c10e7637c9a (diff) | |
download | efl-9594cf4a0d32bc28b9c358aeab2b474d103910cd.tar.gz |
efl_animation: Add rotate animation instance
-rw-r--r-- | src/Makefile_Evas.am | 2 | ||||
-rw-r--r-- | src/lib/evas/Evas_Common.h | 7 | ||||
-rw-r--r-- | src/lib/evas/Evas_Eo.h | 1 | ||||
-rw-r--r-- | src/lib/evas/Evas_Internal.h | 6 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_instance_rotate.c | 314 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_instance_rotate.eo | 12 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_rotate.c | 39 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_rotate.eo | 1 | ||||
-rw-r--r-- | src/lib/evas/include/evas_private.h | 1 |
9 files changed, 383 insertions, 0 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am index 053eac4cb8..2948371f1b 100644 --- a/src/Makefile_Evas.am +++ b/src/Makefile_Evas.am @@ -55,6 +55,7 @@ evas_eolian_pub_files = \ lib/evas/canvas/efl_animation_rotate.eo \ lib/evas/canvas/efl_animation_instance.eo \ lib/evas/canvas/efl_animation_instance_alpha.eo \ + lib/evas/canvas/efl_animation_instance_rotate.eo \ $(NULL) evas_eolian_legacy_files = \ @@ -224,6 +225,7 @@ lib/evas/canvas/efl_animation_alpha.c \ lib/evas/canvas/efl_animation_rotate.c \ lib/evas/canvas/efl_animation_instance.c \ lib/evas/canvas/efl_animation_instance_alpha.c \ +lib/evas/canvas/efl_animation_instance_rotate.c \ $(NULL) EXTRA_DIST2 += \ diff --git a/src/lib/evas/Evas_Common.h b/src/lib/evas/Evas_Common.h index 843a95dd29..6cd1319382 100644 --- a/src/lib/evas/Evas_Common.h +++ b/src/lib/evas/Evas_Common.h @@ -3356,6 +3356,13 @@ typedef Eo Efl_Animation_Instance_Alpha; #endif +#ifndef _EFL_ANIMATION_INSTANCE_ROTATE_EO_CLASS_TYPE +#define _EFL_ANIMATION_INSTANCE_ROTATE_EO_CLASS_TYPE + +typedef Eo Efl_Animation_Instance_Rotate; + +#endif + struct _Efl_Animation_Instance_Animate_Event_Info { double progress; diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h index a9eedc0513..a4acac63dc 100644 --- a/src/lib/evas/Evas_Eo.h +++ b/src/lib/evas/Evas_Eo.h @@ -71,6 +71,7 @@ #include "canvas/efl_animation_rotate.eo.h" #include "canvas/efl_animation_instance.eo.h" #include "canvas/efl_animation_instance_alpha.eo.h" +#include "canvas/efl_animation_instance_rotate.eo.h" #endif /* EFL_EO_API_SUPPORT */ #if defined(EFL_BETA_API_SUPPORT) && defined(EFL_EO_API_SUPPORT) diff --git a/src/lib/evas/Evas_Internal.h b/src/lib/evas/Evas_Internal.h index 14953676a2..4c53466009 100644 --- a/src/lib/evas/Evas_Internal.h +++ b/src/lib/evas/Evas_Internal.h @@ -103,6 +103,12 @@ EOAPI void efl_animation_instance_final_state_show(Eo *obj); EOAPI void efl_animation_instance_alpha_set(Eo *obj, double from_alpha, double to_alpha); +EOAPI void efl_animation_instance_rotate_set(Eo *obj, double from_degree, double to_degree, Efl_Canvas_Object *pivot, double cx, double cy); +EOAPI void efl_animation_instance_rotate_get(const Eo *obj, double *from_degree, double *to_degree, Efl_Canvas_Object **pivot, double *cx, double *cy); + +EOAPI void efl_animation_instance_rotate_absolute_set(Eo *obj, double from_degree, double to_degree, int cx, int cy); +EOAPI void efl_animation_instance_rotate_absolute_get(const Eo *obj, double *from_degree, double *to_degree, int *cx, int *cy); + #ifdef __cplusplus } #endif diff --git a/src/lib/evas/canvas/efl_animation_instance_rotate.c b/src/lib/evas/canvas/efl_animation_instance_rotate.c new file mode 100644 index 0000000000..2150acc611 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_instance_rotate.c @@ -0,0 +1,314 @@ +#include "evas_common_private.h" +#include "evas_private.h" + +#define MY_CLASS EFL_ANIMATION_INSTANCE_ROTATE_CLASS +#define MY_CLASS_NAME efl_class_name_get(MY_CLASS) + +#define EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(anim, ...) \ + do { \ + if (!anim) { \ + CRI("Efl_Animation_Instance " # anim " is NULL!"); \ + return __VA_ARGS__; \ + } \ + if (efl_animation_instance_is_deleted(anim)) { \ + ERR("Efl_Animation_Instance " # anim " has already been deleted!"); \ + return __VA_ARGS__; \ + } \ + } while (0) + +#define EFL_ANIMATION_INSTANCE_ROTATE_DATA_GET(o, pd) \ + Evas_Object_Animation_Instance_Rotate_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_INSTANCE_ROTATE_CLASS) + +typedef struct _Evas_Object_Animation_Instance_Rotate_Property +{ + double degree; +} Evas_Object_Animation_Instance_Rotate_Property; + +typedef struct _Evas_Object_Animation_Instance_Rotate_Absolute_Pivot +{ + Evas_Coord cx, cy; +} Evas_Object_Animation_Instance_Rotate_Absolute_Pivot; + +typedef struct _Evas_Object_Animation_Instance_Rotate_Relative_Pivot +{ + Efl_Canvas_Object *obj; + double cx, cy; +} Evas_Object_Animation_Instance_Rotate_Relative_Pivot; + +struct _Evas_Object_Animation_Instance_Rotate_Data +{ + Evas_Object_Animation_Instance_Rotate_Property from; + Evas_Object_Animation_Instance_Rotate_Property to; + + Evas_Object_Animation_Instance_Rotate_Absolute_Pivot abs_pivot; + Evas_Object_Animation_Instance_Rotate_Relative_Pivot rel_pivot; + + Eina_Bool use_rel_pivot; +}; + +EOLIAN static void +_efl_animation_instance_rotate_rotate_set(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd, + double from_degree, + double to_degree, + Efl_Canvas_Object *pivot, + double cx, + double cy) +{ + EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(eo_obj); + + pd->from.degree = from_degree; + pd->to.degree = to_degree; + + pd->rel_pivot.obj = pivot; + pd->rel_pivot.cx = cx; + pd->rel_pivot.cy = cy; + + //Update absolute pivot based on relative pivot + Evas_Coord x = 0; + Evas_Coord y = 0; + Evas_Coord w = 0; + Evas_Coord h = 0; + + if (pivot) + evas_object_geometry_get(pivot, &x, &y, &w, &h); + else + { + Efl_Canvas_Object *target = efl_animation_instance_target_get(eo_obj); + if (target) + evas_object_geometry_get(target, &x, &y, &w, &h); + } + + pd->abs_pivot.cx = x + (w * cx); + pd->abs_pivot.cy = y + (h * cy); + + pd->use_rel_pivot = EINA_TRUE; +} + +EOLIAN static void +_efl_animation_instance_rotate_rotate_get(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd, + double *from_degree, + double *to_degree, + Efl_Canvas_Object **pivot, + double *cx, + double *cy) +{ + EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(eo_obj); + + //Update relative pivot based on absolute pivot + if (!pd->use_rel_pivot) + { + Evas_Coord x = 0; + Evas_Coord y = 0; + Evas_Coord w = 0; + Evas_Coord h = 0; + + Efl_Canvas_Object *target = efl_animation_instance_target_get(eo_obj); + if (target) + evas_object_geometry_get(target, &x, &y, &w, &h); + + if (w != 0) + pd->rel_pivot.cx = (double)(pd->abs_pivot.cx - x) / w; + else + pd->rel_pivot.cx = 0.0; + + if (h != 0) + pd->rel_pivot.cy = (double)(pd->abs_pivot.cy - y) / h; + else + pd->rel_pivot.cy = 0.0; + } + + if (from_degree) + *from_degree = pd->from.degree; + + if (to_degree) + *to_degree = pd->to.degree; + + if (pivot) + *pivot = pd->rel_pivot.obj; + + if (cx) + *cx = pd->rel_pivot.cx; + + if (cy) + *cy = pd->rel_pivot.cy; +} + +EOLIAN static void +_efl_animation_instance_rotate_rotate_absolute_set(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd, + double from_degree, + double to_degree, + Evas_Coord cx, + Evas_Coord cy) +{ + EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(eo_obj); + + pd->from.degree = from_degree; + pd->to.degree = to_degree; + + pd->abs_pivot.cx = cx; + pd->abs_pivot.cy = cy; + + //Update relative pivot based on absolute pivot + Evas_Coord x = 0; + Evas_Coord y = 0; + Evas_Coord w = 0; + Evas_Coord h = 0; + + Efl_Canvas_Object *target = efl_animation_instance_target_get(eo_obj); + if (target) + evas_object_geometry_get(target, &x, &y, &w, &h); + + pd->rel_pivot.obj = NULL; + + if (w != 0) + pd->rel_pivot.cx = (double)(cx - x) / w; + else + pd->rel_pivot.cx = 0.0; + + if (h != 0) + pd->rel_pivot.cy = (double)(cy - y) / h; + else + pd->rel_pivot.cy = 0.0; + + pd->use_rel_pivot = EINA_FALSE; +} + +EOLIAN static void +_efl_animation_instance_rotate_rotate_absolute_get(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd, + double *from_degree, + double *to_degree, + Evas_Coord *cx, + Evas_Coord *cy) +{ + EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(eo_obj); + + //Update absolute pivot based on relative pivot + if (pd->use_rel_pivot) + { + Evas_Coord x = 0; + Evas_Coord y = 0; + Evas_Coord w = 0; + Evas_Coord h = 0; + + if (pd->rel_pivot.obj) + evas_object_geometry_get(pd->rel_pivot.obj, &x, &y, &w, &h); + else + { + Efl_Canvas_Object *target + = efl_animation_instance_target_get(eo_obj); + if (target) + evas_object_geometry_get(target, &x, &y, &w, &h); + } + + pd->abs_pivot.cx = x + (w * pd->rel_pivot.cx); + pd->abs_pivot.cy = y + (h * pd->rel_pivot.cy); + } + + if (from_degree) + *from_degree = pd->from.degree; + + if (to_degree) + *to_degree = pd->to.degree; + + if (cx) + *cx = pd->abs_pivot.cx; + + if (cy) + *cy = pd->abs_pivot.cy; +} + +static void +_progress_set(Eo *eo_obj, double progress) +{ + EFL_ANIMATION_INSTANCE_ROTATE_DATA_GET(eo_obj, pd); + + Efl_Canvas_Object *target = efl_animation_instance_target_get(eo_obj); + if (!target) return; + + double degree = + (pd->from.degree * (1.0 - progress)) + (pd->to.degree * progress); + + if (pd->use_rel_pivot) + { + efl_gfx_map_rotate(target, + degree, + pd->rel_pivot.obj, + pd->rel_pivot.cx, pd->rel_pivot.cy); + } + else + { + efl_gfx_map_rotate_absolute(target, + degree, + pd->abs_pivot.cx, pd->abs_pivot.cy); + } +} + +static void +_pre_animate_cb(void *data EINA_UNUSED, const Efl_Event *event) +{ + Efl_Animation_Instance_Animate_Event_Info *event_info = event->info; + + _progress_set(event->object, event_info->progress); +} + +EOLIAN static Efl_Object * +_efl_animation_instance_rotate_efl_object_constructor(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd) +{ + eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS)); + + pd->from.degree = 0.0; + pd->to.degree = 0.0; + + pd->rel_pivot.obj = NULL; + pd->rel_pivot.cx = 0.5; + pd->rel_pivot.cy = 0.5; + + pd->abs_pivot.cx = 0; + pd->abs_pivot.cy = 0; + + pd->use_rel_pivot = EINA_TRUE; + + //pre animate event is supported within class only (protected event) + efl_event_callback_add(eo_obj, EFL_ANIMATION_INSTANCE_EVENT_PRE_ANIMATE, + _pre_animate_cb, NULL); + + return eo_obj; +} + +EOLIAN static void +_efl_animation_instance_rotate_efl_object_destructor(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd EINA_UNUSED) +{ + efl_destructor(efl_super(eo_obj, MY_CLASS)); +} + +EOLIAN static void +_efl_animation_instance_rotate_efl_animation_instance_final_state_show(Eo *eo_obj, + Evas_Object_Animation_Instance_Rotate_Data *pd EINA_UNUSED) +{ + EFL_ANIMATION_INSTANCE_ROTATE_CHECK_OR_RETURN(eo_obj); + + _progress_set(eo_obj, 1.0); +} + +/* Internal EO APIs */ + +EOAPI EFL_VOID_FUNC_BODYV(efl_animation_instance_rotate_set, EFL_FUNC_CALL(from_degree, to_degree, pivot, cx, cy), double from_degree, double to_degree, Efl_Canvas_Object *pivot, double cx, double cy); +EOAPI EFL_VOID_FUNC_BODYV_CONST(efl_animation_instance_rotate_get, EFL_FUNC_CALL(from_degree, to_degree, pivot, cx, cy), double *from_degree, double *to_degree, Efl_Canvas_Object **pivot, double *cx, double *cy); + +EOAPI EFL_VOID_FUNC_BODYV(efl_animation_instance_rotate_absolute_set, EFL_FUNC_CALL(from_degree, to_degree, cx, cy), double from_degree, double to_degree, int cx, int cy); +EOAPI EFL_VOID_FUNC_BODYV_CONST(efl_animation_instance_rotate_absolute_get, EFL_FUNC_CALL(from_degree, to_degree, cx, cy), double *from_degree, double *to_degree, int *cx, int *cy); + +#define EFL_ANIMATION_INSTANCE_ROTATE_EXTRA_OPS \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_rotate_set, _efl_animation_instance_rotate_rotate_set), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_rotate_get, _efl_animation_instance_rotate_rotate_get), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_rotate_absolute_set, _efl_animation_instance_rotate_rotate_absolute_set), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_rotate_absolute_get, _efl_animation_instance_rotate_rotate_absolute_get), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_final_state_show, _efl_animation_instance_rotate_efl_animation_instance_final_state_show) + +#include "efl_animation_instance_rotate.eo.c" diff --git a/src/lib/evas/canvas/efl_animation_instance_rotate.eo b/src/lib/evas/canvas/efl_animation_instance_rotate.eo new file mode 100644 index 0000000000..15523c2712 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_instance_rotate.eo @@ -0,0 +1,12 @@ +import efl_animation_types; + +class Efl.Animation.Instance.Rotate (Efl.Animation.Instance) +{ + [[Efl rotate animation instance class]] + legacy_prefix: evas_object_animation_instance; + data: Evas_Object_Animation_Instance_Rotate_Data; + implements { + Efl.Object.constructor; + Efl.Object.destructor; + } +} diff --git a/src/lib/evas/canvas/efl_animation_rotate.c b/src/lib/evas/canvas/efl_animation_rotate.c index 0462b49f0c..15d5480b05 100644 --- a/src/lib/evas/canvas/efl_animation_rotate.c +++ b/src/lib/evas/canvas/efl_animation_rotate.c @@ -220,6 +220,45 @@ _efl_animation_rotate_rotate_absolute_get(Eo *eo_obj, *cy = pd->abs_pivot.cy; } +EOLIAN static Efl_Animation_Instance * +_efl_animation_rotate_efl_animation_instance_create(Eo *eo_obj, + Evas_Object_Animation_Rotate_Data *pd) +{ + EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(eo_obj, NULL); + + Efl_Animation_Instance_Rotate *instance + = efl_add(EFL_ANIMATION_INSTANCE_ROTATE_CLASS, NULL); + + Efl_Canvas_Object *target = efl_animation_target_get(eo_obj); + efl_animation_instance_target_set(instance, target); + + Eina_Bool state_keep = efl_animation_final_state_keep_get(eo_obj); + efl_animation_instance_final_state_keep_set(instance, state_keep); + + double duration = efl_animation_duration_get(eo_obj); + efl_animation_instance_duration_set(instance, duration); + + if (pd->use_rel_pivot) + { + efl_animation_instance_rotate_set(instance, + pd->from.degree, + pd->to.degree, + pd->rel_pivot.obj, + pd->rel_pivot.cx, + pd->rel_pivot.cy); + } + else + { + efl_animation_instance_rotate_absolute_set(instance, + pd->from.degree, + pd->to.degree, + pd->abs_pivot.cx, + pd->abs_pivot.cy); + } + + return instance; +} + EOLIAN static Efl_Object * _efl_animation_rotate_efl_object_constructor(Eo *eo_obj, Evas_Object_Animation_Rotate_Data *pd) diff --git a/src/lib/evas/canvas/efl_animation_rotate.eo b/src/lib/evas/canvas/efl_animation_rotate.eo index 4f1429265a..d72c458707 100644 --- a/src/lib/evas/canvas/efl_animation_rotate.eo +++ b/src/lib/evas/canvas/efl_animation_rotate.eo @@ -35,5 +35,6 @@ class Efl.Animation.Rotate (Efl.Animation) implements { Efl.Object.constructor; Efl.Object.destructor; + Efl.Animation.instance_create; } } diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h index ca83e6b23e..eb6ca1ccf2 100644 --- a/src/lib/evas/include/evas_private.h +++ b/src/lib/evas/include/evas_private.h @@ -112,6 +112,7 @@ typedef struct _Evas_Object_Animation_Alpha_Data Evas_Objec typedef struct _Evas_Object_Animation_Rotate_Data Evas_Object_Animation_Rotate_Data; typedef struct _Evas_Object_Animation_Data Evas_Object_Animation_Data; typedef struct _Evas_Object_Animation_Instance_Alpha_Data Evas_Object_Animation_Instance_Alpha_Data; +typedef struct _Evas_Object_Animation_Instance_Rotate_Data Evas_Object_Animation_Instance_Rotate_Data; typedef struct _Evas_Object_Animation_Instance_Data Evas_Object_Animation_Instance_Data; // 3D stuff |