easing: Add utility functions
We end up copying the same array-of-modes-and-functions code in various places, so it's better to factor it out.
This commit is contained in:
parent
865a682450
commit
bf12e23199
@ -747,74 +747,21 @@ typedef struct _AlphaData {
|
|||||||
|
|
||||||
static GPtrArray *clutter_alphas = NULL;
|
static GPtrArray *clutter_alphas = NULL;
|
||||||
|
|
||||||
/*< private >
|
|
||||||
* _clutter_animation_modes:
|
|
||||||
*
|
|
||||||
* A mapping of animation modes and easing functions.
|
|
||||||
*/
|
|
||||||
static const struct {
|
|
||||||
ClutterAnimationMode mode;
|
|
||||||
ClutterEasingFunc func;
|
|
||||||
const char *name;
|
|
||||||
} _clutter_animation_modes[] = {
|
|
||||||
{ CLUTTER_CUSTOM_MODE, NULL, "custom" },
|
|
||||||
|
|
||||||
{ CLUTTER_LINEAR, clutter_linear, "linear" },
|
|
||||||
{ CLUTTER_EASE_IN_QUAD, clutter_ease_in_quad, "easeInQuad" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUAD, clutter_ease_out_quad, "easeOutQuad" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUAD, clutter_ease_in_out_quad, "easeInOutQuad" },
|
|
||||||
{ CLUTTER_EASE_IN_CUBIC, clutter_ease_in_cubic, "easeInCubic" },
|
|
||||||
{ CLUTTER_EASE_OUT_CUBIC, clutter_ease_out_cubic, "easeOutCubic" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_CUBIC, clutter_ease_in_out_cubic, "easeInOutCubic" },
|
|
||||||
{ CLUTTER_EASE_IN_QUART, clutter_ease_in_quart, "easeInQuart" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUART, clutter_ease_out_quart, "easeOutQuart" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUART, clutter_ease_in_out_quart, "easeInOutQuart" },
|
|
||||||
{ CLUTTER_EASE_IN_QUINT, clutter_ease_in_quint, "easeInQuint" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUINT, clutter_ease_out_quint, "easeOutQuint" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUINT, clutter_ease_in_out_quint, "easeInOutQuint" },
|
|
||||||
{ CLUTTER_EASE_IN_SINE, clutter_ease_in_sine, "easeInSine" },
|
|
||||||
{ CLUTTER_EASE_OUT_SINE, clutter_ease_out_sine, "easeOutSine" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_SINE, clutter_ease_in_out_sine, "easeInOutSine" },
|
|
||||||
{ CLUTTER_EASE_IN_EXPO, clutter_ease_in_expo, "easeInExpo" },
|
|
||||||
{ CLUTTER_EASE_OUT_EXPO, clutter_ease_out_expo, "easeOutExpo" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_EXPO, clutter_ease_in_out_expo, "easeInOutExpo" },
|
|
||||||
{ CLUTTER_EASE_IN_CIRC, clutter_ease_in_circ, "easeInCirc" },
|
|
||||||
{ CLUTTER_EASE_OUT_CIRC, clutter_ease_out_circ, "easeOutCirc" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_CIRC, clutter_ease_in_out_circ, "easeInOutCirc" },
|
|
||||||
{ CLUTTER_EASE_IN_ELASTIC, clutter_ease_in_elastic, "easeInElastic" },
|
|
||||||
{ CLUTTER_EASE_OUT_ELASTIC, clutter_ease_out_elastic, "easeOutElastic" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_ELASTIC, clutter_ease_in_out_elastic, "easeInOutElastic" },
|
|
||||||
{ CLUTTER_EASE_IN_BACK, clutter_ease_in_back, "easeInBack" },
|
|
||||||
{ CLUTTER_EASE_OUT_BACK, clutter_ease_out_back, "easeOutBack" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_BACK, clutter_ease_in_out_back, "easeInOutBack" },
|
|
||||||
{ CLUTTER_EASE_IN_BOUNCE, clutter_ease_in_bounce, "easeInBounce" },
|
|
||||||
{ CLUTTER_EASE_OUT_BOUNCE, clutter_ease_out_bounce, "easeOutBounce" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_BOUNCE, clutter_ease_in_out_bounce, "easeInOutBounce" },
|
|
||||||
|
|
||||||
{ CLUTTER_ANIMATION_LAST, NULL, "sentinel" },
|
|
||||||
};
|
|
||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
clutter_alpha_easing_func (ClutterAlpha *alpha,
|
clutter_alpha_easing_func (ClutterAlpha *alpha,
|
||||||
gpointer data G_GNUC_UNUSED)
|
gpointer data G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
ClutterAlphaPrivate *priv = alpha->priv;
|
ClutterAlphaPrivate *priv = alpha->priv;
|
||||||
ClutterTimeline *timeline = priv->timeline;
|
ClutterTimeline *timeline = priv->timeline;
|
||||||
ClutterEasingFunc easing_func;
|
|
||||||
gdouble t, d;
|
gdouble t, d;
|
||||||
|
|
||||||
if (G_UNLIKELY (priv->timeline == NULL))
|
if (G_UNLIKELY (priv->timeline == NULL))
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
g_assert (_clutter_animation_modes[priv->mode].mode == priv->mode);
|
|
||||||
g_assert (_clutter_animation_modes[priv->mode].func != NULL);
|
|
||||||
|
|
||||||
t = clutter_timeline_get_elapsed_time (timeline);
|
t = clutter_timeline_get_elapsed_time (timeline);
|
||||||
d = clutter_timeline_get_duration (timeline);
|
d = clutter_timeline_get_duration (timeline);
|
||||||
|
|
||||||
easing_func = _clutter_animation_modes[priv->mode].func;
|
return clutter_easing_for_mode (priv->mode, t, d);
|
||||||
|
|
||||||
return easing_func (t, d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -851,16 +798,15 @@ clutter_alpha_set_mode (ClutterAlpha *alpha,
|
|||||||
/* sanity check to avoid getting an out of sync
|
/* sanity check to avoid getting an out of sync
|
||||||
* enum/function mapping
|
* enum/function mapping
|
||||||
*/
|
*/
|
||||||
g_assert (_clutter_animation_modes[mode].mode == mode);
|
g_assert (clutter_get_easing_func_for_mode (mode) != NULL);
|
||||||
g_assert (_clutter_animation_modes[mode].func != NULL);
|
|
||||||
|
|
||||||
clutter_alpha_set_closure_internal (alpha, NULL);
|
clutter_alpha_set_closure_internal (alpha, NULL);
|
||||||
|
|
||||||
priv->mode = mode;
|
priv->mode = mode;
|
||||||
|
|
||||||
CLUTTER_NOTE (ANIMATION, "New easing mode '%s'[%lu]\n",
|
CLUTTER_NOTE (ANIMATION, "New easing mode '%s'[%lu]\n",
|
||||||
_clutter_animation_modes[priv->mode].name,
|
clutter_get_easing_name_for_mode (priv->mode),
|
||||||
_clutter_animation_modes[priv->mode].mode);
|
priv->mode);
|
||||||
|
|
||||||
priv->func = clutter_alpha_easing_func;
|
priv->func = clutter_alpha_easing_func;
|
||||||
priv->user_data = NULL;
|
priv->user_data = NULL;
|
||||||
|
@ -378,3 +378,79 @@ clutter_ease_in_out_bounce (double t,
|
|||||||
else
|
else
|
||||||
return ease_out_bounce_internal (t * 2 - d, d) * 0.5 + 1.0 * 0.5;
|
return ease_out_bounce_internal (t * 2 - d, d) * 0.5 + 1.0 * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*< private >
|
||||||
|
* _clutter_animation_modes:
|
||||||
|
*
|
||||||
|
* A mapping of animation modes and easing functions.
|
||||||
|
*/
|
||||||
|
static const struct {
|
||||||
|
ClutterAnimationMode mode;
|
||||||
|
ClutterEasingFunc func;
|
||||||
|
const char *name;
|
||||||
|
} _clutter_animation_modes[] = {
|
||||||
|
{ CLUTTER_CUSTOM_MODE, NULL, "custom" },
|
||||||
|
|
||||||
|
{ CLUTTER_LINEAR, clutter_linear, "linear" },
|
||||||
|
{ CLUTTER_EASE_IN_QUAD, clutter_ease_in_quad, "easeInQuad" },
|
||||||
|
{ CLUTTER_EASE_OUT_QUAD, clutter_ease_out_quad, "easeOutQuad" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_QUAD, clutter_ease_in_out_quad, "easeInOutQuad" },
|
||||||
|
{ CLUTTER_EASE_IN_CUBIC, clutter_ease_in_cubic, "easeInCubic" },
|
||||||
|
{ CLUTTER_EASE_OUT_CUBIC, clutter_ease_out_cubic, "easeOutCubic" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_CUBIC, clutter_ease_in_out_cubic, "easeInOutCubic" },
|
||||||
|
{ CLUTTER_EASE_IN_QUART, clutter_ease_in_quart, "easeInQuart" },
|
||||||
|
{ CLUTTER_EASE_OUT_QUART, clutter_ease_out_quart, "easeOutQuart" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_QUART, clutter_ease_in_out_quart, "easeInOutQuart" },
|
||||||
|
{ CLUTTER_EASE_IN_QUINT, clutter_ease_in_quint, "easeInQuint" },
|
||||||
|
{ CLUTTER_EASE_OUT_QUINT, clutter_ease_out_quint, "easeOutQuint" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_QUINT, clutter_ease_in_out_quint, "easeInOutQuint" },
|
||||||
|
{ CLUTTER_EASE_IN_SINE, clutter_ease_in_sine, "easeInSine" },
|
||||||
|
{ CLUTTER_EASE_OUT_SINE, clutter_ease_out_sine, "easeOutSine" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_SINE, clutter_ease_in_out_sine, "easeInOutSine" },
|
||||||
|
{ CLUTTER_EASE_IN_EXPO, clutter_ease_in_expo, "easeInExpo" },
|
||||||
|
{ CLUTTER_EASE_OUT_EXPO, clutter_ease_out_expo, "easeOutExpo" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_EXPO, clutter_ease_in_out_expo, "easeInOutExpo" },
|
||||||
|
{ CLUTTER_EASE_IN_CIRC, clutter_ease_in_circ, "easeInCirc" },
|
||||||
|
{ CLUTTER_EASE_OUT_CIRC, clutter_ease_out_circ, "easeOutCirc" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_CIRC, clutter_ease_in_out_circ, "easeInOutCirc" },
|
||||||
|
{ CLUTTER_EASE_IN_ELASTIC, clutter_ease_in_elastic, "easeInElastic" },
|
||||||
|
{ CLUTTER_EASE_OUT_ELASTIC, clutter_ease_out_elastic, "easeOutElastic" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_ELASTIC, clutter_ease_in_out_elastic, "easeInOutElastic" },
|
||||||
|
{ CLUTTER_EASE_IN_BACK, clutter_ease_in_back, "easeInBack" },
|
||||||
|
{ CLUTTER_EASE_OUT_BACK, clutter_ease_out_back, "easeOutBack" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_BACK, clutter_ease_in_out_back, "easeInOutBack" },
|
||||||
|
{ CLUTTER_EASE_IN_BOUNCE, clutter_ease_in_bounce, "easeInBounce" },
|
||||||
|
{ CLUTTER_EASE_OUT_BOUNCE, clutter_ease_out_bounce, "easeOutBounce" },
|
||||||
|
{ CLUTTER_EASE_IN_OUT_BOUNCE, clutter_ease_in_out_bounce, "easeInOutBounce" },
|
||||||
|
|
||||||
|
{ CLUTTER_ANIMATION_LAST, NULL, "sentinel" },
|
||||||
|
};
|
||||||
|
|
||||||
|
ClutterEasingFunc
|
||||||
|
clutter_get_easing_func_for_mode (ClutterAnimationMode mode)
|
||||||
|
{
|
||||||
|
g_assert (_clutter_animation_modes[mode].mode == mode);
|
||||||
|
g_assert (_clutter_animation_modes[mode].func != NULL);
|
||||||
|
|
||||||
|
return _clutter_animation_modes[mode].func;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
clutter_get_easing_name_for_mode (ClutterAnimationMode mode)
|
||||||
|
{
|
||||||
|
g_assert (_clutter_animation_modes[mode].mode == mode);
|
||||||
|
g_assert (_clutter_animation_modes[mode].func != NULL);
|
||||||
|
|
||||||
|
return _clutter_animation_modes[mode].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
clutter_easing_for_mode (ClutterAnimationMode mode,
|
||||||
|
double t,
|
||||||
|
double d)
|
||||||
|
{
|
||||||
|
g_assert (_clutter_animation_modes[mode].mode == mode);
|
||||||
|
g_assert (_clutter_animation_modes[mode].func != NULL);
|
||||||
|
|
||||||
|
return _clutter_animation_modes[mode].func (t, d);
|
||||||
|
}
|
||||||
|
@ -16,6 +16,17 @@ G_BEGIN_DECLS
|
|||||||
*/
|
*/
|
||||||
typedef double (* ClutterEasingFunc) (double t, double d);
|
typedef double (* ClutterEasingFunc) (double t, double d);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
ClutterEasingFunc clutter_get_easing_func_for_mode (ClutterAnimationMode mode);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
const char * clutter_get_easing_name_for_mode (ClutterAnimationMode mode);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
double clutter_easing_for_mode (ClutterAnimationMode mode,
|
||||||
|
double t,
|
||||||
|
double d);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
double clutter_linear (double t,
|
double clutter_linear (double t,
|
||||||
double d);
|
double d);
|
||||||
|
@ -2049,53 +2049,6 @@ clutter_timeline_set_progress_func (ClutterTimeline *timeline,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (timeline), obj_props[PROP_PROGRESS_MODE]);
|
g_object_notify_by_pspec (G_OBJECT (timeline), obj_props[PROP_PROGRESS_MODE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*< private >
|
|
||||||
* _clutter_animation_modes:
|
|
||||||
*
|
|
||||||
* A mapping of animation modes and easing functions.
|
|
||||||
*/
|
|
||||||
static const struct {
|
|
||||||
ClutterAnimationMode mode;
|
|
||||||
ClutterEasingFunc func;
|
|
||||||
const char *name;
|
|
||||||
} _clutter_animation_modes[] = {
|
|
||||||
{ CLUTTER_CUSTOM_MODE, NULL, "custom" },
|
|
||||||
|
|
||||||
{ CLUTTER_LINEAR, clutter_linear, "linear" },
|
|
||||||
{ CLUTTER_EASE_IN_QUAD, clutter_ease_in_quad, "easeInQuad" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUAD, clutter_ease_out_quad, "easeOutQuad" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUAD, clutter_ease_in_out_quad, "easeInOutQuad" },
|
|
||||||
{ CLUTTER_EASE_IN_CUBIC, clutter_ease_in_cubic, "easeInCubic" },
|
|
||||||
{ CLUTTER_EASE_OUT_CUBIC, clutter_ease_out_cubic, "easeOutCubic" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_CUBIC, clutter_ease_in_out_cubic, "easeInOutCubic" },
|
|
||||||
{ CLUTTER_EASE_IN_QUART, clutter_ease_in_quart, "easeInQuart" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUART, clutter_ease_out_quart, "easeOutQuart" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUART, clutter_ease_in_out_quart, "easeInOutQuart" },
|
|
||||||
{ CLUTTER_EASE_IN_QUINT, clutter_ease_in_quint, "easeInQuint" },
|
|
||||||
{ CLUTTER_EASE_OUT_QUINT, clutter_ease_out_quint, "easeOutQuint" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_QUINT, clutter_ease_in_out_quint, "easeInOutQuint" },
|
|
||||||
{ CLUTTER_EASE_IN_SINE, clutter_ease_in_sine, "easeInSine" },
|
|
||||||
{ CLUTTER_EASE_OUT_SINE, clutter_ease_out_sine, "easeOutSine" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_SINE, clutter_ease_in_out_sine, "easeInOutSine" },
|
|
||||||
{ CLUTTER_EASE_IN_EXPO, clutter_ease_in_expo, "easeInExpo" },
|
|
||||||
{ CLUTTER_EASE_OUT_EXPO, clutter_ease_out_expo, "easeOutExpo" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_EXPO, clutter_ease_in_out_expo, "easeInOutExpo" },
|
|
||||||
{ CLUTTER_EASE_IN_CIRC, clutter_ease_in_circ, "easeInCirc" },
|
|
||||||
{ CLUTTER_EASE_OUT_CIRC, clutter_ease_out_circ, "easeOutCirc" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_CIRC, clutter_ease_in_out_circ, "easeInOutCirc" },
|
|
||||||
{ CLUTTER_EASE_IN_ELASTIC, clutter_ease_in_elastic, "easeInElastic" },
|
|
||||||
{ CLUTTER_EASE_OUT_ELASTIC, clutter_ease_out_elastic, "easeOutElastic" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_ELASTIC, clutter_ease_in_out_elastic, "easeInOutElastic" },
|
|
||||||
{ CLUTTER_EASE_IN_BACK, clutter_ease_in_back, "easeInBack" },
|
|
||||||
{ CLUTTER_EASE_OUT_BACK, clutter_ease_out_back, "easeOutBack" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_BACK, clutter_ease_in_out_back, "easeInOutBack" },
|
|
||||||
{ CLUTTER_EASE_IN_BOUNCE, clutter_ease_in_bounce, "easeInBounce" },
|
|
||||||
{ CLUTTER_EASE_OUT_BOUNCE, clutter_ease_out_bounce, "easeOutBounce" },
|
|
||||||
{ CLUTTER_EASE_IN_OUT_BOUNCE, clutter_ease_in_out_bounce, "easeInOutBounce" },
|
|
||||||
|
|
||||||
{ CLUTTER_ANIMATION_LAST, NULL, "sentinel" },
|
|
||||||
};
|
|
||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
clutter_timeline_progress_func (ClutterTimeline *timeline,
|
clutter_timeline_progress_func (ClutterTimeline *timeline,
|
||||||
gdouble elapsed,
|
gdouble elapsed,
|
||||||
@ -2103,14 +2056,8 @@ clutter_timeline_progress_func (ClutterTimeline *timeline,
|
|||||||
gpointer user_data G_GNUC_UNUSED)
|
gpointer user_data G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
ClutterTimelinePrivate *priv = timeline->priv;
|
ClutterTimelinePrivate *priv = timeline->priv;
|
||||||
ClutterEasingFunc easing_func;
|
|
||||||
|
|
||||||
g_assert (_clutter_animation_modes[priv->progress_mode].mode == priv->progress_mode);
|
return clutter_easing_for_mode (priv->progress_mode, elapsed, duration);
|
||||||
g_assert (_clutter_animation_modes[priv->progress_mode].func != NULL);
|
|
||||||
|
|
||||||
easing_func = _clutter_animation_modes[priv->progress_mode].func;
|
|
||||||
|
|
||||||
return easing_func (elapsed, duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user