2007-06-16 21:15:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2007-04-30 08:39:31 +00:00
|
|
|
typedef enum {
|
|
|
|
PATH_POLY,
|
|
|
|
PATH_ELLIPSE,
|
|
|
|
PATH_BSPLINE
|
|
|
|
} path_t;
|
|
|
|
|
|
|
|
#define MAGIC 0.551784
|
|
|
|
#define RADIUS 200
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
2006-08-28 17:11:15 +00:00
|
|
|
ClutterAlpha *alpha;
|
2006-12-04 16:26:35 +00:00
|
|
|
ClutterBehaviour *o_behave, *p_behave;
|
2006-11-20 22:20:48 +00:00
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *group, *rect, *hand;
|
2006-08-15 20:28:41 +00:00
|
|
|
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
|
2006-11-20 22:20:48 +00:00
|
|
|
ClutterColor rect_bg_color = { 0x33, 0x22, 0x22, 0xff };
|
2006-12-05 05:20:39 +00:00
|
|
|
ClutterColor rect_border_color = { 0, 0, 0, 0 };
|
2006-08-15 20:28:41 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
2007-04-30 08:39:31 +00:00
|
|
|
int i;
|
|
|
|
path_t path_type = PATH_POLY;
|
|
|
|
|
|
|
|
ClutterKnot knots_poly[] = {{ 0, 0 }, { 0, 300 }, { 300, 300 },
|
|
|
|
{ 300, 0 }, {0, 0 }};
|
|
|
|
|
|
|
|
ClutterKnot origin = { 200, 200 };
|
|
|
|
|
|
|
|
ClutterKnot knots_bspline[] = {{ -RADIUS, 0 },
|
|
|
|
{ -RADIUS, RADIUS*MAGIC },
|
|
|
|
{ -RADIUS*MAGIC, RADIUS },
|
|
|
|
{ 0, RADIUS },
|
|
|
|
{ RADIUS*MAGIC, RADIUS },
|
|
|
|
{ RADIUS, RADIUS*MAGIC },
|
|
|
|
{ RADIUS, 0 },
|
|
|
|
{ RADIUS, -RADIUS*MAGIC },
|
|
|
|
{ RADIUS*MAGIC, -RADIUS },
|
|
|
|
{ 0, -RADIUS },
|
|
|
|
{ -RADIUS*MAGIC, -RADIUS },
|
|
|
|
{ -RADIUS, -RADIUS*MAGIC },
|
|
|
|
{ -RADIUS, 0}};
|
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (!strncmp (argv[i], "--path", 6))
|
|
|
|
{
|
|
|
|
if (!strncmp (argv[i] + 7, "poly", 4))
|
|
|
|
path_type = PATH_POLY;
|
|
|
|
else if (!strncmp (argv[i] + 7, "bspline", 7))
|
|
|
|
path_type = PATH_BSPLINE;
|
|
|
|
else if (!strncmp (argv[i] + 7, "ellipse", 7))
|
|
|
|
path_type = PATH_ELLIPSE;
|
|
|
|
}
|
|
|
|
else if (!strncmp (argv[i], "--help", 6))
|
|
|
|
{
|
|
|
|
printf ("behave [--path=poly|ellipse|bspline]\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
2007-03-22 18:21:59 +00:00
|
|
|
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);
|
2006-11-20 22:20:48 +00:00
|
|
|
g_signal_connect (stage, "key-press-event",
|
|
|
|
G_CALLBACK (clutter_main_quit),
|
|
|
|
NULL);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
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 */
|
2006-11-20 22:20:48 +00:00
|
|
|
group = clutter_group_new ();
|
2007-06-07 14:41:35 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
2006-11-20 22:20:48 +00:00
|
|
|
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);
|
2006-12-05 05:20:39 +00:00
|
|
|
clutter_color_parse ("DarkSlateGray", &rect_border_color);
|
2006-11-20 22:20:48 +00:00
|
|
|
clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect),
|
|
|
|
&rect_border_color);
|
|
|
|
clutter_actor_show (rect);
|
2006-12-12 20:20:04 +00:00
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
hand = clutter_texture_new_from_pixbuf (pixbuf);
|
2006-11-20 22:20:48 +00:00
|
|
|
clutter_actor_set_position (hand, 0, 0);
|
|
|
|
clutter_actor_show (hand);
|
|
|
|
|
2007-06-07 14:41:35 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (group), rect, hand, NULL);
|
2006-12-12 20:20:04 +00:00
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
/* Make a timeline */
|
2006-11-20 22:20:48 +00:00
|
|
|
timeline = clutter_timeline_new (100, 26); /* num frames, fps */
|
2007-07-26 11:04:04 +00:00
|
|
|
g_object_set (timeline, "loop", TRUE, NULL);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
/* Set an alpha func to power behaviour - ramp is constant rise/fall */
|
2006-11-15 23:37:53 +00:00
|
|
|
alpha = clutter_alpha_new_full (timeline,
|
2007-07-26 13:48:44 +00:00
|
|
|
CLUTTER_ALPHA_RAMP_INC,
|
2006-11-15 23:37:53 +00:00
|
|
|
NULL, NULL);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2006-10-22 23:33:14 +00:00
|
|
|
/* Create a behaviour for that alpha */
|
2006-12-04 16:26:35 +00:00
|
|
|
o_behave = clutter_behaviour_opacity_new (alpha, 0X33, 0xff);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
/* Apply it to our actor */
|
2006-12-04 16:26:35 +00:00
|
|
|
clutter_behaviour_apply (o_behave, group);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2006-10-22 23:33:14 +00:00
|
|
|
/* Make a path behaviour and apply that too */
|
2007-04-30 08:39:31 +00:00
|
|
|
switch (path_type)
|
|
|
|
{
|
|
|
|
case PATH_POLY:
|
|
|
|
p_behave = clutter_behaviour_path_new (alpha, knots_poly, 5);
|
|
|
|
break;
|
|
|
|
case PATH_ELLIPSE:
|
|
|
|
p_behave =
|
2007-05-25 12:07:24 +00:00
|
|
|
clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300,
|
2007-07-26 13:48:44 +00:00
|
|
|
0.0, 360.0);
|
2007-07-26 13:48:50 +00:00
|
|
|
|
2007-07-27 13:44:42 +00:00
|
|
|
clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
|
|
|
|
CLUTTER_X_AXIS,
|
|
|
|
45.0);
|
|
|
|
clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
|
|
|
|
CLUTTER_Z_AXIS,
|
|
|
|
45.0);
|
2007-04-30 08:39:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PATH_BSPLINE:
|
|
|
|
origin.x = 0;
|
|
|
|
origin.y = RADIUS;
|
|
|
|
p_behave =
|
|
|
|
clutter_behaviour_bspline_new (alpha, knots_bspline,
|
|
|
|
sizeof (knots_bspline)/sizeof(ClutterKnot));
|
|
|
|
|
|
|
|
clutter_behaviour_bspline_set_origin (
|
|
|
|
CLUTTER_BEHAVIOUR_BSPLINE (p_behave),
|
|
|
|
&origin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-12-04 16:26:35 +00:00
|
|
|
clutter_behaviour_apply (p_behave, group);
|
2006-10-22 23:33:14 +00:00
|
|
|
|
|
|
|
/* start the timeline and thus the animations */
|
2006-08-15 20:28:41 +00:00
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
|
2006-12-12 20:20:04 +00:00
|
|
|
clutter_actor_show_all (stage);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
2006-12-04 16:26:35 +00:00
|
|
|
g_object_unref (o_behave);
|
|
|
|
g_object_unref (p_behave);
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|