static void on_gesture_begin(ClutterGestureAction *action, ClutterActor *stage, gpointer data) { gfloat x, y; ClutterColor transp = {0, 0, 0, 0}; ClutterColor grey = {30, 30, 30, 128}; switch (tool){ case TOOL_RECTANGLE: clutter_gesture_action_get_press_coords(action, 0, &x, &y); tmpRect = clutter_rectangle_new_with_color(&transp); clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(tmpRect), 1); clutter_rectangle_set_border_color(CLUTTER_RECTANGLE(tmpRect), &grey); clutter_actor_set_position(tmpRect, x, y); clutter_actor_set_size(tmpRect, 0, 0); clutter_actor_add_child(CLUTTER_ACTOR(stage), tmpRect); clutter_actor_show(tmpRect); x_0 = x; y_0 = y; break; default: break; } }
static void gml_gtk_widget_create_rect (ClutterActor *parent, JsonObject *obj) { GList *l = NULL; GList *p = NULL; ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; ClutterActor *rect = clutter_rectangle_new (); l = json_object_get_members (obj); for (p = l; p; p = p->next) { if (!strcmp (p->data, "width")) { clutter_actor_set_width (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "height")) { clutter_actor_set_height (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "x")) { clutter_actor_set_x (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "y")) { clutter_actor_set_y (rect, (float)json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "color")) { clutter_color_from_string (&(color), json_object_get_string_member (obj, p->data)); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &color); } else if (!strcmp (p->data, "border.width")) { clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), json_object_get_int_member (obj, p->data)); } else if (!strcmp (p->data, "border.color")) { clutter_color_from_string (&(color), json_object_get_string_member (obj, p->data)); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect), &color); } } clutter_container_add_actor (CLUTTER_CONTAINER (parent), rect); }
static void enter_event (ClutterActor *actor, ClutterEvent *event, gpointer data) { ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (actor), 2); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (actor), &color); hover_actor = actor; }
void on_timeline_rotation_new_frame(ClutterTimeline * timeline, gint frame_num, gpointer data) { if((++rotation_angle) >= 360) rotation_angle = 0; clutter_actor_set_rotation(rect, CLUTTER_X_AXIS, rotation_angle, 0, 0, 0); if((++color_change_count) >= 100) color_change_count = 0; if(color_change_count == 0) { ClutterColor color = {0xFF, 0xFF, 0xFF, 0xFF}; //White clutter_rectangle_set_color(CLUTTER_RECTANGLE(rect), &color); } else if(color_change_count == 50) { ClutterColor color = {0x00, 0xFF, 0xFF, 0xFF}; //Purple clutter_rectangle_set_color(CLUTTER_RECTANGLE(rect), &color); } }
static void clutter_rectangle_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { ClutterRectangle *rectangle = CLUTTER_RECTANGLE(object); ClutterColor color; switch (prop_id) { case PROP_COLOR: clutter_rectangle_get_color (rectangle, &color); g_value_set_boxed (value, &color); break; case PROP_BORDER_COLOR: clutter_rectangle_get_border_color (rectangle, &color); g_value_set_boxed (value, &color); break; case PROP_BORDER_WIDTH: g_value_set_uint (value, rectangle->priv->border_width); break; case PROP_HAS_BORDER: g_value_set_boolean (value, rectangle->priv->has_border); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void on_drag_begin (ClutterDragAction *action, ClutterActor *actor, gfloat event_x, gfloat event_y, ClutterModifierType modifiers) { gboolean is_copy = (modifiers & CLUTTER_SHIFT_MASK) ? TRUE : FALSE; ClutterActor *drag_handle = NULL; if (is_copy) { ClutterActor *stage = clutter_actor_get_stage (actor); drag_handle = clutter_rectangle_new (); clutter_actor_set_size (drag_handle, 48, 48); clutter_rectangle_set_color (CLUTTER_RECTANGLE (drag_handle), CLUTTER_COLOR_DarkSkyBlue); clutter_container_add_actor (CLUTTER_CONTAINER (stage), drag_handle); clutter_actor_set_position (drag_handle, event_x, event_y); } else drag_handle = actor; clutter_drag_action_set_drag_handle (action, drag_handle); /* fully desaturate the actor */ clutter_actor_animate (actor, CLUTTER_LINEAR, 150, "@effects.disable.factor", 1.0, NULL); }
static void leave_event (ClutterActor *actor, ClutterEvent *event, gpointer data) { clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (actor), 0); hover_actor = NULL; }
static void glide_theme_preview_actor_add_border (GlideThemePreviewActor *preview) { ClutterActor *border = clutter_rectangle_new(); ClutterColor trans = {0x00,0x00,0x00,0x00}; ClutterColor grey = {0xdf,0xdf,0xdf,0xcc}; clutter_rectangle_set_color (CLUTTER_RECTANGLE (border), &trans); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (border), &grey); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (border), 2); clutter_actor_set_size (border, 160, 120); clutter_actor_set_position (border, 0, 0); preview->priv->border = (ClutterActor *)g_object_ref ((GObject *)border); }
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; }
static void color_prop_value_cb (MxSlider *slider, GParamSpec *pspec, ColorPropComp *prop_comp) { float value = mx_slider_get_value (slider) * 255.0f + 0.5f; ColorProp *prop = prop_comp->prop; if (prop->object) { ClutterColor *color; g_object_get (prop->object, prop->prop_name, &color, NULL); ((guint8 *) color)[prop_comp->comp_num] = value; clutter_rectangle_set_color (CLUTTER_RECTANGLE (prop->rect), color); g_object_set (prop->object, prop->prop_name, color, NULL); clutter_color_free (color); } else { ClutterColor color; CoglColor cogl_color; prop->get_func (prop->material, &cogl_color); color.red = cogl_color_get_red_byte (&cogl_color); color.green = cogl_color_get_green_byte (&cogl_color); color.blue = cogl_color_get_blue_byte (&cogl_color); color.alpha = 255; ((guint8 *) &color)[prop_comp->comp_num] = value; cogl_color_set_from_4ub (&cogl_color, color.red, color.green, color.blue, 255); clutter_rectangle_set_color (CLUTTER_RECTANGLE (prop->rect), &color); prop->set_func (prop->material, &cogl_color); } update_prop_comp_label (prop_comp, value); }
static gboolean button_press_color_cb(ClutterActor *actor, ClutterEvent *event, gpointer user_data) { App *app = (App *) user_data; ClutterColor color; clutter_rectangle_get_color(CLUTTER_RECTANGLE(actor), &color); int r = color.red; int g = color.green; int b = color.blue; app->setColor(r, g, b); app->setSelectionPosition(clutter_actor_get_x(actor), clutter_actor_get_y(actor)); return TRUE; // handled. Do not propagate to stage }
gboolean cs_selected_lasso_start (ClutterActor *actor, ClutterEvent *event) { ClutterModifierType state = event->button.modifier_state; g_assert (lasso == NULL); { ClutterColor lassocolor = {0xff,0x0,0x0,0x11}; ClutterColor lassobordercolor = {0xff,0x0,0x0,0x88}; lasso = clutter_rectangle_new_with_color (&lassocolor); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (lasso), &lassobordercolor); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (lasso), LASSO_BORDER); clutter_container_add_actor (CLUTTER_CONTAINER (cs->parasite_root), lasso); } lx = event->button.x; ly = event->button.y; clutter_actor_set_position (lasso, lx-LASSO_BORDER, ly-LASSO_BORDER); clutter_actor_set_size (lasso, LASSO_BORDER*2, LASSO_BORDER*2); manipulate_x = event->button.x; manipulate_y = event->button.y; g_signal_connect (clutter_actor_get_stage (actor), "captured-event", G_CALLBACK (manipulate_lasso_capture), actor); undo = g_string_new (""); redo = g_string_new (""); SELECT_ACTION_PRE2(); if (!((state & CLUTTER_SHIFT_MASK) || (state & CLUTTER_CONTROL_MASK))) { cs_selected_clear (); } return TRUE; }
static void add_color_prop_base (ClutterActor *table, const char *name, ColorProp *prop, const ClutterColor *value) { int table_y = mx_table_get_row_count (MX_TABLE (table)); ClutterActor *label; static const char *color_names[] = { "red", "green", "blue" }; int i; label = mx_label_new_with_text (name); mx_table_add_actor (MX_TABLE (table), label, table_y, 0); prop->rect = clutter_rectangle_new (); clutter_rectangle_set_color (CLUTTER_RECTANGLE (prop->rect), value); clutter_actor_set_size (prop->rect, 20, 0); mx_table_add_actor (MX_TABLE (table), prop->rect, table_y++, 1); for (i = 0; i < G_N_ELEMENTS (color_names); i++) { ClutterActor *slider; char *label_name = g_strconcat (name, " ", color_names[i], NULL); ColorPropComp *prop_comp = g_slice_new (ColorPropComp); label = mx_label_new_with_text (label_name); mx_table_add_actor (MX_TABLE (table), label, table_y, 0); g_free (label_name); slider = mx_slider_new (); mx_table_add_actor (MX_TABLE (table), slider, table_y, 1); mx_slider_set_value (MX_SLIDER (slider), ((guint8 *) value)[i] / 255.0f); prop_comp->comp_num = i; prop_comp->prop = prop; prop_comp->label = mx_label_new (); mx_table_add_actor (MX_TABLE (table), prop_comp->label, table_y, 2); update_prop_comp_label (prop_comp, ((guint8 *) value)[i]); g_signal_connect_data (slider, "notify::value", G_CALLBACK (color_prop_value_cb), prop_comp, (GClosureNotify) color_prop_comp_free, 0); table_y++; } }
static void droppable_group_init (DroppableGroup *group) { clutter_actor_set_opacity (CLUTTER_ACTOR (group), 128); group->background = clutter_rectangle_new (); clutter_container_add_actor (CLUTTER_CONTAINER (group), group->background); clutter_rectangle_set_color (CLUTTER_RECTANGLE (group->background), &default_background_color); clutter_actor_set_size (group->background, 200, 200); g_signal_connect (group, "actor-added", G_CALLBACK (on_actor_added), NULL); }
static ClutterActor * create_source (void) { int x, y; ClutterActor *group = clutter_group_new (); /* Create a group with a different coloured rectangle at each corner */ for (y = 0; y < SOURCE_DIVISIONS_Y; y++) for (x = 0; x < SOURCE_DIVISIONS_X; x++) { ClutterActor *rect = clutter_rectangle_new (); clutter_actor_set_size (rect, DIVISION_WIDTH, DIVISION_HEIGHT); clutter_actor_set_position (rect, DIVISION_WIDTH * x, DIVISION_HEIGHT * y); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), corner_colors + (y * SOURCE_DIVISIONS_X + x)); clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); } return group; }
HandCar * handcar_new() { HandCar *all = g_new0(HandCar, 1); ClutterColor rect_color = { 0xdd, 0xdd, 0xdd, 0xee }; ClutterColor rect_border_color = { 0xee, 0xee, 0xee, 0xdd }; ClutterColor rect_entry_color = { 0xef, 0xef, 0xef, 0xee }; ClutterColor rect_entry_border_color = { 0x96, 0x96, 0x96, 0xaa }; ClutterColor label_color = { 0x55, 0x00, 0x00, 0xff }; ClutterColor time_color = { 0x00, 0x33, 0x55, 0xbb }; GError *error = NULL; all->play = gdk_pixbuf_new_from_file("imgs/start.svg", NULL); all->previous = gdk_pixbuf_new_from_file("imgs/backward.svg", NULL); all->next = gdk_pixbuf_new_from_file("imgs/forward.svg", NULL); all->stop = gdk_pixbuf_new_from_file("imgs/stop.svg", NULL); all->time = 0; all->playing = FALSE; all->player = gst_element_factory_make ("playbin", "player"); if (error) g_error ("FUDEU: %s", error->message); all->label_actor = clutter_label_new_full("DejaVu Sans", "Blind Guardian - <b>Mirror Mirror</b>", &label_color); clutter_label_set_use_markup (CLUTTER_LABEL(all->label_actor), TRUE); all->label_time = clutter_label_new_full("DejaVu Sans", "00:00", &time_color); clutter_label_set_use_markup (CLUTTER_LABEL(all->label_time), TRUE); clutter_actor_set_position (all->label_actor, 10, 15); clutter_actor_set_position (all->label_time, STAGE_WIDTH - 80, STAGE_HEIGHT - 20); all->btn_actor_play = clutter_texture_new_from_pixbuf (all->play); all->btn_actor_next = clutter_texture_new_from_pixbuf (all->next); all->btn_actor_previous = clutter_texture_new_from_pixbuf (all->previous); clutter_actor_set_position (all->btn_actor_previous, 60, 50); clutter_actor_set_position (all->btn_actor_play, 140, 50); clutter_actor_set_position (all->btn_actor_next, 200, 50); all->rect1 = clutter_rectangle_new_with_color (&rect_color); clutter_actor_set_size (all->rect1, 320, 30); clutter_actor_set_position (all->rect1, -5, 10); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE(all->rect1), 4); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE(all->rect1), &rect_border_color); all->rect2 = clutter_rectangle_new_with_color (&rect_entry_color); clutter_actor_set_size (all->rect2, 270, 20); clutter_actor_set_position (all->rect2, 20, STAGE_HEIGHT - 50); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE(all->rect2), 1); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE(all->rect2), &rect_entry_border_color); all->rect3 = clutter_rectangle_new_with_color (&rect_entry_color); clutter_actor_set_size (all->rect3, 270, 203); clutter_actor_set_position (all->rect3, 20, 120); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE(all->rect3), 1); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE(all->rect3), &rect_entry_border_color); all->entry_actor = clutter_entry_new_full ("Monospace", "Teste", &label_color); clutter_actor_set_size (all->entry_actor, 270, 20); clutter_actor_set_position (all->entry_actor, 20, STAGE_HEIGHT - 50); all->video = clutter_gst_video_texture_new (); clutter_actor_set_size (all->video, 270, 203); clutter_actor_set_position (all->video, 20, 120); clutter_actor_set_opacity (all->video, 0xff); // all->clutter_group_add_many (all->container1, all->rect1); all->videosink = clutter_gst_video_sink_new (CLUTTER_TEXTURE(all->video)); g_object_set (all->player, "video-sink", all->videosink, NULL); all->format = GST_FORMAT_TIME; clutter_actor_show(all->btn_actor_play); clutter_actor_show(all->btn_actor_next); clutter_actor_show(all->btn_actor_previous); clutter_actor_show(all->label_actor); clutter_actor_show(all->label_time); clutter_actor_show(all->rect1); clutter_actor_show(all->rect2); clutter_actor_show(all->rect3); clutter_actor_show(all->video); clutter_actor_show(all->entry_actor); return all; }
G_MODULE_EXPORT int test_behave_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; ClutterBehaviour *o_behave, *p_behave; ClutterActor *stage; ClutterActor *group, *rect, *hand; ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff }; ClutterColor rect_bg_color = { 0x33, 0x22, 0x22, 0xff }; ClutterColor rect_border_color = { 0, 0, 0, 0 }; int i; path_t path_type = PATH_POLY; const char *knots_poly = ("M 0, 0 L 0, 300 L 300, 300 " "L 300, 0 L 0, 0"); /* A spiral created with inkscake */ const char *knots_bspline = "M 34.285713,35.219326 " "C 44.026891,43.384723 28.084874,52.378758 20.714286,51.409804 " "C 0.7404474,48.783999 -4.6171866,23.967448 1.904757,8.0764719 " "C 13.570984,-20.348756 49.798303,-26.746504 74.999994,-13.352108 " "C 111.98449,6.3047056 119.56591,55.259271 99.047626,89.505034 " "C 71.699974,135.14925 9.6251774,143.91924 -33.571422,116.17172 " "C -87.929934,81.254291 -97.88804,5.8941057 -62.857155,-46.209236 " "C -20.430061,-109.31336 68.300385,-120.45954 129.2857,-78.114021 " "C 201.15479,-28.21129 213.48932,73.938876 163.80954,143.79074 " "C 106.45226,224.43749 -9.1490153,237.96076 -87.85713,180.93363 " "C -177.29029,116.13577 -192.00272,-12.937817 -127.61907,-100.49494 " "C -55.390344,-198.72081 87.170553,-214.62275 183.57141,-142.87593 " "C 290.59464,-63.223369 307.68641,92.835839 228.57145,198.07645"; for (i = 0; i < argc; ++i) { if (!strncmp (argv[i], "--path", 6)) { if (!strncmp (argv[i] + 7, "poly", 4)) path_type = PATH_POLY; else if (!strncmp (argv[i] + 7, "bspline", 7)) path_type = PATH_BSPLINE; else if (!strncmp (argv[i] + 7, "ellipse", 7)) path_type = PATH_ELLIPSE; } else if (!strncmp (argv[i], "--help", 6)) { printf ("behave [--path=poly|ellipse|bspline]\n"); exit (0); } } clutter_init (&argc, &argv); stage = clutter_stage_get_default (); clutter_stage_hide_cursor (CLUTTER_STAGE (stage)); g_signal_connect (stage, "button-press-event", G_CALLBACK (button_press_cb), NULL); g_signal_connect (stage, "scroll-event", G_CALLBACK (scroll_event_cb), NULL); g_signal_connect (stage, "key-press-event", G_CALLBACK (clutter_main_quit), NULL); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); /* Make a hand */ group = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); clutter_actor_show (group); hand = clutter_texture_new_from_file ("redhand.png", NULL); if (hand == NULL) { g_error("pixbuf load failed"); return 1; } clutter_actor_set_position (hand, 0, 0); clutter_actor_show (hand); rect = clutter_rectangle_new (); clutter_actor_set_position (rect, 0, 0); clutter_actor_set_size (rect, clutter_actor_get_width (hand), clutter_actor_get_height (hand)); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_bg_color); clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), 10); clutter_color_from_string (&rect_border_color, "DarkSlateGray"); clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect), &rect_border_color); clutter_actor_show (rect); clutter_container_add (CLUTTER_CONTAINER (group), rect, hand, NULL); /* Make a timeline */ timeline = clutter_timeline_new (4000); /* num frames, fps */ clutter_timeline_set_loop (timeline, TRUE); g_signal_connect (timeline, "completed", G_CALLBACK (timeline_completed), NULL); /* Set an alpha func to power behaviour - ramp is constant rise */ alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); /* Create a behaviour for that alpha */ o_behave = clutter_behaviour_opacity_new (alpha, 0X33, 0xff); /* Apply it to our actor */ clutter_behaviour_apply (o_behave, group); /* Make a path behaviour and apply that too */ switch (path_type) { case PATH_POLY: { ClutterPath *path = clutter_path_new (); clutter_path_set_description (path, knots_poly); p_behave = clutter_behaviour_path_new (alpha, path); } break; case PATH_ELLIPSE: p_behave = clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300, CLUTTER_ROTATE_CW, 0.0, 360.0); clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave), CLUTTER_X_AXIS, 45.0); clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave), CLUTTER_Z_AXIS, 45.0); break; case PATH_BSPLINE: { ClutterPath *path = clutter_path_new (); clutter_path_set_description (path, knots_bspline); p_behave = clutter_behaviour_path_new (alpha, path); } break; } clutter_behaviour_apply (p_behave, group); /* start the timeline and thus the animations */ clutter_timeline_start (timeline); clutter_actor_show_all (stage); clutter_main(); g_object_unref (o_behave); g_object_unref (p_behave); return 0; }
static void clutter_rectangle_paint (ClutterActor *self) { ClutterRectangle *rectangle = CLUTTER_RECTANGLE(self); ClutterRectanglePrivate *priv; ClutterGeometry geom; ClutterColor tmp_col; rectangle = CLUTTER_RECTANGLE(self); priv = rectangle->priv; CLUTTER_NOTE (PAINT, "painting rect '%s'", clutter_actor_get_name (self) ? clutter_actor_get_name (self) : "unknown"); clutter_actor_get_allocation_geometry (self, &geom); CLUTTER_NOTE (PAINT, "paint to x1: %i, y1: %i x2: %i, y2: %i " "opacity: %i", geom.x, geom.y, geom.x+geom.width, geom.y+geom.height, clutter_actor_get_opacity (self)); /* parent paint call will have translated us into position so * paint from 0, 0 */ if (priv->has_border) { tmp_col.red = priv->border_color.red; tmp_col.green = priv->border_color.green; tmp_col.blue = priv->border_color.blue; tmp_col.alpha = clutter_actor_get_paint_opacity (self) * priv->border_color.alpha / 255; cogl_color (&tmp_col); /* this sucks, but it's the only way to make a border */ cogl_rectangle (priv->border_width, 0, geom.width - priv->border_width, priv->border_width); cogl_rectangle (geom.width - priv->border_width, priv->border_width, priv->border_width, geom.height - priv->border_width); cogl_rectangle (0, geom.height - priv->border_width, geom.width - priv->border_width, priv->border_width); cogl_rectangle (0, 0, priv->border_width, geom.height - priv->border_width); tmp_col.red = priv->color.red; tmp_col.green = priv->color.green; tmp_col.blue = priv->color.blue; tmp_col.alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; cogl_color (&tmp_col); cogl_rectangle (priv->border_width, priv->border_width, geom.width - priv->border_width * 2, geom.height - priv->border_width * 2); } else { tmp_col.red = priv->color.red; tmp_col.green = priv->color.green; tmp_col.blue = priv->color.blue; tmp_col.alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; cogl_color (&tmp_col); cogl_rectangle (0, 0, geom.width, geom.height); } }
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); }
void opt_show_toggle_position (OptShow *show) { OptShowPrivate *priv; ClutterActor *stage; ClutterGeometry stage_geom; g_return_if_fail (OPT_IS_SHOW (show)); priv = show->priv; stage = clutter_stage_get_default (); clutter_actor_get_geometry (stage, &stage_geom); if (!priv->position_label) { ClutterActor *rect; ClutterActor *label; ClutterColor rect_color = { 0x00, 0x00, 0x00, 0x33 }; ClutterColor label_color = { 0xff, 0xff, 0xff, 0xee }; ClutterGeometry rect_geom; rect = clutter_rectangle_new (); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color); rect_geom.width = 102; rect_geom.height = 77; rect_geom.x = stage_geom.width / 2 - rect_geom.width / 2; rect_geom.y = stage_geom.height - rect_geom.height - 20; clutter_actor_set_geometry (rect, &rect_geom); label = clutter_text_new_with_text ("Sans Bold 20", "0/0"); clutter_text_set_color (CLUTTER_TEXT (label), &label_color); clutter_actor_set_position (label, rect_geom.x + 10, rect_geom.y + 10); clutter_group_add_many (CLUTTER_GROUP (stage), rect, label, NULL); priv->position_label = label; priv->position_rect = rect; priv->position_label_visible = FALSE; } if (!priv->position_label_visible) { priv->position_label_visible = TRUE; opt_show_update_position_label (show); clutter_actor_show (priv->position_rect); clutter_actor_show (priv->position_label); } else { clutter_actor_hide (priv->position_label); clutter_actor_hide (priv->position_rect); priv->position_label_visible = FALSE; } }
G_MODULE_EXPORT gint test_shader_main (gint argc, gchar *argv[]) { ClutterActor *actor; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; ClutterShader *shader; GError *error; gchar *file; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Shaders"); clutter_actor_set_size (stage, 512, 384); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); g_print ("applying shaders[%i] named '%s'\n", shader_no, shaders[shader_no].name); shader = clutter_shader_new (); error = NULL; clutter_shader_set_fragment_source (shader, shaders[shader_no].source, -1); clutter_shader_compile (shader, &error); if (error) { g_print ("unable to load shaders[%d] named '%s': %s\n", shader_no, shaders[shader_no].name, error->message); g_error_free (error); return EXIT_FAILURE; } clutter_stage_set_title (CLUTTER_STAGE (stage), "Shader Test"); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); #ifndef TEST_GROUP actor = clutter_texture_new_from_file (file, &error); if (!actor) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); #else actor = clutter_group_new (); { ClutterActor *child1, *child2, *child3, *child4; ClutterColor color = { 0xff, 0x22, 0x66, 0x99 }; child1 = clutter_texture_new_from_file (file, &error); if (!child1) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); child2 = clutter_texture_new_from_file (file, &error); if (!child2) g_error("pixbuf load failed: %s", error ? error->message : "Unknown"); child3 = clutter_rectangle_new (); child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff"); clutter_rectangle_set_color (CLUTTER_RECTANGLE (child3), &color); clutter_actor_set_size (child3, 50, 50); clutter_actor_set_position (child1, 0, 0); clutter_actor_set_position (child2, 50, 100); clutter_actor_set_position (child3, 30, -30); clutter_actor_set_position (child4, -50, 20); clutter_container_add (CLUTTER_CONTAINER (actor), child1, child2, child3, child4, NULL); clutter_actor_show_all (actor); } #endif /* !TEST_GROUP */ g_free (file); clutter_actor_set_shader (actor, shader); clutter_actor_set_position (actor, 100, 100); g_object_unref (shader); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); clutter_actor_set_shader_param_int (actor, "tex", 0); clutter_actor_set_shader_param_float (actor, "brightness", 0.4); clutter_actor_set_shader_param_float (actor, "contrast", -1.9); clutter_actor_set_reactive (actor, TRUE); g_signal_connect (actor, "button-release-event", G_CALLBACK (button_release_cb), NULL); #ifdef COGL_HAS_GLES2 /* On an embedded platform it is difficult to right click so we will cycle through the shaders automatically */ g_timeout_add_seconds (3, timeout_cb, actor); #endif /* Show everying ( and map window ) */ clutter_actor_show_all (stage); clutter_main (); return EXIT_SUCCESS; }
static void clutter_rectangle_paint (ClutterActor *self) { ClutterRectanglePrivate *priv = CLUTTER_RECTANGLE (self)->priv; ClutterGeometry geom; guint8 tmp_alpha; CLUTTER_NOTE (PAINT, "painting rect '%s'", clutter_actor_get_name (self) ? clutter_actor_get_name (self) : "unknown"); clutter_actor_get_allocation_geometry (self, &geom); /* parent paint call will have translated us into position so * paint from 0, 0 */ if (priv->has_border) { /* compute the composited opacity of the actor taking into * account the opacity of the color set by the user */ tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->border_color.alpha / 255; /* paint the border */ cogl_set_source_color4ub (priv->border_color.red, priv->border_color.green, priv->border_color.blue, tmp_alpha); /* this sucks, but it's the only way to make a border */ cogl_rectangle (priv->border_width, 0, geom.width, priv->border_width); cogl_rectangle (geom.width - priv->border_width, priv->border_width, geom.width, geom.height); cogl_rectangle (0, geom.height - priv->border_width, geom.width - priv->border_width, geom.height); cogl_rectangle (0, 0, priv->border_width, geom.height - priv->border_width); tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; /* now paint the rectangle */ cogl_set_source_color4ub (priv->color.red, priv->color.green, priv->color.blue, tmp_alpha); cogl_rectangle (priv->border_width, priv->border_width, geom.width - priv->border_width, geom.height - priv->border_width); } else { /* compute the composited opacity of the actor taking into * account the opacity of the color set by the user */ tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; cogl_set_source_color4ub (priv->color.red, priv->color.green, priv->color.blue, tmp_alpha); cogl_rectangle (0, 0, geom.width, geom.height); } }
int main(int argc, char *argv[]) { ClutterActor *stage; WebKitWebView *web_view; ClutterConstraint *width_binding; ClutterConstraint *height_binding; ClutterConstraint *web_view_height_binding; gfloat stageWidth, stageHeight; ClutterActorBox stageAllocation; ClutterLayoutManager *mainLayout; ClutterActor *mainLayoutContainer; ClutterLayoutManager *toolbarLayout; ClutterActor *toolbarContainer; ClutterLayoutManager *toolbarBinLayout; ClutterActor *toolbarBinContainer; ClutterActor *toolbarBgr; ClutterActor *statusBar; ClutterActor *backFwdBtns; ClutterActor *backBtn; ClutterActor *fwdBtn; ClutterActor *uriGroup; ClutterActor *uriBgr; ClutterActor *uriText; ClutterActor *spacer; GError *error = NULL; ClutterColor whiteColor = { 255, 255, 255, 255 }; ClutterColor blackColor = { 0, 0, 0, 255 }; ClutterColor grayColor = { 200, 200, 200, 255 }; ClutterColor transparentColor = { 0, 0, 0, 0 }; gchar *toolbarBgrPath = clutter_launcher_file_path("toolbar_bgr.png"); gchar *backBtnPath = clutter_launcher_file_path("back_btn.png"); gchar *fwdBtnPath = clutter_launcher_file_path("fwd_btn.png"); g_thread_init(NULL); clutter_threads_init(); clutter_init(&argc, &argv); stage = clutter_stage_get_default(); clutter_actor_set_size(stage, 1024, 768); clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); g_signal_connect (stage, "destroy", G_CALLBACK(clutter_main_quit), NULL); /* make the stage resizable */ clutter_stage_set_user_resizable(CLUTTER_STAGE(stage), TRUE); clutter_actor_show(stage); mainLayout = clutter_box_layout_new(); clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(mainLayout), TRUE); clutter_actor_get_allocation_box(stage, &stageAllocation); stageWidth = stageAllocation.x2 - stageAllocation.x1; stageHeight = stageAllocation.y2 - stageAllocation.y1; web_view = WEBKIT_WEB_VIEW(webkit_web_view_new((guint)stageWidth, (guint)stageHeight - (toolbarHeight + statusBarHeight))); g_object_set(web_view, "reactive", TRUE, NULL); mainLayoutContainer = clutter_box_new(mainLayout); clutter_actor_set_size(mainLayoutContainer, stageWidth, stageHeight); width_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_WIDTH, 0); height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, 0); /* web_view_height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, -(toolbarHeight + statusBarHeight)); */ clutter_actor_add_constraint(mainLayoutContainer, width_binding); clutter_actor_add_constraint(mainLayoutContainer, height_binding); /* clutter_actor_add_constraint(CLUTTER_ACTOR(web_view), web_view_height_binding); */ toolbarBinLayout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_CENTER); toolbarBinContainer = clutter_box_new(toolbarBinLayout); toolbarBgr = clutter_texture_new_from_file(toolbarBgrPath, &error); if (toolbarBgr == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", toolbarBgrPath); exit(1); } clutter_actor_set_height(toolbarBgr, toolbarHeight); clutter_texture_set_repeat(CLUTTER_TEXTURE(toolbarBgr), TRUE, FALSE); clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarBgr, NULL, NULL); toolbarLayout = clutter_box_layout_new(); clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(toolbarLayout), FALSE); clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(toolbarLayout), 16); toolbarContainer = clutter_box_new(toolbarLayout); spacer = clutter_rectangle_new_with_color(&transparentColor); clutter_actor_set_size(spacer, 1, 1); clutter_box_pack(CLUTTER_BOX(toolbarContainer), spacer, NULL, NULL); backFwdBtns = clutter_group_new(); backBtn = clutter_texture_new_from_file(backBtnPath, &error); if (backBtn == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", backBtnPath); exit(1); } clutter_actor_set_reactive(backBtn, TRUE); /* connect the release event */ g_signal_connect (backBtn, "button-release-event", G_CALLBACK (on_back_release_cb), web_view); fwdBtn = clutter_texture_new_from_file(fwdBtnPath, &error); if (fwdBtn == NULL) { fprintf(stderr, "Can't load file: %s. Aborting...\n", fwdBtnPath); exit(1); } clutter_actor_set_reactive(fwdBtn, TRUE); /* connect the release event */ g_signal_connect (fwdBtn, "button-release-event", G_CALLBACK (on_fwd_release_cb), web_view); clutter_actor_set_position(fwdBtn, clutter_actor_get_width(backBtn), 0); clutter_container_add(CLUTTER_CONTAINER(backFwdBtns), backBtn, fwdBtn, NULL); clutter_box_pack(CLUTTER_BOX(toolbarContainer), backFwdBtns, NULL, NULL); uriGroup = clutter_group_new(); uriBgr = clutter_rectangle_new_with_color(&whiteColor); clutter_rectangle_set_border_color(CLUTTER_RECTANGLE(uriBgr), &blackColor); clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(uriBgr), 1); clutter_actor_set_size(uriBgr, 400, 25); uriText = clutter_text_new_full("Helvetica 11px", "http://www.google.com", &blackColor); clutter_text_set_editable(CLUTTER_TEXT(uriText), TRUE); clutter_text_set_single_line_mode(CLUTTER_TEXT(uriText), TRUE); clutter_actor_set_position(uriText, 5, 7); clutter_actor_set_size(uriText, 390, 17); clutter_actor_set_reactive(uriText, TRUE); g_signal_connect(uriText, "activate", G_CALLBACK(on_uri_activate_cb), web_view); clutter_container_add(CLUTTER_CONTAINER(uriGroup), uriBgr, uriText, NULL); clutter_box_pack(CLUTTER_BOX(toolbarContainer), uriGroup, NULL, NULL); clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarContainer, NULL, NULL); clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), toolbarBinContainer, "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE, FALSE); statusBar = clutter_rectangle_new_with_color(&grayColor); clutter_actor_set_height(statusBar, statusBarHeight); clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), statusBar, "y-align", CLUTTER_BOX_ALIGNMENT_END, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE, FALSE); clutter_box_pack_after(CLUTTER_BOX(mainLayoutContainer), CLUTTER_ACTOR(web_view), toolbarBinContainer, "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL); clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE); clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE, TRUE); clutter_container_add(CLUTTER_CONTAINER(stage), mainLayoutContainer, NULL); g_signal_connect(web_view, "webkit-load-finished", G_CALLBACK(load_finished_cb), web_view); g_signal_connect(web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view); /* g_signal_connect(stage, "delete-event", G_CALLBACK(delete_cb), web_view);*/ g_signal_connect(web_view, "notify::uri", G_CALLBACK(notify_uri_cb), uriText); gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/"); gchar *fileURL = filenameToURL(uri); webkit_web_view_load_uri(web_view, fileURL ? fileURL : uri); printf("%s\n", fileURL ? fileURL : uri); g_free(fileURL); g_timeout_add_full(G_PRIORITY_DEFAULT, 3000, timeout_cb, web_view, 0); clutter_threads_enter (); clutter_main(); clutter_threads_leave (); return EXIT_SUCCESS; }
static void clutter_rectangle_paint (ClutterActor *self) { ClutterRectanglePrivate *priv = CLUTTER_RECTANGLE (self)->priv; ClutterGeometry geom; guint8 tmp_alpha; CLUTTER_NOTE (PAINT, "painting rect '%s'", clutter_actor_get_name (self) ? clutter_actor_get_name (self) : "unknown"); clutter_actor_get_allocation_geometry (self, &geom); if (priv->has_border) { /* We paint the border and the content only if the rectangle * is big enough to show them */ if ((priv->border_width * 2) < geom.width && (priv->border_width * 2) < geom.height) { /* compute the composited opacity of the actor taking into * account the opacity of the color set by the user */ tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->border_color.alpha / 255; /* paint the border */ cogl_set_source_color4ub (priv->border_color.red, priv->border_color.green, priv->border_color.blue, tmp_alpha); /* this sucks, but it's the only way to make a border */ cogl_rectangle (priv->border_width, 0, geom.width, priv->border_width); cogl_rectangle (geom.width - priv->border_width, priv->border_width, geom.width, geom.height); cogl_rectangle (0, geom.height - priv->border_width, geom.width - priv->border_width, geom.height); cogl_rectangle (0, 0, priv->border_width, geom.height - priv->border_width); tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; /* now paint the rectangle */ cogl_set_source_color4ub (priv->color.red, priv->color.green, priv->color.blue, tmp_alpha); cogl_rectangle (priv->border_width, priv->border_width, geom.width - priv->border_width, geom.height - priv->border_width); } else { /* Otherwise, we draw a rectangle with the same color * as the border, since we can only fit that into the * allocation. */ tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->border_color.alpha / 255; cogl_set_source_color4ub (priv->border_color.red, priv->border_color.green, priv->border_color.blue, tmp_alpha); cogl_rectangle (0, 0, geom.width, geom.height); } } else { /* compute the composited opacity of the actor taking into * account the opacity of the color set by the user */ tmp_alpha = clutter_actor_get_paint_opacity (self) * priv->color.alpha / 255; cogl_set_source_color4ub (priv->color.red, priv->color.green, priv->color.blue, tmp_alpha); cogl_rectangle (0, 0, geom.width, geom.height); } }