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>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* #ClutterAlpha is a class for calculating an alpha value as a function
|
|
|
|
* of time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "clutter-alpha.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-marshal.h"
|
|
|
|
|
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-14 09:12:56 -05:00
|
|
|
struct _ClutterAlphaPrivate
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
2006-09-08 16:57:31 -04:00
|
|
|
guint timeline_new_frame_id;
|
|
|
|
guint32 alpha;
|
2006-08-28 13:11:15 -04:00
|
|
|
ClutterAlphaFunc func;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TIMELINE,
|
2006-09-08 16:57:31 -04:00
|
|
|
PROP_FUNC,
|
2006-08-28 13:11:15 -04:00
|
|
|
PROP_ALPHA
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Alpha funcs */
|
|
|
|
|
|
|
|
guint32
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_ramp_inc_func (ClutterAlpha *alpha)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
int current_frame_num, nframes;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
current_frame_num =
|
|
|
|
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
|
|
|
nframes =
|
|
|
|
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
return (current_frame_num * CLUTTER_ALPHA_MAX_ALPHA) / nframes;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_ramp_dec_func (ClutterAlpha *alpha)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
int current_frame_num, nframes;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
current_frame_num =
|
|
|
|
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
|
|
|
nframes =
|
|
|
|
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
return ((nframes - current_frame_num) * CLUTTER_ALPHA_MAX_ALPHA) / nframes;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_ramp_func (ClutterAlpha *alpha)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
int current_frame_num, nframes;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
current_frame_num =
|
|
|
|
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
|
|
|
nframes =
|
|
|
|
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
if (current_frame_num > (nframes/2))
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
return ((nframes - current_frame_num)
|
|
|
|
* CLUTTER_ALPHA_MAX_ALPHA) / (nframes/2);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
return (current_frame_num * CLUTTER_ALPHA_MAX_ALPHA) / (nframes/2);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Object */
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeline_new_frame_cb (ClutterTimeline *timeline,
|
|
|
|
guint current_frame_num,
|
|
|
|
ClutterAlpha *alpha)
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
ClutterAlphaPrivate *priv;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
priv = alpha->priv;
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:52:38 -04:00
|
|
|
/* Update alpha value */
|
2006-09-08 16:57:31 -04:00
|
|
|
if (priv->func) {
|
|
|
|
priv->alpha = priv->func(alpha);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (alpha), "alpha");
|
|
|
|
}
|
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-09-08 16:57:31 -04:00
|
|
|
ClutterAlpha *alpha;
|
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
|
|
|
alpha = CLUTTER_ALPHA(object);
|
|
|
|
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;
|
2006-09-08 16:57:31 -04:00
|
|
|
case PROP_FUNC:
|
|
|
|
priv->func = g_value_get_pointer (value);
|
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_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-09-08 16:57:31 -04:00
|
|
|
alpha = CLUTTER_ALPHA(object);
|
|
|
|
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;
|
2006-09-08 16:57:31 -04:00
|
|
|
case PROP_FUNC:
|
|
|
|
g_value_set_pointer (value, priv->func);
|
|
|
|
break;
|
2006-08-28 13:11:15 -04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
object_class = (GObjectClass*) 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-09-08 16:57:31 -04:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_TIMELINE,
|
|
|
|
g_param_spec_object ("timeline",
|
|
|
|
"Timeline",
|
|
|
|
"Timeline",
|
|
|
|
CLUTTER_TYPE_TIMELINE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_FUNC,
|
|
|
|
g_param_spec_pointer ("func",
|
|
|
|
"Alpha function",
|
|
|
|
"Alpha function",
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
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-09-08 16:57:31 -04:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
|
|
|
|
CLUTTER_TYPE_ALPHA,
|
|
|
|
ClutterAlphaPrivate);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
|
|
|
self->priv->func = CLUTTER_ALPHA_RAMP_INC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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-08-28 13:11:15 -04:00
|
|
|
*/
|
2006-09-08 16:57:31 -04:00
|
|
|
gint32
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_set_func (ClutterAlpha *alpha,
|
|
|
|
ClutterAlphaFunc func)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
alpha->priv->func = func;
|
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-08-28 13:11:15 -04:00
|
|
|
*/
|
|
|
|
void
|
2006-09-08 16:57:31 -04:00
|
|
|
clutter_alpha_set_timeline (ClutterAlpha *alpha,
|
2006-08-28 13:11:15 -04:00
|
|
|
ClutterTimeline *timeline)
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
if (alpha->priv->timeline)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
g_signal_handler_disconnect (alpha->priv->timeline,
|
|
|
|
alpha->priv->timeline_new_frame_id);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
g_object_unref (alpha->priv->timeline);
|
|
|
|
alpha->priv->timeline = NULL;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timeline)
|
|
|
|
{
|
2006-09-08 16:57:31 -04:00
|
|
|
alpha->priv->timeline = g_object_ref (timeline);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2006-09-08 16:57:31 -04:00
|
|
|
alpha->priv->timeline_new_frame_id =
|
|
|
|
g_signal_connect (alpha->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-09-08 16:57:31 -04:00
|
|
|
* Return value: The #ClutterTimeline
|
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-09-08 16:57:31 -04:00
|
|
|
* @timeline: #ClutterTimeline timeline
|
|
|
|
* @func: #ClutterAlphaFunc alpha function
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-09-08 16:57:31 -04:00
|
|
|
* Create a new #ClutterAlpha instance.
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2006-09-08 16:57:31 -04:00
|
|
|
* Return Value: a new #ClutterAlpha
|
2006-08-28 13:11:15 -04:00
|
|
|
*/
|
2006-09-08 16:57:31 -04:00
|
|
|
ClutterAlpha*
|
|
|
|
clutter_alpha_new (ClutterTimeline *timeline,
|
|
|
|
ClutterAlphaFunc func)
|
2006-08-28 13:11:15 -04:00
|
|
|
{
|
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-09-08 16:57:31 -04:00
|
|
|
return g_object_new (CLUTTER_TYPE_ALPHA,
|
|
|
|
"timeline", timeline,
|
|
|
|
"func", func,
|
|
|
|
NULL);
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|