void clarity_cover_set_rotation_behaviour(ClarityCover *self, ClutterAlpha *alpha, int final_angle, ClutterRotateDirection direction) { g_return_if_fail(CLARITY_IS_COVER(self)); double current = clutter_actor_get_rotation(CLUTTER_ACTOR(self), CLUTTER_Y_AXIS, 0, 0, 0); if(current < 0) current += 360; else if(current > 360) current -= 360; if(current != final_angle) { self->priv->rotateBehaviour = clutter_behaviour_rotate_new ( alpha, CLUTTER_Y_AXIS, direction , current, final_angle); clutter_behaviour_rotate_set_center( CLUTTER_BEHAVIOUR_ROTATE(self->priv->rotateBehaviour), clutter_actor_get_width(CLUTTER_ACTOR(self)) / 2, 0, 0); clutter_behaviour_apply (self->priv->rotateBehaviour, CLUTTER_ACTOR(self)); } }
G_MODULE_EXPORT gint test_texture_quality_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *depth_behavior; ClutterActor *stage; ClutterActor *image; ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff }; ClutterFog stage_fog = { 10.0, -50.0 }; GError *error; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE); clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog); g_signal_connect (stage, "button-press-event", G_CALLBACK (clutter_main_quit), NULL); error = NULL; image = clutter_texture_new_from_file (argv[1]?argv[1]:"redhand.png", &error); if (error) g_error ("Unable to load image: %s", error->message); if (!argv[1]) g_print ("Hint: the redhand.png isn't a good test image for this test.\n" "This test can take any clutter loadable image as an argument\n"); /* center the image */ clutter_actor_set_position (image, (clutter_actor_get_width (stage) - clutter_actor_get_width (image))/2, (clutter_actor_get_height (stage) - clutter_actor_get_height (image))/2); clutter_container_add (CLUTTER_CONTAINER (stage), image, NULL); timeline = clutter_timeline_new (5000); g_signal_connect (timeline, "completed", G_CALLBACK (timeline_completed), NULL); alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400); clutter_behaviour_apply (depth_behavior, image); clutter_actor_show (stage); clutter_timeline_start (timeline); g_timeout_add (10000, change_filter, image); clutter_main (); g_object_unref (depth_behavior); g_object_unref (timeline); return EXIT_SUCCESS; }
G_MODULE_EXPORT int test_viewport_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *r_behave; ClutterActor *stage; ClutterActor *hand; ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff }; gchar *file; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); /* Make a hand */ file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); hand = clutter_texture_new_from_file (file, NULL); if (!hand) g_error("Unable to load image '%s'", file); g_free (file); clutter_actor_set_position (hand, 300, 200); clutter_actor_set_clip (hand, 20, 21, 132, 170); clutter_actor_set_anchor_point (hand, 86, 125); clutter_actor_show (hand); clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand); /* Make a timeline */ timeline = clutter_timeline_new (7692); clutter_timeline_set_loop (timeline, TRUE); /* Set an alpha func to power behaviour */ alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); /* Create a behaviour for that alpha */ r_behave = clutter_behaviour_rotate_new (alpha, CLUTTER_Z_AXIS, CLUTTER_ROTATE_CW, 0.0, 360.0); /* Apply it to our actor */ clutter_behaviour_apply (r_behave, hand); /* start the timeline and thus the animations */ clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (r_behave); return 0; }
Preview::Preview(): width(0), height(0), blocknr(-1), color(-1), themeID(0), cell_size(20), cache(NULL), enabled(true) { blocks = new Block*[PREVIEW_WIDTH]; for (int i = 0; i < PREVIEW_WIDTH; i++) { blocks[i] = new Block [PREVIEW_HEIGHT]; } w = gtk_clutter_embed_new(); g_signal_connect (w, "size_allocate", G_CALLBACK (resize), this); /* FIXME: We should scale with the rest of the UI, but that requires * changes to the widget layout - i.e. wrap the preview in an * fixed-aspect box. */ gtk_widget_set_size_request (w, 120, 120); ClutterActor *stage; stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (w)); ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); piece = clutter_group_new (); clutter_group_add (CLUTTER_GROUP (stage), piece); piece_timeline = clutter_timeline_new (180); alpha = clutter_alpha_new_full (piece_timeline, CLUTTER_EASE_IN_OUT_SINE); piece_behav = clutter_behaviour_scale_new (alpha, 0.6, 0.6, 1.0, 1.0); clutter_actor_set_anchor_point (piece, 60, 60); clutter_actor_set_position (CLUTTER_ACTOR(piece), 60, 60); clutter_behaviour_apply (piece_behav, piece); }
void on_call_activate_complete (ClutterActor *actor, gpointer user_data) { ClutterAlpha *alpha; ClutterBehaviour *behave; App *app = (App*)user_data; clutter_actor_hide (app->screen_dialpad); /* Setup the pulsing 'calling..' text if need be */ if (app->dialing_timeline == NULL) { app->dialing_timeline = clutter_timeline_new (1000); clutter_timeline_set_loop (app->dialing_timeline, TRUE); alpha = clutter_alpha_new_full (app->dialing_timeline, ALPHA_SINE); behave = clutter_behaviour_opacity_new (alpha, 0xff, 0); clutter_behaviour_apply (behave, app->dial_label); } clutter_timeline_start (app->dialing_timeline); app->dialing_state = TRUE; }
G_MODULE_EXPORT int test_paint_wrapper_main (int argc, char *argv[]) { ClutterAlpha *alpha; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; SuperOH *oh; gint i; GError *error; ClutterActor *real_hand; error = NULL; #ifdef HAVE_CLUTTER_GLX clutter_x11_set_use_argb_visual (TRUE); #endif clutter_init_with_args (&argc, &argv, NULL, super_oh_entries, NULL, &error); if (error) { g_warning ("Unable to initialise Clutter:\n%s", error->message); g_error_free (error); return EXIT_FAILURE; } stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 800, 600); if (use_alpha != 255) { clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE); clutter_actor_set_opacity (stage, use_alpha); } clutter_stage_set_title (CLUTTER_STAGE (stage), "Paint Test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); oh = g_new(SuperOH, 1); oh->stage = stage; /* Create a timeline to manage animation */ oh->timeline = clutter_timeline_new (6000); clutter_timeline_set_loop (oh->timeline, TRUE); /* fire a callback for frame change */ g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh); /* Set up some behaviours to handle scaling */ alpha = clutter_alpha_new_with_func (oh->timeline, my_sine_wave, NULL, NULL); oh->scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, 1.0, 1.0); oh->scaler_2 = clutter_behaviour_scale_new (alpha, 1.0, 1.0, 0.5, 0.5); real_hand = clutter_texture_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", &error); if (real_hand == NULL) { g_error ("image load failed: %s", error->message); return EXIT_FAILURE; } /* create a new group to hold multiple actors in a group */ oh->group = clutter_group_new(); oh->hand = g_new (ClutterActor*, n_hands); oh->stage_width = clutter_actor_get_width (stage); oh->stage_height = clutter_actor_get_height (stage); oh->radius = (oh->stage_width + oh->stage_height) / n_hands; for (i = 0; i < n_hands; i++) { gint x, y, w, h; if (i == 0) oh->hand[i] = real_hand; else oh->hand[i] = clutter_clone_new (real_hand); clutter_actor_set_reactive (oh->hand[i], TRUE); clutter_actor_set_size (oh->hand[i], 200, 213); /* Place around a circle */ w = clutter_actor_get_width (oh->hand[i]); h = clutter_actor_get_height (oh->hand[i]); x = oh->stage_width / 2 + oh->radius * cos (i * G_PI / (n_hands / 2)) - w / 2; y = oh->stage_height / 2 + oh->radius * sin (i * G_PI / (n_hands / 2)) - h / 2; clutter_actor_set_position (oh->hand[i], x, y); clutter_actor_move_anchor_point_from_gravity (oh->hand[i], CLUTTER_GRAVITY_CENTER); g_signal_connect (oh->hand[i], "button-press-event", G_CALLBACK (on_button_press_event), oh); /* paint something before each hand */ g_signal_connect (oh->hand[i], "paint", G_CALLBACK (hand_pre_paint), oh); /* paint something after each hand */ g_signal_connect_after (oh->hand[i], "paint", G_CALLBACK (hand_post_paint), oh); /* Add to our group group */ clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]); if (i % 2) clutter_behaviour_apply (oh->scaler_1, oh->hand[i]); else clutter_behaviour_apply (oh->scaler_2, oh->hand[i]); } oh->paint_guards = g_malloc0 (sizeof (gboolean) * n_hands); /* Add the group to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (oh->group)); /* Show everying ( and map window ) */ clutter_actor_show (stage); g_signal_connect (stage, "key-release-event", G_CALLBACK (input_cb), oh); /* and start it */ clutter_timeline_start (oh->timeline); clutter_main (); g_object_unref (oh->scaler_1); g_object_unref (oh->scaler_2); g_object_unref (oh->timeline); g_free (oh->paint_guards); g_free (oh->hand); g_free (oh); return 0; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterColor stage_color = { 0x34, 0x39, 0x39, 0xff }; ClutterColor white = { 0x72, 0x9f, 0xcf, 0xff }; gint i = 0; Item *item; App *app; gdouble ang = 0.0; ClutterBehaviour *behave; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 800, 600); app = g_new0(App, 1); app->off = 0.0; app->timeline = clutter_timeline_new (300); app->alpha_sine_inc = clutter_alpha_new_full (app->timeline, CLUTTER_EASE_OUT_SINE); app->alpha_ramp = clutter_alpha_new_with_func (app->timeline, label_opacity_alpha_func, NULL, NULL); for (i=0; i<N_ITEMS; i++) { item = g_new0 (Item, 1); item->actor = clutter_texture_new_from_file (ItemDetails[i].img, NULL); if (!item->actor) g_error ("Unable to load '%s'", ItemDetails[i].img); clutter_group_add (CLUTTER_GROUP(stage), item->actor); item->ellipse_behave = clutter_behaviour_ellipse_new (app->alpha_sine_inc, CSW()/4, /* center x */ CSH() - (CSH()/3), /* center y */ CSW()/2, /* width */ CSH() - (CSH()/4), /* height */ CLUTTER_ROTATE_CW, ang, ang + STEP); item->opacity_behave = clutter_behaviour_opacity_new (app->alpha_sine_inc, 0x66, 0x66); item->scale_behave = clutter_behaviour_scale_new (app->alpha_sine_inc, 0.6, 0.6, 0.6, 0.6); clutter_behaviour_apply (item->ellipse_behave, item->actor); clutter_behaviour_apply (item->opacity_behave, item->actor); clutter_behaviour_apply (item->scale_behave, item->actor); app->items = g_slist_append (app->items, item); ang += STEP; } app->label = clutter_text_new_full ("Bitstream Vera Sans 60px", "", &white); clutter_actor_set_position (app->label, CSW()/2 - 30, CSH()/3 - 40); clutter_group_add (CLUTTER_GROUP(stage), app->label); behave = clutter_behaviour_opacity_new (app->alpha_ramp, 0xff, 0); clutter_behaviour_apply (behave, app->label); g_signal_connect (app->timeline, "new-frame", G_CALLBACK(on_timeline_new_frame), app); g_signal_connect (stage, "event", G_CALLBACK (on_input), app); introduce_items (app); clutter_actor_show_all (stage); clutter_main(); return 0; }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Scaling"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); clutter_actor_set_size (stage, 300, 300); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_repeat_count (timeline, -1); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
static gboolean task (gpointer user_data) { ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *depth_behavior; ClutterActor *image[4]; ClutterActor *clone[4]; ClutterActor *stage; gchar *path = user_data; gint i; stage = clutter_stage_get_default (); image[0] = g_object_new (CLUTTER_TYPE_TEXTURE, NULL); g_signal_connect (image[0], "load-finished", G_CALLBACK (on_load_finished), GINT_TO_POINTER (LOAD_SYNC)); image[1] = g_object_new (CLUTTER_TYPE_TEXTURE, "load-data-async", TRUE, NULL); g_signal_connect (image[1], "load-finished", G_CALLBACK (on_load_finished), GINT_TO_POINTER (LOAD_DATA_ASYNC)); image[2] = g_object_new (CLUTTER_TYPE_TEXTURE, "load-async", TRUE, NULL); g_signal_connect (image[2], "load-finished", G_CALLBACK (on_load_finished), GINT_TO_POINTER (LOAD_ASYNC)); for (i = 0; i < 3; i++) { GError *error = NULL; clutter_texture_set_from_file (CLUTTER_TEXTURE (image[i]), path, &error); if (error != NULL) g_error ("Unable to load image at '%s': %s", path != NULL ? path : "<unknown>", error->message); } for (i = 0; i < 3; i++) clutter_container_add (CLUTTER_CONTAINER (stage), image[i], NULL); for (i = 0; i < 3; i++) { clutter_actor_set_position (image[i], 50+i*100, 0+i*50); clone[i]=clutter_clone_new (image[i]); g_signal_connect (image[i], "size-change", G_CALLBACK (size_change_cb), clone[i]); clutter_container_add (CLUTTER_CONTAINER (stage), clone[i], NULL); clutter_actor_set_position (clone[i], 50+i*100, 150+i*50+100); } for (i = 0; i < 3; i++) { timeline = clutter_timeline_new (5000); alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 0); clutter_behaviour_apply (depth_behavior, image[i]); clutter_timeline_start (timeline); } return FALSE; }
int main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *scaler_1, *scaler_2; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; SuperOH *oh; gint i; GError *error; #ifdef REQ_NON_COMPOSITION Window xwin; Atom non_comp_atom; Display *dpy; int one = 1; #endif error = NULL; clutter_init_with_args (&argc, &argv, NULL, super_oh_entries, NULL, &error); if (error) { g_warning ("Unable to initialise Clutter:\n%s", error->message); g_error_free (error); exit (1); } stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 800, 600); clutter_stage_set_title (CLUTTER_STAGE (stage), "Actors Test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); #ifdef REQ_NON_COMPOSITION /* request non-composited mode */ clutter_stage_fullscreen (stage); xwin = clutter_x11_get_stage_window (stage); dpy = XOpenDisplay(NULL); non_comp_atom = XInternAtom(dpy, "_HILDON_NON_COMPOSITED_WINDOW", False); XChangeProperty (dpy, xwin, non_comp_atom, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &one, 1); printf ("stage win is %lx\n", xwin); XSync (dpy, False); #endif oh = g_new(SuperOH, 1); /* Create a timeline to manage animation */ timeline = clutter_timeline_new (360, 60); /* num frames, fps */ g_object_set (timeline, "loop", TRUE, NULL); /* have it loop */ /* fire a callback for frame change */ g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh); /* Set up some behaviours to handle scaling */ alpha = clutter_alpha_new_full (timeline, CLUTTER_ALPHA_SINE, NULL, NULL); scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, 1.0, 1.0); scaler_2 = clutter_behaviour_scale_new (alpha, 1.0, 1.0, 0.5, 0.5); /* create a new group to hold multiple actors in a group */ oh->group = clutter_group_new(); oh->hand = g_new (ClutterActor*, n_hands); for (i = 0; i < n_hands; i++) { gint x, y, w, h; gint radius = get_radius (); /* Create a texture from file, then clone in to same resources */ if (i == 0) { if ((oh->hand[i] = clutter_texture_new_from_file ("redhand.png", &error)) == NULL) { g_error ("image load failed: %s", error->message); exit (1); } } else oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE(oh->hand[0])); /* Place around a circle */ w = clutter_actor_get_width (oh->hand[0]); h = clutter_actor_get_height (oh->hand[0]); x = CLUTTER_STAGE_WIDTH () / 2 + radius * cos (i * M_PI / (n_hands / 2)) - w / 2; y = CLUTTER_STAGE_HEIGHT () / 2 + radius * sin (i * M_PI / (n_hands / 2)) - h / 2; clutter_actor_set_position (oh->hand[i], x, y); clutter_actor_move_anchor_point_from_gravity (oh->hand[i], CLUTTER_GRAVITY_CENTER); /* Add to our group group */ clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]); #if 1 /* FIXME: disabled as causes drift? - see comment above */ if (i % 2) clutter_behaviour_apply (scaler_1, oh->hand[i]); else clutter_behaviour_apply (scaler_2, oh->hand[i]); #endif } /* Add the group to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (oh->group)); /* Show everying ( and map window ) */ clutter_actor_show (stage); g_signal_connect (stage, "button-press-event", G_CALLBACK (input_cb), oh); g_signal_connect (stage, "key-release-event", G_CALLBACK (input_cb), oh); /* and start it */ clutter_timeline_start (timeline); clutter_main (); g_free (oh->hand); g_free (oh); return 0; }
G_MODULE_EXPORT int test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; ClutterColor white_color = { 0xff, 0xff, 0xff, 0xFF }; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *behave; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 300, 300); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 100, 100); clutter_actor_set_position (rect, 100, 100); clutter_group_add (CLUTTER_GROUP (stage), rect); label = clutter_text_new_with_text ("Sans 20px", ""); clutter_text_set_color (CLUTTER_TEXT (label), &white_color); clutter_actor_set_position (label, clutter_actor_get_x (rect), clutter_actor_get_y (rect) + clutter_actor_get_height (rect)); clutter_group_add (CLUTTER_GROUP (stage), label); rect_color.alpha = 0xff; rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 100, 100); clutter_actor_set_size (rect, 100, 100); set_next_gravity (rect); clutter_group_add (CLUTTER_GROUP (stage), rect); timeline = clutter_timeline_new (750); alpha = clutter_alpha_new_with_func (timeline, my_ramp_func, NULL, NULL); behave = clutter_behaviour_scale_new (alpha, 0.0, 0.0, /* scale start */ 1.0, 1.0); /* scale end */ clutter_behaviour_apply (behave, rect); clutter_timeline_set_loop (timeline, TRUE); g_signal_connect_swapped (timeline, "completed", G_CALLBACK (set_next_gravity), rect); clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (timeline); g_object_unref (behave); return EXIT_SUCCESS; }
void aisleriot_slot_renderer_set_animations (AisleriotSlotRenderer *srend, guint n_anims, const AisleriotAnimStart *anims, guint n_unexposed_animated_cards) { AisleriotSlotRendererPrivate *priv; guint i; gint card_num; g_return_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend)); priv = srend->priv; g_return_if_fail (n_anims <= priv->slot->exposed); /* Destroy the current animations */ for (i = 0; i < priv->animations->len; i++) { AnimationData *anim_data; anim_data = &g_array_index (priv->animations, AnimationData, i); if (anim_data->move) g_object_unref (anim_data->move); if (anim_data->rotate) g_object_unref (anim_data->rotate); if (anim_data->depth) g_object_unref (anim_data->depth); clutter_actor_destroy (anim_data->card_tex); g_object_unref (anim_data->card_tex); } g_array_set_size (priv->animations, 0); card_num = priv->slot->cards->len - n_anims; for (i = 0; i < n_anims; i++) { AnimationData anim_data; ClutterAlpha *alpha; ClutterKnot knots[2]; Card card = CARD (priv->slot->cards->data[card_num]); guint card_width, card_height; memset (&anim_data, 0, sizeof (anim_data)); anim_data.card_tex = aisleriot_card_new (priv->cache, anims[i].old_card, card); card_width = clutter_actor_get_width (anim_data.card_tex); card_height = clutter_actor_get_height (anim_data.card_tex); g_object_ref_sink (anim_data.card_tex); if (priv->animation_layer) clutter_container_add (priv->animation_layer, CLUTTER_ACTOR (anim_data.card_tex), NULL); clutter_actor_set_position (anim_data.card_tex, anims[i].cardx, anims[i].cardy); knots[0].x = anims[i].cardx; knots[0].y = anims[i].cardy; aisleriot_game_get_card_offset (priv->slot, card_num, FALSE, &knots[1].x, &knots[1].y); knots[1].x += priv->slot->rect.x; knots[1].y += priv->slot->rect.y; alpha = clutter_alpha_new_full (priv->timeline, CLUTTER_LINEAR); anim_data.move = clutter_behaviour_path_new_with_knots (alpha, knots, G_N_ELEMENTS (knots)); clutter_behaviour_apply (anim_data.move, anim_data.card_tex); if (anims[i].old_card.value != card.value) { int center_x, center_y; center_x = card_width / 2; center_y = card_height / 2; clutter_actor_set_rotation (anim_data.card_tex, CLUTTER_Y_AXIS, 180.0, center_x, center_y, 0); anim_data.rotate = clutter_behaviour_rotate_new (alpha, CLUTTER_Y_AXIS, CLUTTER_ROTATE_CW, 180.0, 0.0); clutter_behaviour_rotate_set_center (CLUTTER_BEHAVIOUR_ROTATE (anim_data.rotate), center_x, center_y, 0); clutter_behaviour_apply (anim_data.rotate, anim_data.card_tex); } if (anims[i].raise) { alpha = clutter_alpha_new_with_func (priv->timeline, aisleriot_slot_sine_animation_mode, NULL, NULL); anim_data.depth = clutter_behaviour_depth_new (alpha, 0, card_height); clutter_behaviour_apply (anim_data.depth, anim_data.card_tex); } g_array_append_val (priv->animations, anim_data); card_num++; } if (n_anims > 0) { clutter_timeline_rewind (priv->timeline); clutter_timeline_start (priv->timeline); } priv->n_unexposed_animated_cards = n_unexposed_animated_cards; clutter_actor_queue_redraw (CLUTTER_ACTOR (srend)); }
G_MODULE_EXPORT int test_behave_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 }; int i; path_t path_type = PATH_POLY; const char *knots_poly = ("M 0, 0 L 0, 300 L 300, 300 " "L 300, 0 L 0, 0"); /* A spiral created with inkscake */ const char *knots_bspline = "M 34.285713,35.219326 " "C 44.026891,43.384723 28.084874,52.378758 20.714286,51.409804 " "C 0.7404474,48.783999 -4.6171866,23.967448 1.904757,8.0764719 " "C 13.570984,-20.348756 49.798303,-26.746504 74.999994,-13.352108 " "C 111.98449,6.3047056 119.56591,55.259271 99.047626,89.505034 " "C 71.699974,135.14925 9.6251774,143.91924 -33.571422,116.17172 " "C -87.929934,81.254291 -97.88804,5.8941057 -62.857155,-46.209236 " "C -20.430061,-109.31336 68.300385,-120.45954 129.2857,-78.114021 " "C 201.15479,-28.21129 213.48932,73.938876 163.80954,143.79074 " "C 106.45226,224.43749 -9.1490153,237.96076 -87.85713,180.93363 " "C -177.29029,116.13577 -192.00272,-12.937817 -127.61907,-100.49494 " "C -55.390344,-198.72081 87.170553,-214.62275 183.57141,-142.87593 " "C 290.59464,-63.223369 307.68641,92.835839 228.57145,198.07645"; 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 (); 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); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); /* Make a hand */ group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); clutter_actor_show (group); hand = clutter_texture_new_from_file ("redhand.png", NULL); if (hand == NULL) { g_error("pixbuf load failed"); return 1; } clutter_actor_set_position (hand, 0, 0); clutter_actor_show (hand); rect = clutter_rectangle_new (); clutter_actor_set_position (rect, 0, 0); clutter_actor_set_size (rect, clutter_actor_get_width (hand), clutter_actor_get_height (hand)); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_bg_color); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), 10); clutter_color_from_string (&rect_border_color, "DarkSlateGray"); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect), &rect_border_color); clutter_actor_show (rect); clutter_container_add (CLUTTER_CONTAINER (group), rect, hand, NULL); /* Make a timeline */ timeline = clutter_timeline_new (4000); /* num frames, fps */ clutter_timeline_set_loop (timeline, TRUE); g_signal_connect (timeline, "completed", G_CALLBACK (timeline_completed), NULL); /* Set an alpha func to power behaviour - ramp is constant rise */ alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); /* 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 */ switch (path_type) { case PATH_POLY: { ClutterPath *path = clutter_path_new (); clutter_path_set_description (path, knots_poly); p_behave = clutter_behaviour_path_new (alpha, path); } break; case PATH_ELLIPSE: p_behave = clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300, CLUTTER_ROTATE_CW, 0.0, 360.0); 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); break; case PATH_BSPLINE: { ClutterPath *path = clutter_path_new (); clutter_path_set_description (path, knots_bspline); p_behave = clutter_behaviour_path_new (alpha, path); } break; } 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; }
int main (int argc, char **argv) { const ClutterColor transp = { 0x00, 0x00, 0x00, 0x00 }; const ClutterColor bg_color = { 0xe0, 0xf2, 0xfc, 0xff }; ClutterTimeline *timeline; ClutterActor *stage; gint i; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Circles"); clutter_stage_set_color (CLUTTER_STAGE (stage), &bg_color); clutter_actor_set_size (stage, SCREEN_W, SCREEN_H); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); timeline = clutter_timeline_new (5000); clutter_timeline_set_loop (timeline, TRUE); for (i = 0; i < N_CIRCLES; i++) { gint size; gdouble *angle; ClutterActor *actor; ClutterAlpha *alpha; ClutterBehaviour *behaviour; actor = clutter_rectangle_new_with_color (&transp); size = (i + 1) * (CIRCLE_W + CIRCLE_G) * 2; clutter_actor_set_size (actor, size, size); clutter_actor_set_position (actor, SCREEN_W - size / 2.0, SCREEN_H - size / 2.0); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); angle = g_slice_new (gdouble); *angle = g_random_double_range (0.0, 90.0); g_object_set_data (G_OBJECT (actor), "angle", angle); g_signal_connect (actor, "paint", G_CALLBACK (circle_paint_cb), NULL); /* Animate */ alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); behaviour = clutter_behaviour_rotate_new (alpha, CLUTTER_Z_AXIS, (i % 2) ? CLUTTER_ROTATE_CW : CLUTTER_ROTATE_CCW, 0.0, 0.0); clutter_behaviour_rotate_set_center (CLUTTER_BEHAVIOUR_ROTATE (behaviour), size / 2, size / 2, 0); clutter_behaviour_apply (behaviour, actor); } ClutterActor *actor2 = clutter_group_new(); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor2); clutter_actor_set_position(actor2, 10, 10); ClutterEffect *effect2 = nineslice_effect_new_from_source(source); clutter_actor_add_effect(actor2, effect2); ClutterActor *actor = clutter_group_new(); clutter_container_add_actor (CLUTTER_CONTAINER (actor2), actor); ClutterEffect *effect = nineslice_effect_new_from_source(source); clutter_actor_add_effect(actor, effect); ClutterActor *text = clutter_text_new_with_text("Sans 40px","Example Text"); clutter_actor_set_position(text, 0, 0); clutter_container_add_actor (CLUTTER_CONTAINER (actor), text); ClutterActor *rect = clutter_rectangle_new(); clutter_actor_set_position(rect, 10, 100); clutter_actor_set_size(rect, 50, 50); clutter_container_add_actor (CLUTTER_CONTAINER (actor), rect); clutter_actor_set_position(actor, 200, 100); //clutter_actor_set_rotation(actor, CLUTTER_Z_AXIS, 30.0, 130, 50, 0); /* GValue cvalue = G_VALUE_INIT; g_value_init(&cvalue, CLUTTER_TYPE_ACTOR_BOX); g_value_set_boxed(&cvalue, clutter_actor_box_new(0.0, 0.0, 0.0, 0.0)); GValue ovalue = G_VALUE_INIT; g_value_init(&ovalue, CLUTTER_TYPE_ACTOR_BOX); g_value_set_boxed(&ovalue, clutter_actor_box_new(50.0, 50.0, 50.0, 50.0)); ClutterState *transition = clutter_state_new(); clutter_state_set_duration(transition, NULL, NULL, 5000); clutter_state_set_key (transition, NULL, "close", G_OBJECT(effect), "padding", CLUTTER_LINEAR, &cvalue, 0.0, 0.0); clutter_state_set_key (transition, NULL, "open", G_OBJECT(effect), "padding", CLUTTER_LINEAR, &ovalue, 0.0, 0.0); //clutter_state_set(transition, NULL, "close", effect, "padding_right", CLUTTER_LINEAR, 0.0, NULL); //clutter_state_set(transition, NULL, "open", effect, "padding_right", CLUTTER_LINEAR, 50.0, NULL); clutter_state_warp_to_state(transition, "close"); clutter_state_set_state(transition, "open"); */ clutter_actor_animate(rect, CLUTTER_LINEAR, 5000, "height", 200.0, NULL); clutter_actor_show_all (stage); clutter_timeline_start (timeline); clutter_main (); return 0; }
int main(int argc,char *argv[]) { ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; clutter_init(&argc, &argv); ClutterActor *stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 521, 577); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); //ClutterActor * _group = clutter_group_new(); _group = clutter_group_new(); clutter_actor_set_position(_group, 0,0); clutter_container_add_actor(CLUTTER_CONTAINER(stage),_group); clutter_actor_show(_group); /** 加载棋盘图片*/ ClutterActor* _board = clutter_texture_new_from_file("./wood/wood.png",NULL); clutter_actor_set_position(_board,0,0); //clutter_actor_set_rotation(_board, CLUTTER_Y_AXIS, 20,0,0,0); //clutter_actor_set_rotation(_board, CLUTTER_X_AXIS, 20,0,0,0); //clutter_actor_set_rotation(_board, CLUTTER_Z_AXIS, 20,0,0,0); //clutter_container_add_actor(CLUTTER_CONTAINER(stage),_board); clutter_container_add_actor(CLUTTER_CONTAINER(_group),_board); clutter_actor_show(_board); #if 0 load_chess(); #else /** 加载棋子*/ ClutterActor* _rking = clutter_texture_new_from_file("./wood/red_king.png",NULL); clutter_actor_set_position(_rking,235,8); clutter_container_add_actor(CLUTTER_CONTAINER(_group),_rking); clutter_actor_show(_rking); clutter_actor_set_reactive(_rking,TRUE); g_signal_connect(_rking, "button-press-event",G_CALLBACK(on_rking_button_press),NULL); timeline=clutter_timeline_new(3000); //g_signal_connect(timeline,"new-frame",G_CALLBACK(on_timeline_new_frame),_rking); clutter_timeline_set_loop(timeline,TRUE); ClutterAlpha* alpha_ = clutter_alpha_new_full(timeline, CLUTTER_EASE_IN_OUT_QUAD);//CLUTTER_EASE_IN_SINE); ClutterBehaviour* behaviour_ = clutter_behaviour_rotate_new(alpha_, CLUTTER_Y_AXIS, CLUTTER_ROTATE_CW, 0, 360); clutter_behaviour_rotate_set_center(CLUTTER_BEHAVIOUR_ROTATE(behaviour_), clutter_actor_get_width(_rking)/2,0,0); clutter_behaviour_apply(behaviour_, _rking); clutter_actor_set_rotation(_group, CLUTTER_X_AXIS, 40,2,600,0); //clutter_actor_set_rotation(_group, CLUTTER_Y_AXIS, 40,221,200,0); #endif clutter_actor_show(stage); clutter_main(); g_object_unref(timeline); printf("\n"); return 0; }
G_MODULE_EXPORT int test_pixmap_main (int argc, char **argv) { GOptionContext *context; Display *xdpy; int screen; ClutterActor *group = NULL, *label, *stage, *tex; Pixmap pixmap; const ClutterColor gry = { 0x99, 0x99, 0x99, 0xFF }; Window win_remote; guint w, h, d; GC gc; ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *depth_behavior; int i; int row_height; #ifdef CLUTTER_WINDOWING_X11 clutter_set_windowing_backend (CLUTTER_WINDOWING_X11); #endif if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; #ifdef CLUTTER_WINDOWING_X11 if (!clutter_check_windowing_backend (CLUTTER_WINDOWING_X11)) g_error ("test-pixmap requires the X11 Clutter backend."); #endif xdpy = clutter_x11_get_default_display (); XSynchronize (xdpy, True); context = g_option_context_new (" - test-pixmap options"); g_option_context_add_main_entries (context, g_options, NULL); g_option_context_parse (context, &argc, &argv, NULL); pixmap = create_pixmap (&w, &h, &d); screen = DefaultScreen(xdpy); win_remote = XCreateSimpleWindow (xdpy, DefaultRootWindow(xdpy), 0, 0, 200, 200, 0, WhitePixel(xdpy, screen), WhitePixel(xdpy, screen)); XMapWindow (xdpy, win_remote); stage = clutter_stage_new (); clutter_actor_set_position (stage, 0, 150); clutter_actor_set_background_color (stage, &gry); clutter_stage_set_title (CLUTTER_STAGE (stage), "X11 Texture from Pixmap"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); timeline = clutter_timeline_new (5000); g_signal_connect (timeline, "completed", G_CALLBACK (timeline_completed), NULL); alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400); if (!disable_x11) { group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Window)"); clutter_container_add_actor (CLUTTER_CONTAINER (group), label); tex = clutter_x11_texture_pixmap_new_with_window (win_remote); clutter_container_add_actor (CLUTTER_CONTAINER (group), tex); clutter_actor_set_position (tex, 0, 20); clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex), TRUE); clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex), CLUTTER_TEXTURE_QUALITY_HIGH); clutter_actor_set_position (group, 0, 0); if (!disable_animation) clutter_behaviour_apply (depth_behavior, group); } if (group) row_height = clutter_actor_get_height (group); else row_height = 0; /* NB: We only draw on the window after being redirected, so we dont * have to worry about handling expose events... */ gc = XCreateGC (xdpy, win_remote, 0, NULL); XSetForeground (xdpy, gc, BlackPixel (xdpy, screen)); XSetLineAttributes(xdpy, gc, 5, LineSolid, CapButt, JoinMiter); for (i = 0; i < 10; i++) XDrawLine (xdpy, win_remote, gc, 0+i*20, 0, 10+i*20+i, 200); group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Pixmap)"); clutter_container_add_actor (CLUTTER_CONTAINER (group), label); tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap); clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex), TRUE); clutter_container_add_actor (CLUTTER_CONTAINER (group), tex); clutter_actor_set_position (tex, 0, 20); clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex), CLUTTER_TEXTURE_QUALITY_HIGH); /* oddly, the actor's size is 0 until it is realized, even though pixmap-height is set */ clutter_actor_set_position (group, 0, row_height); if (!disable_animation) clutter_behaviour_apply (depth_behavior, group); g_signal_connect (stage, "key-release-event", G_CALLBACK (stage_key_release_cb), (gpointer)pixmap); g_signal_connect (stage, "button-press-event", G_CALLBACK (stage_button_press_cb), (gpointer)pixmap); clutter_actor_show (stage); if (!disable_animation) clutter_timeline_start (timeline); clutter_threads_add_timeout (1000, draw_arc, GUINT_TO_POINTER (pixmap)); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *rect; ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff }; ClutterColor rect_color = { 0xee, 0x55, 0x55, 0x99 }; ClutterColor progress_color = { 0x55, 0xee, 0x55, 0xbb }; ClutterBehaviour *r_behaviour, *p_behaviour; const ClutterKnot knots[] = { { 75, 150 }, { 400, 150 } }; g_thread_init (NULL); clutter_threads_init (); clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 600, 300); count_label = clutter_label_new_with_text ("Mono 12", "Counter"); clutter_actor_set_position (count_label, 350, 50); help_label = clutter_label_new_with_text ("Mono 12", "Press 's' to start"); clutter_actor_set_position (help_label, 50, 50); rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_position (rect, 75, 150); clutter_actor_set_size (rect, 50, 50); clutter_actor_set_anchor_point (rect, 25, 25); progress_rect = clutter_rectangle_new_with_color (&progress_color); clutter_actor_set_position (progress_rect, 50, 225); clutter_actor_set_size (progress_rect, 350, 50); clutter_container_add (CLUTTER_CONTAINER (stage), count_label, help_label, rect, progress_rect, NULL); timeline = clutter_timeline_new (150, 50); clutter_timeline_set_loop (timeline, TRUE); r_behaviour = clutter_behaviour_rotate_new (clutter_alpha_new_full (timeline, CLUTTER_ALPHA_RAMP_INC, NULL, NULL), CLUTTER_Z_AXIS, CLUTTER_ROTATE_CW, 0.0, 360.0); clutter_behaviour_apply (r_behaviour, rect); p_behaviour = clutter_behaviour_path_new (clutter_alpha_new_full (timeline, CLUTTER_ALPHA_SINE, NULL, NULL), knots, G_N_ELEMENTS (knots)); clutter_behaviour_apply (p_behaviour, rect); g_signal_connect (stage, "button-press-event", G_CALLBACK (clutter_main_quit), NULL); g_signal_connect (stage, "key-press-event", G_CALLBACK (on_key_press_event), NULL); clutter_actor_show (stage); clutter_threads_enter (); clutter_main (); clutter_threads_leave (); g_object_unref (p_behaviour); g_object_unref (r_behaviour); g_object_unref (timeline); return EXIT_SUCCESS; }