int main(int argc, char *argv[]) { ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; clutter_init (&argc, &argv); /* Get the stage and set its size and color: */ ClutterActor *stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 200, 200); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); /* Add a rectangle to the stage: */ rect = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (rect, 40, 40); clutter_actor_set_position (rect, 10, 10); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); clutter_actor_show (rect); /* Show the stage: */ clutter_actor_show (stage); ClutterTimeline *timeline = clutter_timeline_new(5000 /* milliseconds */); clutter_timeline_set_loop(timeline, TRUE); clutter_timeline_start(timeline); /* Create a clutter alpha for the animation */ ClutterAlpha* alpha = clutter_alpha_new_with_func (timeline, &on_alpha, NULL, NULL); g_object_unref (timeline); /* Create an animation to change the properties */ ClutterAnimation* animation = clutter_actor_animate_with_alpha (rect, alpha, "x", 150.0, "y", 150.0, "opacity", 0, NULL); /* Start the main loop, so we can respond to events: */ clutter_main (); g_object_unref (animation); return EXIT_SUCCESS; }
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; }
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)); }