2007-08-04 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/clutter-behaviour-depth.c: Clarify that what drives
	the movement along the Z axis is the ClutterAlpha object (we
	don't have the luxury of a rollover like the opacity does);
	so, if you want to go from 0 to -100 you have to use a
	decreasing function, just as well if you want to go from 100
	to 0. Using a min-depth of 100 and a max-depth of 0 and an
	increasing function is undefined behaviour.

	* tests/Makefile.am:
	* tests/test-depth.c: Add a test case for the depth behaviour.
This commit is contained in:
Emmanuele Bassi
2007-08-04 08:59:18 +00:00
parent 7cd4ee0517
commit 46506cb93e
6 changed files with 179 additions and 36 deletions

View File

@ -41,6 +41,11 @@
* #ClutterBehaviourDepth is a simple #ClutterBehaviour controlling the
* depth of a set of actors.
*
* The minimum and maximum depth are controlled by the
* ClutterBehaviourDepth:min-depth and ClutterBehaviourDepth:max-depth
* properties. The direction of the motion on the depth axis is controlled
* by the #ClutterAlpha object.
*
* Since: 0.4
*/
@ -50,16 +55,16 @@ G_DEFINE_TYPE (ClutterBehaviourDepth,
struct _ClutterBehaviourDepthPrivate
{
gint depth_start;
gint depth_end;
gint min_depth;
gint max_depth;
};
enum
{
PROP_0,
PROP_DEPTH_START,
PROP_DEPTH_END
PROP_MIN_DEPTH,
PROP_MAX_DEPTH
};
static void
@ -75,18 +80,26 @@ clutter_behaviour_depth_alpha_notify (ClutterBehaviour *behaviour,
guint32 alpha_value)
{
ClutterBehaviourDepthPrivate *priv;
gint delta, depth;
gint depth;
priv = CLUTTER_BEHAVIOUR_DEPTH (behaviour)->priv;
if (priv->depth_end > priv->depth_start)
delta = priv->depth_end - priv->depth_start;
else
delta = priv->depth_start - priv->depth_end;
if (priv->max_depth > priv->min_depth)
{
depth = alpha_value
* (priv->max_depth - priv->min_depth)
/ CLUTTER_ALPHA_MAX_ALPHA;
depth = alpha_value * delta / CLUTTER_ALPHA_MAX_ALPHA;
depth += ((priv->depth_end > priv->depth_start) ? priv->depth_start
: priv->depth_end);
depth += priv->min_depth;
}
else
{
depth = alpha_value
* (priv->min_depth - priv->max_depth)
/ CLUTTER_ALPHA_MAX_ALPHA;
depth += priv->max_depth;
}
CLUTTER_NOTE (BEHAVIOUR, "alpha: %d, depth: %d", alpha_value, depth);
@ -95,6 +108,15 @@ clutter_behaviour_depth_alpha_notify (ClutterBehaviour *behaviour,
GINT_TO_POINTER (depth));
}
static void
clutter_behaviour_depth_applied (ClutterBehaviour *behaviour,
ClutterActor *actor)
{
ClutterBehaviourDepth *depth = CLUTTER_BEHAVIOUR_DEPTH (behaviour);
clutter_actor_set_depth (actor, depth->priv->min_depth);
}
static void
clutter_behaviour_depth_set_property (GObject *gobject,
guint prop_id,
@ -105,11 +127,11 @@ clutter_behaviour_depth_set_property (GObject *gobject,
switch (prop_id)
{
case PROP_DEPTH_START:
depth->priv->depth_start = g_value_get_int (value);
case PROP_MIN_DEPTH:
depth->priv->min_depth = g_value_get_int (value);
break;
case PROP_DEPTH_END:
depth->priv->depth_end = g_value_get_int (value);
case PROP_MAX_DEPTH:
depth->priv->max_depth = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@ -127,11 +149,11 @@ clutter_behaviour_depth_get_property (GObject *gobject,
switch (prop_id)
{
case PROP_DEPTH_START:
g_value_set_int (value, depth->priv->depth_start);
case PROP_MIN_DEPTH:
g_value_set_int (value, depth->priv->min_depth);
break;
case PROP_DEPTH_END:
g_value_set_int (value, depth->priv->depth_end);
case PROP_MAX_DEPTH:
g_value_set_int (value, depth->priv->max_depth);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@ -151,31 +173,32 @@ clutter_behaviour_depth_class_init (ClutterBehaviourDepthClass *klass)
gobject_class->get_property = clutter_behaviour_depth_get_property;
behaviour_class->alpha_notify = clutter_behaviour_depth_alpha_notify;
behaviour_class->applied = clutter_behaviour_depth_applied;
/**
* ClutterBehaviourDepth:depth-start:
* ClutterBehaviourDepth:min-depth:
*
* Minimum depth level to apply to the actors.
*
* Since: 0.4
*/
g_object_class_install_property (gobject_class,
PROP_DEPTH_START,
g_param_spec_int ("depth-start",
PROP_MIN_DEPTH,
g_param_spec_int ("min-depth",
"Minimum Depth",
"Minimum depth to apply",
G_MININT, G_MAXINT, 0,
CLUTTER_PARAM_READWRITE));
/**
* ClutterBehaviourDepth:depth-end:
* ClutterBehaviourDepth:max-depth:
*
* Maximum depth level to apply to the actors.
*
* Since: 0.4
*/
g_object_class_install_property (gobject_class,
PROP_DEPTH_END,
g_param_spec_int ("depth-end",
PROP_MAX_DEPTH,
g_param_spec_int ("max-depth",
"Maximum Depth",
"Maximum depth to apply",
G_MININT, G_MAXINT, 0,
@ -193,8 +216,8 @@ clutter_behaviour_depth_init (ClutterBehaviourDepth *depth)
/**
* clutter_behaviour_depth_new:
* @alpha: a #ClutterAlpha or %NULL
* @depth_start: minimum depth level
* @depth_end: maximum depth level
* @min_depth: minimum depth level
* @max_depth: maximum depth level
*
* Creates a new #ClutterBehaviourDepth which can be used to control
* the ClutterActor:depth property of a set of #ClutterActor<!-- -->s.
@ -205,15 +228,15 @@ clutter_behaviour_depth_init (ClutterBehaviourDepth *depth)
*/
ClutterBehaviour *
clutter_behaviour_depth_new (ClutterAlpha *alpha,
gint depth_start,
gint depth_end)
gint min_depth,
gint max_depth)
{
g_return_val_if_fail (alpha == NULL || CLUTTER_IS_ALPHA (alpha), NULL);
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_DEPTH,
"alpha", alpha,
"depth-start", depth_start,
"depth-end", depth_end,
"min-depth", min_depth,
"max-depth", max_depth,
NULL);
}