static void clutter_canvas_set_property (GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec) { ClutterCanvasPrivate *priv = CLUTTER_CANVAS (gobject)->priv; switch (prop_id) { case PROP_WIDTH: { gint new_size = g_value_get_int (value); if (priv->width != new_size) { priv->width = new_size; clutter_content_invalidate (CLUTTER_CONTENT (gobject)); } } break; case PROP_HEIGHT: { gint new_size = g_value_get_int (value); if (priv->height != new_size) { priv->height = new_size; clutter_content_invalidate (CLUTTER_CONTENT (gobject)); } } break; case PROP_SCALE_FACTOR: clutter_canvas_set_scale_factor (CLUTTER_CANVAS (gobject), g_value_get_int (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; } }
void bacon_video_osd_actor_set_content (BaconVideoOsdActor *osd, const char *icon_name, const char *message) { g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd)); g_free (osd->priv->icon_name); osd->priv->icon_name = g_strdup (icon_name); g_free (osd->priv->message); osd->priv->message = g_strdup (message); if (icon_name != NULL || message != NULL) clutter_content_invalidate (CLUTTER_CONTENT (osd->priv->canvas)); }
/** * clutter_image_set_bytes: * @image: a #ClutterImage * @data: the image data, as a #GBytes * @pixel_format: the Cogl pixel format of the image data * @width: the width of the image data * @height: the height of the image data * @row_stride: the length of each row inside @data * @error: return location for a #GError, or %NULL * * Sets the image data stored inside a #GBytes to be displayed by @image. * * If the image data was successfully loaded, the @image will be invalidated. * * In case of error, the @error value will be set, and this function will * return %FALSE. * * The image data contained inside the #GBytes is copied in texture memory, * and no additional reference is acquired on the @data. * * Return value: %TRUE if the image data was successfully loaded, * and %FALSE otherwise. * * Since: 1.12 */ gboolean clutter_image_set_bytes (ClutterImage *image, GBytes *data, CoglPixelFormat pixel_format, guint width, guint height, guint row_stride, GError **error) { ClutterImagePrivate *priv; CoglTextureFlags flags; g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE); g_return_val_if_fail (data != NULL, FALSE); priv = image->priv; if (priv->texture != NULL) cogl_object_unref (priv->texture); flags = COGL_TEXTURE_NONE; if (width >= 512 && height >= 512) flags |= COGL_TEXTURE_NO_ATLAS; priv->texture = cogl_texture_new_from_data (width, height, flags, pixel_format, COGL_PIXEL_FORMAT_ANY, row_stride, g_bytes_get_data (data, NULL)); if (priv->texture == NULL) { g_set_error_literal (error, CLUTTER_IMAGE_ERROR, CLUTTER_IMAGE_ERROR_INVALID_DATA, _("Unable to load image data")); return FALSE; } clutter_content_invalidate (CLUTTER_CONTENT (image)); return TRUE; }
/* Store image in cache */ static void _xfdashboard_image_content_store_in_cache(XfdashboardImageContent *self, const gchar *inKey) { XfdashboardImageContentPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_IMAGE_CONTENT(self)); g_return_if_fail(inKey && *inKey!=0); priv=self->priv; /* Create cache hashtable */ if(!_xfdashboard_image_content_cache) _xfdashboard_image_content_create_cache(); /* Set key */ if(priv->key) { g_critical(_("Image has already key '%s' set and will be replaced with '%s'"), priv->key, inKey); g_free(priv->key); priv->key=NULL; } priv->key=g_strdup(inKey); /* Store image in cache */ if(g_hash_table_contains(_xfdashboard_image_content_cache, priv->key)) { ClutterContent *content; g_critical(_("An image with key '%s' is already cache and will be replaced."), priv->key); /* Unreference current cached image */ content=CLUTTER_CONTENT(g_hash_table_lookup(_xfdashboard_image_content_cache, inKey)); if(content) { g_object_unref(content); g_debug("Replacing image '%s' which had ref-count %u", priv->key, G_OBJECT(content)->ref_count); } } /* Store new image in cache */ g_hash_table_insert(_xfdashboard_image_content_cache, priv->key, self); g_debug("Added image '%s' with ref-count %d" , priv->key, G_OBJECT(self)->ref_count); }
static gboolean clutter_canvas_invalidate_internal (ClutterCanvas *canvas, int width, int height) { gboolean width_changed = FALSE, height_changed = FALSE; gboolean res = FALSE; GObject *obj; obj = G_OBJECT (canvas); g_object_freeze_notify (obj); if (canvas->priv->width != width) { canvas->priv->width = width; width_changed = TRUE; g_object_notify_by_pspec (obj, obj_props[PROP_WIDTH]); } if (canvas->priv->height != height) { canvas->priv->height = height; height_changed = TRUE; g_object_notify_by_pspec (obj, obj_props[PROP_HEIGHT]); } if (width_changed || height_changed) { clutter_content_invalidate (CLUTTER_CONTENT (canvas)); res = TRUE; } g_object_thaw_notify (obj); return res; }
static void bacon_video_osd_actor_init (BaconVideoOsdActor *osd) { ClutterActor *self; GtkWidgetPath *widget_path; self = CLUTTER_ACTOR (osd); osd->priv = BACON_VIDEO_OSD_ACTOR_GET_PRIVATE (osd); osd->priv->canvas = CLUTTER_CANVAS (clutter_canvas_new ()); g_object_bind_property (self, "width", osd->priv->canvas, "width", G_BINDING_DEFAULT); g_object_bind_property (self, "height", osd->priv->canvas, "height", G_BINDING_DEFAULT); clutter_actor_set_content (self, CLUTTER_CONTENT (osd->priv->canvas)); g_object_unref (osd->priv->canvas); osd->priv->icon_name = NULL; osd->priv->message = NULL; osd->priv->ctx = g_new0 (GsdOsdDrawContext, 1); widget_path = gtk_widget_path_new (); gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); osd->priv->style = gtk_style_context_new (); gtk_style_context_set_path (osd->priv->style, widget_path); gtk_widget_path_free (widget_path); osd->priv->ctx->direction = clutter_get_default_text_direction (); osd->priv->ctx->theme = gtk_icon_theme_get_default (); osd->priv->ctx->style = osd->priv->style; g_signal_connect (osd->priv->canvas, "draw", G_CALLBACK (bacon_video_osd_actor_draw), osd); osd->priv->fade_out_alpha = 1.0; }
/** * clutter_canvas_set_scale_factor: * @canvas: a #ClutterCanvas * @scale: the scale factor, or -1 for the default * * Sets the scaling factor for the Cairo surface used by @canvas. * * This function should rarely be used. * * The default scaling factor of a #ClutterCanvas content uses the * #ClutterSettings:window-scaling-factor property, which is set by * the windowing system. By using this function it is possible to * override that setting. * * Changing the scale factor will invalidate the @canvas. * * Since: 1.18 */ void clutter_canvas_set_scale_factor (ClutterCanvas *canvas, int scale) { ClutterCanvasPrivate *priv; GObject *obj; g_return_if_fail (CLUTTER_IS_CANVAS (canvas)); g_return_if_fail (scale != 0); priv = canvas->priv; if (scale < 0) { if (!priv->scale_factor_set) return; priv->scale_factor_set = FALSE; priv->scale_factor = -1; } else { if (priv->scale_factor_set && priv->scale_factor == scale) return; priv->scale_factor_set = TRUE; priv->scale_factor = scale; } clutter_content_invalidate (CLUTTER_CONTENT (canvas)); obj = G_OBJECT (canvas); g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_FACTOR]); g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_FACTOR_SET]); }
static void on_monitors_changed (MetaScreen *screen, MetaPlugin *plugin) { MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin); __attribute__ ((unused)) ClutterAnimation *animation; int i, n; gchar *wallpaper = NULL; GFile *wallpaper_file = NULL; gchar *filename = NULL; GDesktopBackgroundStyle style; GDesktopBackgroundShading shading_direction; ClutterColor primary_color; ClutterColor secondary_color; gboolean random_colour = FALSE; clutter_actor_destroy_all_children (self->priv->background_group); wallpaper = g_settings_get_string (self->priv->settings, PICTURE_URI_KEY); /* We don't currently support slideshows */ if (!wallpaper || g_str_has_suffix(wallpaper, ".xml")) random_colour = TRUE; else { gchar *color_str; /* Shading direction*/ shading_direction = g_settings_get_enum (self->priv->settings, COLOR_SHADING_TYPE_KEY); /* Primary color */ color_str = g_settings_get_string (self->priv->settings, PRIMARY_COLOR_KEY); if (color_str) { clutter_color_from_string (&primary_color, color_str); g_free (color_str); color_str = NULL; } /* Secondary color */ color_str = g_settings_get_string (self->priv->settings, SECONDARY_COLOR_KEY); if (color_str) { clutter_color_from_string (&secondary_color, color_str); g_free (color_str); color_str = NULL; } /* Picture options: "none", "wallpaper", "centered", "scaled", "stretched", "zoom", "spanned" */ style = g_settings_get_enum (self->priv->settings, BACKGROUND_STYLE_KEY); wallpaper_file = g_file_new_for_uri(wallpaper); filename = g_file_get_path(wallpaper_file); } n = meta_screen_get_n_monitors (screen); for (i = 0; i < n; i++) { MetaBackground *content; MetaRectangle rect; ClutterActor *background; background = meta_background_actor_new (); content = meta_background_new (screen, i, META_BACKGROUND_EFFECTS_NONE); // Don't use rand() here, mesa calls srand() internally when // parsing the driconf XML, but it's nice if the colors are // reproducible. if (random_colour) { clutter_color_init (&primary_color, g_random_int () % 255, g_random_int () % 255, g_random_int () % 255, 255); meta_background_load_color (content, &primary_color); } else { if (style == G_DESKTOP_BACKGROUND_STYLE_NONE || g_str_has_suffix (filename, GNOME_COLOR_HACK)) { if (shading_direction == G_DESKTOP_BACKGROUND_SHADING_SOLID) meta_background_load_color (content, &primary_color); else meta_background_load_gradient (content, shading_direction, &primary_color, &secondary_color); } else { /* Set the background */ meta_background_load_file_async (content, filename, style, NULL, /*TODO use cancellable*/ background_load_file_cb, self); } } clutter_actor_set_content (background, CLUTTER_CONTENT (content)); g_object_unref (content); meta_screen_get_monitor_geometry (screen, i, &rect); clutter_actor_set_position (background, rect.x, rect.y); clutter_actor_set_size (background, rect.width, rect.height); clutter_actor_add_child (self->priv->background_group, background); clutter_actor_set_scale (background, 0.0, 0.0); clutter_actor_show (background); clutter_actor_set_pivot_point (background, 0.5, 0.5); /* Ease in the background using a scale effect */ animation = clutter_actor_animate (background, CLUTTER_EASE_IN_SINE, BACKGROUND_TIMEOUT, "scale-x", 1.0, "scale-y", 1.0, NULL); } if (wallpaper_file) g_object_unref(wallpaper_file); g_free(wallpaper); g_free(filename); }
/** * clutter_image_set_area: * @image: a #ClutterImage * @data: (array): the image data, as an array of bytes * @pixel_format: the Cogl pixel format of the image data * @rect: a rectangle indicating the area that should be set * @row_stride: the length of each row inside @data * @error: return location for a #GError, or %NULL * * Sets the image data to be display by @image, using @rect to indicate * the position and size of the image data to be set. * * If the @image does not have any image data set when this function is * called, a new texture will be created with the size of the width and * height of the rectangle, i.e. calling this function on a newly created * #ClutterImage will be the equivalent of calling clutter_image_set_data(). * * If the image data was successfully loaded, the @image will be invalidated. * * In case of error, the @error value will be set, and this function will * return %FALSE. * * The image data is copied in texture memory. * * Return value: %TRUE if the image data was successfully loaded, * and %FALSE otherwise. * * Since: 1.10 */ gboolean clutter_image_set_area (ClutterImage *image, const guint8 *data, CoglPixelFormat pixel_format, const cairo_rectangle_int_t *area, guint row_stride, GError **error) { ClutterImagePrivate *priv; g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE); g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (area != NULL, FALSE); priv = image->priv; if (priv->texture == NULL) { CoglTextureFlags flags = COGL_TEXTURE_NONE; if (area->width >= 512 && area->height >= 512) flags |= COGL_TEXTURE_NO_ATLAS; priv->texture = cogl_texture_new_from_data (area->width, area->height, flags, pixel_format, COGL_PIXEL_FORMAT_ANY, row_stride, data); } else { gboolean res; res = cogl_texture_set_region (priv->texture, 0, 0, area->x, area->y, area->width, area->height, area->width, area->height, pixel_format, row_stride, data); if (!res) { cogl_object_unref (priv->texture); priv->texture = NULL; } } if (priv->texture == NULL) { g_set_error_literal (error, CLUTTER_IMAGE_ERROR, CLUTTER_IMAGE_ERROR_INVALID_DATA, _("Unable to load image data")); return FALSE; } clutter_content_invalidate (CLUTTER_CONTENT (image)); return TRUE; }