/* Object initialization * Create private structure and set up default values */ static void xfdashboard_text_box_init(XfdashboardTextBox *self) { XfdashboardTextBoxPrivate *priv; priv=self->priv=XFDASHBOARD_TEXT_BOX_GET_PRIVATE(self); /* This actor is react on events */ clutter_actor_set_reactive(CLUTTER_ACTOR(self), TRUE); /* Set up default values */ priv->padding=0.0f; priv->spacing=0.0f; priv->isEditable=FALSE; priv->primaryIconName=NULL; priv->secondaryIconName=NULL; priv->textFont=NULL; priv->textColor=NULL; priv->selectionTextColor=NULL; priv->selectionBackgroundColor=NULL; priv->hintTextFont=NULL; priv->hintTextColor=NULL; priv->showPrimaryIcon=FALSE; priv->showSecondaryIcon=FALSE; priv->selectionColorSet=FALSE; priv->hintTextSet=FALSE; /* Create actors */ g_signal_connect(self, "key-press-event", G_CALLBACK(_xfdashboard_text_box_on_key_press_event), NULL); g_signal_connect(self, "key-release-event", G_CALLBACK(_xfdashboard_text_box_on_key_release_event), NULL); priv->actorPrimaryIcon=xfdashboard_button_new(); xfdashboard_stylable_add_class(XFDASHBOARD_STYLABLE(priv->actorPrimaryIcon), "primary-icon"); clutter_actor_set_reactive(priv->actorPrimaryIcon, TRUE); clutter_actor_hide(priv->actorPrimaryIcon); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->actorPrimaryIcon); g_signal_connect_swapped(priv->actorPrimaryIcon, "clicked", G_CALLBACK(_xfdashboard_text_box_on_primary_icon_clicked), self); priv->actorSecondaryIcon=xfdashboard_button_new(); xfdashboard_stylable_add_class(XFDASHBOARD_STYLABLE(priv->actorSecondaryIcon), "secondary-icon"); clutter_actor_set_reactive(priv->actorSecondaryIcon, TRUE); clutter_actor_hide(priv->actorSecondaryIcon); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->actorSecondaryIcon); g_signal_connect_swapped(priv->actorSecondaryIcon, "clicked", G_CALLBACK(_xfdashboard_text_box_on_secondary_icon_clicked), self); priv->actorTextBox=clutter_text_new(); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->actorTextBox); clutter_actor_set_reactive(priv->actorTextBox, TRUE); clutter_text_set_selectable(CLUTTER_TEXT(priv->actorTextBox), FALSE); clutter_text_set_editable(CLUTTER_TEXT(priv->actorTextBox), FALSE); clutter_text_set_single_line_mode(CLUTTER_TEXT(priv->actorTextBox), TRUE); g_signal_connect_swapped(priv->actorTextBox, "text-changed", G_CALLBACK(_xfdashboard_text_box_on_text_changed), self); priv->actorHintLabel=clutter_text_new(); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->actorHintLabel); clutter_actor_set_reactive(priv->actorHintLabel, FALSE); clutter_text_set_selectable(CLUTTER_TEXT(priv->actorHintLabel), FALSE); clutter_text_set_editable(CLUTTER_TEXT(priv->actorHintLabel), FALSE); clutter_text_set_single_line_mode(CLUTTER_TEXT(priv->actorHintLabel), TRUE); clutter_actor_hide(priv->actorHintLabel); }
static void mex_tile_init (MexTile *self) { MexTilePrivate *priv = self->priv = TILE_PRIVATE (self); const ClutterColor opaque = { 0x00, 0x00, 0x00, 0x00 }; ClutterEffect *fade; /* create a template material for the header background from which cheap * copies can be made for each instance */ if (G_UNLIKELY (!template_material)) template_material = cogl_material_new (); priv->material = cogl_material_copy (template_material); /* layout for primary and secondary labels */ priv->box_layout = mx_box_layout_new (); mx_box_layout_set_spacing (MX_BOX_LAYOUT (priv->box_layout), 12); /* add fade effect to the box layout */ fade = (ClutterEffect*) mx_fade_effect_new (); mx_fade_effect_set_border (MX_FADE_EFFECT (fade), 0, 50, 0, 0); mx_fade_effect_set_color (MX_FADE_EFFECT (fade), &opaque); clutter_actor_add_effect_with_name (priv->box_layout, "fade", fade); clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (fade), TRUE); clutter_actor_push_internal (CLUTTER_ACTOR (self)); clutter_actor_set_parent (priv->box_layout, CLUTTER_ACTOR (self)); clutter_actor_pop_internal (CLUTTER_ACTOR (self)); priv->label = clutter_text_new (); priv->secondary_label = clutter_text_new (); clutter_actor_set_opacity (priv->secondary_label, 128); clutter_container_add (CLUTTER_CONTAINER (priv->box_layout), priv->label, priv->secondary_label, NULL); priv->header_visible = TRUE; priv->timeline = clutter_timeline_new (DURATION); priv->important_alpha = clutter_alpha_new_full (priv->timeline, CLUTTER_EASE_OUT_QUAD); g_signal_connect_object (priv->timeline, "new-frame", G_CALLBACK (mex_tile_important_new_frame_cb), self, 0); g_signal_connect_object (priv->timeline, "completed", G_CALLBACK (mex_tile_timeline_completed_cb), self, 0); g_signal_connect (self, "style-changed", G_CALLBACK (mex_tile_style_changed_cb), NULL); g_signal_connect (self, "actor-added", G_CALLBACK (mex_tile_actor_added), NULL); g_signal_connect (self, "actor-removed", G_CALLBACK (mex_tile_actor_removed), NULL); }
static void mx_combo_box_init (MxComboBox *self) { MxComboBoxPrivate *priv; ClutterActor *menu; priv = self->priv = COMBO_BOX_PRIVATE (self); priv->spacing = 8; priv->label = clutter_text_new (); clutter_actor_add_child (CLUTTER_ACTOR (self), priv->label); menu = mx_menu_new (); mx_widget_set_menu (MX_WIDGET (self), MX_MENU (menu)); g_signal_connect (menu, "action-activated", G_CALLBACK (mx_combo_box_action_activated_cb), self); g_signal_connect (self, "style-changed", G_CALLBACK (mx_combo_box_style_changed), NULL); clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE); }
static void mx_expander_init (MxExpander *self) { MxExpanderPrivate *priv = self->priv = GET_PRIVATE (self); priv->label = clutter_text_new (); clutter_actor_add_child ((ClutterActor *) self, priv->label); priv->arrow = (ClutterActor *) mx_icon_new (); clutter_actor_add_child ((ClutterActor*) self, priv->arrow); clutter_actor_set_name (priv->arrow, "mx-expander-arrow-closed"); /* TODO: make this a style property */ priv->spacing = 10.0f; priv->timeline = clutter_timeline_new (250); clutter_timeline_set_progress_mode (priv->timeline, CLUTTER_EASE_IN_SINE); g_signal_connect (priv->timeline, "new-frame", G_CALLBACK (new_frame), self); g_signal_connect (priv->timeline, "completed", G_CALLBACK (timeline_complete), self); clutter_actor_set_reactive ((ClutterActor *) self, TRUE); g_signal_connect (self, "style-changed", G_CALLBACK (mx_expander_style_changed), NULL); g_signal_connect (self, "actor-added", G_CALLBACK (mx_expander_actor_added), NULL); g_signal_connect (self, "actor-removed", G_CALLBACK (mx_expander_actor_removed), NULL); }
static void shell_status_menu_init (ShellStatusMenu *status) { ShellStatusMenuPrivate *priv; status->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (status, SHELL_TYPE_STATUS_MENU, ShellStatusMenuPrivate); g_object_set (G_OBJECT (status), "orientation", BIG_BOX_ORIENTATION_HORIZONTAL, NULL); priv->client = gconf_client_get_default (); priv->user_icon = CLUTTER_TEXTURE (clutter_texture_new ()); big_box_append (BIG_BOX (status), CLUTTER_ACTOR (status->priv->user_icon), 0); priv->name_box = BIG_BOX (big_box_new (BIG_BOX_ORIENTATION_VERTICAL)); g_object_set (G_OBJECT (priv->name_box), "y-align", BIG_BOX_ALIGNMENT_CENTER, NULL); big_box_append (BIG_BOX (status), CLUTTER_ACTOR (priv->name_box), BIG_BOX_PACK_EXPAND); priv->name = CLUTTER_TEXT (clutter_text_new ()); big_box_append (BIG_BOX (priv->name_box), CLUTTER_ACTOR (priv->name), BIG_BOX_PACK_EXPAND); priv->manager = gdm_user_manager_ref_default (); setup_current_user (status); create_sub_menu (status); }
static VALUE rbclt_text_initialize (int argc, VALUE *argv, VALUE self) { VALUE font_name, text, color; gchar *font_name_s = NULL, *text_s = NULL; ClutterColor *color_s = NULL; ClutterActor *actor; rb_scan_args (argc, argv, "03", &font_name, &text, &color); if (!NIL_P (font_name)) font_name_s = StringValuePtr (font_name); if (!NIL_P (text)) text_s = StringValuePtr (text); if (!NIL_P (color)) color_s = (ClutterColor *) RVAL2BOXED (color, CLUTTER_TYPE_COLOR); actor = clutter_text_new (); if (font_name_s) clutter_text_set_font_name (CLUTTER_TEXT (actor), font_name_s); if (text_s) clutter_text_set_text (CLUTTER_TEXT (actor), text_s); if (color_s) clutter_text_set_color (CLUTTER_TEXT (actor), color_s); rbclt_initialize_unowned (self, actor); return Qnil; }
G_MODULE_EXPORT int test_easing_main (int argc, char *argv[]) { ClutterActor *stage, *rect, *label; ClutterColor stage_color = { 0x88, 0x88, 0xdd, 0xff }; ClutterColor rect_color = { 0xee, 0x33, 0, 0xff }; gchar *text; gfloat stage_width, stage_height; gfloat label_width, label_height; clutter_init_with_args (&argc, &argv, NULL, test_easing_entries, NULL, NULL); stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); main_stage = stage; clutter_actor_get_size (stage, &stage_width, &stage_height); rect = make_bouncer (&rect_color, 50, 50); clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); clutter_actor_set_position (rect, stage_width / 2, stage_height / 2); text = g_strdup_printf ("Easing mode: %s (%d of %d)\n" "Right click to change the easing mode", easing_modes[current_mode].name, current_mode + 1, n_easing_modes); label = clutter_text_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 18px"); clutter_text_set_text (CLUTTER_TEXT (label), text); clutter_actor_get_size (label, &label_width, &label_height); clutter_actor_set_position (label, stage_width - label_width - 10, stage_height - label_height - 10); easing_mode_label = label; g_free (text); g_signal_connect (stage, "button-press-event", G_CALLBACK (on_button_press), rect); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
static ClutterActor * create_instructions (void) { ClutterActor *text; text = clutter_text_new (); clutter_text_set_markup (CLUTTER_TEXT (text), "<b>Instructions:</b>\n" "\tTake shot and save: \tSpace bar\n" "\tSet tilt angle: \t\t\t\tUp/Down Arrows\n" "\tIncrease threshold: \t\t\t+/-"); return text; }
static ClutterActor * create_instructions (void) { ClutterActor *text; text = clutter_text_new (); clutter_text_set_markup (CLUTTER_TEXT (text), "<b>Instructions:</b>\n" "\tChange between skeleton\n" "\t tracking and threshold view: \tSpace bar\n" "\tSet tilt angle: \t\t\t\tUp/Down Arrows\n" "\tIncrease threshold: \t\t\t+/-"); return text; }
static ClutterActor * create_label (const ClutterColor *color, const gchar *text) { ClutterActor *retval = clutter_text_new (); clutter_text_set_color (CLUTTER_TEXT (retval), color); clutter_text_set_markup (CLUTTER_TEXT (retval), text); clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE); clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE); clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE); clutter_text_set_ellipsize (CLUTTER_TEXT (retval), PANGO_ELLIPSIZE_END); return retval; }
static void create_stage (guint width, guint height) { ClutterActor *stage, *instructions; GError *error = NULL; stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Depth File Viewer"); clutter_actor_set_size (stage, width, height + 100); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (on_destroy), NULL); depth_tex = clutter_cairo_texture_new (width, height); clutter_container_add_actor (CLUTTER_CONTAINER (stage), depth_tex); info_text = clutter_text_new (); clutter_actor_set_position (info_text, 50, height + 20); clutter_container_add_actor (CLUTTER_CONTAINER (stage), info_text); clutter_actor_show_all (stage); }
G_MODULE_EXPORT int test_bin_layout_main (int argc, char *argv[]) { ClutterActor *stage, *box, *rect; ClutterLayoutManager *layout; ClutterColor stage_color = { 0xe0, 0xf2, 0xfc, 0xff }; ClutterColor *color; ClutterAction *action; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Box test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); clutter_actor_set_size (stage, 640, 480); layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); box = clutter_box_new (layout); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); clutter_actor_set_anchor_point_from_gravity (box, CLUTTER_GRAVITY_CENTER); clutter_actor_set_position (box, 320, 240); clutter_actor_set_reactive (box, TRUE); clutter_actor_set_name (box, "box"); /* the contents of the texture are created every time the allocation * of the box changes, to keep the background's size the same as the * box's size */ rect = clutter_cairo_texture_new (100, 100); /* first method: use clutter_box_pack() */ clutter_box_pack (CLUTTER_BOX (box), rect, "x-align", CLUTTER_BIN_ALIGNMENT_FILL, "y-align", CLUTTER_BIN_ALIGNMENT_FILL, NULL); clutter_actor_lower_bottom (rect); clutter_actor_set_name (rect, "background"); g_signal_connect (box, "allocation-changed", G_CALLBACK (on_box_allocation_changed), rect); { ClutterActor *tex; GError *error; gchar *file; error = NULL; file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); tex = clutter_texture_new_from_file (file, &error); if (error) g_error ("Unable to create texture: %s", error->message); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE); /* second method: use clutter_bin_layout_add() */ clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), tex, CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); clutter_actor_raise (tex, rect); clutter_actor_set_width (tex, 175); clutter_actor_set_name (tex, "texture"); g_free (file); } color = clutter_color_new (g_random_int_range (0, 255), g_random_int_range (0, 255), g_random_int_range (0, 255), 224); rect = clutter_rectangle_new_with_color (color); /* third method: container_add() and set_alignment() */ clutter_container_add_actor (CLUTTER_CONTAINER (box), rect); clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect, CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END); clutter_actor_set_size (rect, 50, 50); clutter_actor_set_opacity (rect, 0); clutter_actor_set_reactive (rect, TRUE); clutter_actor_raise_top (rect); clutter_actor_set_name (rect, "emblem"); action = clutter_click_action_new (); clutter_actor_add_action (rect, action); g_signal_connect (action, "clicked", G_CALLBACK (on_rect_clicked), box); g_signal_connect (action, "long-press", G_CALLBACK (on_rect_long_press), box); g_signal_connect (box, "enter-event", G_CALLBACK (on_box_enter), rect); g_signal_connect (box, "leave-event", G_CALLBACK (on_box_leave), rect); rect = clutter_text_new (); clutter_text_set_text (CLUTTER_TEXT (rect), "A simple test"); clutter_container_add_actor (CLUTTER_CONTAINER (box), rect); clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect, CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_START); clutter_actor_raise_top (rect); clutter_actor_set_name (rect, "text"); clutter_actor_show_all (stage); clutter_main (); clutter_color_free (color); return EXIT_SUCCESS; }
static void _add_app(MetaSwitcher* self, MetaWindow* app, gint* x, gint* y) { MetaSwitcherPrivate* priv = self->priv; if (!priv->icons) priv->icons = g_hash_table_new(NULL, NULL); // container ClutterActor* actor = clutter_actor_new(); WindowPrivate* win_priv = get_window_private(actor); win_priv->window = app; win_priv->highlight = FALSE; g_hash_table_insert(priv->icons, app, actor); gint w = APP_ACTOR_WIDTH, h = APP_ACTOR_HEIGHT, screen_width, screen_height; /* TODO: @sonald scale app actor width */ MetaScreen *screen = meta_plugin_get_screen(priv->plugin); meta_screen_get_size(screen, &screen_width, &screen_height); if (priv->apps->len) w = (screen_width - priv->apps->len * APP_ICON_PADDING) / priv->apps->len; if (w > APP_ACTOR_WIDTH) w = APP_ACTOR_WIDTH; // add children ClutterContent* canvas = clutter_canvas_new(); g_signal_connect(canvas, "draw", G_CALLBACK(on_icon_background_draw), actor); clutter_canvas_set_size(CLUTTER_CANVAS(canvas), w, h); ClutterActor* bg = clutter_actor_new(); clutter_actor_set_name(bg, "bg"); clutter_actor_set_content(bg, canvas); g_object_unref(canvas); clutter_actor_set_size(bg, w, h); g_object_set(bg, "x-expand", TRUE, "y-expand", TRUE, "x-align", CLUTTER_ACTOR_ALIGN_FILL, "y-align", CLUTTER_ACTOR_ALIGN_FILL, NULL); clutter_actor_add_child(actor, bg); ClutterActor* icon = load_icon_for_window(self, app); if (icon) clutter_actor_add_child(actor, icon); ClutterActor* label = clutter_text_new(); clutter_actor_add_child(actor, label); clutter_text_set_text(CLUTTER_TEXT(label), meta_window_get_title(app)); clutter_text_set_font_name(CLUTTER_TEXT(label), "Sans 10"); ClutterColor clr = {0xff, 0xff, 0xff, 0xff}; clutter_text_set_color(CLUTTER_TEXT(label), &clr); clutter_text_set_ellipsize(CLUTTER_TEXT(label), PANGO_ELLIPSIZE_END); g_object_set(label, "x-align", CLUTTER_ACTOR_ALIGN_CENTER, "y-align", CLUTTER_ACTOR_ALIGN_CENTER, NULL); gfloat pref_width = clutter_actor_get_width(label); if (pref_width > w - 10) { pref_width = w - 10; clutter_actor_set_width(label, pref_width); } /* TODO: @sonald adjust app title position */ clutter_actor_set_position(label, (w - pref_width) / 2, APP_ICON_SIZE + 2); g_debug("%s: size: %d, %d", __func__, w, h); clutter_actor_show(actor); clutter_actor_add_child(priv->top, actor); *x += w; }
int main(int argc, char *argv[]) { ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; ClutterColor actor_color = { 0xff, 0xff, 0xcc, 0xff }; clutter_init (&argc, &argv); /* Get the stage and set its size and color: */ ClutterActor *stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 800, 200); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); /* Add a non-editable text actor to the stage: */ ClutterActor *text = clutter_text_new (); /* Setup text properties */ clutter_text_set_color (CLUTTER_TEXT (text), &actor_color); clutter_text_set_text (CLUTTER_TEXT (text), "Non-editable text: Wizard imps and sweat sock pimps, interstellar mongrel nymphs."); clutter_text_set_font_name (CLUTTER_TEXT (text), "Sans 12"); clutter_text_set_editable (CLUTTER_TEXT (text), FALSE); clutter_text_set_line_wrap (CLUTTER_TEXT (text), FALSE); /* Discover the preferred height and use that height: */ float min_height = 0; float natural_height = 0; clutter_actor_get_preferred_height (text, 750, &min_height, &natural_height); clutter_actor_set_size (text, 750, natural_height); clutter_actor_set_position (text, 5, 5); clutter_container_add_actor (CLUTTER_CONTAINER (stage), text); clutter_actor_show (text); /* Add a multi-line editable text actor to the stage: */ text = clutter_text_new (); /* Setup text properties */ clutter_text_set_color (CLUTTER_TEXT (text), &actor_color); clutter_text_set_text (CLUTTER_TEXT (text), "Editable text: And as I sat there brooding on the old, unknown world, I thought of " "Gatsby's wonder when he first picked out the green light at the end of " "Daisy's dock. He had come a long way to this blue lawn and his dream " "must have seemed so close that he could hardly fail to grasp it. He did " "not know that it was already behind him, somewhere back in that vast " "obscurity beyond the city, where the dark fields of the republic rolled " "on under the night."); clutter_text_set_font_name (CLUTTER_TEXT (text), "Sans 12"); clutter_text_set_editable (CLUTTER_TEXT (text), TRUE); clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE); /* Discover the preferred height and use that height: */ min_height = 0; natural_height = 0; clutter_actor_get_preferred_height (text, 750, &min_height, &natural_height); clutter_actor_set_size (text, 750, natural_height); clutter_actor_set_position (text, 5, 50); clutter_container_add_actor (CLUTTER_CONTAINER (stage), text); clutter_actor_show (text); /* Set focus to handle key presses on the stage: */ clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text); /* Show the stage: */ clutter_actor_show (stage); /* Start the main loop, so we can respond to events: */ clutter_main (); return EXIT_SUCCESS; }
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); }
static void render_logo (void) { ClutterActor *image; ClutterActor *text, *text_shadow; ClutterActor *desc, *desc_shadow; ClutterColor actor_color = {0xff,0xff,0xff,0xff}; ClutterColor shadow_color = {0x00, 0x00, 0x00, 0x88}; ClutterActor *text_group; static gint width, height; gint size; gfloat stage_w, stage_h; PangoFontDescription *pfd; PangoLayout *layout; PangoContext *context; gchar *nibbles = _("Nibbles"); /* Translators: This string will be included in the intro screen, so don't make sure it fits! */ gchar *description = _("A worm game for MATE."); logo = clutter_group_new (); text_group = clutter_group_new (); if (!logo_pixmap) gnibbles_load_logo (properties->tilesize); image = gtk_clutter_texture_new_from_pixbuf (logo_pixmap); stage_w = board->width * properties->tilesize; stage_h = board->height * properties->tilesize; clutter_actor_set_size (CLUTTER_ACTOR (image), stage_w, stage_h); clutter_actor_set_position (CLUTTER_ACTOR (image), 0, 0); clutter_actor_show (image); text = clutter_text_new (); clutter_text_set_color (CLUTTER_TEXT (text), &actor_color); context = gdk_pango_context_get (); layout = clutter_text_get_layout (CLUTTER_TEXT (text)); pfd = pango_context_get_font_description (context); size = pango_font_description_get_size (pfd); pango_font_description_set_size (pfd, (size * stage_w) / 100); pango_font_description_set_family (pfd, "Sans"); pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); pango_layout_set_font_description (layout, pfd); pango_layout_set_text (layout, nibbles, -1); pango_layout_get_pixel_size (layout, &width, &height); text_shadow = clutter_text_new (); clutter_text_set_color (CLUTTER_TEXT (text_shadow), &shadow_color); layout = clutter_text_get_layout (CLUTTER_TEXT (text_shadow)); pango_layout_set_font_description (layout, pfd); pango_layout_set_text (layout, nibbles, -1); clutter_actor_set_position (CLUTTER_ACTOR (text), (stage_w - width) * 0.5 , stage_h * .72); clutter_actor_set_position (CLUTTER_ACTOR (text_shadow), (stage_w - width) * 0.5 + 5, stage_h * .72 + 5); desc = clutter_text_new (); layout = clutter_text_get_layout (CLUTTER_TEXT (desc)); clutter_text_set_color (CLUTTER_TEXT (desc), &actor_color); pango_font_description_set_size (pfd, (size * stage_w) / 400); pango_layout_set_font_description (layout, pfd); pango_layout_set_text (layout, description, -1); pango_layout_get_pixel_size(layout, &width, &height); desc_shadow = clutter_text_new (); layout = clutter_text_get_layout (CLUTTER_TEXT (desc_shadow)); clutter_text_set_color (CLUTTER_TEXT (desc_shadow), &shadow_color); pango_font_description_set_size (pfd, (size * stage_w) / 400); pango_layout_set_font_description (layout, pfd); pango_layout_set_text (layout, description, -1); clutter_actor_set_position (CLUTTER_ACTOR (desc), (stage_w - width) * 0.5, stage_h* .93); clutter_actor_set_position (CLUTTER_ACTOR (desc_shadow), (stage_w - width) * 0.5 + 3, stage_h * .93 + 3); clutter_container_add (CLUTTER_CONTAINER (text_group), CLUTTER_ACTOR (text_shadow), CLUTTER_ACTOR (text), CLUTTER_ACTOR (desc_shadow), CLUTTER_ACTOR (desc), NULL); clutter_container_add (CLUTTER_CONTAINER (logo), CLUTTER_ACTOR (image), CLUTTER_ACTOR (text_group), NULL); clutter_actor_set_opacity (CLUTTER_ACTOR (text_group), 0); clutter_actor_set_scale (CLUTTER_ACTOR (text_group), 0.0, 0.0); clutter_actor_animate (text_group, CLUTTER_EASE_OUT_CIRC, 800, "opacity", 0xff, "scale-x", 1.0, "scale-y", 1.0, "fixed::scale-center-y", stage_w / 2, "fixed::scale-center-x", stage_h / 2, NULL); clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (logo)); }
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; }
static void on_new_kinect_device (GObject *obj, GAsyncResult *res, gpointer user_data) { ClutterActor *stage, *instructions; GError *error = NULL; gint width = 640; gint height = 480; kinect = gfreenect_device_new_finish (res, &error); if (kinect == NULL) { g_debug ("Failed to created kinect device: %s", error->message); g_error_free (error); clutter_main_quit (); return; } g_debug ("Kinect device created!"); stage = clutter_stage_get_default (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Kinect Test"); clutter_actor_set_size (stage, width * 2, height + 200); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (on_destroy), kinect); g_signal_connect (stage, "key-release-event", G_CALLBACK (on_key_release), kinect); depth_tex = clutter_cairo_texture_new (width, height); clutter_container_add_actor (CLUTTER_CONTAINER (stage), depth_tex); video_tex = clutter_cairo_texture_new (width, height); clutter_actor_set_position (video_tex, width, 0.0); clutter_container_add_actor (CLUTTER_CONTAINER (stage), video_tex); info_text = clutter_text_new (); set_info_text (); clutter_actor_set_position (info_text, 50, height + 20); clutter_container_add_actor (CLUTTER_CONTAINER (stage), info_text); instructions = create_instructions (); clutter_actor_set_position (instructions, 50, height + 70); clutter_container_add_actor (CLUTTER_CONTAINER (stage), instructions); clutter_actor_show_all (stage); skeleton = SKELTRACK_SKELETON (skeltrack_skeleton_new ()); g_signal_connect (kinect, "depth-frame", G_CALLBACK (on_depth_frame), NULL); g_signal_connect (kinect, "video-frame", G_CALLBACK (on_video_frame), NULL); g_signal_connect (depth_tex, "draw", G_CALLBACK (on_texture_draw), NULL); gfreenect_device_set_tilt_angle (kinect, 0, NULL, NULL, NULL); gfreenect_device_start_depth_stream (kinect, GFREENECT_DEPTH_FORMAT_MM, NULL); gfreenect_device_start_video_stream (kinect, GFREENECT_RESOLUTION_MEDIUM, GFREENECT_VIDEO_FORMAT_RGB, NULL); }