mutter/tests/test-depth.c
Emmanuele Bassi 46506cb93e 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.
2007-08-04 08:59:18 +00:00

106 lines
3.0 KiB
C

#include <stdlib.h>
#include <clutter/clutter.h>
/* this is a rather contrieved test case emulating a CLUTTER_ALPHA_RAMP
* with two half-ramps. it shows that the direction of the motion on the
* Z axis of a ClutterBehaviourDepth is controlled by the ClutterAlpha
* and not by the minimum and maximum depth.
*/
static gboolean zoom_in = TRUE;
static ClutterBehaviour *d_behave = NULL;
static void
timeline_completed (ClutterTimeline *timeline,
gpointer user_data)
{
ClutterAlpha *alpha;
gint min_depth, max_depth;
if (zoom_in)
{
alpha = clutter_alpha_new_full (timeline,
CLUTTER_ALPHA_RAMP_INC,
NULL, NULL);
min_depth = -100;
max_depth = 0;
zoom_in = FALSE;
}
else
{
alpha = clutter_alpha_new_full (timeline,
CLUTTER_ALPHA_RAMP_DEC,
NULL, NULL);
min_depth = 0;
max_depth = -100;
zoom_in = TRUE;
}
g_object_set (G_OBJECT (d_behave),
"min-depth", min_depth,
"max-depth", max_depth,
NULL);
clutter_behaviour_set_alpha (d_behave, alpha);
clutter_timeline_rewind (timeline);
clutter_timeline_start (timeline);
}
int
main (int argc, char *argv[])
{
ClutterTimeline *timeline;
ClutterActor *stage;
ClutterActor *hand, *label;
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
GdkPixbuf *pixbuf;
GError *error;
clutter_init (&argc, &argv);
error = NULL;
pixbuf = gdk_pixbuf_new_from_file ("redhand.png", &error);
if (error)
g_error ("Unable to load redhand.png: %s", error->message);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
g_signal_connect (stage,
"button-press-event", G_CALLBACK (clutter_main_quit),
NULL);
hand = clutter_texture_new_from_pixbuf (pixbuf);
clutter_actor_set_position (hand, 240, 140);
clutter_actor_show (hand);
label = clutter_label_new_with_text ("Mono 26", "Clutter");
clutter_actor_set_position (label, 100, 100);
clutter_actor_show (label);
clutter_container_add (CLUTTER_CONTAINER (stage), hand, label, NULL);
/* five seconds, at 50 fps */
timeline = clutter_timeline_new (250, 50);
g_signal_connect (timeline,
"completed", G_CALLBACK (timeline_completed),
NULL);
d_behave = clutter_behaviour_depth_new (clutter_alpha_new_full (timeline,
CLUTTER_ALPHA_RAMP_DEC,
NULL, NULL),
0, -100);
clutter_behaviour_apply (d_behave, hand);
clutter_behaviour_apply (d_behave, label);
clutter_actor_show (stage);
clutter_timeline_start (timeline);
clutter_main ();
g_object_unref (d_behave);
g_object_unref (timeline);
return EXIT_SUCCESS;
}