static void prepare_workspace_content(MosesOverview *self, MetaWorkspace *ws) { MosesOverviewPrivate* priv = self->priv; GList* l = meta_workspace_list_windows(ws); if (!priv->clones) { priv->clones = g_ptr_array_new(); } while (l) { MetaWindow* win = l->data; MetaWindowActor* win_actor = META_WINDOW_ACTOR(meta_window_get_compositor_private(win)); if (meta_window_get_window_type(win) == META_WINDOW_DESKTOP) { g_debug("%s: got desktop actor", __func__); priv->background_actor = clutter_clone_new(CLUTTER_ACTOR(win_actor)); } else if (meta_window_get_window_type(win) == META_WINDOW_NORMAL && !meta_window_is_hidden(win)) { ClutterActor* clone = clutter_clone_new(CLUTTER_ACTOR(win_actor)); clutter_actor_set_reactive(clone, TRUE); float x = 0.0, y = 0.0; clutter_actor_get_position(CLUTTER_ACTOR(win_actor), &x, &y); clutter_actor_set_position(clone, x, y); clutter_actor_hide(CLUTTER_ACTOR(win_actor)); g_ptr_array_add(priv->clones, clone); clutter_actor_add_child(CLUTTER_ACTOR(self), clone); g_object_connect(clone, "signal::transitions-completed", G_CALLBACK(on_effect_complete), self, "signal::button-press-event", on_thumb_button_press, self, "signal::enter-event", on_thumb_enter, self, "signal::leave-event", on_thumb_leave, self, NULL); } l = l->next; } ClutterColor clr = CLUTTER_COLOR_INIT(0xff, 0xff, 0xff, 0xff); clutter_actor_set_background_color(CLUTTER_ACTOR(self), &clr); if (priv->background_actor) { #if 0 ClutterEffect* blur = moses_blur_effect_new(); clutter_actor_add_effect_with_name(priv->background_actor, "blur", blur); clutter_actor_insert_child_below(CLUTTER_ACTOR(self), priv->background_actor, NULL); clutter_actor_hide(clutter_clone_get_source(CLUTTER_CLONE(priv->background_actor))); clutter_actor_set_reactive(priv->background_actor, TRUE); #endif } g_object_connect(priv->background_actor ? priv->background_actor: CLUTTER_ACTOR(self), "signal::button-press-event", on_bg_button_press, self, NULL); }
static void mnb_fancy_bin_init (MnbFancyBin *self) { MnbFancyBinPrivate *priv = self->priv = FANCY_BIN_PRIVATE (self); priv->curve_radius = 2; priv->child = clutter_clone_new (NULL); priv->clone = clutter_clone_new (NULL); clutter_actor_add_child(CLUTTER_ACTOR (self), priv->child); clutter_actor_add_child(CLUTTER_ACTOR (self), priv->clone); g_signal_connect (self, "style-changed", G_CALLBACK (mnb_fancy_bin_style_changed_cb), self); }
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); }
/** * shell_global_create_root_pixmap_actor: * @global: a #ShellGlobal * * Creates an actor showing the root window pixmap. * * Return value: (transfer none): a #ClutterActor with the root window pixmap. * The actor is floating, hence (transfer none). */ ClutterActor * shell_global_create_root_pixmap_actor (ShellGlobal *global) { GdkWindow *window; ClutterActor *stage; ClutterColor stage_color; /* The actor created is actually a ClutterClone of global->root_pixmap. */ if (global->root_pixmap == NULL) { global->root_pixmap = clutter_glx_texture_pixmap_new (); clutter_texture_set_repeat (CLUTTER_TEXTURE (global->root_pixmap), TRUE, TRUE); /* The low and medium quality filters give nearest-neighbor resizing. */ clutter_texture_set_filter_quality (CLUTTER_TEXTURE (global->root_pixmap), CLUTTER_TEXTURE_QUALITY_HIGH); /* Initialize to the stage color, since that's what will be seen * in the main view if there's no actual background window. */ stage = mutter_plugin_get_stage (global->plugin); clutter_stage_get_color (CLUTTER_STAGE (stage), &stage_color); clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (global->root_pixmap), /* ClutterColor has the same layout * as one pixel of RGB(A) data. */ (const guchar *)&stage_color, FALSE, /* w, h, rowstride, bpp, flags */ 1, 1, 3, 3, 0, NULL); /* We can only clone an actor within a stage, so we hide the source * texture then add it to the stage */ clutter_actor_hide (global->root_pixmap); clutter_container_add_actor (CLUTTER_CONTAINER (stage), global->root_pixmap); /* This really should never happen; but just in case... */ g_signal_connect (global->root_pixmap, "destroy", G_CALLBACK (root_pixmap_destroy), global); /* Metacity handles changes to some root window properties in its global * event filter, though not _XROOTPMAP_ID. For all root window property * changes, the global filter returns GDK_FILTER_CONTINUE, so our * window specific filter will be called after the global one. * * Because Metacity is already handling root window property updates, * we don't have to worry about adding the PropertyChange mask to the * root window to get PropertyNotify events. */ window = gdk_get_default_root_window (); gdk_window_add_filter (window, root_window_filter, global); update_root_window_pixmap (global); } return clutter_clone_new (global->root_pixmap); }
void mnb_zones_preview_add_window (MnbZonesPreview *preview, MetaWindow *window) { ClutterActor *clone; ClutterActor *group; MetaRectangle rect; MetaWorkspace *workspace; /* TODO: Determine if we need to add a weak reference on the window * in case it gets destroyed during the animation. * I'd have thought that the clone's reference on the texture * would be enough that this wouldn't be necessary. * * We do; while the clone's reference is enough to keep the texture about, * it is not enough to make it possible to map the clone once the texture * has been unparented. */ workspace = meta_window_get_workspace (window); group = mnb_zones_preview_get_workspace_group (preview, meta_workspace_index(workspace)); clone = clutter_clone_new (CLUTTER_ACTOR(window)); g_signal_connect (window, "destroy", G_CALLBACK (mnb_zones_preview_mcw_destroy_cb), clone); g_signal_connect (clone, "destroy", G_CALLBACK (mnb_zones_preview_clone_destroy_cb), window); meta_window_get_outer_rect (window, &rect); clutter_actor_set_position (clone, rect.x, rect.y); clutter_actor_add_child (CLUTTER_ACTOR (group), clone); }
static void mnp_clock_tile_drag_begin (MxDraggable *draggable, gfloat event_x, gfloat event_y, gint event_button, ClutterModifierType modifiers) { ClutterActor *self = CLUTTER_ACTOR (draggable); ClutterActor *stage = clutter_actor_get_stage (self); gfloat orig_x, orig_y; MnpClockTile *tile = (MnpClockTile *)draggable; gfloat width, height; MnpClockTilePriv *priv = tile->priv; clutter_actor_get_size (self, &width, &height); g_object_ref (self); if (priv->clone) clutter_actor_destroy (priv->clone); priv->clone = clutter_clone_new (self); tile->priv->depth = clutter_actor_get_depth (self); clutter_actor_get_transformed_position (self, &orig_x, &orig_y); //clutter_actor_reparent (self, stage); //clutter_actor_set_size (self, width, -1); //clutter_actor_raise_top (self); //clutter_actor_set_position (self, orig_x, orig_y); clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->clone); clutter_actor_set_position (priv->clone, orig_x, orig_y); clutter_actor_set_size (priv->clone, width, height); g_object_unref (self); clutter_actor_animate (self, CLUTTER_EASE_OUT_CUBIC, 250, "opacity", 0, NULL); }
void test_clone_no_map (TestConformSimpleFixture *fixture, gconstpointer data) { ClutterActor *stage; ClutterActor *group; ClutterActor *actor; ClutterActor *clone; stage = clutter_stage_get_default (); group = clutter_group_new (); actor = clutter_rectangle_new (); clutter_actor_hide (group); clutter_container_add_actor (CLUTTER_CONTAINER (group), actor); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); clone = clutter_clone_new (group); clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone); g_assert (CLUTTER_ACTOR_IS_MAPPED (clone)); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); clutter_actor_destroy (CLUTTER_ACTOR (clone)); clutter_actor_destroy (CLUTTER_ACTOR (group)); }
void opt_show_add_slide (OptShow *self, OptSlide *slide) { ClutterActor *bg, *stage; self->priv->slides = g_list_append(self->priv->slides, slide); self->priv->num_slides++; stage = clutter_stage_get_default(); bg = CLUTTER_ACTOR(opt_slide_get_background_texture (slide)); if (bg == NULL) bg = clutter_clone_new(self->priv->bg); clutter_actor_set_size (bg, clutter_actor_get_width (stage), clutter_actor_get_height (stage)); clutter_group_add (CLUTTER_GROUP(slide), bg); clutter_actor_lower_bottom(bg); clutter_actor_show(bg); opt_menu_add_slide (self->priv->menu, slide); }
static void clone_no_map (void) { ClutterActor *stage; ClutterActor *group; ClutterActor *actor; ClutterActor *clone; stage = clutter_test_get_stage (); clutter_actor_show (stage); group = clutter_actor_new (); actor = clutter_actor_new (); clutter_actor_hide (group); clutter_actor_add_child (group, actor); clutter_actor_add_child (stage, group); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); clone = clutter_clone_new (group); clutter_actor_add_child (stage, clone); g_assert (CLUTTER_ACTOR_IS_MAPPED (clone)); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); clutter_actor_destroy (CLUTTER_ACTOR (clone)); clutter_actor_destroy (CLUTTER_ACTOR (group)); }
static void make_ui (ClutterActor *stage) { ClutterActor *editable = NULL; ClutterActor *rectangle = NULL; ClutterActor *label = NULL; ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff }; ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 }; ClutterGeometry editable_geom = {150, 50, 100, 75}; ClutterActor *full_entry = NULL; ClutterActor *cloned_entry = NULL; clutter_stage_set_color (CLUTTER_STAGE (stage), &color_stage); clutter_actor_set_size (stage, WIDTH, HEIGHT); label = clutter_text_new_full ("Sans Bold 32px", "Entry", &color_label); clutter_actor_set_position (label, 0, 50); /* editable */ editable = clutter_text_new_full ("Sans Bold 32px", "ddd", &color_text); clutter_actor_set_position (editable, 150, 50); clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE); clutter_text_set_selection_color (CLUTTER_TEXT (editable), &color_sel); clutter_actor_grab_key_focus (editable); clutter_actor_set_reactive (editable, TRUE); /* rectangle: to create a entry "feeling" */ rectangle = clutter_rectangle_new_with_color (&color_rect); clutter_actor_set_geometry (rectangle, &editable_geom); full_entry = clutter_group_new (); clutter_actor_set_position (full_entry, 0, 50); clutter_actor_set_size (full_entry, 100, 75); clutter_group_add (CLUTTER_GROUP (full_entry), label); clutter_group_add (CLUTTER_GROUP (full_entry), editable); clutter_group_add (CLUTTER_GROUP (full_entry), rectangle); clutter_actor_show_all (full_entry); clutter_actor_set_scale (full_entry, 2, 1); clutter_group_add (CLUTTER_GROUP (stage), full_entry); /* Cloning! */ cloned_entry = clutter_clone_new (full_entry); clutter_actor_set_position (cloned_entry, 50, 200); clutter_actor_set_scale (cloned_entry, 1, 2); clutter_actor_show_all (cloned_entry); clutter_actor_set_reactive (cloned_entry, TRUE); clutter_group_add (CLUTTER_GROUP (stage), cloned_entry); }
/** * shell_global_create_root_pixmap_actor: * @global: a #ShellGlobal * * Creates an actor showing the root window pixmap. * * Return value: (transfer none): a #ClutterActor with the root window pixmap. * The actor is floating, hence (transfer none). */ ClutterActor * shell_global_create_root_pixmap_actor (ShellGlobal *global) { GdkWindow *window; ClutterActor *stage; /* The actor created is actually a ClutterClone of global->root_pixmap. */ if (global->root_pixmap == NULL) { global->root_pixmap = clutter_glx_texture_pixmap_new (); /* The low and medium quality filters give nearest-neighbor resizing. */ clutter_texture_set_filter_quality (CLUTTER_TEXTURE (global->root_pixmap), CLUTTER_TEXTURE_QUALITY_HIGH); /* We can only clone an actor within a stage, so we hide the source * texture then add it to the stage */ clutter_actor_hide (global->root_pixmap); stage = mutter_plugin_get_stage (global->plugin); clutter_container_add_actor (CLUTTER_CONTAINER (stage), global->root_pixmap); g_signal_connect (global->root_pixmap, "paint", G_CALLBACK (root_pixmap_paint), NULL); /* This really should never happen; but just in case... */ g_signal_connect (global->root_pixmap, "destroy", G_CALLBACK (root_pixmap_destroy), global); /* Metacity handles changes to some root window properties in its global * event filter, though not _XROOTPMAP_ID. For all root window property * changes, the global filter returns GDK_FILTER_CONTINUE, so our * window specific filter will be called after the global one. * * Because Metacity is already handling root window property updates, * we don't have to worry about adding the PropertyChange mask to the * root window to get PropertyNotify events. */ window = gdk_get_default_root_window (); gdk_window_add_filter (window, root_window_filter, global); update_root_window_pixmap (global); } return clutter_clone_new (global->root_pixmap); }
/* Gets the desired workspace and creates any workspaces * necessary before it. */ static ClutterActor * mnb_zones_preview_get_workspace_group (MnbZonesPreview *preview, gint workspace) { gint i; GList *w; ClutterActor *bin = NULL; MnbZonesPreviewPrivate *priv = preview->priv; for (w = priv->workspace_bins, i = 0; (i < workspace) && w; w = w->next, i++); if ((i == workspace) && w) return mnb_fancy_bin_get_child (MNB_FANCY_BIN (w->data)); for (; i <= workspace; i++) { ClutterActor *group; /* Create a workspace clone */ bin = mnb_fancy_bin_new (); group = clutter_actor_new (); /* Add background if it's set */ if (priv->workspace_bg) { ClutterActor *bg = clutter_clone_new (priv->workspace_bg); clutter_actor_set_size (bg, priv->width, priv->height); clutter_actor_add_child (CLUTTER_ACTOR (group), bg); } clutter_actor_set_clip (group, 0, 0, priv->width, priv->height); mnb_fancy_bin_set_child (MNB_FANCY_BIN (bin), group); clutter_actor_add_child(CLUTTER_ACTOR (preview), bin); /* This is a bit of a hack, depending on the fact that GList * doesn't change the beginning of the list when appending * (unless the list is NULL). */ priv->workspace_bins = g_list_append (priv->workspace_bins, bin); } return mnb_fancy_bin_get_child (MNB_FANCY_BIN (bin)); }
static void ntf_wm_update_notification (NtfNotification *ntf, MetaWindow *window) { ClutterActor *src_icon; ClutterActor *button; NtfSource *src; const gchar *title; const gchar *summary; const gchar *body; g_return_if_fail (ntf && window); src = ntf_notification_get_source (ntf); if ((src_icon = ntf_source_get_icon (src))) { ClutterActor *icon = clutter_clone_new (src_icon) ; ntf_notification_set_icon (ntf, icon); } title = meta_window_get_title (window); if (title) summary = title; else summary = _("Unknown window"); ntf_notification_set_summary (ntf, summary); body = _("is asking for your attention."); ntf_notification_set_body (ntf, body); ntf_notification_remove_all_buttons (ntf); button = mx_button_new (); mx_button_set_label (MX_BUTTON (button), _("Activate")); g_signal_connect (button, "clicked", G_CALLBACK (ntf_wm_activate_cb), window); ntf_notification_add_button (ntf, button, 0); }
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; }
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; }
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; 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 }; 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; }
void make_ui (App *app) { gint i, xpad, ypad, x ,y, xinit, xdpy, ydpy; ClutterActor *button_texture, *a; ClutterColor text_color = { 0xff, 0xff, 0xff, 0xff }, rect_color = { 0, 0, 0, 0x99 }, black_color = { 0, 0, 0, 0xff }; button_texture = clutter_texture_new_from_file ("button.png", NULL); xpad = (CSW-(3*clutter_actor_get_width(button_texture)))/4; x = xinit = xpad; ypad = xpad/2; y = (CSH - (4 * (ypad + clutter_actor_get_height(button_texture)))); /* * screen_dialpad (group) * +----dpy (group) * +---- (texture:display.png) * +----dpy_entry (text) * +----buttons[0:11]->actor (group) * +---- (texture:button.png) * +---- (text) */ app->screen_dialpad = clutter_group_new(); clutter_actor_set_size (app->screen_dialpad, CSW, CSH); clutter_actor_set_anchor_point_from_gravity (app->screen_dialpad, CLUTTER_GRAVITY_CENTER); clutter_actor_set_position (app->screen_dialpad, CSW/2, CSH/2); app->dpy = clutter_group_new(); a = clutter_texture_new_from_file ("display.png", NULL); clutter_group_add (CLUTTER_GROUP(app->dpy), a); app->dpyx = xdpy = x; app->dpyy = ydpy = (y - clutter_actor_get_height(app->dpy))/2; clutter_actor_set_position (app->dpy, xdpy, ydpy); clutter_group_add(CLUTTER_GROUP(app->screen_dialpad), app->dpy); app->dpy_entry = clutter_text_new_full ("Sans Bold 32px", "", &text_color); clutter_text_set_editable (CLUTTER_TEXT(app->dpy_entry), TRUE); clutter_actor_set_position (app->dpy_entry, 8, 8); clutter_actor_set_size (app->dpy_entry, clutter_actor_get_width (app->dpy) - 16, 32); clutter_group_add (CLUTTER_GROUP(app->dpy), app->dpy_entry); for (i=0; i<12; i++) { gchar buf[8]; gchar label[8]; app->buttons[i] = g_new0(Button, 1); app->buttons[i]->actor = clutter_group_new (); g_snprintf (label, 8, "%d", i+1); clutter_actor_set_name (app->buttons[i]->actor, label); clutter_actor_set_reactive (app->buttons[i]->actor, TRUE); clutter_actor_set_anchor_point_from_gravity (app->buttons[i]->actor, CLUTTER_GRAVITY_CENTER); if ( i == 0 ) a = button_texture; else a = clutter_clone_new(button_texture); clutter_group_add(CLUTTER_GROUP(app->buttons[i]->actor), a); switch (i) { case 9: g_snprintf(buf, 8, "#"); break; case 10: g_snprintf(buf, 8, "0"); break; case 11: g_snprintf(buf, 8, "*"); break; default: g_snprintf(buf, 8, "%i", i+1); break; } a = clutter_text_new_full("Sans Bold 32px", buf, &text_color); clutter_actor_set_position (a, (clutter_actor_get_width (button_texture) - clutter_actor_get_width (a))/2, (clutter_actor_get_height (button_texture) - clutter_actor_get_height (a))/2); clutter_group_add (CLUTTER_GROUP (app->buttons[i]->actor), a); clutter_group_add (CLUTTER_GROUP (app->screen_dialpad), app->buttons[i]->actor); /* need to remember positions for anim - sucky */ app->buttons[i]->sx = x + clutter_actor_get_width (app->buttons[i]->actor)/2; app->buttons[i]->sy = y + clutter_actor_get_height (app->buttons[i]->actor)/2; clutter_actor_set_position (app->buttons[i]->actor, app->buttons[i]->sx, app->buttons[i]->sy); /* Really we should use a Clutter*Box here.. */ if (i % 3 == 2) { x = xinit; y += (ypad + clutter_actor_get_height (button_texture)); } else x += (xpad + clutter_actor_get_width(button_texture)); app->buttons[i]->face = g_strdup (buf); } /* * screen_dial * +---- (rectangle:black) * +---- (texture:call-background.png) * +---- (rectangle:semi transparent) * +----dial_label (text:"Calling...") */ app->screen_dial = clutter_group_new(); clutter_actor_set_anchor_point_from_gravity (app->screen_dial, CLUTTER_GRAVITY_CENTER); clutter_actor_set_position (app->screen_dial, CSW/2, CSH/2); a = clutter_rectangle_new_with_color (&black_color); clutter_actor_set_size (a, CSW, CSH); clutter_group_add (CLUTTER_GROUP(app->screen_dial), a); a = clutter_texture_new_from_file ("call-background.png", NULL); clutter_group_add (CLUTTER_GROUP(app->screen_dial), a); a = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (a, CSW, CSH/6); clutter_actor_set_position (a, 0, (CSH - (CSH/6))/2); clutter_group_add (CLUTTER_GROUP(app->screen_dial), a); app->dial_label = clutter_text_new_full ("Sans Bold 32px", "Calling...", &text_color); clutter_actor_set_position (app->dial_label, 10, (CSH - (CSH/6))/2 + 10); clutter_group_add (CLUTTER_GROUP (app->screen_dial), app->dial_label); }