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 *
{
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_init(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_init(Eo *obj, Ecore_Animator_Data *animator, Ecore_Task_Cb func, const void *data)
{
+ if (animator->func != NULL)
+ {
+ ERR("do not call this function out of '%s' object construction", MY_CLASS_NAME);
+ return;
+ }
+
_ecore_lock();
- _ecore_animator_add(obj, animator, func, data);
+
+ animator->obj = obj;
+ animator->func = func;
+ animator->data = (void *)data;
+
_ecore_unlock();
}
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_init(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_init(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 (animator->func != NULL)
+ {
+ ERR("do not call this function out of '%s' object construction", MY_CLASS_NAME);
+ 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_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();
}
return r;
}
-#include "ecore_animator.eo.c"
\ No newline at end of file
+#include "ecore_animator.eo.c"
class Ecore.Animator (Eo.Base)
{
- eo_prefix: ecore_animator;
- constructors {
- timeline_constructor {
- /*@ Contructor. */
+ legacy_prefix: null;
+ eo_prefix: ecore_obj_animator;
+ methods {
+ init {
+ /*@
+ 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 Do NOT call this method outside of object constructor.
+
+ @note The default @p frametime value is 1/30th of a second.
+
+ @see ecore_obj_animator_timeline_set()
+ @see ecore_animator_frametime_set() */
params {
- @in double runtime;
- @in Ecore_Timeline_Cb func;
- @in const(void)* data;
+ @in Ecore_Task_Cb func; /*@ The function to call when it ticks off */
+ @in const(void)* data; /*@ The data to pass to the function */
}
}
- constructor {
- /*@ Contructor. */
+ timeline_init {
+ /*@
+ 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 Do NOT call this method outside of object constructor.
+
+ @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 */
params {
- @in Ecore_Task_Cb func;
- @in const(void)* data;
+ @in double runtime; /*@ The time to run in seconds */
+ @in Ecore_Timeline_Cb func; /*@ The function to call when it ticks off */
+ @in const(void)* data; /*@ The data to pass to the function */
}
}
}
implements {
- Eo.Base.constructor;
+ Eo.Base.finalize;
Eo.Base.destructor;
Eo.Base.event_freeze;
Eo.Base.event_thaw;
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_init(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_init(1, _anim_cb, &interval2));
fail_if(!animator);
ecore_main_loop_begin();