void clarity_cover_set_album_item (ClarityCover *self, AlbumItem *item) { g_return_if_fail(CLARITY_IS_COVER(self)); ClarityCoverPrivate *priv = CLARITY_COVER_GET_PRIVATE (self); g_return_if_fail(priv); GError *error = NULL; gint y_offset; if (!priv->texture) { priv->texture = gtk_clutter_texture_new(); clutter_container_add_actor(CLUTTER_CONTAINER(self), priv->texture); } // Set cover artwork gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE(priv->texture), item->albumart, &error); if (error) { g_warning("%s", error->message); g_error_free(error); return; } // Add reflection if (! priv->reflection) { y_offset = clutter_actor_get_height (priv->texture) + V_PADDING; priv->reflection = clutter_clone_new (priv->texture); clutter_actor_add_constraint (priv->reflection, clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_X, 0.0)); clutter_actor_add_constraint (priv->reflection, clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_Y, y_offset)); clutter_actor_add_constraint (priv->reflection, clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_WIDTH, 0.0)); clutter_actor_add_constraint (priv->reflection, clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_HEIGHT, 0.0)); g_signal_connect (priv->reflection, "paint", G_CALLBACK (_clone_paint_cb), NULL); clutter_container_add_actor(CLUTTER_CONTAINER(self), priv->reflection); } ClutterActorBox box; gfloat w, h; clutter_actor_get_allocation_box (priv->texture, &box); clutter_actor_box_get_size (&box, &w, &h); if( h > DEFAULT_IMG_SIZE) { gfloat temp = w * DEFAULT_IMG_SIZE / h; clutter_actor_set_size(priv->texture, temp, DEFAULT_IMG_SIZE); } // Add title / artist data if (priv->title) g_free(priv->title); priv->title = g_strdup(item->albumname); if (priv->artist) g_free(priv->artist); priv->artist = g_strdup(item->artist); }
void show_message (void) { ClutterActor *stage, *label; ClutterColor black = { 0, 0, 0, 255 }; ClutterColor white = { 255, 255, 255, 255 }; clutter_init (NULL, NULL); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &black); clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE); label = clutter_text_new_with_text ("Sans 20", "Cannot find suitable screen mode\n" "Media Explorer requires a 720p screen"); clutter_text_set_line_wrap (CLUTTER_TEXT (label), TRUE); clutter_text_set_color (CLUTTER_TEXT (label), &white); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); /* Put the label in the middle */ clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_actor_show (stage); clutter_main (); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *button; ClutterConstraint *align_x_constraint; ClutterConstraint *align_y_constraint; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, 400, 400); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); button = cb_button_new (); cb_button_set_text (CB_BUTTON (button), "hello"); /* the following is equivalent to the two lines above: * * button = g_object_new (CB_TYPE_BUTTON, * "text", "winkle", * NULL); * * because we defined a set_property function, which can accept * a PROP_TEXT parameter, GObject can create a button and set one * or more properties with a single call to g_object_new() */ /* note that the size of the button is left to Clutter's size requisition */ cb_button_set_text_color (CB_BUTTON (button), &white_color); cb_button_set_background_color (CB_BUTTON (button), &yellow_color); g_signal_connect (button, "clicked", G_CALLBACK (clicked), NULL); align_x_constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5); align_y_constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5); clutter_actor_add_constraint (button, align_x_constraint); clutter_actor_add_constraint (button, align_y_constraint); clutter_actor_add_child (stage, button); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
G_MODULE_EXPORT int test_state_script_main (int argc, char *argv[]) { ClutterActor *stage, *button; ClutterScript *script; GError *error = NULL; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return EXIT_FAILURE; script = clutter_script_new (); clutter_script_load_from_file (script, TEST_STATE_SCRIPT_FILE, &error); if (error != NULL) g_error ("Unable to load '%s': %s\n", TEST_STATE_SCRIPT_FILE, error->message); stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "State Script"); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); clutter_actor_show (stage); button = CLUTTER_ACTOR (clutter_script_get_object (script, "button")); clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_script_connect_signals (script, NULL); clutter_main (); g_object_unref (script); return EXIT_SUCCESS; }
int main (int argc, char **argv) { const ClutterColor grey = { 0x40, 0x40, 0x40, 0xff }; ClutterActor *stage, *info_bar; ClutterConstraint *constraint; MxApplication *app; MxWindow *window; mex_init (&argc, &argv); app = mx_application_new (&argc, &argv, "mex-media-controls-test", 0); mex_style_load_default (); window = mx_application_create_window (app); stage = (ClutterActor *)mx_window_get_clutter_stage (window); clutter_stage_set_color (CLUTTER_STAGE (stage), &grey); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); info_bar = mex_info_bar_get_default (); constraint = clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, 0.0); clutter_actor_add_constraint (info_bar, constraint); clutter_container_add_actor (CLUTTER_CONTAINER (stage), info_bar); clutter_actor_set_size (stage, 1024, 768); clutter_actor_show (stage); clutter_main (); return 0; }
G_MODULE_EXPORT int test_texture_material_main (int argc, char *argv[]) { ClutterActor *stage, *box; ClutterLayoutManager *manager; int i; g_thread_init (NULL); clutter_threads_init (); clutter_init (&argc, &argv); stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Texture Material"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); manager = clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL); box = clutter_box_new (manager); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -25.0)); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -25.0)); clutter_actor_set_position (box, 25.0, 25.0); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); for (i = 0; i < 48; i++) { ClutterActor *texture = clutter_texture_new (); clutter_texture_set_load_data_async (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), TESTS_DATADIR "/redhand.png", NULL); clutter_actor_set_width (texture, 96); clutter_container_add_actor (CLUTTER_CONTAINER (box), texture); } clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; GError *error = NULL; ClutterActor *clone; gfloat y_offset; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Reflection"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), "redhand.png", &error); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.2)); y_offset = clutter_actor_get_height (texture) + V_PADDING; clone = clutter_clone_new (texture); clutter_actor_add_constraint (clone, clutter_bind_constraint_new (texture, CLUTTER_BIND_X, 0.0)); clutter_actor_add_constraint (clone, clutter_bind_constraint_new (texture, CLUTTER_BIND_Y, y_offset)); g_signal_connect (clone, "paint", G_CALLBACK (_clone_paint_cb), NULL); clutter_container_add (CLUTTER_CONTAINER (stage), texture, clone, NULL); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
static void editor_toolbar_align (BjbEditorToolbar *self, GdkEvent *event) { gint x_alignment, y_alignment; ClutterConstraint *constraint; BjbEditorToolbarPrivate *priv = self->priv; x_alignment = event->button.x + EDITOR_TOOLBAR_X_OFFSET; y_alignment = event->button.y + EDITOR_TOOLBAR_Y_OFFSET; if ( x_alignment < 0) x_alignment = 0; constraint = clutter_bind_constraint_new (priv->parent_actor, CLUTTER_BIND_Y, y_alignment); clutter_actor_add_constraint (priv->actor, constraint); constraint = clutter_bind_constraint_new (priv->parent_actor, CLUTTER_BIND_X, x_alignment); clutter_actor_add_constraint (priv->actor, constraint); }
static ClutterActor * create_scroll_actor (ClutterActor *stage) { ClutterActor *scroll; ClutterAction *pan_action; /* our scrollable viewport */ scroll = clutter_actor_new (); clutter_actor_set_name (scroll, "scroll"); clutter_actor_add_constraint (scroll, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0)); clutter_actor_add_constraint (scroll, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0)); clutter_actor_add_child (scroll, create_content_actor ()); pan_action = clutter_pan_action_new (); clutter_pan_action_set_interpolate (CLUTTER_PAN_ACTION (pan_action), TRUE); g_signal_connect (pan_action, "pan", G_CALLBACK (on_pan), NULL); clutter_actor_add_action (scroll, pan_action); clutter_actor_set_reactive (scroll, TRUE); return scroll; }
static void test_window (void) { GsdOsdDrawContext ctx; ClutterActor *stage, *actor; ClutterContent *canvas; GtkWidgetPath *widget_path; /* create a resizable stage */ stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "OSD Test"); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Red); clutter_actor_set_size (stage, 300, 300); clutter_actor_show (stage); /* box canvas */ canvas = clutter_canvas_new (); clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 300, 300); actor = clutter_actor_new (); clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0)); clutter_actor_set_content (actor, canvas); g_object_unref (canvas); clutter_actor_add_child (stage, actor); memset (&ctx, 0, sizeof(ctx)); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); ctx.style = gtk_style_context_new (); gtk_style_context_set_path (ctx.style, widget_path); ctx.direction = clutter_get_default_text_direction (); ctx.theme = gtk_icon_theme_get_default (); g_signal_connect (canvas, "draw", G_CALLBACK (draw_box), &ctx); clutter_content_invalidate (canvas); g_signal_connect (stage, "destroy", G_CALLBACK (gtk_main_quit), NULL); }
static void ekiga_extended_video_window_init_clutter (EkigaExtWindow *ew) { GtkWidget *clutter_widget = NULL; clutter_widget = gtk_clutter_embed_new (); gtk_widget_set_size_request (GTK_WIDGET (clutter_widget), STAGE_WIDTH, STAGE_HEIGHT); gtk_container_add (GTK_CONTAINER (ew), clutter_widget); ew->priv->stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter_widget)); clutter_actor_set_background_color (CLUTTER_ACTOR (ew->priv->stage), CLUTTER_COLOR_Black); clutter_stage_set_user_resizable (CLUTTER_STAGE (ew->priv->stage), TRUE); ew->priv->video_stream = CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "disable-slicing", TRUE, NULL)); clutter_actor_add_child (CLUTTER_ACTOR (ew->priv->stage), CLUTTER_ACTOR (ew->priv->video_stream)); clutter_actor_add_constraint (ew->priv->video_stream, clutter_align_constraint_new (ew->priv->stage, CLUTTER_ALIGN_BOTH, 0.5)); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *r1, *r2, *r3; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, 300, 300); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); r1 = clutter_rectangle_new_with_color (&red); clutter_actor_set_size (r1, 150, 150); clutter_actor_add_constraint (r1, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.25)); clutter_actor_add_constraint (r1, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.25)); clutter_actor_set_reactive (r1, TRUE); clutter_actor_set_name (r1, "red"); r2 = clutter_rectangle_new_with_color (&green); clutter_actor_set_size (r2, 150, 150); clutter_actor_add_constraint (r2, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (r2, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_actor_set_reactive (r2, TRUE); clutter_actor_set_depth (r2, -100); clutter_actor_set_name (r2, "green"); r3 = clutter_rectangle_new_with_color (&blue); clutter_actor_set_size (r3, 150, 150); clutter_actor_add_constraint (r3, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.75)); clutter_actor_add_constraint (r3, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.75)); clutter_actor_set_opacity (r3, 125); clutter_actor_set_name (r3, "blue"); clutter_container_add (CLUTTER_CONTAINER (stage), r1, r2, r3, NULL); g_signal_connect (r1, "motion-event", G_CALLBACK (_pointer_motion_cb), NULL); g_signal_connect (r2, "motion-event", G_CALLBACK (_pointer_motion_cb), NULL); clutter_actor_show (stage); clutter_main (); return 0; }
int main (int argc, char *argv[]) { ClutterActor *stage, *box, *bg, *icon, *emblem, *label; ClutterLayoutManager *layout; ClutterContent *canvas, *image; ClutterColor *color; ClutterAction *action; GdkPixbuf *pixbuf; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; /* prepare the stage */ stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "BinLayout"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Aluminium2); clutter_actor_set_size (stage, 640, 480); clutter_actor_show (stage); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* this is our BinLayout, with its default alignments */ layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); /* the main container; this actor will use the BinLayout to lay * out its children; we use the anchor point to keep it centered * on the same position even when we change its size */ box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_actor_set_position (box, 320, 240); clutter_actor_set_reactive (box, TRUE); clutter_actor_set_name (box, "box"); clutter_actor_add_child (stage, box); /* the background is drawn using a canvas content */ canvas = clutter_canvas_new (); g_signal_connect (canvas, "draw", G_CALLBACK (on_canvas_draw), NULL); clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 200, 200); /* this is the background actor; we want it to fill the whole * of the allocation given to it by its parent */ bg = clutter_actor_new (); clutter_actor_set_name (bg, "background"); clutter_actor_set_size (bg, 200, 200); clutter_actor_set_content (bg, canvas); clutter_actor_set_x_expand (bg, TRUE); clutter_actor_set_y_expand (bg, TRUE); clutter_actor_set_x_align (bg, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (bg, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_add_child (box, bg); /* we use the ::transitions-completed signal to get notification * of the end of the sizing animation; this allows us to redraw * the canvas only once the animation has stopped */ g_signal_connect (box, "transitions-completed", G_CALLBACK (redraw_canvas), canvas); /* we use GdkPixbuf to load an image from our data directory */ pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL); image = clutter_image_new (); clutter_image_set_data (CLUTTER_IMAGE (image), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), NULL); g_object_unref (pixbuf); /* this is the icon; it's going to be centered inside the box actor. * we use the content gravity to keep the aspect ratio of the image, * and the scaling filters to get a better result when scaling the * image down. */ icon = clutter_actor_new (); clutter_actor_set_name (icon, "icon"); clutter_actor_set_size (icon, 196, 196); clutter_actor_set_x_expand (icon, TRUE); clutter_actor_set_y_expand (icon, TRUE); clutter_actor_set_x_align (icon, CLUTTER_ACTOR_ALIGN_CENTER); clutter_actor_set_y_align (icon, CLUTTER_ACTOR_ALIGN_CENTER); clutter_actor_set_content_gravity (icon, CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT); clutter_actor_set_content_scaling_filters (icon, CLUTTER_SCALING_FILTER_TRILINEAR, CLUTTER_SCALING_FILTER_LINEAR); clutter_actor_set_content (icon, image); clutter_actor_add_child (box, icon); color = clutter_color_new (g_random_int_range (0, 255), g_random_int_range (0, 255), g_random_int_range (0, 255), 224); /* this is the emblem: a small rectangle with a random color, that we * want to put in the bottom right corner */ emblem = clutter_actor_new (); clutter_actor_set_name (emblem, "emblem"); clutter_actor_set_size (emblem, 48, 48); clutter_actor_set_background_color (emblem, color); clutter_actor_set_x_expand (emblem, TRUE); clutter_actor_set_y_expand (emblem, TRUE); clutter_actor_set_x_align (emblem, CLUTTER_ACTOR_ALIGN_END); clutter_actor_set_y_align (emblem, CLUTTER_ACTOR_ALIGN_END); clutter_actor_set_reactive (emblem, TRUE); clutter_actor_set_opacity (emblem, 0); clutter_actor_add_child (box, emblem); clutter_color_free (color); /* when clicking on the emblem, we want to perform an action */ action = clutter_click_action_new (); clutter_actor_add_action (emblem, action); g_signal_connect (action, "clicked", G_CALLBACK (on_emblem_clicked), box); g_signal_connect (action, "long-press", G_CALLBACK (on_emblem_long_press), box); /* whenever the pointer enters the box, we show the emblem; we hide * the emblem when the pointer leaves the box */ g_signal_connect (box, "enter-event", G_CALLBACK (on_box_enter), emblem); g_signal_connect (box, "leave-event", G_CALLBACK (on_box_leave), emblem); /* a label, that we want to position at the top and center of the box */ label = clutter_text_new (); clutter_actor_set_name (label, "text"); clutter_text_set_text (CLUTTER_TEXT (label), "A simple test"); clutter_actor_set_x_expand (label, TRUE); clutter_actor_set_x_align (label, CLUTTER_ACTOR_ALIGN_CENTER); clutter_actor_set_y_expand (label, TRUE); clutter_actor_set_y_align (label, CLUTTER_ACTOR_ALIGN_START); clutter_actor_add_child (box, label); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *dummy; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return EXIT_FAILURE; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Drop Action"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); target1 = clutter_actor_new (); clutter_actor_set_background_color (target1, CLUTTER_COLOR_LightScarletRed); clutter_actor_set_size (target1, TARGET_SIZE, TARGET_SIZE); clutter_actor_set_opacity (target1, 64); clutter_actor_add_constraint (target1, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_actor_set_x (target1, 10); clutter_actor_set_reactive (target1, TRUE); clutter_actor_add_action_with_name (target1, "drop", clutter_drop_action_new ()); g_signal_connect (clutter_actor_get_action (target1, "drop"), "over-in", G_CALLBACK (on_target_over), GUINT_TO_POINTER (TRUE)); g_signal_connect (clutter_actor_get_action (target1, "drop"), "over-out", G_CALLBACK (on_target_over), GUINT_TO_POINTER (FALSE)); g_signal_connect (clutter_actor_get_action (target1, "drop"), "drop", G_CALLBACK (on_target_drop), NULL); dummy = clutter_actor_new (); clutter_actor_set_background_color (dummy, CLUTTER_COLOR_DarkOrange); clutter_actor_set_size (dummy, 640 - (2 * 10) - (2 * (TARGET_SIZE + 10)), TARGET_SIZE); clutter_actor_add_constraint (dummy, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (dummy, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_actor_set_reactive (dummy, TRUE); target2 = clutter_actor_new (); clutter_actor_set_background_color (target2, CLUTTER_COLOR_LightChameleon); clutter_actor_set_size (target2, TARGET_SIZE, TARGET_SIZE); clutter_actor_set_opacity (target2, 64); clutter_actor_add_constraint (target2, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_actor_set_x (target2, 640 - TARGET_SIZE - 10); clutter_actor_set_reactive (target2, TRUE); clutter_actor_add_action_with_name (target2, "drop", clutter_drop_action_new ()); g_signal_connect (clutter_actor_get_action (target2, "drop"), "over-in", G_CALLBACK (on_target_over), GUINT_TO_POINTER (TRUE)); g_signal_connect (clutter_actor_get_action (target2, "drop"), "over-out", G_CALLBACK (on_target_over), GUINT_TO_POINTER (FALSE)); g_signal_connect (clutter_actor_get_action (target2, "drop"), "drop", G_CALLBACK (on_target_drop), NULL); clutter_actor_add_child (stage, target1); clutter_actor_add_child (stage, dummy); clutter_actor_add_child (stage, target2); add_drag_object (target1); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterState *transitions; GError *error = NULL; gfloat texture_width, texture_height; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_texture_set_sync_size (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), TESTS_DATA_DIR "/redhand.png", &error); if (error != NULL) { g_error ("Problem loading image into texture - %s", error->message); g_error_free (error); return 1; } clutter_actor_get_size (texture, &texture_width, &texture_height); clutter_actor_set_size (stage, texture_width * 2, texture_height * 2); /* set all centres of rotation to the centre of the texture */ clutter_actor_set_rotation (texture, CLUTTER_X_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_z_rotation_from_gravity (texture, 0.0, CLUTTER_GRAVITY_CENTER); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); /* set up the animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "start", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "x-cw", texture, "rotation-angle-x", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-ccw", texture, "rotation-angle-x", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-after", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "y-cw", texture, "rotation-angle-y", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-ccw", texture, "rotation-angle-y", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-after", texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "z-cw", texture, "rotation-angle-z", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "z-ccw", texture, "rotation-angle-z", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set_duration (transitions, NULL, NULL, DURATION); clutter_state_set_duration (transitions, "start", NULL, DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "start", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "x-after", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "y-after", DURATION * 0.5); clutter_state_warp_to_state (transitions, "start"); g_signal_connect (transitions, "completed", G_CALLBACK (_set_next_state), NULL); clutter_state_set_state (transitions, "x-cw"); clutter_actor_show (stage); clutter_main (); return 0; }
G_MODULE_EXPORT int test_snap_constraint_main (int argc, char *argv[]) { ClutterActor *stage, *layer_a, *layer_b, *layer_c; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; /* the main container */ stage = clutter_stage_new (); clutter_actor_set_name (stage, "stage"); clutter_stage_set_title (CLUTTER_STAGE (stage), "Snap Constraint"); clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Aluminium1); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* first layer, with a fixed (100, 25) size */ layer_a = clutter_rectangle_new_with_color (CLUTTER_COLOR_ScarletRed); clutter_actor_set_name (layer_a, "layerA"); clutter_container_add_actor (CLUTTER_CONTAINER (stage), layer_a); clutter_actor_set_size (layer_a, 100.0, 25.0); /* the first layer is anchored to the middle of the stage */ clutter_actor_add_constraint (layer_a, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (layer_a, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); /* second layer, with no implicit size */ layer_b = clutter_rectangle_new_with_color (CLUTTER_COLOR_DarkButter); clutter_actor_set_name (layer_b, "layerB"); clutter_container_add_actor (CLUTTER_CONTAINER (stage), layer_b); /* the second layer tracks the X coordinate and the width of * the first layer */ clutter_actor_add_constraint (layer_b, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_X, 0.0)); clutter_actor_add_constraint (layer_b, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_WIDTH, 0.0)); /* the second layer is snapped between the bottom edge of * the first layer, and the bottom edge of the stage; a * spacing of 10 pixels in each direction is added for padding */ clutter_actor_add_constraint (layer_b, clutter_snap_constraint_new (layer_a, CLUTTER_SNAP_EDGE_TOP, CLUTTER_SNAP_EDGE_BOTTOM, 10.0)); clutter_actor_add_constraint (layer_b, clutter_snap_constraint_new (stage, CLUTTER_SNAP_EDGE_BOTTOM, CLUTTER_SNAP_EDGE_BOTTOM, -10.0)); /* the third layer, with no implicit size */ layer_c = clutter_rectangle_new_with_color (CLUTTER_COLOR_LightChameleon); clutter_actor_set_name (layer_c, "layerC"); clutter_container_add_actor (CLUTTER_CONTAINER (stage), layer_c); /* as for the second layer, the third layer tracks the X * coordinate and width of the first layer */ clutter_actor_add_constraint (layer_c, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_X, 0.0)); clutter_actor_add_constraint (layer_c, clutter_bind_constraint_new (layer_a, CLUTTER_BIND_WIDTH, 0.0)); /* the third layer is snapped between the top edge of the stage * and the top edge of the first layer; again, a spacing of * 10 pixels in each direction is added for padding */ clutter_actor_add_constraint (layer_c, clutter_snap_constraint_new (layer_a, CLUTTER_SNAP_EDGE_BOTTOM, CLUTTER_SNAP_EDGE_TOP, -10.0)); clutter_actor_add_constraint (layer_c, clutter_snap_constraint_new (stage, CLUTTER_SNAP_EDGE_TOP, CLUTTER_SNAP_EDGE_TOP, 10.0)); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage0, *stage1, *stage2, *tex1, *tex2; GtkWidget *window, *clutter0, *clutter1, *clutter2; GtkWidget *notebook, *vbox; ClutterColor col0 = { 0xdd, 0xff, 0xdd, 0xff }; ClutterColor col1 = { 0xff, 0xff, 0xff, 0xff }; ClutterColor col2 = { 0, 0, 0, 0xff }; if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) g_error ("Unable to initialize GtkClutter"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); gtk_window_set_title (GTK_WINDOW (window), "Multiple GtkClutterEmbed"); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); notebook = gtk_notebook_new (); gtk_container_add (GTK_CONTAINER (window), notebook); clutter0 = gtk_clutter_embed_new (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), clutter0, gtk_label_new ("One stage")); stage0 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter0)); clutter_actor_set_background_color (stage0, &col0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox, gtk_label_new ("Two stages")); clutter1 = gtk_clutter_embed_new (); gtk_widget_set_size_request (clutter1, 320, 240); stage1 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter1)); clutter_actor_set_background_color (stage1, &col1); tex1 = gtk_clutter_texture_new (); gtk_clutter_texture_set_from_icon_name (GTK_CLUTTER_TEXTURE (tex1), clutter1, "dialog-information", GTK_ICON_SIZE_DIALOG, NULL); clutter_actor_set_position (tex1, 160 - clutter_actor_get_width (tex1) / 2.0, 120 - clutter_actor_get_height (tex1) / 2.0); clutter_actor_add_child (stage1, tex1); clutter_actor_show (tex1); gtk_container_add (GTK_CONTAINER (vbox), clutter1); clutter2 = gtk_clutter_embed_new (); gtk_widget_set_size_request (clutter2, 320, 120); stage2 = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter2)); clutter_actor_set_background_color (stage2, &col2); tex2 = gtk_clutter_texture_new (); gtk_clutter_texture_set_from_icon_name (GTK_CLUTTER_TEXTURE (tex2), clutter1, "user-info", GTK_ICON_SIZE_BUTTON, NULL); clutter_actor_add_constraint (tex2, clutter_align_constraint_new (stage2, CLUTTER_ALIGN_BOTH, .5)); clutter_actor_add_child (stage2, tex2); gtk_container_add (GTK_CONTAINER (vbox), clutter2); gtk_widget_show_all (window); gtk_main(); return 0; }
static void set_up_stage (CalibArea *calib_area, ClutterActor *stage) { ClutterPoint anchor; ClutterColor color; ClutterContent *success_content; gfloat height; gchar *markup; calib_area->stage = stage; calib_area->action_layer = clutter_actor_new (); calib_area->clock = cc_clock_actor_new (); calib_area->target = cc_target_actor_new (); calib_area->text_title_holder = clutter_actor_new (); calib_area->helper_text_title = clutter_text_new (); calib_area->text_body_holder = clutter_actor_new (); calib_area->helper_text_body = clutter_text_new (); calib_area->error_text = clutter_text_new (); calib_area->success_image = clutter_actor_new (); clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE); clutter_actor_hide (calib_area->target); /* bind the action layer's geometry to the stage's */ clutter_actor_add_constraint (calib_area->action_layer, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0)); clutter_actor_add_child (stage, calib_area->action_layer); g_signal_connect (stage, "allocation-changed", G_CALLBACK (on_allocation_changed), calib_area); clutter_color_from_string (&color, "#000"); color.alpha = WINDOW_OPACITY * 255; clutter_actor_set_background_color (stage, &color); clutter_actor_add_child (calib_area->action_layer, calib_area->clock); clutter_actor_add_constraint (calib_area->clock, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_actor_add_child (calib_area->action_layer, calib_area->target); /* set the helper text */ anchor.x = 0; g_object_set (calib_area->text_title_holder, "pivot-point", &anchor, NULL); clutter_actor_add_child (calib_area->action_layer, calib_area->text_title_holder); clutter_actor_add_child (calib_area->text_title_holder, calib_area->helper_text_title); height = clutter_actor_get_height (calib_area->clock); clutter_actor_add_constraint (calib_area->text_title_holder, clutter_bind_constraint_new (calib_area->clock, CLUTTER_BIND_Y, height * 1.5)); clutter_actor_add_constraint (calib_area->text_title_holder, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, .5)); clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->helper_text_title), PANGO_ALIGN_CENTER); color.red = COLOR_GRAY; color.green = COLOR_GRAY; color.blue = COLOR_GRAY; color.alpha = 255; markup = g_strdup_printf ("<big><b>%s</b></big>", _(HELP_TEXT_TITLE)); clutter_text_set_markup (CLUTTER_TEXT (calib_area->helper_text_title), markup); clutter_text_set_color (CLUTTER_TEXT (calib_area->helper_text_title), &color); g_free (markup); g_object_set (calib_area->text_body_holder, "pivot-point", &anchor, NULL); clutter_actor_add_child (calib_area->action_layer, calib_area->text_body_holder); clutter_actor_add_child (calib_area->text_body_holder, calib_area->helper_text_body); height = clutter_actor_get_height (calib_area->helper_text_title); clutter_actor_add_constraint (calib_area->text_body_holder, clutter_bind_constraint_new (calib_area->text_title_holder, CLUTTER_BIND_Y, height * 1.2)); clutter_actor_add_constraint (calib_area->text_body_holder, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, .5)); clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->helper_text_body), PANGO_ALIGN_CENTER); markup = g_strdup_printf ("<span foreground=\"white\"><big>%s</big></span>", _(HELP_TEXT_MAIN)); clutter_text_set_markup (CLUTTER_TEXT (calib_area->helper_text_body), markup); g_free (markup); /* set the error text */ g_object_set (calib_area->error_text, "pivot-point", &anchor, NULL); clutter_actor_add_child (calib_area->action_layer, calib_area->error_text); height = clutter_actor_get_height (calib_area->helper_text_body); clutter_actor_add_constraint (calib_area->error_text, clutter_bind_constraint_new (calib_area->text_title_holder, CLUTTER_BIND_Y, height * 3)); clutter_actor_add_constraint (calib_area->error_text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, .5)); clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->error_text), PANGO_ALIGN_CENTER); markup = g_strdup_printf ("<span foreground=\"white\"><big>" "<b>%s</b></big></span>", ERROR_MESSAGE); clutter_text_set_markup (CLUTTER_TEXT (calib_area->error_text), markup); g_free (markup); clutter_actor_hide (calib_area->error_text); /* configure success image */ success_content = clutter_image_new (); clutter_actor_set_content (calib_area->success_image, success_content); g_object_unref (success_content); clutter_actor_add_child (stage, calib_area->success_image); clutter_actor_add_constraint (calib_area->success_image, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, .5)); /* animate clock */ calib_area->clock_timeline = clutter_property_transition_new ("angle"); clutter_timeline_set_progress_mode (CLUTTER_TIMELINE (calib_area->clock_timeline), CLUTTER_LINEAR); clutter_timeline_set_duration (CLUTTER_TIMELINE (calib_area->clock_timeline), MAX_TIME); clutter_transition_set_animatable (calib_area->clock_timeline, CLUTTER_ANIMATABLE (calib_area->clock)); clutter_transition_set_from (calib_area->clock_timeline, G_TYPE_FLOAT, .0); clutter_transition_set_to (calib_area->clock_timeline, G_TYPE_FLOAT, 360.0); clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (calib_area->clock_timeline), -1); clutter_timeline_start (CLUTTER_TIMELINE (calib_area->clock_timeline)); g_signal_connect (CLUTTER_TIMELINE (calib_area->clock_timeline), "completed", G_CALLBACK (on_timeout), calib_area); g_signal_connect (stage, "button-press-event", G_CALLBACK (on_button_press_event), calib_area); g_signal_connect (stage, "key-release-event", G_CALLBACK (on_key_release_event), calib_area); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterActor *overlay; ClutterAction *click; GError *error = NULL; const gchar *filename = "redhand.png"; if (argc > 1) filename = argv[1]; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture), TRUE); clutter_actor_set_reactive (texture, TRUE); clutter_actor_set_size (texture, RECTANGLE_SIDE, RECTANGLE_SIDE); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), filename, &error); if (error != NULL) { g_warning ("Error loading %s\n%s", filename, error->message); g_error_free (error); exit (EXIT_FAILURE); } /* overlay is 10px wider and taller than the texture, and centered on it; * initially, it is transparent; but it is made semi-opaque when the * texture is clicked */ overlay = clutter_rectangle_new_with_color (&overlay_color); clutter_actor_set_opacity (overlay, OVERLAY_OPACITY_OFF); clutter_actor_add_constraint (overlay, clutter_bind_constraint_new (texture, CLUTTER_BIND_WIDTH, 10)); clutter_actor_add_constraint (overlay, clutter_bind_constraint_new (texture, CLUTTER_BIND_HEIGHT, 10)); clutter_actor_add_constraint (overlay, clutter_align_constraint_new (texture, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (overlay, clutter_align_constraint_new (texture, CLUTTER_ALIGN_Y_AXIS, 0.5)); click = clutter_click_action_new (); clutter_actor_add_action (texture, click); clutter_container_add (CLUTTER_CONTAINER (stage), texture, overlay, NULL); clutter_actor_raise_top (overlay); g_signal_connect (click, "clicked", G_CALLBACK (click_cb), overlay); g_signal_connect (stage, "key-press-event", G_CALLBACK (key_press_cb), texture); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage, *box; ClutterLayoutManager *layout; GError *error; gint i; error = NULL; if (clutter_init_with_args (&argc, &argv, NULL, entries, NULL, &error) != CLUTTER_INIT_SUCCESS) { g_print ("Unable to run flow-layout: %s", error->message); g_error_free (error); return EXIT_FAILURE; } stage = clutter_stage_new (); clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); clutter_stage_set_title (CLUTTER_STAGE (stage), "Flow Layout"); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL : CLUTTER_FLOW_HORIZONTAL); clutter_flow_layout_set_homogeneous (CLUTTER_FLOW_LAYOUT (layout), is_homogeneous); clutter_flow_layout_set_column_spacing (CLUTTER_FLOW_LAYOUT (layout), x_spacing); clutter_flow_layout_set_row_spacing (CLUTTER_FLOW_LAYOUT (layout), y_spacing); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_set_background_color (box, CLUTTER_COLOR_Aluminium2); clutter_actor_add_child (stage, box); if (!fixed_size) clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); clutter_actor_set_position (box, 0, 0); clutter_actor_set_name (box, "box"); for (i = 0; i < n_rects; i++) { ClutterColor color = CLUTTER_COLOR_INIT (255, 255, 255, 255); gfloat width, height; ClutterActor *rect; gchar *name; name = g_strdup_printf ("rect%02d", i); clutter_color_from_hls (&color, 360.0 / n_rects * i, 0.5, 0.8); rect = clutter_actor_new (); clutter_actor_set_background_color (rect, &color); if (random_size) { width = g_random_int_range (50, 100); height = g_random_int_range (50, 100); } else width = height = 50.f; clutter_actor_set_size (rect, width, height); clutter_actor_set_name (rect, name); clutter_actor_add_child (box, rect); g_free (name); } clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage; GtkWidget *window, *stack, *clutter; GtkWidget *label, *button, *vbox; GdkPixbuf *pixbuf; SuperOH *oh; gint i; GError *error; error = NULL; if (gtk_clutter_init_with_args (&argc, &argv, NULL, NULL, NULL, &error) != CLUTTER_INIT_SUCCESS) { if (error) { g_critical ("Unable to initialize Clutter-GTK: %s", error->message); g_error_free (error); return EXIT_FAILURE; } else g_error ("Unable to initialize Clutter-GTK"); } /* calling gtk_clutter_init* multiple times should be safe */ g_assert (gtk_clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS); pixbuf = gdk_pixbuf_new_from_file (EXAMPLES_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL); if (!pixbuf) g_error("pixbuf load failed"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), WINWIDTH, WINHEIGHT); gtk_window_set_title (GTK_WINDOW (window), "Clutter Embedding"); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_grid_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox), GTK_ORIENTATION_VERTICAL); gtk_widget_set_hexpand (vbox, TRUE); gtk_widget_set_vexpand (vbox, TRUE); gtk_container_add (GTK_CONTAINER (window), vbox); stack = gtk_stack_new (); gtk_container_add (GTK_CONTAINER (vbox), stack); label = gtk_label_new ("This is a label in a stack"); gtk_stack_add_named (GTK_STACK (stack), label, "label"); clutter = gtk_clutter_embed_new (); gtk_stack_add_named (GTK_STACK (stack), clutter, "clutter"); gtk_widget_realize (clutter); stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter)); clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); label = gtk_label_new ("This is a label"); gtk_container_add (GTK_CONTAINER (vbox), label); gtk_widget_set_hexpand (label, TRUE); button = gtk_button_new_with_label ("This is a button...clicky"); g_signal_connect (button, "clicked", G_CALLBACK (clickity), stack); gtk_container_add (GTK_CONTAINER (vbox), button); gtk_widget_set_hexpand (button, TRUE); button = gtk_button_new_with_mnemonic ("_Fullscreen"); g_signal_connect (button, "clicked", G_CALLBACK (on_fullscreen), window); gtk_container_add (GTK_CONTAINER (vbox), button); gtk_widget_set_hexpand (button, TRUE); button = gtk_button_new_with_mnemonic ("_Quit"); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_container_add (GTK_CONTAINER (vbox), button); gtk_widget_set_hexpand (button, TRUE); oh = g_new (SuperOH, 1); oh->stage = stage; oh->group = clutter_actor_new (); clutter_actor_set_pivot_point (oh->group, 0.5, 0.5); for (i = 0; i < NHANDS; i++) { gint x, y, w, h; /* Create a texture from pixbuf, then clone in to same resources */ if (i == 0) { oh->hand[i] = gtk_clutter_texture_new (); gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE (oh->hand[i]), pixbuf, NULL); } else oh->hand[i] = clutter_clone_new (oh->hand[0]); /* Place around a circle */ w = clutter_actor_get_width (oh->hand[0]); h = clutter_actor_get_height (oh->hand[0]); x = WINWIDTH / 2 + RADIUS * cos (i * M_PI / (NHANDS / 2)) - w / 2; y = WINHEIGHT / 2 + RADIUS * sin (i * M_PI / (NHANDS / 2)) - h / 2; clutter_actor_set_position (oh->hand[i], x, y); clutter_actor_set_pivot_point (oh->hand[i], 0.5, 0.5); /* Add to our group group */ clutter_actor_add_child (oh->group, oh->hand[i]); } /* Add the group to the stage */ clutter_actor_add_child (stage, oh->group); clutter_actor_add_constraint (oh->group, clutter_align_constraint_new (oh->stage, CLUTTER_ALIGN_BOTH, 0.5)); g_signal_connect (stage, "button-press-event", G_CALLBACK (input_cb), oh); g_signal_connect (stage, "key-release-event", G_CALLBACK (input_cb), oh); gtk_widget_show_all (window); /* Create a timeline to manage animation */ timeline = clutter_timeline_new (6000); clutter_timeline_set_repeat_count (timeline, -1); /* fire a callback for frame change */ g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh); /* and start it */ clutter_timeline_start (timeline); gtk_main (); return 0; }
int main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; GtkWidget *window, *clutter; GtkWidget *button, *vbox; gint i; if (gtk_clutter_init_with_args (&argc, &argv, NULL, NULL, NULL, NULL) != CLUTTER_INIT_SUCCESS) g_error ("Unable to initialize GtkClutter"); if (argc != 1) do_rotate = FALSE; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (window), vbox); clutter = gtk_clutter_embed_new (); gtk_widget_set_size_request (clutter, WINWIDTH, WINHEIGHT); gtk_box_pack_start (GTK_BOX (vbox), clutter, TRUE, TRUE, 0); stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter)); button = gtk_button_new_with_mnemonic ("_Quit"); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); clutter_actor_set_background_color (stage, &stage_color); nwidgets = 0; /* create a new group to hold multiple actors in a group */ group = clutter_actor_new (); clutter_actor_set_pivot_point (group, 0.5, 0.5); for (i = 0; i < MAX_NWIDGETS; i++) { widgets[i] = create_gtk_actor (i); nwidgets++; add_clutter_actor (widgets[i], group, i); } /* Add the group to the stage and center it*/ clutter_actor_add_child (stage, group); clutter_actor_add_constraint (group, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); gtk_widget_show_all (window); /* Create a timeline to manage animation */ timeline = clutter_timeline_new (6000); clutter_timeline_set_repeat_count (timeline, -1); /* fire a callback for frame change */ g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), stage); /* and start it */ clutter_timeline_start (timeline); g_timeout_add_seconds (3, add_or_remove_timeout, NULL); gtk_main(); return 0; }
int main (int argc, char *argv[]) { ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *stage; ClutterActor *texture; CoglHandle *cogl_texture; GError *error = NULL; gfloat width; const gchar *filename = "redhand.png"; if (argc > 1) filename = argv[1]; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_set_background_color (box, &box_color); texture = clutter_texture_new_from_file (filename, &error); if (error != NULL) g_error ("Error loading file %s; message was:\n%s", filename, error->message); /* * get a reference to the underlying Cogl texture * for copying onto each Clutter texture placed into the layout */ cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture)); /* * add gradually turning and shrinking textures, * smallest one last; each actor ends up on top * of the one added just before it */ for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625) { ClutterActor *texture_copy = clutter_texture_new (); clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy), cogl_texture); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy), TRUE); clutter_actor_set_z_rotation_from_gravity (texture_copy, (gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125), CLUTTER_GRAVITY_CENTER); clutter_actor_set_width (texture_copy, width); clutter_actor_add_child (box, texture_copy); } clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_actor_add_child (stage, box); clutter_actor_show (stage); clutter_main (); return 0; }
int main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; ClutterConstraint *constraint; GtkWidget *window, *clutter; GtkWidget *label, *button, *vbox; GdkPixbuf *pixbuf; SuperOH *oh; gint i; GError *error; error = NULL; gtk_clutter_init_with_args (&argc, &argv, NULL, NULL, NULL, &error); if (error) g_error ("Unable to initialize: %s", error->message); pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL); if (!pixbuf) g_error("pixbuf load failed"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (window), vbox); clutter = gtk_clutter_embed_new (); gtk_widget_set_size_request (clutter, WINWIDTH, WINHEIGHT); gtk_container_add (GTK_CONTAINER (vbox), clutter); stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter)); label = gtk_label_new ("This is a label"); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); button = gtk_button_new_with_label ("This is a button...clicky"); g_signal_connect (button, "clicked", G_CALLBACK (clickity), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label ("Fullscreen"); gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_BUTTON)); g_signal_connect (button, "clicked", G_CALLBACK (on_fullscreen), window); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); button = gtk_button_new_from_stock (GTK_STOCK_QUIT); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); /* and its background color */ clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); oh = g_new (SuperOH, 1); oh->stage = stage; /* create a new group to hold multiple actors in a group */ oh->group = clutter_group_new (); for (i = 0; i < NHANDS; i++) { gint x, y, w, h; /* Create a texture from pixbuf, then clone in to same resources */ if (i == 0) { oh->hand[i] = gtk_clutter_texture_new (); gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE (oh->hand[i]), pixbuf, NULL); } else oh->hand[i] = clutter_clone_new (oh->hand[0]); /* Place around a circle */ w = clutter_actor_get_width (oh->hand[0]); h = clutter_actor_get_height (oh->hand[0]); x = WINWIDTH/2 + RADIUS * cos (i * M_PI / (NHANDS/2)) - w/2; y = WINHEIGHT/2 + RADIUS * sin (i * M_PI / (NHANDS/2)) - h/2; clutter_actor_set_position (oh->hand[i], x, y); /* Add to our group group */ clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]); } /* Add the group to the stage */ clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (oh->group)); constraint = clutter_align_constraint_new (oh->stage, CLUTTER_ALIGN_X_AXIS, 0.5); clutter_actor_add_constraint (oh->group, constraint); constraint = clutter_align_constraint_new (oh->stage, CLUTTER_ALIGN_Y_AXIS, 0.5); clutter_actor_add_constraint (oh->group, constraint); g_signal_connect (stage, "button-press-event", G_CALLBACK (input_cb), oh); g_signal_connect (stage, "key-release-event", G_CALLBACK (input_cb), oh); gtk_widget_show_all (window); /* Only show the actors after parent show otherwise it will just be * unrealized when the clutter foreign window is set. widget_show * will call show on the stage. */ clutter_actor_show_all (CLUTTER_ACTOR (oh->group)); /* Create a timeline to manage animation */ timeline = clutter_timeline_new (6000); 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); /* and start it */ clutter_timeline_start (timeline); gtk_main(); return 0; }
int main (int argc, char **argv) { ClutterActor *stage; ClutterActor *fader; ClutterConstraint *constraint; CoglHandle tex0, tex1; GError *error = NULL; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; if (argc != 3) { g_print ("usage: %s <image1> <image2>\n", argv[0]); return 1; } tex0 = cogl_texture_new_from_file (argv[1], COGL_TEXTURE_NO_SLICING | COGL_TEXTURE_NO_ATLAS, COGL_PIXEL_FORMAT_ANY, &error); if (tex0 == COGL_INVALID_HANDLE) { g_print ("error opening %s: %s\n", argv[1], error->message); g_clear_error (&error); return 1; } tex1 = cogl_texture_new_from_file (argv[2], COGL_TEXTURE_NO_SLICING | COGL_TEXTURE_NO_ATLAS, COGL_PIXEL_FORMAT_ANY, &error); if (tex1 == COGL_INVALID_HANDLE) { cogl_handle_unref (tex0); g_print ("error opening %s: %s\n", argv[2], error->message); g_clear_error (&error); return 1; } fader = foo_fader_new (); foo_fader_set_texture_0 (FOO_FADER (fader), tex0); foo_fader_set_texture_1 (FOO_FADER (fader), tex1); cogl_handle_unref (tex0); cogl_handle_unref (tex1); stage = clutter_stage_get_default (); clutter_stage_set_fullscreen (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "button-press-event", G_CALLBACK (button_press_event_cb), fader); clutter_container_add_actor (CLUTTER_CONTAINER (stage), fader); constraint = clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0f); clutter_actor_add_constraint (fader, constraint); /* massive hack --- nothing to see here! */ foo_fader_set_progress (FOO_FADER (fader), 0.00001f); clutter_actor_show (stage); clutter_main (); return 0; }
int main (int argc, char *argv[]) { ClutterActor *stage, *actor; ClutterContent *canvas; ClutterTransition *transition; /* initialize Clutter */ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return EXIT_FAILURE; /* create a stage */ stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Rectangle with rounded corners"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); clutter_actor_set_size (stage, 500, 500); clutter_actor_show (stage); /* our 2D canvas, courtesy of Cairo */ canvas = clutter_canvas_new (); clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 300, 300); /* the actor that will display the contents of the canvas */ actor = clutter_actor_new (); clutter_actor_set_content (actor, canvas); clutter_actor_set_content_gravity (actor, CLUTTER_CONTENT_GRAVITY_CENTER); clutter_actor_set_content_scaling_filters (actor, CLUTTER_SCALING_FILTER_TRILINEAR, CLUTTER_SCALING_FILTER_LINEAR); clutter_actor_set_pivot_point (actor, 0.5f, 0.5f); clutter_actor_add_constraint (actor, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); clutter_actor_set_request_mode (actor, CLUTTER_REQUEST_CONTENT_SIZE); clutter_actor_add_child (stage, actor); /* the actor now owns the canvas */ g_object_unref (canvas); /* create the continuous animation of the actor spinning around its center */ transition = clutter_property_transition_new ("rotation-angle-y"); clutter_transition_set_from (transition, G_TYPE_DOUBLE, 0.0); clutter_transition_set_to (transition, G_TYPE_DOUBLE, 360.0); clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 2000); clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1); clutter_actor_add_transition (actor, "rotateActor", transition); /* the actor now owns the transition */ g_object_unref (transition); /* quit on destroy */ g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); /* connect our drawing code */ g_signal_connect (canvas, "draw", G_CALLBACK (draw_content), NULL); /* invalidate the canvas, so that we can draw before the main loop starts */ clutter_content_invalidate (canvas); clutter_main (); return EXIT_SUCCESS; }
WindowPanel::WindowPanel() : auto_hide_(false) { ClutterLayoutManager * main_layout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FIXED, CLUTTER_BIN_ALIGNMENT_FIXED); actor_ = clutter_box_new(main_layout); ClutterActor * menu = clutter_cairo_texture_new(110, 22); clutter_actor_set_position(menu, 10.0f, 0.0f); cairo_t * context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(menu)); cairo_move_to(context, 0.0, 0.0); cairo_line_to(context, 0.0, 19.0); cairo_curve_to(context, 1.0, 21.0, 2.0, 22.0, 3.0, 22.0); cairo_line_to(context, 107.0, 22.0); cairo_curve_to(context, 108.0, 22.0, 109.0, 21.0, 110.0, 19.0); cairo_line_to(context, 110.0, 0.0); cairo_close_path(context); cairo_set_source_rgb(context, 0.8, 0.8, 0.8); cairo_fill_preserve(context); cairo_set_line_width(context, 1.0); cairo_set_source_rgb(context, 0.0, 0.0, 0.0); cairo_stroke(context); cairo_select_font_face(context, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(context, 12.0); cairo_text_extents_t extents; cairo_text_extents(context, DISPLAY_NAME, &extents); cairo_move_to(context, 55.0 - ((extents.width / 2.0) + extents.x_bearing), 11.0 - ((extents.height / 2.0) + extents.y_bearing)); cairo_text_path(context, DISPLAY_NAME); cairo_set_source_rgb(context, 0.0, 0.0, 0.0); cairo_fill(context); cairo_destroy(context); clutter_box_pack(CLUTTER_BOX(actor_), menu, NULL, NULL); ClutterLayoutManager * controls_layout = clutter_box_layout_new(); clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(controls_layout), 10u); ClutterActor * controls = clutter_box_new(controls_layout); clutter_actor_add_constraint(controls, clutter_align_constraint_new(clutter_stage_get_default(), CLUTTER_ALIGN_X_AXIS, 0.95f)); clutter_actor_add_constraint(controls, clutter_bind_constraint_new(clutter_stage_get_default(), CLUTTER_BIND_Y, 5.0f)); fullscreen_button_ = clutter_cairo_texture_new(18, 16); clutter_actor_set_reactive(fullscreen_button_, TRUE); g_signal_connect(fullscreen_button_, "button-press-event", G_CALLBACK(fullscreen_clicked_cb), this); g_signal_connect(fullscreen_button_, "enter-event", G_CALLBACK(actor_highlight_on_cb), fullscreen_button_); g_signal_connect(fullscreen_button_, "leave-event", G_CALLBACK(actor_highlight_off_cb), fullscreen_button_); clutter_box_pack(CLUTTER_BOX(controls), fullscreen_button_, NULL, NULL); close_button_ = clutter_cairo_texture_new(15, 15); context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(close_button_)); cairo_move_to(context, 1.0, 3.0); cairo_line_to(context, 3.0, 1.0); cairo_line_to(context, 8.0, 6.0); cairo_line_to(context, 13.0, 1.0); cairo_line_to(context, 15.0, 3.0); cairo_line_to(context, 10.0, 8.0); cairo_line_to(context, 15.0, 13.0); cairo_line_to(context, 13.0, 15.0); cairo_line_to(context, 8.0, 10.0); cairo_line_to(context, 3.0, 15.0); cairo_line_to(context, 1.0, 13.0); cairo_line_to(context, 6.0, 8.0); cairo_close_path(context); cairo_set_source_rgb(context, 1.0, 1.0, 1.0); cairo_fill_preserve(context); cairo_set_line_width(context, 1.0); cairo_set_source_rgb(context, 0.0, 0.0, 0.0); cairo_stroke(context); cairo_destroy(context); clutter_actor_set_reactive(close_button_, TRUE); g_signal_connect(close_button_, "button-press-event", G_CALLBACK(close_clicked_cb), NULL); g_signal_connect(close_button_, "enter-event", G_CALLBACK(actor_highlight_on_cb), close_button_); g_signal_connect(close_button_, "leave-event", G_CALLBACK(actor_highlight_off_cb), close_button_); clutter_box_pack(CLUTTER_BOX(controls), close_button_, NULL, NULL); draw_window_controls(); clutter_box_pack(CLUTTER_BOX(actor_), controls, NULL, NULL); g_signal_connect(clutter_stage_get_default(), "fullscreen", G_CALLBACK(fullscreen_status_changed_cb), this); g_signal_connect(clutter_stage_get_default(), "unfullscreen", G_CALLBACK(fullscreen_status_changed_cb), this); g_signal_connect(clutter_stage_get_default(), "motion-event", G_CALLBACK(show_panel_cb), this); }
int main (int argc, char *argv[]) { ClutterActor *stage, *box, *bg, *bg2, *inset, *labelContainer, *contentContainer, *labelbg, *fixed, *upper, *lower, *lowerInner; ClutterLayoutManager *layout, *labelContainer_l, *layoutFixed; ClutterTimeline *timeline; ClutterContent *canvas, *canvas1; ClutterColor color_with_trans = {0,0,0,0}; clutter_x11_set_use_argb_visual (TRUE); if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return (1); /* prepare the stage */ stage = clutter_stage_new (); clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE); clutter_stage_set_color (CLUTTER_STAGE (stage), &color_with_trans); clutter_stage_set_title (CLUTTER_STAGE (stage), "IPLocation Database"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_WHITE); clutter_actor_set_size (stage, 648, 246); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); clutter_actor_show (stage); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_actor_new (); clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); clutter_actor_set_background_color (box, CLUTTER_COLOR_WHITE); clutter_actor_set_layout_manager (box, layout); clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 1)); clutter_actor_set_name (box, "box"); clutter_actor_add_child (stage, box); bg = clutter_actor_new (); //clutter_actor_set_background_color (bg, clutter_color_new (50, 50, 50, 255)); clutter_actor_set_name (bg, "background"); clutter_actor_set_reactive (bg, TRUE); //clutter_actor_set_x_expand (bg, TRUE); //clutter_actor_set_y_expand (bg, TRUE); clutter_actor_set_x_align (bg, CLUTTER_ACTOR_ALIGN_END); clutter_actor_set_y_align (bg, CLUTTER_ACTOR_ALIGN_FILL); canvas1 = clutter_canvas_new (); clutter_canvas_set_size (CLUTTER_CANVAS (canvas1), 300, 300); clutter_actor_set_content (bg, canvas1); /*clutter_actor_set_content_scaling_filters (bg2, CLUTTER_SCALING_FILTER_TRILINEAR, CLUTTER_SCALING_FILTER_LINEAR);*/ g_object_unref (canvas1); clutter_actor_add_child (box, bg); bg2 = clutter_actor_new (); //clutter_actor_set_background_color (bg2, clutter_color_new (0, 100, 100, 255*.5)); clutter_actor_set_name (bg2, "background"); clutter_actor_set_reactive (bg2, TRUE); clutter_actor_set_size (bg2, 0, 0); //clutter_actor_set_x_expand (bg2, TRUE); //clutter_actor_set_y_expand (bg2, TRUE); clutter_actor_set_x_align (bg2, CLUTTER_ACTOR_ALIGN_END); clutter_actor_set_y_align (bg2, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_clip_to_allocation(bg2, TRUE); clutter_actor_add_child (box, bg2); clutter_actor_set_layout_manager (bg2, clutter_box_layout_new ()); canvas = clutter_canvas_new (); clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 300, 300); clutter_actor_set_content (bg2, canvas); /*clutter_actor_set_content_scaling_filters (bg2, CLUTTER_SCALING_FILTER_TRILINEAR, CLUTTER_SCALING_FILTER_LINEAR);*/ g_object_unref (canvas); inset = clutter_actor_new (); //clutter_actor_set_background_color (inset, clutter_color_new (255, 0, 0, 255)); clutter_actor_set_name (inset, "inset"); clutter_actor_set_reactive (inset, TRUE); clutter_actor_set_margin_top (inset, 18); clutter_actor_set_margin_right (inset, 18); clutter_actor_set_margin_bottom (inset, 18); clutter_actor_set_margin_left (inset, 48); //clutter_actor_set_x_expand (inset, TRUE); //clutter_actor_set_y_expand (inset, TRUE); clutter_actor_set_x_align (inset, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (inset, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_clip_to_allocation(inset, TRUE); clutter_actor_add_child (bg2, inset); layout = clutter_box_layout_new (); clutter_box_layout_set_vertical (CLUTTER_BOX_LAYOUT (layout), TRUE); clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (layout), 5); clutter_actor_set_layout_manager (inset, layout); labelContainer = clutter_actor_new (); clutter_actor_set_size (labelContainer, 0, 35); //clutter_actor_set_background_color (labelContainer, clutter_color_new (34, 134, 158, 255)); clutter_actor_set_name (labelContainer, "labelContainer"); clutter_actor_set_reactive (labelContainer, TRUE); //clutter_actor_set_x_expand (labelContainer, TRUE); //clutter_actor_set_y_expand (labelContainer, TRUE); clutter_actor_add_child (inset, labelContainer); labelContainer_l = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); clutter_actor_set_layout_manager (labelContainer, labelContainer_l); labelbg = clutter_actor_new (); clutter_actor_set_background_color (labelbg, clutter_color_new (34, 134, 158, 255)); clutter_actor_set_name (labelbg, "labelbg"); //clutter_actor_set_x_expand (labelbg, TRUE); clutter_actor_set_size (labelbg, 0, 35); clutter_actor_set_x_align (labelbg, CLUTTER_ACTOR_ALIGN_START); clutter_actor_set_y_align (labelbg, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_add_child (labelContainer, labelbg); contentContainer = clutter_actor_new (); clutter_actor_set_size (contentContainer, 0, 0); clutter_actor_set_background_color (contentContainer, clutter_color_new (0.290196*255, 0.427451*255, 0.462745*255, 255)); clutter_actor_set_name (contentContainer, "labelContainer"); //clutter_actor_set_x_expand (contentContainer, TRUE); //clutter_actor_set_y_expand (contentContainer, TRUE); clutter_actor_set_layout_manager (contentContainer, clutter_fixed_layout_new ()); clutter_actor_add_child (inset, contentContainer); fixed = clutter_actor_new (); clutter_actor_set_background_color (fixed, clutter_color_new (9, 53, 71, 255)); clutter_actor_set_name (fixed, "fixed"); clutter_actor_set_size (fixed, 582, 210-40); clutter_actor_set_position (fixed, 582, 0); layoutFixed = clutter_box_layout_new (); clutter_box_layout_set_vertical (CLUTTER_BOX_LAYOUT (layoutFixed), TRUE); clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (layoutFixed), 8); clutter_actor_set_layout_manager (fixed, layoutFixed); clutter_actor_add_child (contentContainer, fixed); //------------------------------------------------------------------------// lower = clutter_actor_new (); clutter_actor_set_size (lower, 0, 0); clutter_actor_set_name (lower, "lower"); //clutter_actor_set_x_expand (lower, TRUE); //clutter_actor_set_y_expand (lower, TRUE); clutter_actor_set_margin_right (lower, 8); clutter_actor_set_margin_top (lower, 8); clutter_actor_set_margin_left (lower, 8); clutter_actor_set_layout_manager (lower, clutter_fixed_layout_new ()); clutter_actor_set_clip_to_allocation(lower, TRUE); clutter_actor_add_child (fixed, lower); lowerInner = clutter_actor_new (); clutter_actor_set_background_color (lowerInner, clutter_color_new (255, 255, 255, 30)); clutter_actor_set_name (lowerInner, "fixed"); clutter_actor_set_size (lowerInner, 566, 113); clutter_actor_set_position (lowerInner, 566, 0); clutter_actor_add_child (lower, lowerInner); upper = clutter_actor_new (); clutter_actor_set_size (upper, 0, 33); clutter_actor_set_name (upper, "upper"); clutter_actor_set_x_expand (upper, TRUE); //clutter_actor_set_y_expand (upper, TRUE); clutter_actor_set_margin_bottom (upper, 8); clutter_actor_set_margin_right (upper, 8); clutter_actor_set_margin_left (upper, 8); //clutter_actor_set_layout_manager (upper, clutter_fixed_layout_new ()); clutter_actor_add_child (fixed, upper); timeline = clutter_timeline_new (57/24.*1000); clutter_timeline_add_marker_at_time(timeline, "first", (40-35)/24.*1000); clutter_timeline_add_marker_at_time(timeline, "second", (46-35)/24.*1000); clutter_timeline_add_marker_at_time(timeline, "third", (51-35)/24.*1000); clutter_timeline_add_marker_at_time(timeline, "fourth", (52-35)/24.*1000); clutter_timeline_add_marker_at_time(timeline, "fifth", (58-35)/24.*1000); g_signal_connect (timeline, "marker-reached::first", G_CALLBACK (plate1anim), bg); g_signal_connect (timeline, "marker-reached::second", G_CALLBACK (plate2anim), bg2); g_signal_connect (timeline, "marker-reached::third", G_CALLBACK (plate3anim), labelbg); g_signal_connect (timeline, "marker-reached::fourth", G_CALLBACK (plate4anim), fixed); g_signal_connect (timeline, "marker-reached::fifth", G_CALLBACK (plate5anim), lowerInner); g_signal_connect (canvas1, "draw", G_CALLBACK (draw_1), NULL); g_signal_connect (bg, "paint", G_CALLBACK (on_actor_resize), canvas); g_signal_connect (canvas, "draw", G_CALLBACK (draw), NULL); g_signal_connect (bg2, "paint", G_CALLBACK (on_actor_resize), canvas); clutter_content_invalidate (canvas); clutter_timeline_start (timeline); clutter_main (); return (EXIT_SUCCESS); }
int main(int argc, char *argv[]) { ClutterActor *stage; WebKitWebView *web_view; ClutterConstraint *width_binding; ClutterConstraint *height_binding; ClutterConstraint *web_view_height_binding; gfloat stageWidth, stageHeight; ClutterActorBox stageAllocation; ClutterLayoutManager *mainLayout; ClutterActor *mainLayoutContainer; ClutterLayoutManager *toolbarLayout; ClutterActor *toolbarContainer; ClutterLayoutManager *toolbarBinLayout; ClutterActor *toolbarBinContainer; ClutterActor *toolbarBgr; ClutterActor *statusBar; ClutterActor *backFwdBtns; ClutterActor *backBtn; ClutterActor *fwdBtn; ClutterActor *uriGroup; ClutterActor *uriBgr; ClutterActor *uriText; ClutterActor *spacer; GError *error = NULL; ClutterColor whiteColor = { 255, 255, 255, 255 }; ClutterColor blackColor = { 0, 0, 0, 255 }; ClutterColor grayColor = { 200, 200, 200, 255 }; ClutterColor transparentColor = { 0, 0, 0, 0 }; gchar *toolbarBgrPath = clutter_launcher_file_path("toolbar_bgr.png"); gchar *backBtnPath = clutter_launcher_file_path("back_btn.png"); gchar *fwdBtnPath = clutter_launcher_file_path("fwd_btn.png"); g_thread_init(NULL); clutter_threads_init(); clutter_init(&argc, &argv); stage = clutter_stage_get_default(); clutter_actor_set_size(stage, 1024, 768); clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK(clutter_main_quit), NULL); /* make the stage resizable */ clutter_stage_set_user_resizable(CLUTTER_STAGE(stage), TRUE); clutter_actor_show(stage); mainLayout = clutter_box_layout_new(); clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(mainLayout), TRUE); clutter_actor_get_allocation_box(stage, &stageAllocation); stageWidth = stageAllocation.x2 - stageAllocation.x1; stageHeight = stageAllocation.y2 - stageAllocation.y1; web_view = WEBKIT_WEB_VIEW(webkit_web_view_new((guint)stageWidth, (guint)stageHeight - (toolbarHeight + statusBarHeight))); g_object_set(web_view, "reactive", TRUE, NULL); mainLayoutContainer = clutter_box_new(mainLayout); clutter_actor_set_size(mainLayoutContainer, stageWidth, stageHeight); width_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_WIDTH, 0); height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, 0); /* web_view_height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, -(toolbarHeight + statusBarHeight)); */ clutter_actor_add_constraint(mainLayoutContainer, width_binding); clutter_actor_add_constraint(mainLayoutContainer, height_binding); /* clutter_actor_add_constraint(CLUTTER_ACTOR(web_view), web_view_height_binding); */ toolbarBinLayout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_CENTER); toolbarBinContainer = clutter_box_new(toolbarBinLayout); toolbarBgr = clutter_texture_new_from_file(toolbarBgrPath, &error); if (toolbarBgr == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", toolbarBgrPath); exit(1); } clutter_actor_set_height(toolbarBgr, toolbarHeight); clutter_texture_set_repeat(CLUTTER_TEXTURE(toolbarBgr), TRUE, FALSE); clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarBgr, NULL, NULL); toolbarLayout = clutter_box_layout_new(); clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(toolbarLayout), FALSE); clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(toolbarLayout), 16); toolbarContainer = clutter_box_new(toolbarLayout); spacer = clutter_rectangle_new_with_color(&transparentColor); clutter_actor_set_size(spacer, 1, 1); clutter_box_pack(CLUTTER_BOX(toolbarContainer), spacer, NULL, NULL); backFwdBtns = clutter_group_new(); backBtn = clutter_texture_new_from_file(backBtnPath, &error); if (backBtn == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", backBtnPath); exit(1); } clutter_actor_set_reactive(backBtn, TRUE); /* connect the release event */ g_signal_connect (backBtn, "button-release-event", G_CALLBACK (on_back_release_cb), web_view); fwdBtn = clutter_texture_new_from_file(fwdBtnPath, &error); if (fwdBtn == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", fwdBtnPath); exit(1); } clutter_actor_set_reactive(fwdBtn, TRUE); /* connect the release event */ g_signal_connect (fwdBtn, "button-release-event", G_CALLBACK (on_fwd_release_cb), web_view); clutter_actor_set_position(fwdBtn, clutter_actor_get_width(backBtn), 0); clutter_container_add(CLUTTER_CONTAINER(backFwdBtns), backBtn, fwdBtn, NULL); clutter_box_pack(CLUTTER_BOX(toolbarContainer), backFwdBtns, NULL, NULL); uriGroup = clutter_group_new(); uriBgr = clutter_rectangle_new_with_color(&whiteColor); clutter_rectangle_set_border_color(CLUTTER_RECTANGLE(uriBgr), &blackColor); clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(uriBgr), 1); clutter_actor_set_size(uriBgr, 400, 25); uriText = clutter_text_new_full("Helvetica 11px", "http://www.google.com", &blackColor); clutter_text_set_editable(CLUTTER_TEXT(uriText), TRUE); clutter_text_set_single_line_mode(CLUTTER_TEXT(uriText), TRUE); clutter_actor_set_position(uriText, 5, 7); clutter_actor_set_size(uriText, 390, 17); clutter_actor_set_reactive(uriText, TRUE); g_signal_connect(uriText, "activate", G_CALLBACK(on_uri_activate_cb), web_view); clutter_container_add(CLUTTER_CONTAINER(uriGroup), uriBgr, uriText, NULL); clutter_box_pack(CLUTTER_BOX(toolbarContainer), uriGroup, NULL, NULL); clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarContainer, NULL, NULL); clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), toolbarBinContainer, "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE, FALSE); statusBar = clutter_rectangle_new_with_color(&grayColor); clutter_actor_set_height(statusBar, statusBarHeight); clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), statusBar, "y-align", CLUTTER_BOX_ALIGNMENT_END, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE, FALSE); clutter_box_pack_after(CLUTTER_BOX(mainLayoutContainer), CLUTTER_ACTOR(web_view), toolbarBinContainer, "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE, TRUE); clutter_container_add(CLUTTER_CONTAINER(stage), mainLayoutContainer, NULL); g_signal_connect(web_view, "webkit-load-finished", G_CALLBACK(load_finished_cb), web_view); g_signal_connect(web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view); /* g_signal_connect(stage, "delete-event", G_CALLBACK(delete_cb), web_view);*/ g_signal_connect(web_view, "notify::uri", G_CALLBACK(notify_uri_cb), uriText); gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/"); gchar *fileURL = filenameToURL(uri); webkit_web_view_load_uri(web_view, fileURL ? fileURL : uri); printf("%s\n", fileURL ? fileURL : uri); g_free(fileURL); g_timeout_add_full(G_PRIORITY_DEFAULT, 3000, timeout_cb, web_view, 0); clutter_threads_enter (); clutter_main(); clutter_threads_leave (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterLayoutManager *layout; ClutterActor *box; ClutterActor *rect; ClutterActor *text; ClutterState *transitions; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "btn"); clutter_actor_set_background_color (stage, &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL); box = clutter_actor_new (); clutter_actor_set_layout_manager (box, layout); clutter_actor_set_position (box, 25, 25); clutter_actor_set_reactive (box, TRUE); clutter_actor_set_size (box, 100, 30); /* background for the button */ rect = clutter_rectangle_new_with_color (&yellow); clutter_actor_add_child (box, rect); /* text for the button */ text = clutter_text_new_full ("Sans 10pt", "Hover me", &white); /* * NB don't set the height, so the actor assumes the height of the text; * then when added to the bin layout, it gets centred on it; * also if you don't set the width, the layout goes gets really wide; * the 10pt text fits inside the 30px height of the rectangle */ clutter_actor_set_width (text, 100); clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), text, CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); /* animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "fade-out", box, "opacity", CLUTTER_LINEAR, 180, NULL); /* * NB you can't use an easing mode where alpha > 1.0 if you're * animating to a value of 255, as the value you're animating * to will possibly go > 255 */ clutter_state_set (transitions, NULL, "fade-in", box, "opacity", CLUTTER_LINEAR, 255, NULL); clutter_state_set_duration (transitions, NULL, NULL, 50); clutter_state_warp_to_state (transitions, "fade-out"); g_signal_connect (box, "enter-event", G_CALLBACK (_pointer_enter_cb), transitions); g_signal_connect (box, "leave-event", G_CALLBACK (_pointer_leave_cb), transitions); /* bind the stage size to the box size + 50px in each axis */ clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_HEIGHT, 50.0)); clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_WIDTH, 50.0)); clutter_actor_add_child (stage, box); clutter_actor_show (stage); clutter_main (); g_object_unref (transitions); return 0; }