summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-07-02 12:18:12 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-07-02 12:18:32 +0200
commite7e3e7798c0204bec46a18ddc49bc90f9bdb56b7 (patch)
treec797931bc938194cdedcb546139f38cbf9fffede
parent31ed46bc17478d6438f8421d693f333618960973 (diff)
downloadefl-devs/jeyzu/eo_add_custom_death.tar.gz
ecore: animator use eo_add() instead of eo_add_custom()devs/jeyzu/eo_add_custom_death
see 31ed46bc and f92e5d50
-rw-r--r--src/lib/ecore/ecore_anim.c80
-rw-r--r--src/lib/ecore/ecore_animator.eo68
-rw-r--r--src/tests/ecore/ecore_test_animator.c7
3 files changed, 99 insertions, 56 deletions
diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c
index 892359f2ab..0eda5ed0b3 100644
--- a/src/lib/ecore/ecore_anim.c
+++ b/src/lib/ecore/ecore_anim.c
@@ -37,7 +37,7 @@ struct _Ecore_Animator_Data
typedef struct _Ecore_Animator_Data Ecore_Animator_Data;
-static Eina_Bool _ecore_animator_run(void *data);
+static Eina_Bool _ecore_animator_timeline_run(void *data);
static Eina_Bool _ecore_animator(void *data);
static int animators_delete_me = 0;
@@ -154,42 +154,35 @@ _do_tick(void)
return ECORE_CALLBACK_RENEW;
}
-static Eina_Bool
-_ecore_animator_add(Ecore_Animator *obj,
- Ecore_Animator_Data *animator,
- Ecore_Task_Cb func,
- const void *data)
+EOLIAN static Eo *
+_ecore_animator_eo_base_finalize(Eo *obj, Ecore_Animator_Data *animator)
{
- if (EINA_UNLIKELY(!eina_main_loop_is()))
- {
- eo_error_set(obj);
- EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
- }
-
- animator->obj = obj;
- eo_do_super(obj, MY_CLASS, eo_constructor());
- eo_manual_free_set(obj, EINA_TRUE);
-
- if (!func)
+ if (!animator->func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
- return EINA_FALSE;
+ goto finalize;
}
- animator->func = func;
- animator->data = (void *)data;
+ if (EINA_UNLIKELY(!eina_main_loop_is()))
+ {
+ eo_error_set(obj);
+ EINA_MAIN_LOOP_CHECK_RETURN_VAL(
+ eo_do_super(obj, MY_CLASS, eo_finalize()));
+ goto finalize;
+ }
+
+ _ecore_lock();
+
+ eo_manual_free_set(obj, EINA_TRUE);
animator->just_added = EINA_TRUE;
animators = (Ecore_Animator_Data *)eina_inlist_append(EINA_INLIST_GET(animators), EINA_INLIST_GET(animator));
+
_begin_tick();
- return EINA_TRUE;
-}
+ _ecore_unlock();
-EOLIAN static void
-_ecore_animator_eo_base_constructor(Eo *obj, Ecore_Animator_Data *_pd EINA_UNUSED)
-{
- eo_error_set(obj);
- ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
+finalize:
+ return eo_do_super(obj, MY_CLASS, eo_finalize());
}
EAPI Ecore_Animator *
@@ -198,17 +191,23 @@ ecore_animator_add(Ecore_Task_Cb func,
{
Ecore_Animator *animator = NULL;
- animator = eo_add_custom(MY_CLASS, _ecore_parent,
- ecore_animator_constructor(func, data));
+ animator = eo_add(MY_CLASS, _ecore_parent,
+ ecore_obj_animator_task_set(func, data));
eo_unref(animator);
return animator;
}
EOLIAN static void
-_ecore_animator_constructor(Eo *obj, Ecore_Animator_Data *animator, Ecore_Task_Cb func, const void *data)
+_ecore_animator_task_set(Eo *obj, Ecore_Animator_Data *animator, Ecore_Task_Cb func, const void *data)
{
+ if (func == NULL) return;
+
_ecore_lock();
- _ecore_animator_add(obj, animator, func, data);
+
+ animator->obj = obj;
+ animator->func = func;
+ animator->data = (void *)data;
+
_ecore_unlock();
}
@@ -218,27 +217,28 @@ ecore_animator_timeline_add(double runtime,
const void *data)
{
Ecore_Animator *animator;
- animator = eo_add_custom(MY_CLASS, _ecore_parent,
- ecore_animator_timeline_constructor(runtime, func, data));
+ animator = eo_add(MY_CLASS, _ecore_parent,
+ ecore_obj_animator_timeline_set(runtime, func, data));
eo_unref(animator);
return animator;
}
EOLIAN static void
-_ecore_animator_timeline_constructor(Eo *obj, Ecore_Animator_Data *animator, double runtime, Ecore_Timeline_Cb func, const void *data)
+_ecore_animator_timeline_set(Eo *obj, Ecore_Animator_Data *animator, double runtime, Ecore_Timeline_Cb func, const void *data)
{
- _ecore_lock();
- if (runtime <= 0.0) runtime = 0.0;
+ if (func == NULL) return;
+ if (runtime < 0.0) runtime = 0.0;
- if (!_ecore_animator_add(obj, animator, _ecore_animator_run, NULL)) goto unlock;
+ _ecore_lock();
+ animator->obj = obj;
+ animator->func = _ecore_animator_timeline_run;
animator->data = obj;
animator->run_func = func;
animator->run_data = (void *)data;
animator->start = ecore_loop_time_get();
animator->run = runtime;
-unlock:
_ecore_unlock();
}
@@ -656,7 +656,7 @@ _ecore_animator_run_get(void)
}
static Eina_Bool
-_ecore_animator_run(void *data)
+_ecore_animator_timeline_run(void *data)
{
Ecore_Animator *obj = data;
Ecore_Animator_Data *animator = eo_data_scope_get(obj, MY_CLASS);
@@ -687,4 +687,4 @@ _ecore_animator(void *data EINA_UNUSED)
return r;
}
-#include "ecore_animator.eo.c" \ No newline at end of file
+#include "ecore_animator.eo.c"
diff --git a/src/lib/ecore/ecore_animator.eo b/src/lib/ecore/ecore_animator.eo
index e9a3999dda..9a548c99cd 100644
--- a/src/lib/ecore/ecore_animator.eo
+++ b/src/lib/ecore/ecore_animator.eo
@@ -1,26 +1,66 @@
class Ecore.Animator (Eo.Base)
{
- eo_prefix: ecore_animator;
- constructors {
- timeline_constructor {
- /*@ Contructor. */
- params {
- @in double runtime;
- @in Ecore_Timeline_Cb func;
- @in const(void)* data;
+ legacy_prefix: null;
+ eo_prefix: ecore_obj_animator;
+ properties {
+ task {
+ set {
+ /*@
+ Set the @p func to be called at every animation tick during main loop execution.
+
+ The function @p func will be called every N seconds where N is
+ the @p frametime interval set by ecore_animator_frametime_set(). The
+ function will be passed the @p data pointer as its parameter.
+
+ When the animator @p func is called, it must return a boolean value.
+ If it returns EINA_TRUE (or ECORE_CALLBACK_RENEW), it will be called again at
+ the next tick, or if it returns EINA_FALSE (or ECORE_CALLBACK_CANCEL) it will be
+ deleted automatically making any references/handles for it invalid.
+
+ @note The default @p frametime value is 1/30th of a second.
+
+ @see ecore_obj_animator_timeline_set()
+ @see ecore_animator_frametime_set() */
+ }
+ values {
+ Ecore_Task_Cb func; /*@ The function to call when it ticks off */
+ const(void)* data; /*@ The data to pass to the function */
}
}
- constructor {
- /*@ Contructor. */
- params {
- @in Ecore_Task_Cb func;
- @in const(void)* data;
+ timeline {
+ set {
+ /*@
+ Set the @p func to be called at every animation tick during main loop execution, that runs for a limited time
+
+ This function is just like ecore_obj_animator_task_set() except the animator only
+ runs for a limited time specified in seconds by @p runtime. Once the
+ runtime the animator has elapsed (animator finished) it will automatically
+ be deleted. The callback function @p func can return ECORE_CALLBACK_RENEW
+ to keep the animator running or ECORE_CALLBACK_CANCEL ro stop it and have
+ it be deleted automatically at any time.
+
+ The @p func will ALSO be passed a position parameter that will be in value
+ from 0.0 to 1.0 to indicate where along the timeline (0.0 start, 1.0 end)
+ the animator run is at. If the callback wishes not to have a linear
+ transition it can "map" this value to one of several curves and mappings
+ via ecore_animator_pos_map().
+
+ @note The default @p frametime value is 1/30th of a second.
+
+ @see ecore_obj_animator_task_set()
+ @see ecore_animator_pos_map()
+ @since 1.1.0 */
+ }
+ values {
+ double runtime; /*@ The time to run in seconds */
+ Ecore_Timeline_Cb func; /*@ The function to call when it ticks off */
+ const(void)* data; /*@ The data to pass to the function */
}
}
}
implements {
- Eo.Base.constructor;
Eo.Base.destructor;
+ Eo.Base.finalize;
Eo.Base.event_freeze;
Eo.Base.event_thaw;
}
diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c
index 852e8b58d7..f2816bfd38 100644
--- a/src/tests/ecore/ecore_test_animator.c
+++ b/src/tests/ecore/ecore_test_animator.c
@@ -29,15 +29,18 @@ START_TEST(ecore_test_animators)
fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
ecore_animator_frametime_set(interval1);
- animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval1));
+ animator = eo_add(ECORE_ANIMATOR_CLASS, NULL);
+ fail_if(animator);
+
+ animator = eo_add(ECORE_ANIMATOR_CLASS, NULL, ecore_obj_animator_timeline_set(1, _anim_cb, &interval1));
fail_if(!animator);
ecore_main_loop_begin();
ecore_animator_frametime_set(interval2);
prev = 0;
- animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval2));
+ animator = eo_add(ECORE_ANIMATOR_CLASS, NULL, ecore_obj_animator_timeline_set(1, _anim_cb, &interval2));
fail_if(!animator);
ecore_main_loop_begin();