static void gtk_css_image_icon_theme_draw (GtkCssImage *image, cairo_t *cr, double width, double height) { GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image); GError *error = NULL; GtkIconInfo *icon_info; GdkPixbuf *pixbuf; gint size; size = floor (MIN (width, height)); if (size <= 0) return; icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme->icon_theme, icon_theme->name, size, icon_theme->scale, GTK_ICON_LOOKUP_USE_BUILTIN); if (icon_info == NULL) { /* XXX: render missing icon image here? */ return; } pixbuf = gtk_icon_info_load_symbolic (icon_info, &icon_theme->color, NULL, NULL, NULL, NULL, &error); if (pixbuf == NULL) { /* XXX: render missing icon image here? */ g_error_free (error); return; } cairo_translate (cr, width / 2.0, height / 2.0); cairo_scale (cr, 1.0 / icon_theme->scale, 1.0 / icon_theme->scale); gdk_cairo_set_source_pixbuf (cr, pixbuf, - gdk_pixbuf_get_width (pixbuf) / 2.0, - gdk_pixbuf_get_height (pixbuf) / 2.0); cairo_paint (cr); g_object_unref (pixbuf); g_object_unref (icon_info); }
static GdkPixbuf * impl_load_pixbuf_gicon (GtkIconInfo *info, int size, StIconColors *colors, GError **error) { int scaled_width, scaled_height; GdkPixbuf *pixbuf; int width, height; if (colors) { GdkRGBA foreground_color; GdkRGBA success_color; GdkRGBA warning_color; GdkRGBA error_color; rgba_from_clutter (&foreground_color, &colors->foreground); rgba_from_clutter (&success_color, &colors->success); rgba_from_clutter (&warning_color, &colors->warning); rgba_from_clutter (&error_color, &colors->error); pixbuf = gtk_icon_info_load_symbolic (info, &foreground_color, &success_color, &warning_color, &error_color, NULL, error); } else { pixbuf = gtk_icon_info_load_icon (info, error); } if (!pixbuf) return NULL; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); if (compute_pixbuf_scale (width, height, size, size, &scaled_width, &scaled_height)) { GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled; } return pixbuf; }
static void set_calibration_status (CalibArea *area) { GtkIconTheme *icon_theme; GtkIconInfo *icon_info; GdkRGBA white; icon_theme = gtk_icon_theme_get_default (); icon_info = gtk_icon_theme_lookup_icon (icon_theme, ICON_SUCCESS, ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN); if (icon_info == NULL) { g_warning ("Failed to find icon \"%s\"", ICON_SUCCESS); goto out; } gdk_rgba_parse (&white, "White"); area->icon_success = gtk_icon_info_load_symbolic (icon_info, &white, NULL, NULL, NULL, NULL, NULL); g_object_unref (icon_info); if (!area->icon_success) g_warning ("Failed to load icon \"%s\"", ICON_SUCCESS); out: area->success = finish (&area->calibrator, &area->axis, &area->swap); if (area->success && area->icon_success) { set_success (area); g_timeout_add (END_TIME, (GSourceFunc) draw_success_end_wait_callback, area); } else { on_delete_event (NULL, NULL, area); } }
static GdkPixbuf * load_pixbuf (GsdMediaKeysWindow *window, const char *name, int icon_size) { GtkIconTheme *theme; GtkIconInfo *info; GdkPixbuf *pixbuf; GtkStyleContext *context; GdkRGBA color; if (window != NULL && gtk_widget_has_screen (GTK_WIDGET (window))) { theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))); } else { theme = gtk_icon_theme_get_default (); } context = gtk_widget_get_style_context (GTK_WIDGET (window)); gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &color); info = gtk_icon_theme_lookup_icon (theme, name, icon_size, GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (info == NULL) { g_warning ("Failed to load '%s'", name); return NULL; } pixbuf = gtk_icon_info_load_symbolic (info, &color, NULL, NULL, NULL, NULL, NULL); gtk_icon_info_free (info); return pixbuf; }
static cairo_surface_t * ensure_surface_for_gicon (GtkIconHelper *self, GtkCssStyle *style, GtkTextDirection dir, gint scale, GIcon *gicon) { GtkIconHelperPrivate *priv = self->priv; GtkIconTheme *icon_theme; gint width, height; GtkIconInfo *info; GtkIconLookupFlags flags; cairo_surface_t *surface; GdkPixbuf *destination; gboolean symbolic; icon_theme = gtk_css_icon_theme_value_get_icon_theme (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME)); flags = get_icon_lookup_flags (self, style, dir); ensure_icon_size (self, &width, &height); info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, gicon, MIN (width, height), scale, flags); if (info) { symbolic = gtk_icon_info_is_symbolic (info); if (symbolic) { GdkRGBA fg, success_color, warning_color, error_color; gtk_icon_theme_lookup_symbolic_colors (style, &fg, &success_color, &warning_color, &error_color); destination = gtk_icon_info_load_symbolic (info, &fg, &success_color, &warning_color, &error_color, NULL, NULL); } else { destination = gtk_icon_info_load_icon (info, NULL); } g_object_unref (info); } else { destination = NULL; } if (destination == NULL) { destination = gtk_icon_theme_load_icon (icon_theme, "image-missing", width, flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); /* We include this image as resource, so we always have it available or * the icontheme code is broken */ g_assert (destination); symbolic = FALSE; } surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, gtk_widget_get_window (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self)))); if (!symbolic) { GtkCssIconEffect icon_effect; icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_EFFECT)); gtk_css_icon_effect_apply (icon_effect, surface); } else { priv->rendered_surface_is_symbolic = TRUE; } g_object_unref (destination); return surface; }
static void gtk_css_image_icon_theme_snapshot (GtkCssImage *image, GtkSnapshot *snapshot, double width, double height) { GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image); GError *error = NULL; GtkIconInfo *icon_info; GskTexture *texture; GdkPixbuf *pixbuf; double texture_width, texture_height; gint size; size = floor (MIN (width, height)); if (size <= 0) return; icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme->icon_theme, icon_theme->name, size, icon_theme->scale, GTK_ICON_LOOKUP_USE_BUILTIN); if (icon_info == NULL) { /* XXX: render missing icon image here? */ return; } pixbuf = gtk_icon_info_load_symbolic (icon_info, &icon_theme->color, &icon_theme->success, &icon_theme->warning, &icon_theme->error, NULL, &error); if (pixbuf == NULL) { /* XXX: render missing icon image here? */ g_error_free (error); return; } texture = gsk_texture_new_for_pixbuf (pixbuf); texture_width = (double) gdk_pixbuf_get_width (pixbuf) / icon_theme->scale; texture_height = (double) gdk_pixbuf_get_height (pixbuf) / icon_theme->scale; gtk_snapshot_append_texture_node (snapshot, texture, &GRAPHENE_RECT_INIT( (width - texture_width) / 2.0, (height - texture_height) / 2.0, texture_width, texture_height ), "CssImageIconTheme<%s@%d>", icon_theme->name, icon_theme->scale); g_object_unref (texture); g_object_unref (pixbuf); g_object_unref (icon_info); }