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>
|
2007-05-16 07:32:50 -04:00
|
|
|
* Tomas Frydrych <tf@openedhand.com>
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
2007-05-16 07:32:50 -04:00
|
|
|
* Copyright (C) 2006, 2007 OpenedHand
|
2006-08-28 13:11:15 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
2008-02-08 08:52:11 -05:00
|
|
|
* <figure id="alpha-functions">
|
|
|
|
* <title>Graphic representation of some alpha functions</title>
|
|
|
|
* <graphic fileref="alpha-func.png" format="PNG"/>
|
|
|
|
* </figure>
|
|
|
|
*
|
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
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 16:27:53 -05:00
|
|
|
#include <math.h>
|
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
#include "clutter-alpha.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-marshal.h"
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 16:27:53 -05:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2008-04-02 23:09:28 -04:00
|
|
|
G_DEFINE_TYPE (ClutterAlpha, clutter_alpha, G_TYPE_INITIALLY_UNOWNED);
|
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;
|
2008-04-18 11:03:30 -04:00
|
|
|
|
|
|
|
GClosure *closure;
|
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 */
|
2008-04-18 11:03:30 -04:00
|
|
|
if (G_LIKELY (priv->closure))
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-04-18 11:03:30 -04:00
|
|
|
GValue params = { 0, };
|
|
|
|
GValue result_value = { 0, };
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
g_object_ref (alpha);
|
2006-08-28 13:11:15 -04:00
|
|
|
|
2008-04-18 11:03:30 -04:00
|
|
|
g_value_init (&result_value, G_TYPE_UINT);
|
|
|
|
|
|
|
|
g_value_init (¶ms, CLUTTER_TYPE_ALPHA);
|
|
|
|
g_value_set_object (¶ms, alpha);
|
|
|
|
|
|
|
|
g_closure_invoke (priv->closure,
|
|
|
|
&result_value,
|
|
|
|
1,
|
|
|
|
¶ms,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
priv->alpha = g_value_get_uint (&result_value);
|
|
|
|
|
|
|
|
g_value_unset (&result_value);
|
|
|
|
g_value_unset (¶ms);
|
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);
|
2008-02-08 08:40:50 -05: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;
|
|
|
|
|
2008-04-18 11:03:30 -04:00
|
|
|
if (priv->closure)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-04-18 11:03:30 -04:00
|
|
|
g_closure_unref (priv->closure);
|
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,
|
2006-12-04 11:26:35 -05:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-11-15 18:37:53 -05:00
|
|
|
/**
|
|
|
|
* 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,
|
2006-12-04 11:26:35 -05:00
|
|
|
CLUTTER_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;
|
|
|
|
}
|
|
|
|
|
2008-04-18 11:03:30 -04:00
|
|
|
/**
|
|
|
|
* clutter_alpha_set_closure:
|
|
|
|
* @alpha: A #ClutterAlpha
|
|
|
|
* @closure: A #GClosure
|
|
|
|
*
|
|
|
|
* Sets the #GClosure used to compute
|
|
|
|
* the alpha value at each frame of the #ClutterTimeline
|
|
|
|
* bound to @alpha.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_alpha_set_closure (ClutterAlpha *alpha,
|
|
|
|
GClosure *closure)
|
|
|
|
{
|
|
|
|
ClutterAlphaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ALPHA (alpha));
|
|
|
|
g_return_if_fail (closure != NULL);
|
|
|
|
|
|
|
|
priv = alpha->priv;
|
|
|
|
|
|
|
|
if (priv->closure)
|
|
|
|
g_closure_unref (priv->closure);
|
|
|
|
|
|
|
|
priv->closure = g_closure_ref (closure);
|
|
|
|
g_closure_sink (closure);
|
|
|
|
|
|
|
|
if (G_CLOSURE_NEEDS_MARSHAL (closure))
|
|
|
|
{
|
|
|
|
GClosureMarshal marshal = clutter_marshal_UINT__VOID;
|
|
|
|
|
|
|
|
g_closure_set_marshal (closure, marshal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-28 13:11:15 -04:00
|
|
|
/**
|
|
|
|
* 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;
|
2008-04-18 11:03:30 -04:00
|
|
|
GClosure *closure;
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ALPHA (alpha));
|
|
|
|
|
|
|
|
priv = alpha->priv;
|
|
|
|
|
2008-04-18 11:03:30 -04:00
|
|
|
closure = g_cclosure_new (G_CALLBACK (func), data, (GClosureNotify) destroy);
|
|
|
|
clutter_alpha_set_closure (alpha, closure);
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_RAMP_INC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_ramp_inc_func().
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_RAMP_DEC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_ramp_dec_func().
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_RAMP:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_ramp_func().
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 03:14:53 -05:00
|
|
|
static guint32
|
|
|
|
sincx1024_func (ClutterAlpha *alpha,
|
|
|
|
ClutterAngle angle,
|
|
|
|
ClutterFixed offset)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
gint current_frame_num, n_frames;
|
|
|
|
ClutterAngle x;
|
2007-01-30 14:35:19 -05:00
|
|
|
unsigned int sine;
|
2007-01-16 03:14:53 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-01-30 14:35:19 -05:00
|
|
|
x -= (512 * 512 / angle);
|
|
|
|
|
|
|
|
sine = ((clutter_sini (x) + offset)/2) * CLUTTER_ALPHA_MAX_ALPHA;
|
2007-01-16 03:14:53 -05:00
|
|
|
|
2007-01-30 14:35:19 -05:00
|
|
|
sine = sine >> CFX_Q;
|
|
|
|
|
|
|
|
return sine;
|
2007-01-16 03:14:53 -05:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* The following two functions are left in place for reference
|
|
|
|
* purposes.
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
static guint32
|
|
|
|
sincx_func (ClutterAlpha *alpha,
|
2007-01-15 14:43:09 -05:00
|
|
|
ClutterFixed angle,
|
|
|
|
ClutterFixed offset)
|
2007-01-15 13:37:12 -05:00
|
|
|
{
|
2007-01-15 14:43:09 -05:00
|
|
|
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 = CLUTTER_FIXED_MUL (x, CFX_PI) - CLUTTER_FIXED_DIV (CFX_PI, angle);
|
|
|
|
|
|
|
|
sine = (clutter_fixed_sin (x) + offset)/2;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (ALPHA, "sine: %2f\n", CLUTTER_FIXED_TO_DOUBLE (sine));
|
|
|
|
|
2007-10-02 10:53:32 -04:00
|
|
|
return CLUTTER_FIXED_TO_INT (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
2007-01-15 13:37:12 -05:00
|
|
|
}
|
|
|
|
|
2007-01-30 14:35:19 -05:00
|
|
|
/* NB: angle is not in radians but in muliples of PI, i.e., 2.0
|
|
|
|
* represents full circle.
|
|
|
|
*/
|
2007-01-04 14:56:01 -05:00
|
|
|
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 * M_PI) / n_frames ;
|
|
|
|
sine = (sin (x - (M_PI / angle)) + offset) * 0.5f;
|
|
|
|
|
2007-01-30 14:35:19 -05:00
|
|
|
CLUTTER_NOTE (ALPHA, "sine: %2f\n",sine);
|
2007-01-04 14:56:01 -05:00
|
|
|
|
2007-01-19 11:04:06 -05:00
|
|
|
return CLUTTER_FLOAT_TO_INT ((sine * (gdouble) CLUTTER_ALPHA_MAX_ALPHA));
|
2007-01-04 14:56:01 -05:00
|
|
|
}
|
2007-01-16 03:14:53 -05:00
|
|
|
#endif
|
2007-01-19 11:04:06 -05:00
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SINE:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_sine_func().
|
|
|
|
*
|
|
|
|
* Since: 0.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)
|
|
|
|
{
|
2007-01-15 14:43:09 -05:00
|
|
|
#if 0
|
2007-01-30 14:35:19 -05:00
|
|
|
return sinc_func (alpha, 2.0, 1.0);
|
2007-01-15 14:43:09 -05:00
|
|
|
#else
|
2007-01-30 14:35:19 -05:00
|
|
|
/* 2.0 above represents full circle */
|
|
|
|
return sincx1024_func (alpha, 1024, CFX_ONE);
|
2007-01-15 14:43:09 -05:00
|
|
|
#endif
|
2007-01-04 14:56:01 -05:00
|
|
|
}
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SINE_INC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_sine_inc_func().
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
|
2007-01-04 14:56:01 -05:00
|
|
|
/**
|
|
|
|
* clutter_sine_inc_func:
|
|
|
|
* @alpha: a #ClutterAlpha
|
|
|
|
* @dummy: unused argument
|
|
|
|
*
|
2007-05-17 08:03:43 -04:00
|
|
|
* Convenience alpha function for a sine wave over interval [0, pi / 2].
|
2007-05-16 09:46:54 -04:00
|
|
|
* You can use this function as the alpha function for
|
|
|
|
* clutter_alpha_set_func().
|
2007-01-04 14:56:01 -05:00
|
|
|
*
|
|
|
|
* Return value: an alpha value.
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
guint32
|
|
|
|
clutter_sine_inc_func (ClutterAlpha *alpha,
|
|
|
|
gpointer dummy)
|
|
|
|
{
|
2007-05-16 09:46:54 -04:00
|
|
|
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 = clutter_sini (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
|
|
|
2007-06-11 11:47:26 -04:00
|
|
|
return ((guint32)sine) >> CFX_Q;
|
2007-05-16 09:46:54 -04:00
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SINE_DEC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_sine_dec_func().
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
|
|
|
|
2007-05-16 09:46:54 -04:00
|
|
|
/**
|
|
|
|
* clutter_sine_dec_func:
|
|
|
|
* @alpha: a #ClutterAlpha
|
|
|
|
* @dummy: unused argument
|
|
|
|
*
|
2007-05-17 08:03:43 -04:00
|
|
|
* Convenience alpha function for a sine wave over interval [pi / 2, pi].
|
2007-05-16 09:46:54 -04:00
|
|
|
* 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 = clutter_sini (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
|
|
|
2007-06-11 11:47:26 -04:00
|
|
|
return ((guint32)sine) >> CFX_Q;
|
2006-08-28 13:11:15 -04:00
|
|
|
}
|
2007-01-30 11:51:49 -05:00
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SINE_HALF:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_sine_half_func().
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
|
2007-05-16 09:53:39 -04:00
|
|
|
/**
|
|
|
|
* clutter_sine_half_func:
|
|
|
|
* @alpha: a #ClutterAlpha
|
|
|
|
* @dummy: unused argument
|
|
|
|
*
|
2007-05-17 08:03:43 -04:00
|
|
|
* Convenience alpha function for a sine wave over interval [0, pi].
|
2007-05-16 09:53:39 -04:00
|
|
|
* 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 = clutter_sini (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
|
|
|
2007-06-11 11:47:26 -04:00
|
|
|
return ((guint32)sine) >> CFX_Q;
|
2007-05-16 09:53:39 -04:00
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SQUARE:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_square_func().
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
|
2007-01-30 11:51:49 -05:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2007-05-16 07:32:50 -04:00
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SMOOTHSTEP_INC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_smoothstep_inc_func().
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-16 07:32:50 -04:00
|
|
|
|
|
|
|
/**
|
2007-05-30 06:52:06 -04:00
|
|
|
* clutter_smoothstep_inc_func:
|
2007-05-16 07:32:50 -04:00
|
|
|
* @alpha: a #ClutterAlpha
|
2007-05-30 06:52:06 -04:00
|
|
|
* @dummy: unused
|
2007-05-16 07:32:50 -04:00
|
|
|
*
|
|
|
|
* 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
|
2007-05-30 06:52:06 -04:00
|
|
|
clutter_smoothstep_inc_func (ClutterAlpha *alpha,
|
2007-07-04 08:29:44 -04:00
|
|
|
gpointer dummy)
|
2007-05-16 07:32:50 -04:00
|
|
|
{
|
2007-05-25 06:56:09 -04:00
|
|
|
ClutterTimeline *timeline;
|
2007-05-16 07:32:50 -04:00
|
|
|
gint frame;
|
|
|
|
gint n_frames;
|
2007-08-15 09:29:43 -04:00
|
|
|
guint32 r;
|
|
|
|
guint32 x;
|
2007-05-16 07:32:50 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/*
|
2007-05-30 06:52:06 -04:00
|
|
|
* Convert x to 8.24 for next step.
|
2007-05-16 07:32:50 -04:00
|
|
|
*/
|
2007-05-30 06:52:06 -04:00
|
|
|
x = CFX_DIV (frame, n_frames) << 8;
|
2007-05-16 07:32:50 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 CFX_INT (r * CLUTTER_ALPHA_MAX_ALPHA);
|
|
|
|
}
|
2007-05-17 03:09:24 -04:00
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_SMOOTHSTEP_DEC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_smoothstep_dec_func().
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
|
2007-05-30 06:52:06 -04:00
|
|
|
/**
|
|
|
|
* 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,
|
2007-07-04 08:29:44 -04:00
|
|
|
gpointer dummy)
|
2007-05-30 06:52:06 -04:00
|
|
|
{
|
|
|
|
return CLUTTER_ALPHA_MAX_ALPHA - clutter_smoothstep_inc_func (alpha, dummy);
|
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_EXP_INC:
|
|
|
|
*
|
|
|
|
* Convenience symbol for clutter_exp_inc_func()
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
|
2007-05-17 03:09:24 -04:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2008-02-26 08:57:53 -05:00
|
|
|
result = CLAMP (clutter_pow2x (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
2007-05-17 03:09:24 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-23 08:11:10 -05:00
|
|
|
/**
|
|
|
|
* CLUTTER_ALPHA_EXP_DEC:
|
|
|
|
*
|
|
|
|
* Convenience symbold for clutter_exp_dec_func().
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-17 03:09:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2008-02-26 08:57:53 -05:00
|
|
|
result = CLAMP (clutter_pow2x (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
2007-05-17 03:09:24 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|