2006-08-28 13:11:15 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Jorn Baayen <jorn@openedhand.com>
|
2006-11-15 18:37:53 -05:00
|
|
|
* Emmanuele Bassi <ebassi@openedhand.com>
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-alpha
|
|
|
|
* @short_description: A class for calculating an alpha value as a function
|
|
|
|
* of time.
|
|
|
|
*
|
2006-11-17 13:45:31 -05:00
|
|
|
* #ClutterAlpha is a class for calculating an integer value between
|
|
|
|
* 0 and %CLUTTER_ALPHA_MAX_ALPHA as a function of time. You should
|
|
|
|
* provide a #ClutterTimeline and bind it to the #ClutterAlpha object;
|
|
|
|
* you should also provide a function returning the alpha value depending
|
|
|
|
* on the position inside the timeline; this function will be executed
|
|
|
|
* each time a new frame in the #ClutterTimeline is reached. Since the
|
|
|
|
* alpha function is controlled by the timeline instance, you can pause
|
|
|
|
* or stop the #ClutterAlpha from calling the alpha function by controlling
|
|
|
|
* the #ClutterTimeline object.
|
|
|
|
*
|
|
|
|
* #ClutterAlpha is used to "drive" a #ClutterBehaviour instance.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
#include "clutter-alpha.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-marshal.h"
|
2006-11-15 16:19:01 -05:00
|
|
|
#include <math.h>
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
G_DEFINE_TYPE (ClutterAlpha, clutter_alpha, G_TYPE_OBJECT);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2006-11-14 09:12:56 -05:00
|
|
|
struct _ClutterAlphaPrivate
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
2006-11-15 18:37:53 -05:00
|
|
|
guint timeline_new_frame_id;
|
|
|
|
|
|
|
|
guint32 alpha;
|
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
ClutterAlphaFunc func;
|
2006-11-15 18:37:53 -05:00
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify destroy;
|
2006-08-28 13:11:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
PROP_TIMELINE,
|
|
|
|
PROP_ALPHA
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeline_new_frame_cb (ClutterTimeline *timeline,
|
|
|
|
guint current_frame_num,
|
|
|
|
ClutterAlpha *alpha)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlphaPrivate *priv = alpha->priv;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
/* Update alpha value and notify */
|
|
|
|
if (priv->func)
|
|
|
|
{
|
|
|
|
g_object_ref (alpha);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
priv->alpha = priv->func (alpha, priv->data);
|
2006-09-08 16:57:31 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
g_object_notify (G_OBJECT (alpha), "alpha");
|
|
|
|
g_object_unref (alpha);
|
2006-09-08 16:57:31 -04:00
|
|
|
}
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlpha *alpha;
|
2006-09-08 16:57:31 -04:00
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
alpha = CLUTTER_ALPHA (object);
|
2006-09-08 16:57:31 -04:00
|
|
|
priv = alpha->priv;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_TIMELINE:
|
|
|
|
clutter_alpha_set_timeline (alpha, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
ClutterAlpha *alpha;
|
2006-08-28 13:11:15 -04:00
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
alpha = CLUTTER_ALPHA (object);
|
2006-09-08 16:57:31 -04:00
|
|
|
priv = alpha->priv;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_TIMELINE:
|
|
|
|
g_value_set_object (value, priv->timeline);
|
|
|
|
break;
|
|
|
|
case PROP_ALPHA:
|
2006-08-29 Jorn Baayen <jorn@openedhand.com>
* clutter/clutter-behaviour.c: (_clutter_behaviour_finalize),
(_clutter_behaviour_set_property),
(_clutter_behaviour_get_property), (clutter_behaviour_class_init),
(clutter_behaviour_init), (clutter_behaviour_apply),
(clutter_behaviour_remove), (clutter_behaviour_remove_all),
(clutter_behaviour_actors_foreach):
* clutter/clutter-behaviour.h:
* clutter/clutter-behaviours.c:
(clutter_behaviour_property_change),
(clutter_behaviour_opacity_dispose),
(clutter_behaviour_opacity_finalize),
(clutter_behaviour_opacity_class_init),
(clutter_behaviour_opacity_init):
* clutter/clutter-behaviours.h:
* clutter/clutter-marshal.list:
* examples/behave.c: (main):
Behaviours track generic GObject properties.
* clutter/clutter-video-texture.h:
Remove signal prototypes - they are already specified in
clutter-media.h.
2006-08-29 09:20:29 -04:00
|
|
|
g_value_set_uint (value, priv->alpha);
|
2006-08-28 13:11:15 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_finalize (GObject *object)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlphaPrivate *priv = CLUTTER_ALPHA (object)->priv;
|
|
|
|
|
|
|
|
if (priv->destroy)
|
|
|
|
{
|
|
|
|
priv->destroy (priv->data);
|
2006-11-17 13:45:31 -05:00
|
|
|
|
|
|
|
priv->destroy = NULL;
|
|
|
|
priv->data = NULL;
|
|
|
|
priv->func = NULL;
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
G_OBJECT_CLASS (clutter_alpha_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_dispose (GObject *object)
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
ClutterAlpha *self = CLUTTER_ALPHA(object);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
clutter_alpha_set_timeline (self, NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_alpha_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_class_init (ClutterAlphaClass *klass)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
object_class->set_property = clutter_alpha_set_property;
|
|
|
|
object_class->get_property = clutter_alpha_get_property;
|
|
|
|
object_class->finalize = clutter_alpha_finalize;
|
|
|
|
object_class->dispose = clutter_alpha_dispose;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterAlphaPrivate));
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
/**
|
|
|
|
* ClutterAlpha:timeline:
|
|
|
|
*
|
|
|
|
* A #ClutterTimeline instance used to drive the alpha function.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-15 18:37:53 -05:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_TIMELINE,
|
|
|
|
g_param_spec_object ("timeline",
|
|
|
|
"Timeline",
|
|
|
|
"Timeline",
|
|
|
|
CLUTTER_TYPE_TIMELINE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
/**
|
|
|
|
* ClutterAlpha:alpha:
|
|
|
|
*
|
|
|
|
* The alpha value as computed by the alpha function.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-15 18:37:53 -05:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ALPHA,
|
|
|
|
g_param_spec_uint ("alpha",
|
|
|
|
"Alpha value",
|
|
|
|
"Alpha value",
|
|
|
|
0,
|
|
|
|
CLUTTER_ALPHA_MAX_ALPHA,
|
|
|
|
0,
|
|
|
|
G_PARAM_READABLE));
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_alpha_init (ClutterAlpha *self)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
CLUTTER_TYPE_ALPHA,
|
|
|
|
ClutterAlphaPrivate);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-09-08 16:57:31 -04:00
|
|
|
* clutter_alpha_get_alpha:
|
2006-08-28 13:11:15 -04:00
|
|
|
* @alpha: A #ClutterAlpha
|
|
|
|
*
|
|
|
|
* Query the current alpha value.
|
|
|
|
*
|
2006-09-08 16:57:31 -04:00
|
|
|
* Return Value: The current alpha value for the alpha
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
guint32
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_get_alpha (ClutterAlpha *alpha)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), FALSE);
|
|
|
|
|
|
|
|
return alpha->priv->alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_alpha_set_func:
|
|
|
|
* @alpha: A #ClutterAlpha
|
|
|
|
* @func: A #ClutterAlphaAlphaFunc
|
2006-11-15 18:37:53 -05:00
|
|
|
* @data: user data to be passed to the alpha function, or %NULL
|
|
|
|
* @destroy: notify function used when disposing the alpha function
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-11-15 18:37:53 -05:00
|
|
|
* Sets the #ClutterAlphaFunc function used to compute
|
|
|
|
* the alpha value at each frame of the #ClutterTimeline
|
|
|
|
* bound to @alpha.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
|
|
|
void
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_set_func (ClutterAlpha *alpha,
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlphaFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ALPHA (alpha));
|
|
|
|
|
|
|
|
priv = alpha->priv;
|
|
|
|
|
|
|
|
if (priv->destroy)
|
|
|
|
{
|
|
|
|
priv->destroy (priv->data);
|
|
|
|
priv->func = NULL;
|
|
|
|
priv->data = NULL;
|
|
|
|
priv->destroy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->func = func;
|
|
|
|
priv->data = data;
|
|
|
|
priv->destroy = destroy;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_alpha_set_timeline:
|
|
|
|
* @alpha: A #ClutterAlpha
|
2006-09-08 16:57:31 -04:00
|
|
|
* @timeline: A #ClutterTimeline
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-09-08 16:57:31 -04:00
|
|
|
* Binds @alpha to @timeline.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
|
|
|
void
|
2006-11-15 18:37:53 -05:00
|
|
|
clutter_alpha_set_timeline (ClutterAlpha *alpha,
|
2006-08-28 13:11:15 -04:00
|
|
|
ClutterTimeline *timeline)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ALPHA (alpha));
|
|
|
|
g_return_if_fail (timeline == NULL || CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = alpha->priv;
|
|
|
|
|
|
|
|
if (priv->timeline)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->timeline,
|
|
|
|
timeline_new_frame_cb,
|
|
|
|
alpha);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
g_object_unref (priv->timeline);
|
|
|
|
priv->timeline = NULL;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timeline)
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
priv->timeline = g_object_ref (timeline);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
g_signal_connect (priv->timeline, "new-frame",
|
|
|
|
G_CALLBACK (timeline_new_frame_cb),
|
|
|
|
alpha);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_alpha_get_timeline:
|
|
|
|
* @alpha: A #ClutterAlpha
|
|
|
|
*
|
2006-11-17 13:45:31 -05:00
|
|
|
* Gets the #ClutterTimeline bound to @alpha.
|
|
|
|
*
|
|
|
|
* Return value: a #ClutterTimeline instance
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
|
|
|
ClutterTimeline *
|
|
|
|
clutter_alpha_get_timeline (ClutterAlpha *alpha)
|
|
|
|
{
|
2006-11-14 09:12:56 -05:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), NULL);
|
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
return alpha->priv->timeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_alpha_new:
|
2006-11-15 18:37:53 -05:00
|
|
|
*
|
|
|
|
* Creates a new #ClutterAlpha instance. You must set a function
|
|
|
|
* to compute the alpha value using clutter_alpha_set_func() and
|
|
|
|
* bind a #ClutterTimeline object to the #ClutterAlpha instance
|
|
|
|
* using clutter_alpha_set_timeline().
|
|
|
|
*
|
|
|
|
* You should use the newly created #ClutterAlpha instance inside
|
|
|
|
* a #ClutterBehaviour object.
|
|
|
|
*
|
|
|
|
* Return value: the newly created empty #ClutterAlpha instance.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-15 18:37:53 -05:00
|
|
|
*/
|
|
|
|
ClutterAlpha *
|
|
|
|
clutter_alpha_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CLUTTER_TYPE_ALPHA, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_alpha_new_full:
|
2006-09-08 16:57:31 -04:00
|
|
|
* @timeline: #ClutterTimeline timeline
|
|
|
|
* @func: #ClutterAlphaFunc alpha function
|
2006-11-15 18:37:53 -05:00
|
|
|
* @data: data to be passed to the alpha function
|
|
|
|
* @destroy: notify to be called when removing the alpha function
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-11-17 13:45:31 -05:00
|
|
|
* Creates a new #ClutterAlpha instance and sets the timeline
|
2006-11-15 18:37:53 -05:00
|
|
|
* and alpha function.
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-11-17 13:45:31 -05:00
|
|
|
* Return Value: the newly created #ClutterAlpha
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlpha *
|
|
|
|
clutter_alpha_new_full (ClutterTimeline *timeline,
|
|
|
|
ClutterAlphaFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
ClutterAlpha *retval;
|
|
|
|
|
2006-11-14 09:12:56 -05:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
retval = clutter_alpha_new ();
|
|
|
|
|
|
|
|
clutter_alpha_set_timeline (retval, timeline);
|
|
|
|
clutter_alpha_set_func (retval, func, data, destroy);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-17 13:45:31 -05:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-17 13:45:31 -05:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-17 13:45:31 -05:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-17 13:45:31 -05:00
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
guint32
|
|
|
|
clutter_sine_func (ClutterAlpha *alpha,
|
|
|
|
gpointer dummy)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
gint current_frame_num, n_frames;
|
|
|
|
gdouble x;
|
|
|
|
|
|
|
|
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 * 2.0f * M_PI) / n_frames ;
|
|
|
|
|
|
|
|
CLUTTER_DBG ("%2f\n", ((sin (x - (M_PI / 2.0f)) + 1.0f) * 0.5f));
|
|
|
|
|
|
|
|
return (guint32) (((sin (x - (M_PI / 2.0f)) + 1.0f) * 0.5f)
|
2006-11-17 13:45:31 -05:00
|
|
|
* (gdouble) CLUTTER_ALPHA_MAX_ALPHA);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|