From f1b15efcdc6ac2efd15d2946c93a1cb2a3a5b063 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 8 Jan 2009 18:54:48 +0000 Subject: [PATCH] [tests] Adds a flowery clutter_cairo_texture unit test This is simply a copy of flowers.c from the old clutter-cairo repo --- tests/interactive/Makefile.am | 3 +- tests/interactive/test-clutter-cairo-flowers.c | 212 +++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 tests/interactive/test-clutter-cairo-flowers.c diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am index 33b3714..08a2be0 100644 --- a/tests/interactive/Makefile.am +++ b/tests/interactive/Makefile.am @@ -39,7 +39,8 @@ UNIT_TESTS = \ test-easing.c \ test-binding-pool.c \ test-text.c \ - test-text-field.c + test-text-field.c \ + test-clutter-cairo-flowers.c if X11_TESTS UNIT_TESTS += test-pixmap.c diff --git a/tests/interactive/test-clutter-cairo-flowers.c b/tests/interactive/test-clutter-cairo-flowers.c new file mode 100644 index 0000000..c665316 --- /dev/null +++ b/tests/interactive/test-clutter-cairo-flowers.c @@ -0,0 +1,212 @@ +/* + * Pretty cairo flower hack. + */ + +#include + +#include /* for sleep(), used for screenshots */ +#include +#include "math.h" + +#define PETAL_MIN 20 +#define PETAL_VAR 40 +#define N_FLOWERS 40 /* reduce if you have a small card */ + +typedef struct Flower +{ + ClutterActor *ctex; + gint x,y,rot,v,rv; +} +Flower; + +ClutterActor* +make_flower_actor (void) +{ + /* No science here, just a hack from toying */ + gint i, j; + + double colors[] = { + 0.71, 0.81, 0.83, + 1.0, 0.78, 0.57, + 0.64, 0.30, 0.35, + 0.73, 0.40, 0.39, + 0.91, 0.56, 0.64, + 0.70, 0.47, 0.45, + 0.92, 0.75, 0.60, + 0.82, 0.86, 0.85, + 0.51, 0.56, 0.67, + 1.0, 0.79, 0.58, + + }; + + gint size; + gint petal_size; + gint n_groups; /* Num groups of petals 1-3 */ + gint n_petals; /* num of petals 4 - 8 */ + gint pm1, pm2; + + gint idx, last_idx = -1; + + ClutterActor *ctex; + cairo_t *cr; + + petal_size = PETAL_MIN + rand() % PETAL_VAR; + size = petal_size * 8; + + n_groups = rand() % 3 + 1; + + ctex = clutter_cairo_texture_new (size, size); + + cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (ctex)); + + cairo_set_tolerance (cr, 0.1); + + /* Clear */ + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + + cairo_translate(cr, size/2, size/2); + + for (i=0; iy += flowers[i]->v; + flowers[i]->rot += flowers[i]->rv; + + if (flowers[i]->y > (gint)clutter_actor_get_height + (clutter_stage_get_default ())) + flowers[i]->y = -clutter_actor_get_height (flowers[i]->ctex); + + clutter_actor_set_position (flowers[i]->ctex, + flowers[i]->x, flowers[i]->y); + + clutter_actor_set_rotation (flowers[i]->ctex, + CLUTTER_Z_AXIS, + flowers[i]->rot, + clutter_actor_get_width (flowers[i]->ctex)/2, + clutter_actor_get_height (flowers[i]->ctex)/2, + 0); + } + + return TRUE; +} + +void foo(void) { g_usleep(10000000); } + +int +test_clutter_cairo_flowers_main (int argc, char **argv) +{ + int i; + ClutterActor *stage; + ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; + Flower *flowers[N_FLOWERS]; + + srand(time(NULL)); + + clutter_init (&argc, &argv); + + stage = clutter_stage_get_default (); + + clutter_stage_set_color (CLUTTER_STAGE (stage), + &stage_color); + + g_object_set(stage, "fullscreen", TRUE, NULL); + + for (i=0; i< N_FLOWERS; i++) + { + flowers[i] = g_new0(Flower, 1); + flowers[i]->ctex = make_flower_actor(); + flowers[i]->x = rand() % clutter_actor_get_width(stage) + - (PETAL_MIN+PETAL_VAR)*2; + flowers[i]->y = rand() % clutter_actor_get_height(stage); + flowers[i]->rv = rand() % 5 + 1; + flowers[i]->v = rand() % 10 + 2; + + clutter_group_add (CLUTTER_GROUP(stage), flowers[i]->ctex); + clutter_actor_set_position (flowers[i]->ctex, + flowers[i]->x, flowers[i]->y); + } + + g_timeout_add (50, tick, flowers); + + clutter_actor_show_all (CLUTTER_ACTOR (stage)); + + g_signal_connect (stage, "key-press-event", + G_CALLBACK (clutter_main_quit), + NULL); + + clutter_main(); + + return 1; +} + -- 2.7.4