diff --git a/examples/Makefile.am b/examples/Makefile.am index d70a20d9d..0e957a23e 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = test super-oh behave test-text bspline +noinst_PROGRAMS = test super-oh behave test-text INCLUDES = -I$(top_srcdir)/ LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la @@ -27,12 +27,6 @@ test_text_LDFLAGS = \ $(CLUTTER_LIBS) \ $(GCONF_LIBS) -bspline_SOURCES = bspline.c -bspline_CFLAGS = $(CLUTTER_CFLAGS) $(GCONF_CFLAGS) -bspline_LDFLAGS = \ - $(CLUTTER_LIBS) \ - $(GCONF_LIBS) - EXTRA_DIST = redhand.png \ clutter-logo-800x600.png \ README diff --git a/examples/behave.c b/examples/behave.c index 0f16cd882..89c9a4a24 100644 --- a/examples/behave.c +++ b/examples/behave.c @@ -33,6 +33,15 @@ scroll_event_cb (ClutterStage *stage, : "down"); } +typedef enum { + PATH_POLY, + PATH_ELLIPSE, + PATH_BSPLINE +} path_t; + +#define MAGIC 0.551784 +#define RADIUS 200 + int main (int argc, char *argv[]) { @@ -45,10 +54,47 @@ main (int argc, char *argv[]) ClutterColor rect_bg_color = { 0x33, 0x22, 0x22, 0xff }; ClutterColor rect_border_color = { 0, 0, 0, 0 }; GdkPixbuf *pixbuf; + int i; + char *p; + 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[] = {{ 0, 0 }, { 0, 300 }, { 300, 300 }, - { 300, 0 }, {0, 0 }}; + 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); + } + } + clutter_init (&argc, &argv); stage = clutter_stage_get_default (); @@ -112,7 +158,30 @@ main (int argc, char *argv[]) clutter_behaviour_apply (o_behave, group); /* Make a path behaviour and apply that too */ - p_behave = clutter_behaviour_path_new (alpha, knots, 5); + switch (path_type) + { + case PATH_POLY: + p_behave = clutter_behaviour_path_new (alpha, knots_poly, 5); + break; + case PATH_ELLIPSE: + p_behave = + clutter_behaviour_ellipse_new (alpha, &origin, 400, 300, + 1024, 0); + 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; + } + clutter_behaviour_apply (p_behave, group); /* start the timeline and thus the animations */ diff --git a/examples/bspline.c b/examples/bspline.c deleted file mode 100644 index 9291a7e33..000000000 --- a/examples/bspline.c +++ /dev/null @@ -1,97 +0,0 @@ -#include - -#define MAGIC 0.551784 -#define RADIUS 200 - -int -main (int argc, char *argv[]) -{ - ClutterTimeline *timeline; - ClutterAlpha *alpha; - ClutterBehaviour *p_behave; - ClutterActor *stage; - ClutterActor *hand; - ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff }; - GdkPixbuf *pixbuf; - guint i; - -#if 1 - /* Circular path defined using a spline consisting of 4 bezier curves */ - ClutterKnot knots[] = {{ -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}}; - - ClutterKnot origin = { 0, RADIUS }; -#else - /* Approximation of a sine wave over <0,pi> */ - ClutterKnot knots[] = {{ 0, 0 }, - { 2*RADIUS/3, 2*RADIUS*1.299 }, - { 4*RADIUS/3, 2*RADIUS*1.299 }, - { 2*RADIUS, 0 }}; - - ClutterKnot origin = { 0, 0}; -#endif - - clutter_init (&argc, &argv); - - stage = clutter_stage_get_default (); - clutter_stage_hide_cursor (CLUTTER_STAGE (stage)); - - 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 */ - hand = clutter_texture_new_from_pixbuf (pixbuf); - clutter_actor_set_position (hand, 0, RADIUS); - clutter_actor_show (hand); - clutter_group_add (CLUTTER_GROUP (stage), hand); - - /* 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_inc is constant rise */ - alpha = clutter_alpha_new_full (timeline, - CLUTTER_ALPHA_RAMP_INC, - NULL, NULL); - - /* Make a path behaviour and apply that too */ - p_behave = - clutter_behaviour_bspline_new (alpha, knots, - sizeof (knots)/sizeof(ClutterKnot)); - - clutter_behaviour_bspline_set_origin (CLUTTER_BEHAVIOUR_BSPLINE (p_behave), - &origin); - - clutter_behaviour_apply (p_behave, hand); - - /* start the timeline and thus the animations */ - clutter_timeline_start (timeline); - - clutter_actor_show_all (stage); - - clutter_main(); - - g_object_unref (p_behave); - - return 0; -}