[clutter/master-next: 20/51] easing: Add utility functions
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/master-next: 20/51] easing: Add utility functions
- Date: Wed, 25 Apr 2012 16:39:21 +0000 (UTC)
commit 6b473f44ff2e44ec507689303c6d39fc68679597
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Wed Apr 11 14:11:28 2012 +0100
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.
clutter/clutter-alpha.c | 62 ++---------------------------------
clutter/clutter-easing.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
clutter/clutter-easing.h | 11 ++++++
clutter/clutter-timeline.c | 55 +-------------------------------
4 files changed, 92 insertions(+), 112 deletions(-)
---
diff --git a/clutter/clutter-alpha.c b/clutter/clutter-alpha.c
index 730e27f..36a2155 100644
--- a/clutter/clutter-alpha.c
+++ b/clutter/clutter-alpha.c
@@ -747,74 +747,21 @@ typedef struct _AlphaData {
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
clutter_alpha_easing_func (ClutterAlpha *alpha,
gpointer data G_GNUC_UNUSED)
{
ClutterAlphaPrivate *priv = alpha->priv;
ClutterTimeline *timeline = priv->timeline;
- ClutterEasingFunc easing_func;
gdouble t, d;
if (G_UNLIKELY (priv->timeline == NULL))
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);
d = clutter_timeline_get_duration (timeline);
- easing_func = _clutter_animation_modes[priv->mode].func;
-
- return easing_func (t, d);
+ return clutter_easing_for_mode (priv->mode, t, d);
}
/**
@@ -851,16 +798,15 @@ clutter_alpha_set_mode (ClutterAlpha *alpha,
/* sanity check to avoid getting an out of sync
* enum/function mapping
*/
- g_assert (_clutter_animation_modes[mode].mode == mode);
- g_assert (_clutter_animation_modes[mode].func != NULL);
+ g_assert (clutter_get_easing_func_for_mode (mode) != NULL);
clutter_alpha_set_closure_internal (alpha, NULL);
priv->mode = mode;
CLUTTER_NOTE (ANIMATION, "New easing mode '%s'[%lu]\n",
- _clutter_animation_modes[priv->mode].name,
- _clutter_animation_modes[priv->mode].mode);
+ clutter_get_easing_name_for_mode (priv->mode),
+ priv->mode);
priv->func = clutter_alpha_easing_func;
priv->user_data = NULL;
diff --git a/clutter/clutter-easing.c b/clutter/clutter-easing.c
index c2c6556..a8cf636 100644
--- a/clutter/clutter-easing.c
+++ b/clutter/clutter-easing.c
@@ -378,3 +378,79 @@ clutter_ease_in_out_bounce (double t,
else
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);
+}
diff --git a/clutter/clutter-easing.h b/clutter/clutter-easing.h
index c2ddd16..04f0e28 100644
--- a/clutter/clutter-easing.h
+++ b/clutter/clutter-easing.h
@@ -17,6 +17,17 @@ G_BEGIN_DECLS
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
double clutter_linear (double t,
double d);
G_GNUC_INTERNAL
diff --git a/clutter/clutter-timeline.c b/clutter/clutter-timeline.c
index 485be13..bea9fe9 100644
--- a/clutter/clutter-timeline.c
+++ b/clutter/clutter-timeline.c
@@ -2049,53 +2049,6 @@ clutter_timeline_set_progress_func (ClutterTimeline *timeline,
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
clutter_timeline_progress_func (ClutterTimeline *timeline,
gdouble elapsed,
@@ -2103,14 +2056,8 @@ clutter_timeline_progress_func (ClutterTimeline *timeline,
gpointer user_data G_GNUC_UNUSED)
{
ClutterTimelinePrivate *priv = timeline->priv;
- ClutterEasingFunc easing_func;
-
- g_assert (_clutter_animation_modes[priv->progress_mode].mode == priv->progress_mode);
- g_assert (_clutter_animation_modes[priv->progress_mode].func != NULL);
-
- easing_func = _clutter_animation_modes[priv->progress_mode].func;
- return easing_func (elapsed, duration);
+ return clutter_easing_for_mode (priv->progress_mode, elapsed, duration);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]