diff options
author | Jaehyun Cho <jae_hyun.cho@samsung.com> | 2017-08-25 12:03:08 +0900 |
---|---|---|
committer | Jaehyun Cho <jae_hyun.cho@samsung.com> | 2017-09-18 20:47:22 +0900 |
commit | aa91ad31c12f4b91a9bfbce33ad3989d5ebbd7b9 (patch) | |
tree | 90d60fbe10ab4d38349a30b287d08458b21a9bca | |
parent | 831437ecad63a59d31a039c21d449a150a24b32c (diff) | |
download | efl-aa91ad31c12f4b91a9bfbce33ad3989d5ebbd7b9.tar.gz |
efl_animation: Add scale animation instance
-rw-r--r-- | src/Makefile_Evas.am | 5 | ||||
-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 | 8 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_instance_scale.c | 297 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_instance_scale.eo | 10 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_instance_scale_private.h | 49 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_scale.c | 40 | ||||
-rw-r--r-- | src/lib/evas/canvas/efl_animation_scale.eo | 1 |
9 files changed, 417 insertions, 1 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am index 76ffaf1d57..536d412783 100644 --- a/src/Makefile_Evas.am +++ b/src/Makefile_Evas.am @@ -51,6 +51,7 @@ evas_eolian_pub_files = \ lib/evas/canvas/efl_animation_instance.eo \ lib/evas/canvas/efl_animation_instance_alpha.eo \ lib/evas/canvas/efl_animation_instance_rotate.eo \ + lib/evas/canvas/efl_animation_instance_scale.eo \ $(NULL) evas_eolian_legacy_files = \ @@ -135,7 +136,8 @@ lib/evas/canvas/efl_animation_rotate_private.h \ lib/evas/canvas/efl_animation_scale_private.h \ lib/evas/canvas/efl_animation_instance_private.h \ lib/evas/canvas/efl_animation_instance_alpha_private.h \ -lib/evas/canvas/efl_animation_instance_rotate_private.h +lib/evas/canvas/efl_animation_instance_rotate_private.h \ +lib/evas/canvas/efl_animation_instance_scale_private.h # Linebreak @@ -228,6 +230,7 @@ lib/evas/canvas/efl_animation_scale.c \ lib/evas/canvas/efl_animation_instance.c \ lib/evas/canvas/efl_animation_instance_alpha.c \ lib/evas/canvas/efl_animation_instance_rotate.c \ +lib/evas/canvas/efl_animation_instance_scale.c \ $(NULL) EXTRA_DIST2 += \ diff --git a/src/lib/evas/Evas_Common.h b/src/lib/evas/Evas_Common.h index 88807897f4..c87fa3ce63 100644 --- a/src/lib/evas/Evas_Common.h +++ b/src/lib/evas/Evas_Common.h @@ -3372,6 +3372,13 @@ typedef Eo Efl_Animation_Instance_Rotate; #endif +#ifndef _EFL_ANIMATION_INSTANCE_SCALE_EO_CLASS_TYPE +#define _EFL_ANIMATION_INSTANCE_SCALE_EO_CLASS_TYPE + +typedef Eo Efl_Animation_Instance_Scale; + +#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 b5c39dc6a9..ac367aac35 100644 --- a/src/lib/evas/Evas_Eo.h +++ b/src/lib/evas/Evas_Eo.h @@ -62,6 +62,7 @@ #include "canvas/efl_animation_instance.eo.h" #include "canvas/efl_animation_instance_alpha.eo.h" #include "canvas/efl_animation_instance_rotate.eo.h" +#include "canvas/efl_animation_instance_scale.eo.h" #endif /* EFL_EO_API_SUPPORT */ diff --git a/src/lib/evas/Evas_Internal.h b/src/lib/evas/Evas_Internal.h index b791e5a3b7..30104c8baa 100644 --- a/src/lib/evas/Evas_Internal.h +++ b/src/lib/evas/Evas_Internal.h @@ -107,6 +107,14 @@ EOAPI void efl_animation_instance_rotate_absolute_set(Eo *obj, double from_degre EOAPI void efl_animation_instance_rotate_absolute_get(const Eo *obj, double *from_degree, double *to_degree, int *cx, int *cy); /* Efl.Animation.Instance.Rotate END */ +/* Efl.Animation.Instance.Scale */ +EOAPI void efl_animation_instance_scale_set(Eo *obj, double from_scale_x, double from_scale_y, double to_scale_x, double to_scale_y, Efl_Canvas_Object *pivot, double cx, double cy); +EOAPI void efl_animation_instance_scale_get(const Eo *obj, double *from_scale_x, double *from_scale_y, double *to_scale_x, double *to_scale_y, Efl_Canvas_Object **pivot, double *cx, double *cy); + +EOAPI void efl_animation_instance_scale_absolute_set(Eo *obj, double from_scale_x, double from_scale_y, double to_scale_x, double to_scale_y, int cx, int cy); +EOAPI void efl_animation_instance_scale_absolute_get(const Eo *obj, double *from_scale_x, double *from_scale_y, double *to_scale_x, double *to_scale_y, int *cx, int *cy); +/* Efl.Animation.Instance.Scale END */ + #ifdef __cplusplus } #endif diff --git a/src/lib/evas/canvas/efl_animation_instance_scale.c b/src/lib/evas/canvas/efl_animation_instance_scale.c new file mode 100644 index 0000000000..d2923ce486 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_instance_scale.c @@ -0,0 +1,297 @@ +#include "efl_animation_instance_scale_private.h" + +EOLIAN static void +_efl_animation_instance_scale_scale_set(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd, + double from_scale_x, + double from_scale_y, + double to_scale_x, + double to_scale_y, + Efl_Canvas_Object *pivot, + double cx, + double cy) +{ + EFL_ANIMATION_INSTANCE_SCALE_CHECK_OR_RETURN(eo_obj); + + pd->from.scale_x = from_scale_x; + pd->from.scale_y = from_scale_y; + + pd->to.scale_x = to_scale_x; + pd->to.scale_y = to_scale_y; + + 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_scale_scale_get(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd, + double *from_scale_x, + double *from_scale_y, + double *to_scale_x, + double *to_scale_y, + Efl_Canvas_Object **pivot, + double *cx, + double *cy) +{ + EFL_ANIMATION_INSTANCE_SCALE_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_scale_x) + *from_scale_x = pd->from.scale_x; + + if (from_scale_y) + *from_scale_y = pd->from.scale_y; + + if (to_scale_x) + *to_scale_x = pd->to.scale_x; + + if (to_scale_y) + *to_scale_y = pd->to.scale_y; + + 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_scale_scale_absolute_set(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd, + double from_scale_x, + double from_scale_y, + double to_scale_x, + double to_scale_y, + Evas_Coord cx, + Evas_Coord cy) +{ + EFL_ANIMATION_INSTANCE_SCALE_CHECK_OR_RETURN(eo_obj); + + pd->from.scale_x = from_scale_x; + pd->from.scale_y = from_scale_y; + + pd->to.scale_x = to_scale_x; + pd->to.scale_y = to_scale_y; + + 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_scale_scale_absolute_get(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd, + double *from_scale_x, + double *from_scale_y, + double *to_scale_x, + double *to_scale_y, + Evas_Coord *cx, + Evas_Coord *cy) +{ + EFL_ANIMATION_INSTANCE_SCALE_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_scale_x) + *from_scale_x = pd->from.scale_x; + + if (from_scale_y) + *from_scale_y = pd->from.scale_y; + + if (to_scale_x) + *to_scale_x = pd->to.scale_x; + + if (to_scale_y) + *to_scale_y = pd->to.scale_y; + + if (cx) + *cx = pd->abs_pivot.cx; + + if (cy) + *cy = pd->abs_pivot.cy; +} + +EOLIAN static void +_efl_animation_instance_scale_efl_animation_instance_duration_set(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd EINA_UNUSED, + double duration) +{ + EFL_ANIMATION_INSTANCE_SCALE_CHECK_OR_RETURN(eo_obj); + + /* For a single animation instance, duration should be equal to or bigger + * than 0.0. */ + if (duration < 0.0) return; + + //For a single animation instance, total duration is the same as duration. + efl_animation_instance_total_duration_set(eo_obj, duration); + + efl_animation_instance_duration_set(efl_super(eo_obj, MY_CLASS), duration); +} + +static void +_progress_set(Eo *eo_obj, double progress) +{ + EFL_ANIMATION_INSTANCE_SCALE_DATA_GET(eo_obj, pd); + + Efl_Canvas_Object *target = efl_animation_instance_target_get(eo_obj); + if (!target) return; + + double scale_x = + (pd->from.scale_x * (1.0 - progress)) + (pd->to.scale_x * progress); + + double scale_y = + (pd->from.scale_y * (1.0 - progress)) + (pd->to.scale_y * progress); + + if (pd->use_rel_pivot) + { + efl_gfx_map_zoom(target, + scale_x, scale_y, + pd->rel_pivot.obj, + pd->rel_pivot.cx, pd->rel_pivot.cy); + } + else + { + efl_gfx_map_zoom_absolute(target, + scale_x, scale_y, + 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_scale_efl_object_constructor(Eo *eo_obj, + Efl_Animation_Instance_Scale_Data *pd) +{ + eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS)); + + pd->from.scale_x = 1.0; + pd->from.scale_y = 1.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; +} + +/* Internal EO APIs */ + +EOAPI EFL_VOID_FUNC_BODYV(efl_animation_instance_scale_set, EFL_FUNC_CALL(from_scale_x, from_scale_y, to_scale_x, to_scale_y, pivot, cx, cy), double from_scale_x, double from_scale_y, double to_scale_x, double to_scale_y, Efl_Canvas_Object *pivot, double cx, double cy); +EOAPI EFL_VOID_FUNC_BODYV_CONST(efl_animation_instance_scale_get, EFL_FUNC_CALL(from_scale_x, from_scale_y, to_scale_x, to_scale_y, pivot, cx, cy), double *from_scale_x, double *from_scale_y, double *to_scale_x, double *to_scale_y, Efl_Canvas_Object **pivot, double *cx, double *cy); + +EOAPI EFL_VOID_FUNC_BODYV(efl_animation_instance_scale_absolute_set, EFL_FUNC_CALL(from_scale_x, from_scale_y, to_scale_x, to_scale_y, cx, cy), double from_scale_x, double from_scale_y, double to_scale_x, double to_scale_y, int cx, int cy); +EOAPI EFL_VOID_FUNC_BODYV_CONST(efl_animation_instance_scale_absolute_get, EFL_FUNC_CALL(from_scale_x, from_scale_y, to_scale_x, to_scale_y, cx, cy), double *from_scale_x, double *from_scale_y, double *to_scale_x, double *to_scale_y, int *cx, int *cy); + +#define EFL_ANIMATION_INSTANCE_SCALE_EXTRA_OPS \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_scale_set, _efl_animation_instance_scale_scale_set), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_scale_get, _efl_animation_instance_scale_scale_get), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_scale_absolute_set, _efl_animation_instance_scale_scale_absolute_set), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_scale_absolute_get, _efl_animation_instance_scale_scale_absolute_get), \ + EFL_OBJECT_OP_FUNC(efl_animation_instance_duration_set, _efl_animation_instance_scale_efl_animation_instance_duration_set) + +#include "efl_animation_instance_scale.eo.c" diff --git a/src/lib/evas/canvas/efl_animation_instance_scale.eo b/src/lib/evas/canvas/efl_animation_instance_scale.eo new file mode 100644 index 0000000000..6c8bf0b2cc --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_instance_scale.eo @@ -0,0 +1,10 @@ +import efl_animation_types; + +class Efl.Animation.Instance.Scale (Efl.Animation.Instance) +{ + [[Efl scale animation instance class]] + data: Efl_Animation_Instance_Scale_Data; + implements { + Efl.Object.constructor; + } +} diff --git a/src/lib/evas/canvas/efl_animation_instance_scale_private.h b/src/lib/evas/canvas/efl_animation_instance_scale_private.h new file mode 100644 index 0000000000..bf050f33b3 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_instance_scale_private.h @@ -0,0 +1,49 @@ +#define EFL_ANIMATION_INSTANCE_PROTECTED +#define EFL_ANIMATION_INSTANCE_SCALE_PROTECTED + +#include "evas_common_private.h" + +#define MY_CLASS EFL_ANIMATION_INSTANCE_SCALE_CLASS +#define MY_CLASS_NAME efl_class_name_get(MY_CLASS) + +#define EFL_ANIMATION_INSTANCE_SCALE_CHECK_OR_RETURN(inst, ...) \ + do { \ + if (!inst) { \ + CRI("Efl_Animation_Instance " # inst " is NULL!"); \ + return __VA_ARGS__; \ + } \ + if (efl_animation_instance_is_deleted(inst)) { \ + ERR("Efl_Animation_Instance " # inst " has already been deleted!"); \ + return __VA_ARGS__; \ + } \ + } while (0) + +#define EFL_ANIMATION_INSTANCE_SCALE_DATA_GET(o, pd) \ + Efl_Animation_Instance_Scale_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_INSTANCE_SCALE_CLASS) + +typedef struct _Efl_Animation_Instance_Scale_Property +{ + double scale_x, scale_y; +} Efl_Animation_Instance_Scale_Property; + +typedef struct _Efl_Animation_Instance_Scale_Absolute_Pivot +{ + Evas_Coord cx, cy; +} Efl_Animation_Instance_Scale_Absolute_Pivot; + +typedef struct _Efl_Animation_Instance_Scale_Relative_Pivot +{ + Efl_Canvas_Object *obj; + double cx, cy; +} Efl_Animation_Instance_Scale_Relative_Pivot; + +typedef struct _Efl_Animation_Instance_Scale_Data +{ + Efl_Animation_Instance_Scale_Property from; + Efl_Animation_Instance_Scale_Property to; + + Efl_Animation_Instance_Scale_Absolute_Pivot abs_pivot; + Efl_Animation_Instance_Scale_Relative_Pivot rel_pivot; + + Eina_Bool use_rel_pivot; +} Efl_Animation_Instance_Scale_Data; diff --git a/src/lib/evas/canvas/efl_animation_scale.c b/src/lib/evas/canvas/efl_animation_scale.c index fa624ae83c..2ffb2885b7 100644 --- a/src/lib/evas/canvas/efl_animation_scale.c +++ b/src/lib/evas/canvas/efl_animation_scale.c @@ -216,6 +216,46 @@ _efl_animation_scale_efl_animation_duration_set(Eo *eo_obj, efl_animation_duration_set(efl_super(eo_obj, MY_CLASS), duration); } +EOLIAN static Efl_Animation_Instance * +_efl_animation_scale_efl_animation_instance_create(Eo *eo_obj, + Efl_Animation_Scale_Data *pd) +{ + EFL_ANIMATION_SCALE_CHECK_OR_RETURN(eo_obj, NULL); + + Efl_Animation_Instance_Scale *instance + = efl_add(EFL_ANIMATION_INSTANCE_SCALE_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); + + double total_duration = efl_animation_total_duration_get(eo_obj); + efl_animation_instance_total_duration_set(instance, total_duration); + + if (pd->use_rel_pivot) + { + efl_animation_instance_scale_set(instance, + pd->from.scale_x, pd->from.scale_y, + pd->to.scale_x, pd->to.scale_y, + pd->rel_pivot.obj, + pd->rel_pivot.cx, pd->rel_pivot.cy); + } + else + { + efl_animation_instance_scale_absolute_set(instance, + pd->from.scale_x, pd->from.scale_y, + pd->to.scale_x, pd->to.scale_y, + pd->abs_pivot.cx, pd->abs_pivot.cy); + } + + return instance; +} + EOLIAN static Efl_Object * _efl_animation_scale_efl_object_constructor(Eo *eo_obj, Efl_Animation_Scale_Data *pd) diff --git a/src/lib/evas/canvas/efl_animation_scale.eo b/src/lib/evas/canvas/efl_animation_scale.eo index 7e3be30b57..5fb32ee8fb 100644 --- a/src/lib/evas/canvas/efl_animation_scale.eo +++ b/src/lib/evas/canvas/efl_animation_scale.eo @@ -38,5 +38,6 @@ class Efl.Animation.Scale (Efl.Animation) implements { Efl.Object.constructor; Efl.Animation.duration { set; } + Efl.Animation.instance_create; } } |