From d4f96f97289eab6ea810ee8fc14b6c29ccec15ae Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Fri, 25 Aug 2017 11:10:58 +0900 Subject: [PATCH] efl_animation: Add rotate animation --- src/Makefile_Evas.am | 3 + src/lib/evas/Evas_Common.h | 7 + src/lib/evas/Evas_Eo.h | 1 + src/lib/evas/canvas/efl_animation_rotate.c | 198 ++++++++++++++++++ src/lib/evas/canvas/efl_animation_rotate.eo | 37 ++++ .../canvas/efl_animation_rotate_private.h | 48 +++++ 6 files changed, 294 insertions(+) create mode 100644 src/lib/evas/canvas/efl_animation_rotate.c create mode 100644 src/lib/evas/canvas/efl_animation_rotate.eo create mode 100644 src/lib/evas/canvas/efl_animation_rotate_private.h diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am index 8da24671ef..87cc6ea03b 100644 --- a/src/Makefile_Evas.am +++ b/src/Makefile_Evas.am @@ -46,6 +46,7 @@ evas_eolian_pub_files = \ lib/evas/canvas/efl_gfx_map.eo \ lib/evas/canvas/efl_animation.eo \ lib/evas/canvas/efl_animation_alpha.eo \ + lib/evas/canvas/efl_animation_rotate.eo \ lib/evas/canvas/efl_animation_object.eo \ lib/evas/canvas/efl_animation_object_alpha.eo \ $(NULL) @@ -128,6 +129,7 @@ lib/evas/canvas/efl_canvas_surface.h \ lib/evas/common3d/primitives/primitive_common.h \ lib/evas/canvas/efl_animation_private.h \ lib/evas/canvas/efl_animation_alpha_private.h \ +lib/evas/canvas/efl_animation_rotate_private.h \ lib/evas/canvas/efl_animation_object_private.h \ lib/evas/canvas/efl_animation_object_alpha_private.h @@ -217,6 +219,7 @@ lib/evas/canvas/efl_input_hold.c \ lib/evas/canvas/efl_input_focus.c \ lib/evas/canvas/efl_animation.c \ lib/evas/canvas/efl_animation_alpha.c \ +lib/evas/canvas/efl_animation_rotate.c \ lib/evas/canvas/efl_animation_object.c \ lib/evas/canvas/efl_animation_object_alpha.c \ $(NULL) diff --git a/src/lib/evas/Evas_Common.h b/src/lib/evas/Evas_Common.h index 6cbd287e39..47fe1d7292 100644 --- a/src/lib/evas/Evas_Common.h +++ b/src/lib/evas/Evas_Common.h @@ -3344,6 +3344,13 @@ typedef Eo Efl_Animation_Alpha; #endif +#ifndef _EFL_ANIMATION_ROTATE_EO_CLASS_TYPE +#define _EFL_ANIMATION_ROTATE_EO_CLASS_TYPE + +typedef Eo Efl_Animation_Rotate; + +#endif + #ifndef _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE #define _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h index d806deaa8d..811f2523a7 100644 --- a/src/lib/evas/Evas_Eo.h +++ b/src/lib/evas/Evas_Eo.h @@ -57,6 +57,7 @@ #include "canvas/efl_animation.eo.h" #include "canvas/efl_animation_alpha.eo.h" +#include "canvas/efl_animation_rotate.eo.h" #include "canvas/efl_animation_object.eo.h" #include "canvas/efl_animation_object_alpha.eo.h" diff --git a/src/lib/evas/canvas/efl_animation_rotate.c b/src/lib/evas/canvas/efl_animation_rotate.c new file mode 100644 index 0000000000..31b590f565 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_rotate.c @@ -0,0 +1,198 @@ +#include "efl_animation_rotate_private.h" + +EOLIAN static void +_efl_animation_rotate_rotate_set(Eo *eo_obj, + Efl_Animation_Rotate_Data *pd, + double from_degree, + double to_degree, + Efl_Canvas_Object *pivot, + double cx, + double cy) +{ + EFL_ANIMATION_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_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_rotate_rotate_get(Eo *eo_obj, + Efl_Animation_Rotate_Data *pd, + double *from_degree, + double *to_degree, + Efl_Canvas_Object **pivot, + double *cx, + double *cy) +{ + EFL_ANIMATION_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_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_rotate_rotate_absolute_set(Eo *eo_obj, + Efl_Animation_Rotate_Data *pd, + double from_degree, + double to_degree, + Evas_Coord cx, + Evas_Coord cy) +{ + EFL_ANIMATION_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_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_rotate_rotate_absolute_get(Eo *eo_obj, + Efl_Animation_Rotate_Data *pd, + double *from_degree, + double *to_degree, + Evas_Coord *cx, + Evas_Coord *cy) +{ + EFL_ANIMATION_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; + + if (pd->rel_pivot.obj) + evas_object_geometry_get(pd->rel_pivot.obj, &x, &y, &w, &h); + else + { + Efl_Canvas_Object *target = efl_animation_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; +} + +EOLIAN static Efl_Object * +_efl_animation_rotate_efl_object_constructor(Eo *eo_obj, + Efl_Animation_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; + + return eo_obj; +} + +#include "efl_animation_rotate.eo.c" diff --git a/src/lib/evas/canvas/efl_animation_rotate.eo b/src/lib/evas/canvas/efl_animation_rotate.eo new file mode 100644 index 0000000000..d42415e934 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_rotate.eo @@ -0,0 +1,37 @@ +import efl_animation_types; + +class Efl.Animation.Rotate (Efl.Animation) +{ + [[Efl rotate animation class]] + data: Efl_Animation_Rotate_Data; + methods { + @property rotate { + set { + } + get { + } + values { + from_degree: double; [[Rotation degree when animation starts]] + to_degree: double; [[Rotation degree when animation ends]] + pivot: Efl.Canvas.Object; [[Pivot object for the center point. If the pivot object is NULL, then the object is rotated on itself.]] + cx: double; [[X relative coordinate of the center point. The left end is 0.0 and the right end is 1.0 (the center is 0.5).]] + cy: double; [[Y relative coordinate of the center point. The top end is 0.0 and the bottom end is 1.0 (the center is 0.5).]] + } + } + @property rotate_absolute { + set { + } + get { + } + values { + from_degree: double; [[Rotation degree when animation starts]] + to_degree: double; [[Rotation degree when animation ends]] + cx: int; [[X absolute coordinate of the center point.]] + cy: int; [[Y absolute coordinate of the center point.]] + } + } + } + implements { + Efl.Object.constructor; + } +} diff --git a/src/lib/evas/canvas/efl_animation_rotate_private.h b/src/lib/evas/canvas/efl_animation_rotate_private.h new file mode 100644 index 0000000000..58e7d12554 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_rotate_private.h @@ -0,0 +1,48 @@ +#define EFL_ANIMATION_PROTECTED + +#include "evas_common_private.h" + +#define MY_CLASS EFL_ANIMATION_ROTATE_CLASS +#define MY_CLASS_NAME efl_class_name_get(MY_CLASS) + +#define EFL_ANIMATION_ROTATE_CHECK_OR_RETURN(anim, ...) \ + do { \ + if (!anim) { \ + CRI("Efl_Animation " # anim " is NULL!"); \ + return __VA_ARGS__; \ + } \ + if (efl_animation_is_deleted(anim)) { \ + ERR("Efl_Animation " # anim " has already been deleted!"); \ + return __VA_ARGS__; \ + } \ + } while (0) + +#define EFL_ANIMATION_ROTATE_DATA_GET(o, pd) \ + Efl_Animation_Rotate_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_ROTATE_CLASS) + +typedef struct _Efl_Animation_Rotate_Property +{ + double degree; +} Efl_Animation_Rotate_Property; + +typedef struct _Efl_Animation_Rotate_Absolute_Pivot +{ + Evas_Coord cx, cy; +} Efl_Animation_Rotate_Absolute_Pivot; + +typedef struct _Efl_Animation_Rotate_Relative_Pivot +{ + Efl_Canvas_Object *obj; + double cx, cy; +} Efl_Animation_Rotate_Relative_Pivot; + +typedef struct _Efl_Animation_Rotate_Data +{ + Efl_Animation_Rotate_Property from; + Efl_Animation_Rotate_Property to; + + Efl_Animation_Rotate_Absolute_Pivot abs_pivot; + Efl_Animation_Rotate_Relative_Pivot rel_pivot; + + Eina_Bool use_rel_pivot; +} Efl_Animation_Rotate_Data;