gtk: Port icontheme to GtkSymbolicPaintable

This commit is contained in:
Benjamin Otte
2021-08-28 00:23:29 +02:00
parent 49d109c29e
commit 2808f9c75b
5 changed files with 44 additions and 69 deletions

View File

@@ -27,6 +27,7 @@
#include "gtksettingsprivate.h"
#include "gtksnapshot.h"
#include "gtkstyleproviderprivate.h"
#include "gtksymbolicpaintable.h"
#include "gtkiconthemeprivate.h"
G_DEFINE_TYPE (GtkCssImageIconTheme, _gtk_css_image_icon_theme, GTK_TYPE_CSS_IMAGE)
@@ -88,13 +89,12 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
}
gtk_icon_paintable_snapshot_with_colors (icon, snapshot,
icon_width,
icon_height,
&icon_theme->color,
&icon_theme->success,
&icon_theme->warning,
&icon_theme->error);
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (icon),
snapshot,
icon_width,
icon_height,
icon_theme->colors,
G_N_ELEMENTS (icon_theme->colors));
if (x != 0 || y != 0)
gtk_snapshot_restore (snapshot);
}
@@ -156,7 +156,7 @@ gtk_css_image_icon_theme_compute (GtkCssImage *image,
copy->icon_theme = gtk_icon_theme_get_for_display (display);
copy->serial = gtk_icon_theme_get_serial (copy->icon_theme);
copy->scale = gtk_style_provider_get_scale (provider);
gtk_icon_theme_lookup_symbolic_colors (style, &copy->color, &copy->success, &copy->warning, &copy->error);
gtk_icon_theme_lookup_symbolic_colors (style, &copy->colors[0], &copy->colors[3], &copy->colors[2], &copy->colors[1]);
return GTK_CSS_IMAGE (copy);
}

View File

@@ -40,10 +40,7 @@ struct _GtkCssImageIconTheme
GtkCssImage parent;
GtkIconTheme *icon_theme;
GdkRGBA color;
GdkRGBA success;
GdkRGBA warning;
GdkRGBA error;
GdkRGBA colors[4];
int serial;
int scale;
char *name;

View File

@@ -45,11 +45,12 @@
#include "gtkiconcacheprivate.h"
#include "gtkintl.h"
#include "gtkmain.h"
#include "gtkprivate.h"
#include "gtksettingsprivate.h"
#include "gtksnapshot.h"
#include "gtkstylecontextprivate.h"
#include "gtkstyleproviderprivate.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "gtksymbolicpaintable.h"
#include "gtkwidgetprivate.h"
#include "gdkpixbufutilsprivate.h"
#include "gdk/gdktextureprivate.h"
@@ -3481,6 +3482,7 @@ theme_subdir_load (GtkIconTheme *self,
*/
static void icon_paintable_init (GdkPaintableInterface *iface);
static void icon_symbolic_paintable_init (GtkSymbolicPaintableInterface *iface);
enum
{
@@ -3492,7 +3494,9 @@ enum
G_DEFINE_TYPE_WITH_CODE (GtkIconPaintable, gtk_icon_paintable, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
icon_paintable_init))
icon_paintable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SYMBOLIC_PAINTABLE,
icon_symbolic_paintable_init))
static void
gtk_icon_paintable_init (GtkIconPaintable *icon)
@@ -3954,43 +3958,18 @@ icon_paintable_snapshot (GdkPaintable *paintable,
double width,
double height)
{
GtkIconPaintable *icon = GTK_ICON_PAINTABLE (paintable);
gtk_icon_paintable_snapshot_with_colors (icon, snapshot, width, height,
NULL, NULL, NULL, NULL);
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable), snapshot, width, height, NULL, 0);
}
/**
* gtk_icon_paintable_snapshot_with_colors:
* @icon: a `GtkIconPaintable`
* @snapshot: a `GdkSnapshot` to snapshot to
* @width: width to snapshot in
* @height: height to snapshot in
* @foreground_color: (nullable): a `GdkRGBA` representing the foreground color
* of the icon or %NULL to use the default color.
* @success_color: (nullable): a `GdkRGBA` representing the warning color
* of the icon or %NULL to use the default color
* @warning_color: (nullable): a `GdkRGBA` representing the warning color
* of the icon or %NULL to use the default color
* @error_color: (nullable): a `GdkRGBA` representing the error color
* of the icon or %NULL to use the default color
*
* Snapshots the `GtkIconPaintable`.
*
* This is similar to the implementation of [method@Gdk.Paintable.snapshot],
* but if the icon is symbolic it will be recolored with the specified colors
* (which usually comes from the theme).
*/
void
gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
GtkSnapshot *snapshot,
double width,
double height,
const GdkRGBA *foreground_color,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color)
static void
gtk_icon_paintable_snapshot_symbolic (GtkSymbolicPaintable *paintable,
GtkSnapshot *snapshot,
double width,
double height,
const GdkRGBA *colors,
gsize n_colors)
{
GtkIconPaintable *icon = GTK_ICON_PAINTABLE (paintable);
GdkTexture *texture;
int texture_width, texture_height;
double render_width;
@@ -4006,8 +3985,8 @@ gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
graphene_vec4_t offset;
init_color_matrix (&matrix, &offset,
foreground_color, success_color,
warning_color, error_color);
&colors[0], &colors[3],
&colors[2], &colors[1]);
gtk_snapshot_push_color_matrix (snapshot, &matrix, &offset);
}
@@ -4068,6 +4047,12 @@ icon_paintable_init (GdkPaintableInterface *iface)
iface->get_intrinsic_height = icon_paintable_get_intrinsic_height;
}
static void
icon_symbolic_paintable_init (GtkSymbolicPaintableInterface *iface)
{
iface->snapshot_symbolic = gtk_icon_paintable_snapshot_symbolic;
}
/**
* gtk_icon_paintable_new_for_file:
* @file: a `GFile`

View File

@@ -32,14 +32,6 @@ void gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
GdkRGBA *success_out,
GdkRGBA *warning_out,
GdkRGBA *error_out);
void gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
GtkSnapshot *snapshot,
double width,
double height,
const GdkRGBA *foreground_color,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color);
int gtk_icon_theme_get_serial (GtkIconTheme *self);

View File

@@ -28,6 +28,7 @@
#include "gtkcsstransformvalueprivate.h"
#include "gtkiconthemeprivate.h"
#include "gtksnapshot.h"
#include "gtksymbolicpaintable.h"
#include "gsktransform.h"
#include <math.h>
@@ -97,8 +98,8 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
{
GskTransform *transform;
gboolean has_shadow;
gboolean is_icon_paintable;
GdkRGBA fg, sc, wc, ec;
gboolean is_symbolic_paintable;
GdkRGBA colors[4];
g_return_if_fail (GTK_IS_CSS_STYLE (style));
g_return_if_fail (snapshot != NULL);
@@ -112,19 +113,19 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
has_shadow = gtk_css_shadow_value_push_snapshot (style->icon->icon_shadow, snapshot);
is_icon_paintable = GTK_IS_ICON_PAINTABLE (paintable);
if (is_icon_paintable)
is_symbolic_paintable = GTK_IS_SYMBOLIC_PAINTABLE (paintable);
if (is_symbolic_paintable)
{
gtk_icon_theme_lookup_symbolic_colors (style, &fg, &sc, &wc, &ec);
gtk_icon_theme_lookup_symbolic_colors (style, &colors[0], &colors[3], &colors[2], &colors[1]);
if (fg.alpha == 0.0f)
if (gdk_rgba_is_clear (&colors[0]))
goto transparent;
}
if (transform == NULL)
{
if (is_icon_paintable)
gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec);
if (is_symbolic_paintable)
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable), snapshot, width, height, colors, G_N_ELEMENTS (colors));
else
gdk_paintable_snapshot (paintable, snapshot, width, height);
}
@@ -137,8 +138,8 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
gtk_snapshot_transform (snapshot, transform);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
if (is_icon_paintable)
gtk_icon_paintable_snapshot_with_colors (GTK_ICON_PAINTABLE (paintable), snapshot, width, height, &fg, &sc, &wc, &ec);
if (is_symbolic_paintable)
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable), snapshot, width, height, colors, G_N_ELEMENTS (colors));
else
gdk_paintable_snapshot (paintable, snapshot, width, height);