static void gd_tagged_entry_tag_ensure_close_surface (GdTaggedEntryTag *tag, GtkStyleContext *context) { GtkIconInfo *info; GdkPixbuf *pixbuf; gint icon_size; gint scale_factor; if (tag->close_surface != NULL) return; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, NULL); scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (tag->entry)); info = gtk_icon_theme_lookup_icon_for_scale (gtk_icon_theme_get_default (), "window-close-symbolic", icon_size, scale_factor, GTK_ICON_LOOKUP_GENERIC_FALLBACK); /* FIXME: we need a fallback icon in case the icon is not found */ pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL); tag->close_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, tag->window); g_object_unref (info); g_object_unref (pixbuf); }
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 void ensure_surface_for_icon_name_or_gicon (GtkIconHelper *self, GtkStyleContext *context) { GtkIconTheme *icon_theme; gint width, height, scale; GtkIconInfo *info; GtkIconLookupFlags flags; if (!check_invalidate_surface (self, context)) return; icon_theme = gtk_icon_theme_get_default (); flags = get_icon_lookup_flags (self); ensure_icon_size (self, context, &width, &height); scale = get_scale_factor (self, context); if (self->priv->storage_type == GTK_IMAGE_ICON_NAME && self->priv->icon_name != NULL) { info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, self->priv->icon_name, MIN (width, height), scale, flags); } else if (self->priv->storage_type == GTK_IMAGE_GICON && self->priv->gicon != NULL) { info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, self->priv->gicon, MIN (width, height), scale, flags); } else { g_assert_not_reached (); return; } ensure_stated_surface_from_info (self, context, info, scale); if (info) g_object_unref (info); }
static void from_name (GtkSourcePixbufHelper *helper, GtkWidget *widget, gint size) { GdkScreen *screen; GtkIconTheme *icon_theme; GtkIconInfo *info; GtkIconLookupFlags flags; gint scale; screen = gtk_widget_get_screen (widget); icon_theme = gtk_icon_theme_get_for_screen (screen); flags = GTK_ICON_LOOKUP_USE_BUILTIN; scale = gtk_widget_get_scale_factor (widget); info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, helper->icon_name, size, scale, flags); if (info) { GdkPixbuf *pixbuf; if (gtk_icon_info_is_symbolic (info)) { GtkStyleContext *context; context = gtk_widget_get_style_context (widget); pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL); } else { pixbuf = gtk_icon_info_load_icon (info, NULL); } set_cache (helper, pixbuf); } }
static gboolean gtk_color_swatch_render_overlay (GtkCssGadget *gadget, cairo_t *cr, int x, int y, int width, int height, gpointer data) { GtkWidget *widget; GtkColorSwatch *swatch; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkIconInfo *icon_info = NULL; gint scale; widget = gtk_css_gadget_get_owner (gadget); swatch = GTK_COLOR_SWATCH (widget); theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); scale = gtk_widget_get_scale_factor (widget); if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GIcon *gicon; gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } /* now draw the overlay image */ if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { cairo_surface_t *surface; surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget)); gtk_render_icon_surface (context, cr, surface, x, y); cairo_surface_destroy (surface); g_object_unref (pixbuf); } g_object_unref (icon_info); } return FALSE; }
static gboolean swatch_draw (GtkWidget *widget, cairo_t *cr) { GtkColorSwatch *swatch = (GtkColorSwatch*)widget; gdouble width, height; GtkStyleContext *context; GtkStateFlags state; GtkIconTheme *theme; GtkBorder border, padding; GdkRectangle rect; GtkIconInfo *icon_info = NULL; gint scale; theme = gtk_icon_theme_get_default (); context = gtk_widget_get_style_context (widget); state = gtk_style_context_get_state (context); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gtk_render_background (context, cr, 0, 0, width, height); if (swatch->priv->has_color) { cairo_pattern_t *pattern; cairo_matrix_t matrix; gtk_render_content_path (context, cr, 0, 0, width, height); if (swatch->priv->use_alpha) { cairo_save (cr); cairo_clip_preserve (cr); cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); cairo_fill_preserve (cr); pattern = _gtk_color_chooser_get_checkered_pattern (); cairo_matrix_init_scale (&matrix, 0.125, 0.125); cairo_pattern_set_matrix (pattern, &matrix); cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); cairo_mask (cr, pattern); cairo_pattern_destroy (pattern); cairo_restore (cr); gdk_cairo_set_source_rgba (cr, &swatch->priv->color); } else { cairo_set_source_rgb (cr, swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue); } cairo_fill (cr); } gtk_render_frame (context, cr, 0, 0, width, height); scale = gtk_widget_get_scale_factor (widget); if (swatch->priv->icon) { icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); } else if ((state & GTK_STATE_FLAG_SELECTED) != 0) { GIcon *gicon; gicon = g_themed_icon_new ("object-select-symbolic"); /* fallback for themes that don't have object-select-symbolic */ g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply"); icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE, scale, GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_USE_BUILTIN); g_object_unref (gicon); } /* now draw the overlay image */ gtk_style_context_get_border (context, state, &border); gtk_style_context_get_padding (context, state, &padding); rect.width = width - (border.left + border.right + padding.left + padding.right); rect.height = height - (border.top + border.bottom + padding.top + padding.bottom); rect.x = border.left + padding.left; rect.y = border.top + padding.top; gtk_style_context_save_to_node (context, swatch->priv->overlay_node); gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height); gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height); if (icon_info != NULL) { GdkPixbuf *pixbuf; pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL); if (pixbuf != NULL) { cairo_surface_t *surface; surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget)); gtk_render_icon_surface (context, cr, surface, rect.x + (rect.width - (gdk_pixbuf_get_width (pixbuf) / scale)) / 2, rect.y + (rect.height - (gdk_pixbuf_get_height (pixbuf) / scale)) / 2); cairo_surface_destroy (surface); g_object_unref (pixbuf); } g_object_unref (icon_info); } if (gtk_widget_has_visible_focus (widget)) gtk_render_focus (context, cr, 0, 0, width, height); gtk_style_context_restore (context); return FALSE; }
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); }