From 7d7372af43ec23d5c89c55ba57600a47bcd07471 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 20 Jan 2009 16:42:49 +0000 Subject: [PATCH] [animation] Move the alpha value to floating point The current Alpha value is an unsigned integer that can be used implicitly as a fixed point value. This makes writing an alpha function overshooting below and above the current range basically impossible without complicating an already complex code, and creating weird corner cases. For this reason, the Alpha value should be defined as a floating point normalized value, spanning a range between 0.0 and 1.0; in order to allow overshooting, the valid range is extended one unit below and one unit above, thus making it -1.0 .. 2.0. This commit updates the various users of the ClutterAlpha API and the tests cases. This commit also removes all the current alpha functions exposed in the public API. --- clutter/clutter-alpha.c | 967 ++----------------------- clutter/clutter-alpha.h | 74 +- clutter/clutter-animation.c | 9 +- clutter/clutter-behaviour-depth.c | 6 +- clutter/clutter-behaviour-ellipse.c | 4 +- clutter/clutter-behaviour-opacity.c | 5 +- clutter/clutter-behaviour-path.c | 7 +- clutter/clutter-behaviour-rotate.c | 4 +- clutter/clutter-behaviour-scale.c | 6 +- clutter/clutter-behaviour.c | 8 +- clutter/clutter-behaviour.h | 2 +- clutter/clutter-interval.c | 2 - clutter/clutter-marshal.list | 1 + clutter/clutter-script.c | 24 +- tests/interactive/test-actors.c | 13 +- tests/interactive/test-layout.c | 2 +- tests/interactive/test-paint-wrapper.c | 12 +- tests/interactive/test-scale.c | 11 +- 18 files changed, 107 insertions(+), 1050 deletions(-) diff --git a/clutter/clutter-alpha.c b/clutter/clutter-alpha.c index 78b79a275..eeef07d0c 100644 --- a/clutter/clutter-alpha.c +++ b/clutter/clutter-alpha.c @@ -8,7 +8,8 @@ * Emmanuele Bassi * Tomas Frydrych * - * Copyright (C) 2006, 2007 OpenedHand + * Copyright (C) 2006, 2007, 2008 OpenedHand + * Copyright (C) 2009 Intel Corp. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,8 +32,8 @@ * @short_description: A class for calculating an alpha value as a function * of time. * - * #ClutterAlpha is a class for calculating an integer value between - * 0 and %CLUTTER_ALPHA_MAX_ALPHA as a function of time. + * #ClutterAlpha is a class for calculating an floating point value + * dependent only on the position of a #ClutterTimeline. * * A #ClutterAlpha binds a #ClutterTimeline to a progress function which * translates the time T into an adimensional factor alpha. The factor can @@ -42,7 +43,8 @@ * You should provide a #ClutterTimeline and bind it to the #ClutterAlpha * instance using clutter_alpha_set_timeline(). You should also set an * "animation mode", either by using the #ClutterAnimatioMode values that - * Clutter itself provides or by registering custom functions. + * Clutter itself provides or by registering custom functions using + * clutter_alpha_register_func(). * * Instead of a #ClutterAnimationMode you may provide a function returning * the alpha value depending on the progress of the timeline, using @@ -54,12 +56,8 @@ * pause, stop or resume the #ClutterAlpha from calling the alpha function by * using the appropriate functions of the #ClutterTimeline object. * - * #ClutterAlpha is used to "drive" a #ClutterBehaviour instance. - * - *
- * Graphic representation of some alpha functions - * - *
+ * #ClutterAlpha is used to "drive" a #ClutterBehaviour instance, and it + * is internally used by the #ClutterAnimation API. * * Since: 0.2 */ @@ -85,7 +83,7 @@ struct _ClutterAlphaPrivate ClutterTimeline *timeline; guint timeline_new_frame_id; - guint32 alpha; + gdouble alpha; GClosure *closure; @@ -160,7 +158,7 @@ clutter_alpha_get_property (GObject *object, break; case PROP_ALPHA: - g_value_set_uint (value, priv->alpha); + g_value_set_double (value, priv->alpha); break; case PROP_MODE: @@ -199,6 +197,7 @@ static void clutter_alpha_class_init (ClutterAlphaClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; object_class->set_property = clutter_alpha_set_property; object_class->get_property = clutter_alpha_get_property; @@ -214,29 +213,30 @@ clutter_alpha_class_init (ClutterAlphaClass *klass) * * Since: 0.2 */ - g_object_class_install_property (object_class, - PROP_TIMELINE, - g_param_spec_object ("timeline", - "Timeline", - "Timeline", - CLUTTER_TYPE_TIMELINE, - CLUTTER_PARAM_READWRITE)); + pspec = g_param_spec_object ("timeline", + "Timeline", + "Timeline used by the alpha", + CLUTTER_TYPE_TIMELINE, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_TIMELINE, pspec); + /** * ClutterAlpha:alpha: * - * The alpha value as computed by the alpha function. + * The alpha value as computed by the alpha function. The linear + * interval is 0.0 to 1.0, but the Alpha allows overshooting by + * one unit in each direction, so the valid interval is -1.0 to 2.0. * * Since: 0.2 */ - g_object_class_install_property (object_class, - PROP_ALPHA, - g_param_spec_uint ("alpha", - "Alpha value", - "Alpha value", - 0, - CLUTTER_ALPHA_MAX_ALPHA, - 0, - CLUTTER_PARAM_READABLE)); + pspec = g_param_spec_double ("alpha", + "Alpha value", + "Alpha value", + -1.0, 2.0, + 0.0, + CLUTTER_PARAM_READABLE); + g_object_class_install_property (object_class, PROP_ALPHA, pspec); + /** * ClutterAlpha:mode: * @@ -250,15 +250,13 @@ clutter_alpha_class_init (ClutterAlphaClass *klass) * * Since: 1.0 */ - g_object_class_install_property (object_class, - PROP_MODE, - g_param_spec_ulong ("mode", - "Mode", - "Progress mode", - 0, G_MAXULONG, - CLUTTER_CUSTOM_MODE, - G_PARAM_CONSTRUCT | - CLUTTER_PARAM_READWRITE)); + pspec = g_param_spec_ulong ("mode", + "Mode", + "Progress mode", + 0, G_MAXULONG, + CLUTTER_CUSTOM_MODE, + G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_MODE, pspec); } static void @@ -269,6 +267,7 @@ clutter_alpha_init (ClutterAlpha *self) ClutterAlphaPrivate); self->priv->mode = CLUTTER_CUSTOM_MODE; + self->priv->alpha = 0.0; } /** @@ -281,11 +280,11 @@ clutter_alpha_init (ClutterAlpha *self) * * Since: 0.2 */ -guint32 +gdouble clutter_alpha_get_alpha (ClutterAlpha *alpha) { ClutterAlphaPrivate *priv; - guint32 retval = 0; + gdouble retval = 0; g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), 0); @@ -298,18 +297,14 @@ clutter_alpha_get_alpha (ClutterAlpha *alpha) g_object_ref (alpha); - g_value_init (&result_value, G_TYPE_UINT); + g_value_init (&result_value, G_TYPE_DOUBLE); g_value_init (¶ms, CLUTTER_TYPE_ALPHA); g_value_set_object (¶ms, alpha); - g_closure_invoke (priv->closure, - &result_value, - 1, - ¶ms, - NULL); + g_closure_invoke (priv->closure, &result_value, 1, ¶ms, NULL); - retval = g_value_get_uint (&result_value); + retval = g_value_get_double (&result_value); g_value_unset (&result_value); g_value_unset (¶ms); @@ -349,7 +344,7 @@ clutter_alpha_set_closure (ClutterAlpha *alpha, if (G_CLOSURE_NEEDS_MARSHAL (closure)) { - GClosureMarshal marshal = clutter_marshal_UINT__VOID; + GClosureMarshal marshal = clutter_marshal_DOUBLE__VOID; g_closure_set_marshal (closure, marshal); } @@ -563,18 +558,6 @@ static const struct { ClutterAlphaFunc func; } animation_modes[] = { { CLUTTER_CUSTOM_MODE, NULL }, - { CLUTTER_LINEAR, clutter_ramp_inc_func }, - { CLUTTER_SINE_IN, clutter_sine_in_func }, - { CLUTTER_SINE_OUT, clutter_sine_out_func }, - { CLUTTER_SINE_IN_OUT, clutter_sine_in_out_func }, - { CLUTTER_EASE_IN, clutter_ease_in_func }, - { CLUTTER_EASE_OUT, clutter_ease_out_func }, - { CLUTTER_EASE_IN_OUT, clutter_ease_in_out_func }, - { CLUTTER_EXPO_IN, clutter_exp_in_func }, - { CLUTTER_EXPO_OUT, clutter_exp_out_func }, - { CLUTTER_EXPO_IN_OUT, clutter_exp_in_out_func }, - { CLUTTER_SMOOTH_IN_OUT, clutter_smoothstep_inc_func }, - { CLUTTER_ANIMATION_LAST, NULL }, }; typedef struct _AlphaData { @@ -728,867 +711,3 @@ clutter_alpha_register_closure (GClosure *closure) return clutter_alphas->len + CLUTTER_ANIMATION_LAST; } - -/** - * clutter_ramp_inc_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a monotonic increasing ramp. You - * can use this function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.2 - */ -guint32 -clutter_ramp_inc_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - return (current_frame_num * CLUTTER_ALPHA_MAX_ALPHA) / n_frames; -} - -/** - * CLUTTER_ALPHA_RAMP_DEC: - * - * Convenience symbol for clutter_ramp_dec_func(). - * - * Since: 0.2 - */ - -/** - * clutter_ramp_dec_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a monotonic decreasing ramp. You - * can use this function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.2 - */ -guint32 -clutter_ramp_dec_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - return (n_frames - current_frame_num) - * CLUTTER_ALPHA_MAX_ALPHA - / n_frames; -} - -/** - * CLUTTER_ALPHA_RAMP: - * - * Convenience symbol for clutter_ramp_func(). - * - * Since: 0.2 - */ - -/** - * clutter_ramp_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a full ramp function (increase for - * half the time, decrease for the remaining half). You can use this - * function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.2 - */ -guint32 -clutter_ramp_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - if (current_frame_num > (n_frames / 2)) - { - return (n_frames - current_frame_num) - * CLUTTER_ALPHA_MAX_ALPHA - / (n_frames / 2); - } - else - { - return current_frame_num - * CLUTTER_ALPHA_MAX_ALPHA - / (n_frames / 2); - } -} - -static guint32 -sincx1024_func (ClutterAlpha *alpha, - ClutterAngle angle, - ClutterFixed offset) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = angle * current_frame_num / n_frames; - - x -= (512 * 512 / angle); - - sine = ((cogl_angle_sin (x) + offset) / 2) - * CLUTTER_ALPHA_MAX_ALPHA; - - sine = sine >> COGL_FIXED_Q; - - return sine; -} - -#if 0 -/* - * The following two functions are left in place for reference - * purposes. - */ -static guint32 -sincx_func (ClutterAlpha *alpha, - ClutterFixed angle, - ClutterFixed offset) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - ClutterFixed x, sine; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = angle * current_frame_num / n_frames; - x = COGL_FIXED_FAST_MUL (x, COGL_FIXED_PI) - - COGL_FIXED_FAST_DIV (COGL_FIXED_PI, angle); - - sine = (cogl_fixed_sin (x) + offset) / 2; - - CLUTTER_NOTE (ALPHA, "sine: %2f\n", COGL_FIXED_TO_DOUBLE (sine)); - - return COGL_FIXED_TO_INT (sine * CLUTTER_ALPHA_MAX_ALPHA); -} - -/* NB: angle is not in radians but in muliples of PI, i.e., 2.0 - * represents full circle. - */ -static guint32 -sinc_func (ClutterAlpha *alpha, - float angle, - float offset) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - gdouble x, sine; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - /* FIXME: fixed point, and fixed point sine() */ - - x = (gdouble) (current_frame_num * angle * G_PI) / n_frames ; - sine = (sin (x - (G_PI / angle)) + offset) * 0.5f; - - CLUTTER_NOTE (ALPHA, "sine: %2f\n",sine); - - return COGL_FLOAT_TO_INT ((sine * (gdouble) CLUTTER_ALPHA_MAX_ALPHA)); -} -#endif - -/** - * CLUTTER_ALPHA_SINE: - * - * Convenience symbol for clutter_sine_func(). - * - * Since: 0.2 - */ - -/** - * clutter_sine_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a sine wave. You can use this - * function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.2 - */ -guint32 -clutter_sine_func (ClutterAlpha *alpha, - gpointer dummy) -{ -#if 0 - return sinc_func (alpha, 2.0, 1.0); -#else - /* 2.0 above represents full circle */ - return sincx1024_func (alpha, 1024, COGL_FIXED_1); -#endif -} - -/** - * CLUTTER_ALPHA_SINE_INC: - * - * Convenience symbol for clutter_sine_inc_func(). - * - * Since: 0.2 - */ - -/** - * clutter_sine_inc_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a sine wave over interval [0, pi / 2]. - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.2 - */ -guint32 -clutter_sine_inc_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline * timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = 256 * frame / n_frames; - - sine = cogl_angle_sin (x) * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * CLUTTER_ALPHA_SINE_DEC: - * - * Convenience symbol for clutter_sine_dec_func(). - * - * Since: 0.2 - */ - -/** - * clutter_sine_dec_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a sine wave over interval [pi / 2, pi]. - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.4 - */ -guint32 -clutter_sine_dec_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline * timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = 256 * frame / n_frames + 256; - - sine = cogl_angle_sin (x) * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * CLUTTER_ALPHA_SINE_HALF: - * - * Convenience symbol for clutter_sine_half_func(). - * - * Since: 0.4 - */ - -/** - * clutter_sine_half_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a sine wave over interval [0, pi]. - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.4 - */ -guint32 -clutter_sine_half_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = 512 * frame / n_frames; - - sine = cogl_angle_sin (x) * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * clutter_sine_in_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for (sin(x) + 1) over the - * interval [-pi/2, 0]. - * - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_sine_in_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - /* XXX- if we use 768 we overflow */ - x = 256 * frame / n_frames + 767; - - sine = (cogl_angle_sin (x) + 1) * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * clutter_sine_in_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for sin(x) over the interval [0, pi/2]. - * - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_sine_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = 256 * frame / n_frames; - - sine = cogl_angle_sin (x) * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * clutter_sine_in_out_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for (sin(x) + 1) / 2 over the - * interval [-pi/2, pi/2]. - * - * You can use this function as the alpha function for - * clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_sine_in_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint frame; - gint n_frames; - ClutterAngle x; - ClutterFixed sine; - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = -256 * frame / n_frames + 256; - - sine = (cogl_angle_sin (x) + 1) / 2 * CLUTTER_ALPHA_MAX_ALPHA; - - return ((guint32) sine) >> COGL_FIXED_Q; -} - -/** - * CLUTTER_ALPHA_SQUARE: - * - * Convenience symbol for clutter_square_func(). - * - * Since: 0.4 - * - * Deprecated: 1.0: Use clutter_square_func() instead - */ - -/** - * clutter_square_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a square wave. You can use this - * function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value - * - * Since: 0.4 - */ -guint32 -clutter_square_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint current_frame_num, n_frames; - - timeline = clutter_alpha_get_timeline (alpha); - - current_frame_num = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - return (current_frame_num > (n_frames / 2)) ? CLUTTER_ALPHA_MAX_ALPHA - : 0; -} - -/** - * CLUTTER_ALPHA_SMOOTHSTEP_INC: - * - * Convenience symbol for clutter_smoothstep_inc_func(). - * - * Since: 0.4 - */ - -/** - * clutter_smoothstep_inc_func: - * @alpha: a #ClutterAlpha - * @dummy: unused - * - * Convenience alpha function for a smoothstep curve. You can use this - * function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value - * - * Since: 0.4 - */ -guint32 -clutter_smoothstep_inc_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gint frame; - gint n_frames; - guint32 r; - guint32 x; - - /* - * The smoothstep function uses f(x) = -2x^3 + 3x^2 where x is from <0,1>, - * and precission is critical -- we use 8.24 fixed format for this operation. - * The earlier operations involve division, which we cannot do in 8.24 for - * numbers in <0,1> we use ClutterFixed. - */ - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - /* - * Convert x to 8.24 for next step. - */ - x = COGL_FIXED_FAST_DIV (frame, n_frames) << 8; - - /* - * f(x) = -2x^3 + 3x^2 - * - * Convert result to ClutterFixed to avoid overflow in next step. - */ - r = ((x >> 12) * (x >> 12) * 3 - (x >> 15) * (x >> 16) * (x >> 16)) >> 8; - - return COGL_FIXED_TO_INT (r * CLUTTER_ALPHA_MAX_ALPHA); -} - -/** - * CLUTTER_ALPHA_SMOOTHSTEP_DEC: - * - * Convenience symbol for clutter_smoothstep_dec_func(). - * - * Since: 0.4 - */ - -/** - * clutter_smoothstep_dec_func: - * @alpha: a #ClutterAlpha - * @dummy: unused - * - * Convenience alpha function for a downward smoothstep curve. You can use - * this function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value - * - * Since: 0.4 - */ -guint32 -clutter_smoothstep_dec_func (ClutterAlpha *alpha, - gpointer dummy) -{ - return CLUTTER_ALPHA_MAX_ALPHA - clutter_smoothstep_inc_func (alpha, dummy); -} - -/** - * CLUTTER_ALPHA_EXP_INC: - * - * Convenience symbol for clutter_exp_inc_func() - * - * Since: 0.4 - */ - -/** - * clutter_exp_inc_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a 2^x curve. You can use this function as the - * alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.4 - */ -guint32 -clutter_exp_inc_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline * timeline; - gint frame; - gint n_frames; - ClutterFixed x; - ClutterFixed x_alpha_max = 0x100000; - guint32 result; - - /* - * Choose x_alpha_max such that - * - * (2^x_alpha_max) - 1 == CLUTTER_ALPHA_MAX_ALPHA - */ -#if CLUTTER_ALPHA_MAX_ALPHA != 0xffff -#error Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA -#endif - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = x_alpha_max * frame / n_frames; - - result = CLAMP (cogl_fixed_pow2 (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA); - - return result; -} - -/** - * CLUTTER_ALPHA_EXP_DEC: - * - * Convenience symbold for clutter_exp_dec_func(). - * - * Since: 0.4 - */ - -/** - * clutter_exp_dec_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a decreasing 2^x curve. You can use this - * function as the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 0.4 - */ -guint32 -clutter_exp_dec_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline * timeline; - gint frame; - gint n_frames; - ClutterFixed x; - ClutterFixed x_alpha_max = 0x100000; - guint32 result; - - /* - * Choose x_alpha_max such that - * - * (2^x_alpha_max) - 1 == CLUTTER_ALPHA_MAX_ALPHA - */ -#if CLUTTER_ALPHA_MAX_ALPHA != 0xffff -#error Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA -#endif - - timeline = clutter_alpha_get_timeline (alpha); - frame = clutter_timeline_get_current_frame (timeline); - n_frames = clutter_timeline_get_n_frames (timeline); - - x = (x_alpha_max * (n_frames - frame)) / n_frames; - - result = CLAMP (cogl_fixed_pow2 (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA); - - return result; -} - -static inline gdouble -clutter_cubic_bezier (ClutterAlpha *alpha, - gdouble x_1, - gdouble y_1, - gdouble x_2, - gdouble y_2) -{ - ClutterTimeline *timeline; - gdouble t, b_t, res; - - /* the cubic bezier has a parametric form of: - * - * B(t) = (1 - t)^3 * P_0 - * + 3t * (1 - t)^2 * P_1 - * + 3t^2 * (1 - t) * P_2 - * + t^3 * P_3 (with t included in [0, 1]) - * - * the P_0 and P_3 points are set to (0, 0) and (1, 1) respectively, - * and the curve never passes through P_1 and P_2 - with these two - * points merely acting as control points for the curve starting - * from P_0 and ending at P_3. - * - * since the starting point is (0, 0) we can simplify the previous - * parametric form to: - * - * B(t) = 3t * (1 - t)^2 * P_1 - * + 3t^2 * (1 - t) * P_2 - * + t^3 * P_3 (with t included in [0, 1]) - * - * and, similarly, since the final point is (1, 1) we can simplify - * it further to: - * - * B(t) = 3t * (1 - t)^2 * P_1 - * + 3t^2 * (1 - t) * P_2 - * + t^3 (with t included in [0, 1]) - * - * since an alpha function has only a time parameter and we have two - * coordinates for each point, we pass the time as the first - * coordinate for the point and then we solve the cubic beziér curve - * for the second coordinate at the same point. - */ - - timeline = clutter_alpha_get_timeline (alpha); - t = clutter_timeline_get_progress (timeline); - - b_t = 3 * t * pow (1 - t, 2) * x_1 - + 3 * pow (t, 2) * (1 - t) * x_2 - + pow (t, 3); - - res = 3 * b_t * pow (1 - b_t, 2) * y_1 - + 3 * pow (b_t, 2) * (1 - b_t) * y_2 - + pow (b_t, 3); - - return res; -} - -/** - * clutter_ease_in_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a cubic Beziér curve with control - * points at (0.42, 0) and (1, 0). You can use this function as the - * alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_ease_in_func (ClutterAlpha *alpha, - gpointer dummy) -{ - gdouble res; - - res = clutter_cubic_bezier (alpha, 0.42, 0, 1, 0); - - return CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); -} - -/** - * clutter_ease_out_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a cubic Beziér curve with control - * points at (0, 0) and (0.58, 1). You can use this function as the - * alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_ease_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - gdouble res; - - res = clutter_cubic_bezier (alpha, 0, 0, 0.58, 1); - - return CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); -} - -/** - * clutter_ease_in_out_func: - * @alpha: a #ClutterAlpha - * @dummy: unused argument - * - * Convenience alpha function for a cubic Beziér curve with control - * points at (0.42, 0) and (0.58, 1). You can use this function as - * the alpha function for clutter_alpha_set_func(). - * - * Return value: an alpha value. - * - * Since: 1.0 - */ -guint32 -clutter_ease_in_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - gdouble res; - - res = clutter_cubic_bezier (alpha, 0.42, 0, 0.58, 1); - - return CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); -} - -guint32 -clutter_exp_in_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gdouble progress, res; - - timeline = clutter_alpha_get_timeline (alpha); - progress = clutter_timeline_get_progress (timeline); - - res = pow (2, 10 * (progress - 1)); - res = CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); - - return res; -} - -guint32 -clutter_exp_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gdouble progress, res; - - timeline = clutter_alpha_get_timeline (alpha); - progress = clutter_timeline_get_progress (timeline); - - res = -pow (2, (-10 * progress)) + 1; - res = CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); - - return res; -} - -guint32 -clutter_exp_in_out_func (ClutterAlpha *alpha, - gpointer dummy) -{ - ClutterTimeline *timeline; - gdouble progress, res; - - timeline = clutter_alpha_get_timeline (alpha); - progress = clutter_timeline_get_progress (timeline); - - if (progress < 0.5) - res = 0.5 * pow (2, (10 * (progress - 1))); - else - res = 0.5 * -pow (2, (-10 * progress)) + 1; - - res = CLAMP (res * CLUTTER_ALPHA_MAX_ALPHA, 0, CLUTTER_ALPHA_MAX_ALPHA); - - return res; -} diff --git a/clutter/clutter-alpha.h b/clutter/clutter-alpha.h index 8872f7a9e..5f64d1d7d 100644 --- a/clutter/clutter-alpha.h +++ b/clutter/clutter-alpha.h @@ -8,7 +8,8 @@ * Emmanuele Bassi * Tomas Frydrych * - * Copyright (C) 2006, 2007 OpenedHand + * Copyright (C) 2006, 2007, 2008 OpenedHand + * Copyright (C) 2009 Intel Corp. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -52,15 +53,14 @@ typedef struct _ClutterAlphaPrivate ClutterAlphaPrivate; * @alpha: a #ClutterAlpha * @user_data: user data passed to the function * - * A function of time, which returns a value between 0 and - * %CLUTTER_ALPHA_MAX_ALPHA. + * A function returning a value depending on the position of + * the #ClutterTimeline bound to @alpha. * - * Return value: an unsigned integer value, between 0 and - * %CLUTTER_ALPHA_MAX_ALPHA. + * Return value: a floating point value * * Since: 0.2 */ -typedef guint32 (*ClutterAlphaFunc) (ClutterAlpha *alpha, +typedef gdouble (*ClutterAlphaFunc) (ClutterAlpha *alpha, gpointer user_data); /** @@ -76,6 +76,7 @@ struct _ClutterAlpha { /*< private >*/ GInitiallyUnowned parent; + ClutterAlphaPrivate *priv; }; @@ -98,15 +99,6 @@ struct _ClutterAlphaClass void (*_clutter_alpha_5) (void); }; -/** - * CLUTTER_ALPHA_MAX_ALPHA: - * - * Maximum value returned by #ClutterAlphaFunc - * - * Since: 0.2 - */ -#define CLUTTER_ALPHA_MAX_ALPHA (0xffff) - GType clutter_alpha_get_type (void) G_GNUC_CONST; ClutterAlpha * clutter_alpha_new (void); @@ -117,7 +109,7 @@ ClutterAlpha * clutter_alpha_new_with_func (ClutterTimeline *timeline, gpointer data, GDestroyNotify destroy); -guint32 clutter_alpha_get_alpha (ClutterAlpha *alpha); +gdouble clutter_alpha_get_alpha (ClutterAlpha *alpha); void clutter_alpha_set_func (ClutterAlpha *alpha, ClutterAlphaFunc func, gpointer data, @@ -135,56 +127,6 @@ gulong clutter_alpha_register_func (ClutterAlphaFunc func, gpointer data); gulong clutter_alpha_register_closure (GClosure *closure); -/* convenience functions */ -guint32 clutter_ramp_inc_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_ramp_dec_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_ramp_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_sine_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_inc_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_dec_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_half_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_in_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_out_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_sine_in_out_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_square_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_smoothstep_inc_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_smoothstep_dec_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_exp_inc_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_exp_dec_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_ease_in_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_ease_out_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_ease_in_out_func (ClutterAlpha *alpha, - gpointer dummy); - -guint32 clutter_exp_in_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_exp_out_func (ClutterAlpha *alpha, - gpointer dummy); -guint32 clutter_exp_in_out_func (ClutterAlpha *alpha, - gpointer dummy); - G_END_DECLS #endif /* __CLUTTER_ALPHA_H__ */ diff --git a/clutter/clutter-animation.c b/clutter/clutter-animation.c index 5994ff38e..900c5fba3 100644 --- a/clutter/clutter-animation.c +++ b/clutter/clutter-animation.c @@ -664,7 +664,7 @@ on_alpha_notify (GObject *gobject, { ClutterAnimationPrivate *priv = animation->priv; GList *properties, *p; - guint32 alpha_value; + gdouble alpha_value; gboolean is_animatable = FALSE; ClutterAnimatable *animatable = NULL; @@ -683,7 +683,6 @@ on_alpha_notify (GObject *gobject, { const gchar *p_name = p->data; ClutterInterval *interval; - gdouble factor; GValue value = { 0, }; interval = g_hash_table_lookup (priv->properties, p_name); @@ -691,8 +690,6 @@ on_alpha_notify (GObject *gobject, g_value_init (&value, clutter_interval_get_value_type (interval)); - factor = (gdouble) alpha_value / CLUTTER_ALPHA_MAX_ALPHA; - if (is_animatable) { const GValue *initial, *final; @@ -704,7 +701,7 @@ on_alpha_notify (GObject *gobject, clutter_animatable_animate_property (animatable, animation, p_name, initial, final, - factor, + alpha_value, &value); g_object_set_property (priv->object, p_name, &value); @@ -713,7 +710,7 @@ on_alpha_notify (GObject *gobject, { CLUTTER_NOTE (ANIMATION, "Standard property `%s'", p_name); - if (clutter_interval_compute_value (interval, factor, &value)) + if (clutter_interval_compute_value (interval, alpha_value, &value)) g_object_set_property (priv->object, p_name, &value); } diff --git a/clutter/clutter-behaviour-depth.c b/clutter/clutter-behaviour-depth.c index 90fc456af..3aee44712 100644 --- a/clutter/clutter-behaviour-depth.c +++ b/clutter/clutter-behaviour-depth.c @@ -74,7 +74,7 @@ alpha_notify_foreach (ClutterBehaviour *behaviour, static void clutter_behaviour_depth_alpha_notify (ClutterBehaviour *behaviour, - guint32 alpha_value) + gdouble alpha_value) { ClutterFixed factor; ClutterBehaviourDepthPrivate *priv; @@ -83,11 +83,11 @@ clutter_behaviour_depth_alpha_notify (ClutterBehaviour *behaviour, priv = CLUTTER_BEHAVIOUR_DEPTH (behaviour)->priv; /* Need to create factor as to avoid borking signedness */ - factor = COGL_FIXED_FROM_INT (alpha_value) / CLUTTER_ALPHA_MAX_ALPHA; + factor = COGL_FIXED_FROM_FLOAT (alpha_value); depth = priv->depth_start + COGL_FIXED_TO_INT (factor * (priv->depth_end - priv->depth_start)); - CLUTTER_NOTE (BEHAVIOUR, "alpha: %d, depth: %d", alpha_value, depth); + CLUTTER_NOTE (BEHAVIOUR, "alpha: %.4f, depth: %d", alpha_value, depth); clutter_behaviour_actors_foreach (behaviour, alpha_notify_foreach, diff --git a/clutter/clutter-behaviour-ellipse.c b/clutter/clutter-behaviour-ellipse.c index a5d4bff35..4b97355e6 100644 --- a/clutter/clutter-behaviour-ellipse.c +++ b/clutter/clutter-behaviour-ellipse.c @@ -205,7 +205,7 @@ clamp_angle (ClutterAngle a) static void clutter_behaviour_ellipse_alpha_notify (ClutterBehaviour *behave, - guint32 alpha) + gdouble alpha) { ClutterBehaviourEllipse *self = CLUTTER_BEHAVIOUR_ELLIPSE (behave); ClutterBehaviourEllipsePrivate *priv = self->priv; @@ -225,7 +225,7 @@ clutter_behaviour_ellipse_alpha_notify (ClutterBehaviour *behave, end -= 1024; } - angle = (end - start) * alpha / CLUTTER_ALPHA_MAX_ALPHA + start; + angle = (end - start) * alpha + start; clutter_behaviour_ellipse_advance (self, angle, &knot); diff --git a/clutter/clutter-behaviour-opacity.c b/clutter/clutter-behaviour-opacity.c index f31099442..0ad25c22b 100644 --- a/clutter/clutter-behaviour-opacity.c +++ b/clutter/clutter-behaviour-opacity.c @@ -87,7 +87,7 @@ alpha_notify_foreach (ClutterBehaviour *behaviour, static void clutter_behaviour_alpha_notify (ClutterBehaviour *behave, - guint32 alpha_value) + gdouble alpha_value) { ClutterBehaviourOpacityPrivate *priv; guint8 opacity; @@ -96,10 +96,9 @@ clutter_behaviour_alpha_notify (ClutterBehaviour *behave, opacity = alpha_value * (priv->opacity_end - priv->opacity_start) - / CLUTTER_ALPHA_MAX_ALPHA + priv->opacity_start; - CLUTTER_NOTE (BEHAVIOUR, "alpha: %u, opacity: %u", + CLUTTER_NOTE (BEHAVIOUR, "alpha: %.4f, opacity: %u", alpha_value, opacity); diff --git a/clutter/clutter-behaviour-path.c b/clutter/clutter-behaviour-path.c index 7594fdbfb..eea1733b7 100644 --- a/clutter/clutter-behaviour-path.c +++ b/clutter/clutter-behaviour-path.c @@ -123,7 +123,7 @@ actor_apply_knot_foreach (ClutterBehaviour *behaviour, static void clutter_behaviour_path_alpha_notify (ClutterBehaviour *behave, - guint32 alpha_value) + gdouble alpha_value) { ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (behave); ClutterBehaviourPathPrivate *priv = pathb->priv; @@ -131,10 +131,7 @@ clutter_behaviour_path_alpha_notify (ClutterBehaviour *behave, guint knot_num; if (priv->path) - knot_num = clutter_path_get_position (priv->path, - alpha_value - / (gdouble) CLUTTER_ALPHA_MAX_ALPHA, - &position); + knot_num = clutter_path_get_position (priv->path, alpha_value, &position); else { memset (&position, 0, sizeof (position)); diff --git a/clutter/clutter-behaviour-rotate.c b/clutter/clutter-behaviour-rotate.c index 3e13c6dab..6864ca963 100644 --- a/clutter/clutter-behaviour-rotate.c +++ b/clutter/clutter-behaviour-rotate.c @@ -117,7 +117,7 @@ ClutterFixed clamp_angle (ClutterFixed a) static void clutter_behaviour_rotate_alpha_notify (ClutterBehaviour *behaviour, - guint32 alpha_value) + gdouble alpha_value) { ClutterFixed factor, angle, start, end; ClutterBehaviourRotate *rotate_behaviour; @@ -126,7 +126,7 @@ clutter_behaviour_rotate_alpha_notify (ClutterBehaviour *behaviour, rotate_behaviour = CLUTTER_BEHAVIOUR_ROTATE (behaviour); priv = rotate_behaviour->priv; - factor = COGL_FIXED_FROM_INT (alpha_value) / CLUTTER_ALPHA_MAX_ALPHA; + factor = COGL_FIXED_FROM_FLOAT (alpha_value); angle = 0; start = priv->angle_start; diff --git a/clutter/clutter-behaviour-scale.c b/clutter/clutter-behaviour-scale.c index f358a71f0..babb44ae7 100644 --- a/clutter/clutter-behaviour-scale.c +++ b/clutter/clutter-behaviour-scale.c @@ -90,7 +90,7 @@ scale_frame_foreach (ClutterBehaviour *behaviour, static void clutter_behaviour_scale_alpha_notify (ClutterBehaviour *behave, - guint32 alpha_value) + gdouble alpha_value) { ClutterBehaviourScalePrivate *priv; ClutterFixed scale_x, scale_y; @@ -101,7 +101,7 @@ clutter_behaviour_scale_alpha_notify (ClutterBehaviour *behave, /* Fix the start/end values, avoids potential rounding errors on large * values. */ - if (alpha_value == CLUTTER_ALPHA_MAX_ALPHA) + if (alpha_value == 1.0) { scale_x = priv->x_scale_end; scale_y = priv->y_scale_end; @@ -115,7 +115,7 @@ clutter_behaviour_scale_alpha_notify (ClutterBehaviour *behave, { ClutterFixed factor; - factor = COGL_FIXED_FROM_INT (alpha_value) / CLUTTER_ALPHA_MAX_ALPHA; + factor = COGL_FIXED_FROM_FLOAT (alpha_value); scale_x = COGL_FIXED_FAST_MUL (factor, (priv->x_scale_end - priv->x_scale_start)); diff --git a/clutter/clutter-behaviour.c b/clutter/clutter-behaviour.c index 006be1bda..f4bdf546f 100644 --- a/clutter/clutter-behaviour.c +++ b/clutter/clutter-behaviour.c @@ -240,7 +240,7 @@ clutter_behaviour_get_property (GObject *object, static void clutter_behaviour_alpha_notify_unimplemented (ClutterBehaviour *behaviour, - guint32 alpha_value) + gdouble alpha_value) { g_warning ("ClutterBehaviourClass::alpha_notify not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (behaviour))); @@ -533,11 +533,9 @@ notify_cb (GObject *object, if (klass->alpha_notify) { - guint32 alpha_value; + gdouble alpha_value = clutter_alpha_get_alpha (behave->priv->alpha); - alpha_value = clutter_alpha_get_alpha (behave->priv->alpha); - - CLUTTER_NOTE (BEHAVIOUR, "calling %s::alpha_notify (%p, %d)", + CLUTTER_NOTE (BEHAVIOUR, "calling %s::alpha_notify (%p, %.4f)", g_type_name (G_TYPE_FROM_CLASS (klass)), behave, alpha_value); diff --git a/clutter/clutter-behaviour.h b/clutter/clutter-behaviour.h index c190961e5..74ac9134c 100644 --- a/clutter/clutter-behaviour.h +++ b/clutter/clutter-behaviour.h @@ -113,7 +113,7 @@ struct _ClutterBehaviourClass /*< public >*/ /* vfunc, not signal */ void (*alpha_notify) (ClutterBehaviour *behave, - guint32 alpha_value); + gdouble alpha_value); /* signals */ void (*applied) (ClutterBehaviour *behave, diff --git a/clutter/clutter-interval.c b/clutter/clutter-interval.c index efdf58dff..35f38189d 100644 --- a/clutter/clutter-interval.c +++ b/clutter/clutter-interval.c @@ -891,8 +891,6 @@ clutter_interval_compute_value (ClutterInterval *interval, g_return_val_if_fail (CLUTTER_IS_INTERVAL (interval), FALSE); g_return_val_if_fail (value != NULL, FALSE); - factor = CLAMP (factor, 0.0, 1.0); - return CLUTTER_INTERVAL_GET_CLASS (interval)->compute_value (interval, factor, value); diff --git a/clutter/clutter-marshal.list b/clutter/clutter-marshal.list index 613d84a9e..d68ce4b27 100644 --- a/clutter/clutter-marshal.list +++ b/clutter/clutter-marshal.list @@ -1,5 +1,6 @@ BOOLEAN:BOXED BOOLEAN:STRING,UINT,ENUM +DOUBLE:VOID UINT:VOID VOID:BOXED VOID:INT diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index d4b23754e..8b357de70 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -528,30 +528,8 @@ static const struct ClutterAlphaFunc symbol; } clutter_alphas[] = { #define ALPHA_FUNC(func,nick) { #func, nick, func } - ALPHA_FUNC (clutter_ramp_inc_func, "ramp-inc"), - ALPHA_FUNC (clutter_ramp_dec_func, "ramp-dec"), - ALPHA_FUNC (clutter_ramp_func, "ramp"), - ALPHA_FUNC (clutter_sine_inc_func, "sine-inc"), - ALPHA_FUNC (clutter_sine_dec_func, "sine-dec"), - ALPHA_FUNC (clutter_sine_half_func, "sine-half"), - ALPHA_FUNC (clutter_sine_in_func, "sine-in"), - ALPHA_FUNC (clutter_sine_out_func, "sine-out"), - ALPHA_FUNC (clutter_sine_in_out_func, "sine-in-out"), - ALPHA_FUNC (clutter_sine_func, "sine"), - ALPHA_FUNC (clutter_square_func, "square"), - ALPHA_FUNC (clutter_smoothstep_inc_func, "smoothstep-inc"), - ALPHA_FUNC (clutter_smoothstep_dec_func, "smoothstep-dec"), - ALPHA_FUNC (clutter_exp_inc_func, "exp-inc"), - ALPHA_FUNC (clutter_exp_dec_func, "exp-dec"), - ALPHA_FUNC (clutter_ramp_inc_func, "linear"), - ALPHA_FUNC (clutter_ease_in_func, "ease-in"), - ALPHA_FUNC (clutter_ease_out_func, "ease-out"), - ALPHA_FUNC (clutter_ease_in_out_func, "ease-in-out"), - ALPHA_FUNC (clutter_exp_in_func, "exp-in"), - ALPHA_FUNC (clutter_exp_out_func, "exp-out"), - ALPHA_FUNC (clutter_exp_in_out_func, "exp-in-out"), - ALPHA_FUNC (clutter_smoothstep_inc_func, "smooth-in-out") #undef ALPHA_FUNC + { NULL, NULL, NULL } }; static const gint n_clutter_alphas = G_N_ELEMENTS (clutter_alphas); diff --git a/tests/interactive/test-actors.c b/tests/interactive/test-actors.c index ded1e1a24..819adfaae 100644 --- a/tests/interactive/test-actors.c +++ b/tests/interactive/test-actors.c @@ -123,6 +123,16 @@ frame_cb (ClutterTimeline *timeline, } } +static gdouble +my_sine_wave (ClutterAlpha *alpha, + gpointer dummy G_GNUC_UNUSED) +{ + ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha); + gdouble progress = clutter_timeline_get_progress (timeline); + + return sin (progress * G_PI); +} + G_MODULE_EXPORT int test_actors_main (int argc, char *argv[]) { @@ -168,8 +178,7 @@ test_actors_main (int argc, char *argv[]) g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh); /* Set up some behaviours to handle scaling */ - alpha = clutter_alpha_new_with_func (timeline, clutter_sine_func, - NULL, NULL); + alpha = clutter_alpha_new_with_func (timeline, my_sine_wave, NULL, NULL); scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, diff --git a/tests/interactive/test-layout.c b/tests/interactive/test-layout.c index f446779cc..4b70260a8 100644 --- a/tests/interactive/test-layout.c +++ b/tests/interactive/test-layout.c @@ -765,7 +765,7 @@ test_layout_main (int argc, char *argv[]) G_CALLBACK (relayout_on_frame), NULL); - alpha = clutter_alpha_new_full (main_timeline, CLUTTER_SINE_IN_OUT); + alpha = clutter_alpha_new_full (main_timeline, CLUTTER_LINEAR); behaviour = clutter_behaviour_scale_new (alpha, 1.0, 1.0, 2.0, 2.0); box = my_thing_new (10, 10); diff --git a/tests/interactive/test-paint-wrapper.c b/tests/interactive/test-paint-wrapper.c index 5bc60f018..79f4b4c01 100644 --- a/tests/interactive/test-paint-wrapper.c +++ b/tests/interactive/test-paint-wrapper.c @@ -160,6 +160,16 @@ hand_post_paint (ClutterActor *actor, oh->paint_guards[actor_num] = FALSE; } +static gdouble +my_sine_wave (ClutterAlpha *alpha, + gpointer dummy G_GNUC_UNUSED) +{ + ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha); + gdouble progress = clutter_timeline_get_progress (timeline); + + return sin (progress * G_PI); +} + G_MODULE_EXPORT int test_paint_wrapper_main (int argc, char *argv[]) { @@ -205,7 +215,7 @@ test_paint_wrapper_main (int argc, char *argv[]) g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh); /* Set up some behaviours to handle scaling */ - alpha = clutter_alpha_new_full (timeline, CLUTTER_SINE_IN_OUT); + alpha = clutter_alpha_new_with_func (timeline, my_sine_wave, NULL, NULL); scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, diff --git a/tests/interactive/test-scale.c b/tests/interactive/test-scale.c index 0a466cb5d..7a2d86fdf 100644 --- a/tests/interactive/test-scale.c +++ b/tests/interactive/test-scale.c @@ -36,6 +36,15 @@ set_next_gravity (ClutterActor *actor) gindex = 0; } +static gdouble +my_ramp_func (ClutterAlpha *alpha, + gpointer unused) +{ + ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha); + + return clutter_timeline_get_progress (timeline); +} + G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { @@ -79,7 +88,7 @@ test_scale_main (int argc, char *argv[]) timeline = clutter_timeline_new_for_duration (750); alpha = clutter_alpha_new_with_func (timeline, - clutter_ramp_func, + my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha,