double height)
{
GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image);
- GdkTexture *texture;
- double texture_width, texture_height;
+ GtkIconInfo *icon_info;
+ double icon_width, icon_height;
gint size;
- gboolean symbolic;
+ double x, y;
size = floor (MIN (width, height));
if (size <= 0)
return;
if (size == icon_theme->cached_size &&
- icon_theme->cached_texture != NULL)
+ icon_theme->cached_icon != NULL)
{
- texture = icon_theme->cached_texture;
- symbolic = icon_theme->cached_symbolic;
+ icon_info = icon_theme->cached_icon;
}
else
{
- GtkIconInfo *icon_info;
-
icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme->icon_theme,
icon_theme->name,
size,
g_assert (icon_info != NULL);
- symbolic = gtk_icon_info_is_symbolic (icon_info);
- texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL));
-
- g_clear_object (&icon_theme->cached_texture);
+ g_clear_object (&icon_theme->cached_icon);
icon_theme->cached_size = size;
- icon_theme->cached_texture = texture;
- icon_theme->cached_symbolic = symbolic;
-
- g_object_unref (icon_info);
+ icon_theme->cached_icon = icon_info;
}
- texture_width = (double) gdk_texture_get_width (texture) / icon_theme->scale;
- texture_height = (double) gdk_texture_get_height (texture) / icon_theme->scale;
+ icon_width = (double) MIN (gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (icon_info)), width);
+ icon_height = (double) MIN (gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (icon_info)), height);
- if (symbolic)
+ x = (width - icon_width) / 2;
+ y = (height - icon_height) / 2;
+
+ if (x != 0 || y != 0)
{
- const GdkRGBA *fg = &icon_theme->color;
- const GdkRGBA *sc = &icon_theme->success;
- const GdkRGBA *wc = &icon_theme->warning;
- const GdkRGBA *ec = &icon_theme->error;
- graphene_matrix_t matrix;
- graphene_vec4_t offset;
-
-
- graphene_matrix_init_from_float (&matrix,
- (float[16]) {
- sc->red - fg->red, sc->green - fg->green, sc->blue - fg->blue, 0,
- wc->red - fg->red, wc->green - fg->green, wc->blue - fg->blue, 0,
- ec->red - fg->red, ec->green - fg->green, ec->blue - fg->blue, 0,
- 0, 0, 0, fg->alpha
- });
- graphene_vec4_init (&offset, fg->red, fg->green, fg->blue, 0);
-
- gtk_snapshot_push_color_matrix (snapshot, &matrix, &offset);
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
}
-
- gtk_snapshot_append_texture (snapshot,
- texture,
- &GRAPHENE_RECT_INIT(
- (width - texture_width) / 2.0,
- (height - texture_height) / 2.0,
- texture_width,
- texture_height
- ));
- if (symbolic)
- gtk_snapshot_pop (snapshot);
+ gtk_icon_info_snapshot_with_colors (icon_info, snapshot,
+ icon_width,
+ icon_height,
+ &icon_theme->color,
+ &icon_theme->success,
+ &icon_theme->warning,
+ &icon_theme->error);
+ if (x != 0 || y != 0)
+ gtk_snapshot_restore (snapshot);
}
static guint
g_free (icon_theme->name);
icon_theme->name = NULL;
- g_clear_object (&icon_theme->cached_texture);
+ g_clear_object (&icon_theme->cached_icon);
G_OBJECT_CLASS (_gtk_css_image_icon_theme_parent_class)->dispose (object);
}
icon_theme->icon_theme = gtk_icon_theme_get_default ();
icon_theme->scale = 1;
icon_theme->cached_size = -1;
- icon_theme->cached_texture = NULL;
+ icon_theme->cached_icon = NULL;
}
int cached_size;
gboolean cached_symbolic;
- GdkTexture *cached_texture;
+ GtkIconInfo *cached_icon;
};
struct _GtkCssImageIconThemeClass
return TRUE;
}
-
-static void
-icon_info_paintable_snapshot (GdkPaintable *paintable,
- GdkSnapshot *snapshot,
- double width,
- double height)
+static GdkTexture *
+icon_info_get_texture (GtkIconInfo *icon_info)
{
- GtkIconInfo *icon_info = GTK_ICON_INFO (paintable);
GdkTexture *texture = NULL;
g_mutex_lock (&icon_info->cache_lock);
g_mutex_unlock (&icon_info->cache_lock);
+ return texture;
+}
+
+static void
+icon_info_paintable_snapshot (GdkPaintable *paintable,
+ GdkSnapshot *snapshot,
+ double width,
+ double height)
+{
+ GtkIconInfo *icon_info = GTK_ICON_INFO (paintable);
+ GdkTexture *texture;
+
+ texture = icon_info_get_texture (icon_info);
+ if (texture)
+ {
+ if (icon_info->desired_scale != 1)
+ {
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_scale (snapshot, 1.0 / icon_info->desired_scale, 1.0 / icon_info->desired_scale);
+ }
+
+ gtk_snapshot_append_texture (snapshot, texture,
+ &GRAPHENE_RECT_INIT (0, 0, width * icon_info->desired_scale, height * icon_info->desired_scale));
+
+ if (icon_info->desired_scale != 1)
+ gtk_snapshot_restore (snapshot);
+
+ g_object_unref (texture);
+ }
+}
+
+void
+gtk_icon_info_snapshot_with_colors (GtkIconInfo *icon_info,
+ GdkSnapshot *snapshot,
+ double width,
+ double height,
+ const GdkRGBA *foreground_color,
+ const GdkRGBA *success_color,
+ const GdkRGBA *warning_color,
+ const GdkRGBA *error_color)
+{
+ GdkTexture *texture;
+
+ texture = icon_info_get_texture (icon_info);
if (texture)
{
+ gboolean symbolic = gtk_icon_info_is_symbolic (icon_info);
+
if (icon_info->desired_scale != 1)
{
gtk_snapshot_save (snapshot);
gtk_snapshot_scale (snapshot, 1.0 / icon_info->desired_scale, 1.0 / icon_info->desired_scale);
}
+ if (symbolic)
+ {
+ const GdkRGBA *fg = foreground_color;
+ const GdkRGBA *sc = success_color;
+ const GdkRGBA *wc = warning_color;
+ const GdkRGBA *ec = error_color;
+ graphene_matrix_t matrix;
+ graphene_vec4_t offset;
+
+ graphene_matrix_init_from_float (&matrix,
+ (float[16]) {
+ sc->red - fg->red, sc->green - fg->green, sc->blue - fg->blue, 0,
+ wc->red - fg->red, wc->green - fg->green, wc->blue - fg->blue, 0,
+ ec->red - fg->red, ec->green - fg->green, ec->blue - fg->blue, 0,
+ 0, 0, 0, fg->alpha
+ });
+ graphene_vec4_init (&offset, fg->red, fg->green, fg->blue, 0);
+
+ gtk_snapshot_push_color_matrix (snapshot, &matrix, &offset);
+ }
+
gtk_snapshot_append_texture (snapshot, texture,
&GRAPHENE_RECT_INIT (0, 0, width * icon_info->desired_scale, height * icon_info->desired_scale));
+ if (symbolic)
+ gtk_snapshot_pop (snapshot);
+
if (icon_info->desired_scale != 1)
gtk_snapshot_restore (snapshot);
}
}
+
static GdkPaintableFlags
icon_info_paintable_get_flags (GdkPaintable *paintable)
{
const gchar * gtk_icon_info_get_filename (GtkIconInfo *self);
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_info_is_symbolic (GtkIconInfo *self);
+void gtk_icon_info_snapshot_with_colors (GtkIconInfo *icon_info,
+ GdkSnapshot *snapshot,
+ double width,
+ double height,
+ const GdkRGBA *foreground_color,
+ const GdkRGBA *success_color,
+ const GdkRGBA *warning_color,
+ const GdkRGBA *error_color);
GDK_AVAILABLE_IN_ALL
GdkPaintable * gtk_icon_info_load_icon (GtkIconInfo *self,
GError **error);