mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
2006-08-28 Jorn Baayen <jorn@openedhand.com>
* clutter/Makefile.am: * clutter/clutter-alpha.c: * clutter/clutter-alpha.h: * clutter/clutter-behaviours.c: (clutter_behaviour_opacity_dispose), (clutter_behaviour_opacity_init), (clutter_behaviour_opacity_frame_foreach), (clutter_behaviour_opacity_frame): * clutter/clutter-behaviours.h: * clutter/clutter-timeline.c: (clutter_timeline_class_init): * clutter/clutter-timeline.h: * clutter/clutter.h: * examples/behave.c: (main): Separate alpha calculation into its own class. * clutter/clutter-behaviour.c: (clutter_behaviour_set_timelime): Correct NULL check.
This commit is contained in:
parent
149a4bac0c
commit
bc3d914ccd
22
ChangeLog
22
ChangeLog
@ -1,3 +1,25 @@
|
||||
2006-08-28 Jorn Baayen <jorn@openedhand.com>
|
||||
|
||||
* clutter/Makefile.am:
|
||||
* clutter/clutter-alpha.c:
|
||||
* clutter/clutter-alpha.h:
|
||||
* clutter/clutter-behaviours.c:
|
||||
(clutter_behaviour_opacity_dispose),
|
||||
(clutter_behaviour_opacity_init),
|
||||
(clutter_behaviour_opacity_frame_foreach),
|
||||
(clutter_behaviour_opacity_frame):
|
||||
* clutter/clutter-behaviours.h:
|
||||
* clutter/clutter-timeline.c: (clutter_timeline_class_init):
|
||||
* clutter/clutter-timeline.h:
|
||||
* clutter/clutter.h:
|
||||
* examples/behave.c: (main):
|
||||
|
||||
Separate alpha calculation into its own class.
|
||||
|
||||
* clutter/clutter-behaviour.c: (clutter_behaviour_set_timelime):
|
||||
|
||||
Correct NULL check.
|
||||
|
||||
2006-08-15 Matthew Allum <mallum@openedhand.com>
|
||||
|
||||
* clutter/clutter-behaviour.h:
|
||||
|
@ -23,6 +23,7 @@ source_h = \
|
||||
$(srcdir)/clutter-label.h \
|
||||
$(srcdir)/clutter-behaviour.h \
|
||||
$(srcdir)/clutter-behaviours.h \
|
||||
$(srcdir)/clutter-alpha.h \
|
||||
$(srcdir)/clutter-main.h
|
||||
|
||||
clutter-marshal.h: clutter-marshal.list
|
||||
@ -87,6 +88,7 @@ source_c = clutter-main.c \
|
||||
clutter-actor.c \
|
||||
clutter-behaviour.c \
|
||||
clutter-behaviours.c \
|
||||
clutter-alpha.c \
|
||||
clutter-enum-types.c
|
||||
|
||||
source_h_priv = clutter-private.h
|
||||
|
339
clutter/clutter-alpha.c
Normal file
339
clutter/clutter-alpha.c
Normal file
@ -0,0 +1,339 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
G_DEFINE_TYPE (ClutterAlpha, clutter_alpha, G_TYPE_OBJECT);
|
||||
|
||||
struct ClutterAlphaPrivate
|
||||
{
|
||||
ClutterTimeline *timeline;
|
||||
guint timeline_new_frame_id;
|
||||
guint32 alpha;
|
||||
ClutterAlphaFunc func;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_TIMELINE,
|
||||
PROP_FUNC,
|
||||
PROP_ALPHA
|
||||
};
|
||||
|
||||
/* Alpha funcs */
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_inc_func (ClutterAlpha *alpha)
|
||||
{
|
||||
int current_frame_num, nframes;
|
||||
|
||||
current_frame_num =
|
||||
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
||||
nframes =
|
||||
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
||||
|
||||
return (current_frame_num * CLUTTER_ALPHA_MAX_ALPHA) / nframes;
|
||||
}
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_dec_func (ClutterAlpha *alpha)
|
||||
{
|
||||
int current_frame_num, nframes;
|
||||
|
||||
current_frame_num =
|
||||
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
||||
nframes =
|
||||
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
||||
|
||||
return ((nframes - current_frame_num) * CLUTTER_ALPHA_MAX_ALPHA) / nframes;
|
||||
}
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_func (ClutterAlpha *alpha)
|
||||
{
|
||||
int current_frame_num, nframes;
|
||||
|
||||
current_frame_num =
|
||||
clutter_timeline_get_current_frame (alpha->priv->timeline);
|
||||
nframes =
|
||||
clutter_timeline_get_n_frames (alpha->priv->timeline);
|
||||
|
||||
if (current_frame_num > (nframes/2))
|
||||
{
|
||||
return ((nframes - current_frame_num)
|
||||
* CLUTTER_ALPHA_MAX_ALPHA) / (nframes/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (current_frame_num * CLUTTER_ALPHA_MAX_ALPHA) / (nframes/2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Object */
|
||||
|
||||
static void
|
||||
timeline_new_frame_cb (ClutterTimeline *timeline,
|
||||
guint current_frame_num,
|
||||
ClutterAlpha *alpha)
|
||||
{
|
||||
ClutterAlphaPrivate *priv;
|
||||
|
||||
priv = alpha->priv;
|
||||
|
||||
/* Update alpha value */
|
||||
if (priv->func) {
|
||||
priv->alpha = priv->func(alpha);
|
||||
|
||||
g_object_notify (G_OBJECT (alpha), "alpha");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_alpha_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ClutterAlpha *alpha;
|
||||
ClutterAlphaPrivate *priv;
|
||||
|
||||
alpha = CLUTTER_ALPHA(object);
|
||||
priv = alpha->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TIMELINE:
|
||||
clutter_alpha_set_timeline (alpha, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_FUNC:
|
||||
priv->func = g_value_get_pointer (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)
|
||||
{
|
||||
ClutterAlpha *alpha;
|
||||
ClutterAlphaPrivate *priv;
|
||||
|
||||
alpha = CLUTTER_ALPHA(object);
|
||||
priv = alpha->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TIMELINE:
|
||||
g_value_set_object (value, priv->timeline);
|
||||
break;
|
||||
case PROP_FUNC:
|
||||
g_value_set_pointer (value, priv->func);
|
||||
break;
|
||||
case PROP_ALPHA:
|
||||
g_value_set_int (value, priv->alpha);
|
||||
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)
|
||||
{
|
||||
ClutterAlpha *self = CLUTTER_ALPHA(object);
|
||||
|
||||
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;
|
||||
|
||||
object_class = (GObjectClass*) klass;
|
||||
|
||||
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));
|
||||
|
||||
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_int ("alpha",
|
||||
"Alpha value",
|
||||
"Alpha value",
|
||||
0,
|
||||
CLUTTER_ALPHA_MAX_ALPHA,
|
||||
0,
|
||||
G_PARAM_READABLE));
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_alpha_init (ClutterAlpha *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
|
||||
CLUTTER_TYPE_ALPHA,
|
||||
ClutterAlphaPrivate);
|
||||
|
||||
self->priv->func = CLUTTER_ALPHA_RAMP_INC;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_alpha_get_alpha:
|
||||
* @alpha: A #ClutterAlpha
|
||||
*
|
||||
* Query the current alpha value.
|
||||
*
|
||||
* Return Value: The current alpha value for the alpha
|
||||
*/
|
||||
gint32
|
||||
clutter_alpha_get_alpha (ClutterAlpha *alpha)
|
||||
{
|
||||
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
|
||||
clutter_alpha_set_func (ClutterAlpha *alpha,
|
||||
ClutterAlphaFunc func)
|
||||
{
|
||||
alpha->priv->func = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_alpha_set_timeline:
|
||||
* @alpha: A #ClutterAlpha
|
||||
* @timeline: A #ClutterTimeline
|
||||
*
|
||||
* Binds @alpha to @timeline.
|
||||
*/
|
||||
void
|
||||
clutter_alpha_set_timeline (ClutterAlpha *alpha,
|
||||
ClutterTimeline *timeline)
|
||||
{
|
||||
if (alpha->priv->timeline)
|
||||
{
|
||||
g_signal_handler_disconnect (alpha->priv->timeline,
|
||||
alpha->priv->timeline_new_frame_id);
|
||||
|
||||
g_object_unref (alpha->priv->timeline);
|
||||
alpha->priv->timeline = NULL;
|
||||
}
|
||||
|
||||
if (timeline)
|
||||
{
|
||||
alpha->priv->timeline = g_object_ref (timeline);
|
||||
|
||||
alpha->priv->timeline_new_frame_id =
|
||||
g_signal_connect (alpha->priv->timeline,
|
||||
"new-frame",
|
||||
G_CALLBACK (timeline_new_frame_cb),
|
||||
alpha);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_alpha_get_timeline:
|
||||
* @alpha: A #ClutterAlpha
|
||||
*
|
||||
* Return value: The #ClutterTimeline
|
||||
*/
|
||||
ClutterTimeline *
|
||||
clutter_alpha_get_timeline (ClutterAlpha *alpha)
|
||||
{
|
||||
return alpha->priv->timeline;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_alpha_new:
|
||||
* @timeline: #ClutterTimeline timeline
|
||||
* @func: #ClutterAlphaFunc alpha function
|
||||
*
|
||||
* Create a new #ClutterAlpha instance.
|
||||
*
|
||||
* Return Value: a new #ClutterAlpha
|
||||
*/
|
||||
ClutterAlpha*
|
||||
clutter_alpha_new (ClutterTimeline *timeline,
|
||||
ClutterAlphaFunc func)
|
||||
{
|
||||
return g_object_new (CLUTTER_TYPE_ALPHA,
|
||||
"timeline", timeline,
|
||||
"func", func,
|
||||
NULL);
|
||||
}
|
118
clutter/clutter-alpha.h
Normal file
118
clutter/clutter-alpha.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _HAVE_CLUTTER_ALPHA_H
|
||||
#define _HAVE_CLUTTER_ALPHA_H
|
||||
|
||||
/* clutter-alpha.h */
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "clutter-timeline.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_ALPHA clutter_alpha_get_type()
|
||||
|
||||
#define CLUTTER_ALPHA(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
CLUTTER_TYPE_ALPHA, ClutterAlpha))
|
||||
|
||||
#define CLUTTER_ALPHA_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||
CLUTTER_TYPE_ALPHA, ClutterAlphaClass))
|
||||
|
||||
#define CLUTTER_IS_ALPHA(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
CLUTTER_TYPE_ALPHA))
|
||||
|
||||
#define CLUTTER_IS_ALPHA_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||
CLUTTER_TYPE_ALPHA))
|
||||
|
||||
#define CLUTTER_ALPHA_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
CLUTTER_TYPE_ALPHA, ClutterAlphaClass))
|
||||
|
||||
typedef struct _ClutterAlpha ClutterAlpha;
|
||||
typedef struct _ClutterAlphaClass ClutterAlphaClass;
|
||||
typedef struct ClutterAlphaPrivate ClutterAlphaPrivate;
|
||||
|
||||
typedef guint32 (*ClutterAlphaFunc) (ClutterAlpha *alpha);
|
||||
|
||||
struct _ClutterAlpha
|
||||
{
|
||||
GObject parent;
|
||||
ClutterAlphaPrivate *priv;
|
||||
};
|
||||
|
||||
struct _ClutterAlphaClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*_clutter_alpha_1) (void);
|
||||
void (*_clutter_alpha_2) (void);
|
||||
void (*_clutter_alpha_3) (void);
|
||||
void (*_clutter_alpha_4) (void);
|
||||
void (*_clutter_alpha_5) (void);
|
||||
};
|
||||
|
||||
#define CLUTTER_ALPHA_MAX_ALPHA 0xffff
|
||||
|
||||
ClutterAlpha *
|
||||
clutter_alpha_new (ClutterTimeline *timeline,
|
||||
ClutterAlphaFunc func);
|
||||
|
||||
gint32
|
||||
clutter_alpha_get_alpha (ClutterAlpha *alpha);
|
||||
|
||||
void
|
||||
clutter_alpha_set_func (ClutterAlpha *alpha,
|
||||
ClutterAlphaFunc func);
|
||||
|
||||
void
|
||||
clutter_alpha_set_timeline (ClutterAlpha *alpha,
|
||||
ClutterTimeline *timeline);
|
||||
|
||||
ClutterTimeline *
|
||||
clutter_alpha_get_timeline (ClutterAlpha *alpha);
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_inc_func (ClutterAlpha *alpha);
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_dec_func (ClutterAlpha *alpha);
|
||||
|
||||
guint32
|
||||
clutter_alpha_ramp_func (ClutterAlpha *alpha);
|
||||
|
||||
#define CLUTTER_ALPHA_RAMP_INC clutter_alpha_ramp_inc_func
|
||||
#define CLUTTER_ALPHA_RAMP_DEC clutter_alpha_ramp_dec_func
|
||||
#define CLUTTER_ALPHA_RAMP clutter_alpha_ramp_func
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -230,7 +230,7 @@ clutter_behaviour_set_timelime (ClutterBehaviour *behave,
|
||||
priv->timeline = NULL;
|
||||
}
|
||||
|
||||
if (behave)
|
||||
if (timeline)
|
||||
{
|
||||
g_object_ref(timeline);
|
||||
priv->timeline = timeline;
|
||||
|
@ -148,9 +148,10 @@ G_DEFINE_TYPE (ClutterBehaviourOpacity, \
|
||||
|
||||
struct ClutterBehaviourOpacityPrivate
|
||||
{
|
||||
guint8 opacity_start;
|
||||
guint8 opacity_end;
|
||||
gulong handler_id; /* FIXME: handle in parent class ? */
|
||||
ClutterAlpha *alpha;
|
||||
guint8 opacity_start;
|
||||
guint8 opacity_end;
|
||||
gulong handler_id; /* FIXME: handle in parent class ? */
|
||||
};
|
||||
|
||||
#define CLUTTER_BEHAVIOUR_OPACITY_GET_PRIVATE(obj) \
|
||||
@ -166,9 +167,18 @@ clutter_behaviour_opacity_dispose (GObject *object)
|
||||
if (self->priv)
|
||||
{
|
||||
if (self->priv->handler_id)
|
||||
g_signal_handler_disconnect
|
||||
(clutter_behaviour_get_timelime (CLUTTER_BEHAVIOUR(self)),
|
||||
self->priv->handler_id);
|
||||
{
|
||||
g_signal_handler_disconnect
|
||||
(clutter_behaviour_get_timelime (CLUTTER_BEHAVIOUR(self)),
|
||||
self->priv->handler_id);
|
||||
self->priv->handler_id = 0;
|
||||
}
|
||||
|
||||
if (self->priv->alpha)
|
||||
{
|
||||
g_object_unref (self->priv->alpha);
|
||||
self->priv->alpha = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (clutter_behaviour_opacity_parent_class)->dispose (object);
|
||||
@ -220,11 +230,10 @@ clutter_behaviour_opacity_frame_foreach (ClutterActor *actor,
|
||||
|
||||
priv = CLUTTER_BEHAVIOUR_OPACITY_GET_PRIVATE (behave);
|
||||
|
||||
alpha = clutter_timeline_get_alpha
|
||||
(clutter_behaviour_get_timelime (CLUTTER_BEHAVIOUR(behave)));
|
||||
alpha = clutter_alpha_get_alpha (priv->alpha);
|
||||
|
||||
opacity = (alpha * (priv->opacity_end - priv->opacity_start))
|
||||
/ CLUTTER_TIMELINE_MAX_ALPHA;
|
||||
/ CLUTTER_ALPHA_MAX_ALPHA;
|
||||
|
||||
opacity += priv->opacity_start;
|
||||
|
||||
@ -234,9 +243,9 @@ clutter_behaviour_opacity_frame_foreach (ClutterActor *actor,
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_behaviour_opacity_frame (ClutterTimeline *timelime,
|
||||
gint frame_num,
|
||||
gpointer data)
|
||||
clutter_behaviour_opacity_frame (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer data)
|
||||
{
|
||||
ClutterBehaviourOpacity *behave;
|
||||
|
||||
@ -249,23 +258,27 @@ clutter_behaviour_opacity_frame (ClutterTimeline *timelime,
|
||||
}
|
||||
|
||||
ClutterBehaviour*
|
||||
clutter_behaviour_opacity_new (ClutterTimeline *timeline,
|
||||
guint8 opacity_start,
|
||||
guint8 opacity_end)
|
||||
clutter_behaviour_opacity_new (ClutterAlpha *alpha,
|
||||
guint8 opacity_start,
|
||||
guint8 opacity_end)
|
||||
{
|
||||
ClutterBehaviourOpacity *behave;
|
||||
ClutterTimeline *timeline;
|
||||
|
||||
timeline = clutter_alpha_get_timeline (alpha);
|
||||
|
||||
behave = g_object_new (CLUTTER_TYPE_BEHAVIOUR_OPACITY,
|
||||
"timeline", timeline,
|
||||
NULL);
|
||||
|
||||
behave->priv->alpha = g_object_ref (alpha);
|
||||
|
||||
behave->priv->opacity_start = opacity_start;
|
||||
behave->priv->opacity_end = opacity_end;
|
||||
|
||||
/* FIXME: Should be part of regular behave functionality */
|
||||
behave->priv->handler_id
|
||||
= g_signal_connect (timeline,
|
||||
"new-frame",
|
||||
= g_signal_connect (alpha,
|
||||
"notify::alpha",
|
||||
G_CALLBACK (clutter_behaviour_opacity_frame),
|
||||
behave);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "clutter-behaviour.h"
|
||||
#include "clutter-alpha.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -94,9 +95,9 @@ struct _ClutterBehaviourOpacityClass
|
||||
GType clutter_behaviour_opacity_get_type (void);
|
||||
|
||||
ClutterBehaviour*
|
||||
clutter_behaviour_opacity_new (ClutterTimeline *timeline,
|
||||
guint8 opacity_start,
|
||||
guint8 opacity_end);
|
||||
clutter_behaviour_opacity_new (ClutterAlpha *alpha,
|
||||
guint8 opacity_start,
|
||||
guint8 opacity_end);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -51,9 +51,6 @@ struct ClutterTimelinePrivate
|
||||
gulong last_frame_msecs;
|
||||
gulong start_frame_secs;
|
||||
|
||||
guint32 alpha;
|
||||
ClutterTimelineAlphaFunc alpha_func;
|
||||
|
||||
guint loop : 1;
|
||||
};
|
||||
|
||||
@ -62,8 +59,7 @@ enum
|
||||
PROP_0,
|
||||
PROP_FPS,
|
||||
PROP_NFRAMES,
|
||||
PROP_LOOP,
|
||||
PROP_ALPHA
|
||||
PROP_LOOP
|
||||
};
|
||||
|
||||
enum
|
||||
@ -77,41 +73,6 @@ enum
|
||||
|
||||
static int timeline_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
/* Alpha funcs */
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_inc_func (ClutterTimeline *timeline)
|
||||
{
|
||||
return (timeline->priv->current_frame_num * CLUTTER_TIMELINE_MAX_ALPHA)
|
||||
/ timeline->priv->nframes;
|
||||
}
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_dec_func (ClutterTimeline *timeline)
|
||||
{
|
||||
return ((timeline->priv->nframes - timeline->priv->current_frame_num)
|
||||
* CLUTTER_TIMELINE_MAX_ALPHA)
|
||||
/ timeline->priv->nframes;
|
||||
}
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_func (ClutterTimeline *timeline)
|
||||
{
|
||||
|
||||
if (timeline->priv->current_frame_num > (timeline->priv->nframes/2))
|
||||
{
|
||||
return (((timeline->priv->nframes) - timeline->priv->current_frame_num)
|
||||
* CLUTTER_TIMELINE_MAX_ALPHA)
|
||||
/ (timeline->priv->nframes/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (timeline->priv->current_frame_num * CLUTTER_TIMELINE_MAX_ALPHA)
|
||||
/ (timeline->priv->nframes/2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Object */
|
||||
|
||||
static void
|
||||
@ -134,9 +95,6 @@ clutter_timeline_set_property (GObject *object,
|
||||
case PROP_NFRAMES:
|
||||
priv->nframes = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_ALPHA:
|
||||
priv->alpha = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_LOOP:
|
||||
priv->loop = g_value_get_boolean (value);
|
||||
break;
|
||||
@ -226,16 +184,6 @@ clutter_timeline_class_init (ClutterTimelineClass *klass)
|
||||
50,
|
||||
G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ALPHA,
|
||||
g_param_spec_int ("alpha",
|
||||
"Alpha value for timeline",
|
||||
"Alpha value for timeline",
|
||||
0,
|
||||
CLUTTER_TIMELINE_MAX_ALPHA,
|
||||
0,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_NFRAMES,
|
||||
g_param_spec_int ("num-frames",
|
||||
@ -295,8 +243,6 @@ clutter_timeline_init (ClutterTimeline *self)
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
|
||||
CLUTTER_TYPE_TIMELINE,
|
||||
ClutterTimelinePrivate);
|
||||
|
||||
self->priv->alpha_func = CLUTTER_ALPHA_RAMP_INC;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -351,10 +297,6 @@ timeline_timeout_func (gpointer data)
|
||||
|
||||
priv->last_frame_msecs = msecs;
|
||||
|
||||
/* Update alpha value */
|
||||
if (priv->alpha_func)
|
||||
priv->alpha = priv->alpha_func(timeline);
|
||||
|
||||
/* Advance frames */
|
||||
priv->current_frame_num += nframes;;
|
||||
|
||||
@ -607,35 +549,6 @@ clutter_timeline_is_playing (ClutterTimeline *timeline)
|
||||
return (timeline->priv->timeout_id != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_timeline_get_alpha:
|
||||
* @timeline: A #ClutterTimeline
|
||||
*
|
||||
* Query the timelines current alpha value.
|
||||
*
|
||||
* Return Value: The current alpha value for the timeline
|
||||
*/
|
||||
gint32
|
||||
clutter_timeline_get_alpha (ClutterTimeline *timeline)
|
||||
{
|
||||
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), FALSE);
|
||||
|
||||
return timeline->priv->alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_timeline_set_alpha_func:
|
||||
* @timeline: A #ClutterTimeline
|
||||
* @func: A #ClutterTimelineAlphaFunc
|
||||
*
|
||||
*/
|
||||
void
|
||||
clutter_timeline_set_alpha_func (ClutterTimeline *timeline,
|
||||
ClutterTimelineAlphaFunc func)
|
||||
{
|
||||
timeline->priv->alpha_func = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_timeline_new:
|
||||
* @nframes: #ClutterTimeline number of frames
|
||||
|
@ -84,8 +84,6 @@ struct _ClutterTimelineClass
|
||||
void (*_clutter_timeline_5) (void);
|
||||
};
|
||||
|
||||
#define CLUTTER_TIMELINE_MAX_ALPHA 0xffff
|
||||
|
||||
GType clutter_timeline_get_type (void);
|
||||
|
||||
ClutterTimeline*
|
||||
@ -127,28 +125,6 @@ clutter_timeline_get_n_frames (ClutterTimeline *timeline);
|
||||
gboolean
|
||||
clutter_timeline_is_playing (ClutterTimeline *timeline);
|
||||
|
||||
/* Alpha funcs */
|
||||
|
||||
gint32
|
||||
clutter_timeline_get_alpha (ClutterTimeline *timeline);
|
||||
|
||||
void
|
||||
clutter_timeline_set_alpha_func (ClutterTimeline *timeline,
|
||||
ClutterTimelineAlphaFunc func);
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_inc_func (ClutterTimeline *timeline);
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_dec_func (ClutterTimeline *timeline);
|
||||
|
||||
guint32
|
||||
clutter_timeline_alpha_ramp_func (ClutterTimeline *timeline);
|
||||
|
||||
#define CLUTTER_ALPHA_RAMP_INC clutter_timeline_alpha_ramp_inc_func
|
||||
#define CLUTTER_ALPHA_RAMP_DEC clutter_timeline_alpha_ramp_dec_func
|
||||
#define CLUTTER_ALPHA_RAMP clutter_timeline_alpha_ramp_func
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "clutter-clone-texture.h"
|
||||
#include "clutter-video-texture.h"
|
||||
#include "clutter-label.h"
|
||||
#include "clutter-alpha.h"
|
||||
#include "clutter-enum-types.h"
|
||||
|
||||
#endif
|
||||
|
@ -4,6 +4,7 @@ int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
ClutterTimeline *timeline;
|
||||
ClutterAlpha *alpha;
|
||||
ClutterBehaviour *behave;
|
||||
ClutterActor *stage, *hand;
|
||||
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
|
||||
@ -32,10 +33,10 @@ main (int argc, char *argv[])
|
||||
g_object_set(timeline, "loop", TRUE, 0);
|
||||
|
||||
/* Set an alpha func to power behaviour - ramp is constant rise/fall */
|
||||
clutter_timeline_set_alpha_func (timeline, CLUTTER_ALPHA_RAMP);
|
||||
alpha = clutter_alpha_new (timeline, CLUTTER_ALPHA_RAMP);
|
||||
|
||||
/* Create a behaviour for that time line */
|
||||
behave = clutter_behaviour_opacity_new (timeline, 0X33 ,0xff);
|
||||
behave = clutter_behaviour_opacity_new (alpha, 0X33 ,0xff);
|
||||
|
||||
/* Apply it to our actor */
|
||||
clutter_behaviour_apply (behave, hand);
|
||||
|
Loading…
Reference in New Issue
Block a user