ecore animators... IN!

SVN revision: 11520
This commit is contained in:
Carsten Haitzler 2004-09-05 08:00:10 +00:00
parent f8aaef0cf7
commit 5ef8dedf2e
6 changed files with 189 additions and 3 deletions

View File

@ -74,6 +74,7 @@ extern "C" {
typedef void Ecore_Event_Handler; /**< A handle for an event handler */
typedef void Ecore_Event_Filter; /**< A handle for an event filter */
typedef void Ecore_Event; /**< A handle for an event */
typedef void Ecore_Animator; /**< A handle for animators */
#endif
typedef struct _Ecore_Event_Exe_Exit Ecore_Event_Exe_Exit; /**< Spawned Exe exit event */
typedef struct _Ecore_Event_Signal_User Ecore_Event_Signal_User; /**< User signal event */
@ -180,6 +181,11 @@ extern "C" {
Ecore_Timer *ecore_timer_add(double in, int (*func) (void *data), const void *data);
void *ecore_timer_del(Ecore_Timer *timer);
Ecore_Animator *ecore_animator_add(int (*func) (void *data), const void *data);
void *ecore_animator_del(Ecore_Animator *animator);
void ecore_animator_frametime_set(double frametime);
double ecore_animator_frametime_get(void);
#ifdef __cplusplus
}

View File

@ -10,6 +10,7 @@ Ecore_Data.h
libecore_la_SOURCES = \
ecore.c \
ecore_app.c \
ecore_anim.c \
ecore_events.c \
ecore_exe.c \
ecore_hash.c \

View File

@ -58,6 +58,7 @@ ecore_shutdown(void)
return _ecore_init_count;
if (_ecore_fps_debug) _ecore_fps_debug_shutdown();
_ecore_animator_shutdown();
_ecore_exe_shutdown();
_ecore_idle_enterer_shutdown();
_ecore_idle_exiter_shutdown();

View File

@ -0,0 +1,166 @@
#include "ecore_private.h"
#include "Ecore.h"
static int _ecore_animator(void *data);
static Ecore_Timer *timer = NULL;
static int animators_delete_me = 0;
static Ecore_Animator *animators = NULL;
static double animators_frametime = 1.0 / 30.0;
/**
* Add a animator to tick off at every animaton tick during main loop execution.
* @param func The function to call when it ticks off
* @param data The data to pass to the function
* @return A handle to the new animator
* @ingroup Ecore_Animator_Group
*
* This function adds a animator and returns its handle on success and NULL on
* failure. The function @p func will be called every N seconds where N is the
* 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 value of either 1 or 0.
* If it returns 1, it will be called again at the next tick, or if it returns
* 0 it will be deleted automatically making any references/handles for it
* invalid.
*/
Ecore_Animator *
ecore_animator_add(int (*func) (void *data), const void *data)
{
Ecore_Animator *animator;
if (!func) return NULL;
animator = calloc(1, sizeof(Ecore_Animator));
if (!animator) return NULL;
ECORE_MAGIC_SET(animator, ECORE_MAGIC_ANIMATOR);
animator->func = func;
animator->data = (void *)data;
animators = _ecore_list_append(animators, animator);
if (!timer)
timer = ecore_timer_add(animators_frametime, _ecore_animator, NULL);
return animator;
}
/**
* Delete the specified animator from the animator list.
* @param animator The animator to delete
* @return The data pointer set for the animator
* @ingroup Ecore_Animator_Group
*
* Delete the specified @p aqnimator from the set of animators that are executed
* during main loop execution. This function returns the data parameter that
* was being passed to the callback on success, or NULL on failure. After this
* call returns the specified animator object @p animator is invalid and should not
* be used again. It will not get called again after deletion.
*/
void *
ecore_animator_del(Ecore_Animator *animator)
{
if (!ECORE_MAGIC_CHECK(animator, ECORE_MAGIC_ANIMATOR))
{
ECORE_MAGIC_FAIL(animator, ECORE_MAGIC_ANIMATOR,
"ecore_animator_del");
return NULL;
}
if (animator->delete_me) return animator->data;
animator->delete_me = 1;
animators_delete_me++;
return animator->data;
}
/**
* Set the animator call interval in seconds.
* @param frametime The time in seconds in between animator ticks.
*
* This function sets the time interval (in seconds) inbetween animator ticks.
*/
void
ecore_animator_frametime_set(double frametime)
{
if (frametime < 0.0) frametime = 0.0;
if (animators_frametime == frametime) return;
animators_frametime = frametime;
if (timer)
{
ecore_timer_del(timer);
timer = NULL;
}
if (animators)
timer = ecore_timer_add(animators_frametime, _ecore_animator, NULL);
}
/**
* Get the animator call interval in seconds.
* @return The time in second in between animator ticks.
*
* this function retrieves the time inbetween animator ticks, in seconds.
*/
double
ecore_animator_frametime_get(void)
{
return animators_frametime;
}
void
_ecore_animator_shutdown(void)
{
if (timer)
{
ecore_timer_del(timer);
timer = NULL;
}
while (animators)
{
Ecore_Animator *animator;
animator = animators;
animators = _ecore_list_remove(animators, animator);
ECORE_MAGIC_SET(animator, ECORE_MAGIC_NONE);
free(animator);
}
}
static int
_ecore_animator(void *data)
{
Ecore_Oldlist *l;
for (l = (Ecore_Oldlist *)animators; l;)
{
Ecore_Animator *animator;
animator = (Ecore_Animator *)l;
l = l->next;
if (!animator->delete_me)
{
if (!animator->func(animator->data))
animator->delete_me = 1;
}
}
if (animators_delete_me)
{
for (l = (Ecore_Oldlist *)animators; l;)
{
Ecore_Animator *animator;
animator = (Ecore_Animator *)l;
l = l->next;
if (animator->delete_me)
{
animators = _ecore_list_remove(animators, animator);
ECORE_MAGIC_SET(animator, ECORE_MAGIC_NONE);
free(animator);
animators_delete_me--;
if (animators_delete_me == 0) break;
}
}
}
if (!animators)
{
timer = NULL;
return 0;
}
return 1;
}

View File

@ -22,6 +22,7 @@
#define ECORE_MAGIC_EVENT_HANDLER 0xf79317f0
#define ECORE_MAGIC_EVENT_FILTER 0xf78218ff
#define ECORE_MAGIC_EVENT 0xf77119fe
#define ECORE_MAGIC_ANIMATOR 0xf7643ea5
#define ECORE_MAGIC Ecore_Magic __magic
@ -57,6 +58,7 @@ typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler;
typedef struct _Ecore_Event_Handler Ecore_Event_Handler;
typedef struct _Ecore_Event_Filter Ecore_Event_Filter;
typedef struct _Ecore_Event Ecore_Event;
typedef struct _Ecore_Animator Ecore_Animator;
struct _Ecore_Exe
{
@ -154,6 +156,15 @@ struct _Ecore_Event
void *data;
};
struct _Ecore_Animator
{
Ecore_Oldlist __list_data;
ECORE_MAGIC;
signed char delete_me : 1;
int (*func) (void *data);
void *data;
};
#endif
void _ecore_magic_fail(void *d, Ecore_Magic m, Ecore_Magic req_m, const char *fname);
@ -201,6 +212,9 @@ void _ecore_exe_shutdown(void);
Ecore_Exe *_ecore_exe_find(pid_t pid);
void *_ecore_exe_free(Ecore_Exe *exe);
void _ecore_animator_shutdown(void);
void *_ecore_list_append (void *in_list, void *in_item);
void *_ecore_list_prepend (void *in_list, void *in_item);
void *_ecore_list_append_relative (void *in_list, void *in_item, void *in_relative);

View File

@ -1,8 +1,6 @@
#include "ecore_private.h"
#include "Ecore.h"
/* FIXME: write code for timers... */
static void _ecore_timer_set(Ecore_Timer *timer, double at, double in, int (*func) (void *data), void *data);
static int timers_added = 0;
@ -49,7 +47,7 @@ ecore_timer_add(double in, int (*func) (void *data), const void *data)
/**
* Delete the specified timer from the timer list.
* @param timer
* @param timer The timer to delete
* @return The data pointer set for the timer
* @ingroup Ecore_Timer_Group
*