1
0
Fork 0
mutter-performance-source/examples/behave.c
Emmanuele Bassi 4bd3fa583e 2007-03-22 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-private.h: Remove inclusion of backend-specific
	headers; update the main context object; add the declarations for
	the event queue functions.

	* clutter/clutter-backend.[ch]: Add the abstract ClutterBackend
	object, which holds backend-specific settings, the main stage,
	and the event queue. Every backend must implement a subclass of
	ClutterBackend and ClutterStage.

	* clutter/clutter-feature.c: Protect the GLX specific calls
	behing #ifdef HAVE_CLUTTER_GLX.

	* clutter/clutter-actor.c:
	* clutter/clutter-group.c:
	* clutter/clutter-clone-texture.c: Include GL/gl.h

	* clutter/clutter-event.[ch]: Update public API and implement the
	event queue private API; hold a reference on the event objects;
	move out the keysym-to-unicode table; add the new event types.

	* clutter/clutter-color.h: Include clutter-fixed.h

	* clutter/clutter-main.c: Update API; get the main stage
	from the backend object; process the event received from the
	queue; lock/unlock the main mutex if we have one; move the
	initialisation process sooner in the init sequence, in order to
	have the backend object when we check for options; call the
	backed vfuncs in the pre/post parse hooks.

	* clutter/clutter-stage.c: Make ClutterStage and abstract class,
	implemented by the backends.

	* clutter/clutter/glx/clutter-glx.h:
	* clutter/clutter/glx/clutter-backend-glx.[ch]:
	* clutter/clutter/glx/clutter-event-glx.c:
	* clutter/clutter/glx/clutter-stage-glx.[ch]:
	* clutter/clutter/glx/Makefile.am: Add the GLX backend.

	* clutter/clutter/egl/clutter-backend-egl.[ch]:
	* clutter/clutter/egl/clutter-event-egl.c:
	* clutter/clutter/egl/clutter-stage-egl.[ch]:
	* clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend.

	* examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00

129 lines
3.8 KiB
C

#include <clutter/clutter.h>
static void
button_press_cb (ClutterStage *stage,
ClutterButtonEvent *event,
gpointer data)
{
const gchar *click_type;
switch (event->type)
{
case CLUTTER_2BUTTON_PRESS:
click_type = "double";
break;
case CLUTTER_3BUTTON_PRESS:
click_type = "triple";
break;
default:
click_type = "single";
break;
}
g_print ("%s button press event\n", click_type);
}
static void
scroll_event_cb (ClutterStage *stage,
ClutterScrollEvent *event,
gpointer data)
{
g_print ("scroll direction: %s\n",
event->direction == CLUTTER_SCROLL_UP ? "up"
: "down");
}
int
main (int argc, char *argv[])
{
ClutterTimeline *timeline;
ClutterAlpha *alpha;
ClutterBehaviour *o_behave, *p_behave;
ClutterActor *stage;
ClutterActor *group, *rect, *hand;
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
ClutterColor rect_bg_color = { 0x33, 0x22, 0x22, 0xff };
ClutterColor rect_border_color = { 0, 0, 0, 0 };
GdkPixbuf *pixbuf;
ClutterKnot knots[] = {{ 0, 0 }, { 0, 300 }, { 300, 300 },
{ 300, 0 }, {0, 0 }};
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
g_signal_connect (stage, "button-press-event",
G_CALLBACK (button_press_cb),
NULL);
g_signal_connect (stage, "scroll-event",
G_CALLBACK (scroll_event_cb),
NULL);
g_signal_connect (stage, "key-press-event",
G_CALLBACK (clutter_main_quit),
NULL);
pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
if (!pixbuf)
g_error("pixbuf load failed");
clutter_stage_set_color (CLUTTER_STAGE (stage),
&stage_color);
/* Make a hand */
group = clutter_group_new ();
clutter_group_add (CLUTTER_GROUP (stage), group);
clutter_actor_show (group);
rect = clutter_rectangle_new ();
clutter_actor_set_position (rect, 0, 0);
clutter_actor_set_size (rect,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf));
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect),
&rect_bg_color);
clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), 10);
clutter_color_parse ("DarkSlateGray", &rect_border_color);
clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect),
&rect_border_color);
clutter_actor_show (rect);
hand = clutter_texture_new_from_pixbuf (pixbuf);
clutter_actor_set_position (hand, 0, 0);
clutter_actor_show (hand);
clutter_group_add_many (CLUTTER_GROUP (group), rect, hand, NULL);
/* Make a timeline */
timeline = clutter_timeline_new (100, 26); /* num frames, fps */
g_object_set (timeline, "loop", TRUE, 0);
/* Set an alpha func to power behaviour - ramp is constant rise/fall */
alpha = clutter_alpha_new_full (timeline,
CLUTTER_ALPHA_SINE,
NULL, NULL);
/* Create a behaviour for that alpha */
o_behave = clutter_behaviour_opacity_new (alpha, 0X33, 0xff);
/* Apply it to our actor */
clutter_behaviour_apply (o_behave, group);
/* Make a path behaviour and apply that too */
p_behave = clutter_behaviour_path_new (alpha, knots, 5);
clutter_behaviour_apply (p_behave, group);
/* start the timeline and thus the animations */
clutter_timeline_start (timeline);
clutter_actor_show_all (stage);
clutter_main();
g_object_unref (o_behave);
g_object_unref (p_behave);
return 0;
}