int main (int argc, char *argv[]) { ClutterActor *stage; ClutterAction *action1; ClutterAction *action2; ClutterActor *actor1; ClutterActor *actor2; 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); actor1 = clutter_actor_new (); clutter_actor_set_name (actor1, "Red Button"); clutter_actor_set_background_color (actor1, CLUTTER_COLOR_Red); clutter_actor_set_size (actor1, 100, 100); clutter_actor_set_reactive (actor1, TRUE); clutter_actor_set_position (actor1, 50, 150); clutter_actor_add_child (stage, actor1); actor2 = clutter_actor_new (); clutter_actor_set_name (actor2, "Blue Button"); clutter_actor_set_background_color (actor2, CLUTTER_COLOR_Blue); clutter_actor_set_size (actor2, 100, 100); clutter_actor_set_position (actor2, 250, 150); clutter_actor_set_reactive (actor2, TRUE); clutter_actor_add_child (stage, actor2); action1 = clutter_click_action_new (); clutter_actor_add_action (actor1, action1); action2 = clutter_click_action_new (); clutter_actor_add_action (actor2, action2); g_signal_connect (action1, "clicked", G_CALLBACK (clicked_cb), NULL); g_signal_connect (action2, "clicked", G_CALLBACK (clicked_cb), NULL); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
/* Object initialization * Create private structure and set up default values */ static void xfdashboard_live_workspace_init(XfdashboardLiveWorkspace *self) { XfdashboardLiveWorkspacePrivate *priv; ClutterAction *action; priv=self->priv=XFDASHBOARD_LIVE_WORKSPACE_GET_PRIVATE(self); /* Set default values */ priv->windowTracker=xfdashboard_window_tracker_get_default(); priv->workspace=NULL; /* Set up this actor */ clutter_actor_set_reactive(CLUTTER_ACTOR(self), TRUE); /* Connect signals */ action=xfdashboard_click_action_new(); clutter_actor_add_action(CLUTTER_ACTOR(self), action); g_signal_connect_swapped(action, "clicked", G_CALLBACK(_xfdashboard_live_workspace_on_clicked), self); g_signal_connect_swapped(priv->windowTracker, "window-opened", G_CALLBACK(_xfdashboard_live_workspace_on_window_opened), self); g_signal_connect_swapped(priv->windowTracker, "window-closed", G_CALLBACK(_xfdashboard_live_workspace_on_window_closed), self); g_signal_connect_swapped(priv->windowTracker, "window-geometry-changed", G_CALLBACK(_xfdashboard_live_workspace_on_window_geometry_changed), self); g_signal_connect_swapped(priv->windowTracker, "window-state-changed", G_CALLBACK(_xfdashboard_live_workspace_on_window_state_changed), self); g_signal_connect_swapped(priv->windowTracker, "window-workspace-changed", G_CALLBACK(_xfdashboard_live_workspace_on_window_workspace_changed), self); g_signal_connect_swapped(priv->windowTracker, "window-stacking-changed", G_CALLBACK(_xfdashboard_live_workspace_on_window_stacking_changed), self); }
G_MODULE_EXPORT int test_drag_main (int argc, char *argv[]) { ClutterActor *stage, *handle; ClutterAction *action; GError *error; error = NULL; clutter_init_with_args (&argc, &argv, "test-drag", entries, NULL, &error); if (error != NULL) { g_print ("Unable to run test-drag: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Drag Test"); clutter_actor_set_size (stage, 800, 600); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); handle = clutter_rectangle_new (); clutter_rectangle_set_color (CLUTTER_RECTANGLE (handle), CLUTTER_COLOR_SkyBlue); clutter_actor_set_size (handle, 128, 128); clutter_actor_set_position (handle, (800 - 128) / 2, (600 - 128) / 2); clutter_actor_set_reactive (handle, TRUE); clutter_container_add_actor (CLUTTER_CONTAINER (stage), handle); g_signal_connect (handle, "enter-event", G_CALLBACK (on_enter), NULL); g_signal_connect (handle, "leave-event", G_CALLBACK (on_leave), NULL); action = clutter_drag_action_new (); clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action), x_drag_threshold, y_drag_threshold); clutter_drag_action_set_drag_axis (CLUTTER_DRAG_ACTION (action), get_drag_axis (drag_axis)); g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL); g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL); clutter_actor_add_action (handle, action); clutter_actor_add_effect_with_name (handle, "disable", clutter_desaturate_effect_new (0.0)); clutter_actor_add_effect_with_name (handle, "curl", clutter_page_turn_effect_new (0.0, 45.0, 12.0)); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
/* Called when a new view was added to viewpad */ static void _xfdashboard_view_selector_on_view_added(XfdashboardViewSelector *self, XfdashboardView *inView, gpointer inUserData) { XfdashboardViewSelectorPrivate *priv; ClutterActor *button; gchar *viewName; const gchar *viewIcon; gboolean isActive; ClutterAction *action; g_return_if_fail(XFDASHBOARD_IS_VIEW_SELECTOR(self)); g_return_if_fail(XFDASHBOARD_IS_VIEW(inView)); priv=self->priv; /* Create button for newly added view */ viewName=g_markup_printf_escaped("%s", xfdashboard_view_get_name(inView)); viewIcon=xfdashboard_view_get_icon(inView); button=xfdashboard_toggle_button_new_full_with_icon_name(viewIcon, viewName); xfdashboard_toggle_button_set_auto_toggle(XFDASHBOARD_TOGGLE_BUTTON(button), FALSE); g_object_set_data(G_OBJECT(button), "view", inView); g_signal_connect_swapped(button, "clicked", G_CALLBACK(_xfdashboard_view_selector_on_view_button_clicked), self); /* Set toggle state depending of if view is active or not and connect * signal to get notified if toggle state changes to proxy signal */ g_signal_connect_swapped(button, "toggled", G_CALLBACK(_xfdashboard_view_selector_on_toggle_button_state_changed), self); isActive=(xfdashboard_viewpad_get_active_view(priv->viewpad)==inView); xfdashboard_toggle_button_set_toggle_state(XFDASHBOARD_TOGGLE_BUTTON(button), isActive); /* Add tooltip */ action=xfdashboard_tooltip_action_new(); xfdashboard_tooltip_action_set_text(XFDASHBOARD_TOOLTIP_ACTION(action), viewName); clutter_actor_add_action(button, action); /* If view is disabled hide button otherwise show and connect signals * to get notified if enabled state has changed */ if(!xfdashboard_view_get_enabled(inView)) clutter_actor_hide(button); else clutter_actor_show(button); g_signal_connect(inView, "disabled", G_CALLBACK(_xfdashboard_view_selector_on_view_enable_state_changed), button); g_signal_connect(inView, "enabled", G_CALLBACK(_xfdashboard_view_selector_on_view_enable_state_changed), button); g_signal_connect(inView, "activated", G_CALLBACK(_xfdashboard_view_selector_on_view_activated), button); g_signal_connect(inView, "deactivated", G_CALLBACK(_xfdashboard_view_selector_on_view_deactivated), button); g_signal_connect(inView, "icon-changed", G_CALLBACK(_xfdashboard_view_selector_on_view_icon_changed), button); g_signal_connect(inView, "name-changed", G_CALLBACK(_xfdashboard_view_selector_on_view_name_changed), action); /* Add button as child actor */ clutter_actor_add_child(CLUTTER_ACTOR(self), button); /* Release allocated resources */ g_free(viewName); }
static void add_drag_object (ClutterActor *target) { ClutterActor *parent; if (drag == NULL) { ClutterAction *action; drag = clutter_actor_new (); clutter_actor_set_background_color (drag, CLUTTER_COLOR_LightSkyBlue); clutter_actor_set_size (drag, HANDLE_SIZE, HANDLE_SIZE); clutter_actor_set_position (drag, (TARGET_SIZE - HANDLE_SIZE) / 2.0, (TARGET_SIZE - HANDLE_SIZE) / 2.0); clutter_actor_set_reactive (drag, TRUE); action = clutter_drag_action_new (); g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL); g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL); clutter_actor_add_action (drag, action); } parent = clutter_actor_get_parent (drag); if (parent == target) { clutter_actor_save_easing_state (target); clutter_actor_set_easing_mode (target, CLUTTER_LINEAR); clutter_actor_set_opacity (target, 255); clutter_actor_restore_easing_state (target); return; } g_object_ref (drag); if (parent != NULL && parent != stage) { clutter_actor_remove_child (parent, drag); clutter_actor_save_easing_state (parent); clutter_actor_set_easing_mode (parent, CLUTTER_LINEAR); clutter_actor_set_opacity (parent, 64); clutter_actor_restore_easing_state (parent); } clutter_actor_add_child (target, drag); clutter_actor_save_easing_state (target); clutter_actor_set_easing_mode (target, CLUTTER_LINEAR); clutter_actor_set_opacity (target, 255); clutter_actor_restore_easing_state (target); g_object_unref (drag); }
static void slider_init(Slider *self) { SliderPrivate *priv; ClutterLayoutManager *layout; priv = self->priv = SLIDER_GET_PRIVATE(self); priv->pos = 0.5; layout = clutter_bin_layout_new( CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); ClutterColor col = {127, 127, 127, 255}; priv->box = clutter_actor_new(); clutter_actor_set_background_color(priv->box, &col); clutter_actor_set_layout_manager(priv->box, layout); clutter_actor_set_reactive(CLUTTER_ACTOR(priv->box), TRUE); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->box); col.red = 40; col.green = 40; col.blue = 70; priv->handle = clutter_actor_new(); clutter_actor_set_background_color(priv->handle, &col); clutter_actor_set_layout_manager(priv->handle, layout); clutter_actor_set_reactive(CLUTTER_ACTOR(priv->handle), TRUE); clutter_actor_add_child(CLUTTER_ACTOR(self), priv->handle); priv->track_clicked = clutter_click_action_new(); clutter_actor_add_action(CLUTTER_ACTOR(priv->box), priv->track_clicked); g_signal_connect( priv->track_clicked, "clicked", G_CALLBACK(slider_clicked), self); priv->handle_dragged = clutter_drag_action_new(); clutter_actor_add_action(CLUTTER_ACTOR(priv->handle), priv->handle_dragged); g_signal_connect( priv->handle_dragged, "drag-motion", G_CALLBACK(handle_dragged), self); g_signal_connect(priv->box, "scroll-event", G_CALLBACK(scrolled), self); g_signal_connect(priv->handle, "scroll-event", G_CALLBACK(scrolled), self); }
/* Object initialization * Create private structure and set up default values */ static void xfdashboard_button_init(XfdashboardButton *self) { XfdashboardButtonPrivate *priv; priv=self->priv=XFDASHBOARD_BUTTON_GET_PRIVATE(self); /* This actor reacts on events */ clutter_actor_set_reactive(CLUTTER_ACTOR(self), TRUE); /* Connect signals */ priv->clickAction=xfdashboard_click_action_new(); clutter_actor_add_action(CLUTTER_ACTOR(self), priv->clickAction); g_signal_connect(priv->clickAction, "clicked", G_CALLBACK(_xfdashboard_button_clicked), NULL); }
void test_clutter(){ ClutterActor *stage; ClutterAction *action; stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(app.stage)); action = clutter_gesture_action_new(); clutter_actor_add_action(CLUTTER_ACTOR(stage), action); g_signal_connect(action, "gesture-begin", G_CALLBACK(on_gesture_begin), NULL); g_signal_connect(action, "gesture-progress", G_CALLBACK(on_gesture_progress), NULL); g_signal_connect(action, "gesture-end", G_CALLBACK(on_gesture_end), NULL); //~ g_signal_connect(stage, "button-press-event", G_CALLBACK(on_button_press), NULL); tool = TOOL_RECTANGLE; }
/* object init: create a private structure and pack * composed ClutterActors into it */ static void cb_button_init (CbButton *self) { CbButtonPrivate *priv; ClutterLayoutManager *layout; priv = self->priv = CB_BUTTON_GET_PRIVATE (self); clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE); /* the only child of this actor is a ClutterBox with a * ClutterBinLayout: painting and allocation of the actor basically * involves painting and allocating this child box */ layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER); priv->child = clutter_box_new (layout); /* set the parent of the ClutterBox to this instance */ clutter_actor_set_parent (priv->child, CLUTTER_ACTOR (self)); /* add text label to the button; see the ClutterText API docs * for more information about available properties */ priv->label = g_object_new (CLUTTER_TYPE_TEXT, "line-alignment", PANGO_ALIGN_CENTER, "ellipsize", PANGO_ELLIPSIZE_END, NULL); clutter_container_add_actor (CLUTTER_CONTAINER (priv->child), priv->label); /* add a ClutterClickAction on this actor, so we can proxy its * "clicked" signal into a signal from this actor */ priv->click_action = clutter_click_action_new (); clutter_actor_add_action (CLUTTER_ACTOR (self), priv->click_action); g_signal_connect (priv->click_action, "clicked", G_CALLBACK (cb_button_clicked), NULL); }
/* Set menu item actor */ static void _xfdashboard_popup_menu_item_meta_set_menu_item(XfdashboardPopupMenuItemMeta *self, ClutterActor *inMenuItem) { XfdashboardPopupMenuItemMetaPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_POPUP_MENU_ITEM_META(self)); g_return_if_fail(CLUTTER_IS_ACTOR(inMenuItem)); priv=self->priv; /* This function can only be called once so no menu item must be set yet */ if(priv->menuItem || priv->clickAction) { g_critical(_("Attempting to set menu item %s at %s but it is already set."), G_OBJECT_TYPE_NAME(inMenuItem), G_OBJECT_TYPE_NAME(self)); return; } /* Set value if changed */ if(priv->menuItem!=inMenuItem) { /* Set value */ priv->menuItem=inMenuItem; g_object_add_weak_pointer(G_OBJECT(priv->menuItem), (gpointer*)&priv->menuItem); /* Apply style for menu item if possible */ if(XFDASHBOARD_IS_STYLABLE(priv->menuItem)) { xfdashboard_stylable_add_class(XFDASHBOARD_STYLABLE(priv->menuItem), "popup-menu-item"); } /* Create click action and add it to menu item actor */ priv->clickAction=xfdashboard_click_action_new(); g_signal_connect_swapped(priv->clickAction, "clicked", G_CALLBACK(_xfdashboard_popup_menu_item_meta_clicked), self); clutter_actor_add_action(priv->menuItem, priv->clickAction); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardPopupMenuItemMetaProperties[PROP_MENU_ITEM]); } }
static void clutter_widget_init ( ClutterWidget *_self ) { ClutterWidgetPrivate *priv; ClutterAction *action; ClutterState *state; _self->priv = priv = CLUTTER_WIDGET_GET_PRIVATE (_self); priv->borderColor = *CLUTTER_COLOR_LightGray; clutter_actor_set_reactive ( CLUTTER_ACTOR(_self), TRUE ); // TODO: only in drag-bar { action = clutter_drag_action_new (); clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action), 0, 0); clutter_drag_action_set_drag_axis ( CLUTTER_DRAG_ACTION (action), CLUTTER_DRAG_X_AXIS&CLUTTER_DRAG_Y_AXIS ); g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL); g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL); clutter_actor_add_action (CLUTTER_ACTOR(_self), action); clutter_actor_add_effect_with_name (CLUTTER_ACTOR(_self), "disable", clutter_desaturate_effect_new (0.0)); // } TODO end // init state machine state = clutter_state_new (); g_object_set_data_full ( G_OBJECT (_self), "hover-state-machine", state, g_object_unref ); g_signal_connect ( _self, "enter-event", G_CALLBACK (on_enter), state ); g_signal_connect ( _self, "leave-event", G_CALLBACK (on_leave), state ); clutter_state_set ( state, NULL, "normal", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_DarkGray, NULL ); clutter_state_set ( state, NULL, "hover", _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_LightSkyBlue, NULL ); clutter_state_set_duration ( state, NULL, NULL, 200 ); // set init state clutter_state_set_state (state, "normal"); }
/* A workspace was created */ static void _xfdashboard_workspace_selector_on_workspace_added(XfdashboardWorkspaceSelector *self, XfdashboardWindowTrackerWorkspace *inWorkspace, gpointer inUserData) { ClutterActor *actor; gint index; ClutterAction *action; g_return_if_fail(XFDASHBOARD_IS_WORKSPACE_SELECTOR(self)); g_return_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WORKSPACE(inWorkspace)); /* Get index of workspace for insertion */ index=xfdashboard_window_tracker_workspace_get_number(inWorkspace); /* Create new live workspace actor and insert at index */ actor=xfdashboard_live_workspace_new_for_workspace(inWorkspace); g_signal_connect_swapped(actor, "clicked", G_CALLBACK(_xfdashboard_workspace_selector_on_workspace_clicked), self); clutter_actor_insert_child_at_index(CLUTTER_ACTOR(self), actor, index); action=xfdashboard_drop_action_new(); clutter_actor_add_action(actor, action); g_signal_connect_swapped(action, "begin", G_CALLBACK(_xfdashboard_workspace_selector_on_drop_begin), actor); g_signal_connect_swapped(action, "drop", G_CALLBACK(_xfdashboard_workspace_selector_on_drop_drop), actor); }
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; }
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 *stage; ClutterActor *texture; gchar *image_path; GError *error = NULL; if (argc < 2) { g_print ("Usage: %s <path to image file>\n", argv[0]); exit (EXIT_FAILURE); } image_path = 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_actor_set_reactive (texture, TRUE); clutter_actor_set_width (texture, STAGE_SIDE); clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture), TRUE); clutter_actor_add_action (texture, clutter_drag_action_new ()); g_object_set (G_OBJECT (texture), "scale-gravity", CLUTTER_GRAVITY_NORTH_WEST, NULL); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), image_path, &error); if (error != NULL) { g_warning ("Error loading %s\n%s", image_path, error->message); g_error_free (error); exit (EXIT_FAILURE); } clutter_actor_set_y (texture, (STAGE_SIDE - clutter_actor_get_height (texture)) * 0.5); g_signal_connect (texture, "button-release-event", G_CALLBACK (clicked_cb), NULL); g_signal_connect_swapped (stage, "key-press-event", G_CALLBACK (key_press_cb), texture); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
static void on_gesture_end(ClutterGestureAction *action, ClutterActor *stage, gpointer data) { ClutterActor *new_actor, *texture, *actor; gfloat x, y, w, h; GError *error = NULL; GdkColor color; guint16 alpha; gint iw = 125; gint ih = 126; gboolean repeat_x = FALSE; gboolean repeat_y = TRUE; guint bgr; new_actor = tmpRect; gtk_color_button_get_color(GTK_COLOR_BUTTON(app.colorpicker), &color); alpha = gtk_color_button_get_alpha(GTK_COLOR_BUTTON(app.colorpicker)); ClutterColor col = { CLAMP(((color.red / 65535.0) * 255), 0, 255), CLAMP(((color.green / 65535.0) * 255), 0, 255), CLAMP(((color.blue / 65535.0) * 255), 0, 255), CLAMP(((alpha / 65535.0) * 255), 0, 255), }; clutter_rectangle_set_color(CLUTTER_RECTANGLE(new_actor), &col); clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(new_actor), 0); tmpRect = NULL; clutter_actor_get_position(new_actor, &x, &y); clutter_actor_get_size(new_actor, &w, &h); if (background_image_file != NULL){ texture = clutter_texture_new_from_file(background_image_file, &error); if (error != NULL){ g_print("Loading image failed\n"); g_error_free(error); } clutter_actor_set_position(texture, x, y); clutter_actor_set_size(texture, w, h); clutter_actor_add_child(stage, texture); clutter_actor_show(texture); bgr = gtk_combo_box_get_active(GTK_COMBO_BOX(app.background_repeat_select)); switch (bgr){ case 0: repeat_x = repeat_y = FALSE; break; case 1: repeat_x = TRUE; repeat_y = FALSE; break; case 2: repeat_x = FALSE; repeat_y = TRUE; break; case 3: repeat_x = repeat_y = TRUE; break; } clutter_texture_get_base_size(CLUTTER_TEXTURE(texture), &iw, &ih); clutter_actor_set_clip(texture, 0, 0, repeat_x ? w : iw, repeat_y ? h : ih); clutter_texture_set_sync_size(CLUTTER_TEXTURE(texture), TRUE); clutter_texture_set_repeat(CLUTTER_TEXTURE(texture), TRUE, TRUE); clutter_texture_set_keep_aspect_ratio(CLUTTER_TEXTURE(texture), TRUE); actor = texture; clutter_actor_destroy(new_actor); } else { actor = new_actor; } tool = TOOL_SELECT; clutter_actor_add_action(actor, clutter_drag_action_new()); clutter_actor_set_reactive(actor, TRUE); actors = g_list_append(actors, actor); GdkWindow *gdk_window; gdk_window = gtk_widget_get_window(app.stage); gdk_window_set_cursor(gdk_window, NULL); }
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; }
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; }