[gtk/wip/otte/symbolic-paintable: 2/4] gtk: Port icontheme to GtkSymbolicPaintable




commit d8e4d9b7cad9e344311ba85a6bdd27bdd6e5fd49
Author: Benjamin Otte <otte redhat com>
Date:   Sat Aug 28 00:23:29 2021 +0200

    gtk: Port icontheme to GtkSymbolicPaintable

 gtk/gtkcssimageicontheme.c        | 16 +++++-----
 gtk/gtkcssimageiconthemeprivate.h |  5 +---
 gtk/gtkicontheme.c                | 63 +++++++++++++++------------------------
 gtk/gtkiconthemeprivate.h         |  8 -----
 gtk/gtkrendericon.c               | 21 ++++++-------
 gtk/gtksymbolicpaintable.h        |  2 +-
 6 files changed, 45 insertions(+), 70 deletions(-)
---
diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c
index 109b0abd83..b9096b1006 100644
--- a/gtk/gtkcssimageicontheme.c
+++ b/gtk/gtkcssimageicontheme.c
@@ -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);
 }
diff --git a/gtk/gtkcssimageiconthemeprivate.h b/gtk/gtkcssimageiconthemeprivate.h
index 5b1540d413..b0b4d09794 100644
--- a/gtk/gtkcssimageiconthemeprivate.h
+++ b/gtk/gtkcssimageiconthemeprivate.h
@@ -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;
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 52a57bd69f..eb6b7285d3 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -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`
diff --git a/gtk/gtkiconthemeprivate.h b/gtk/gtkiconthemeprivate.h
index 44225fb57a..bab1011d69 100644
--- a/gtk/gtkiconthemeprivate.h
+++ b/gtk/gtkiconthemeprivate.h
@@ -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);
 
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index a434c73010..2cd601aa34 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -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);
 
diff --git a/gtk/gtksymbolicpaintable.h b/gtk/gtksymbolicpaintable.h
index 66b984973b..26d8320085 100644
--- a/gtk/gtksymbolicpaintable.h
+++ b/gtk/gtksymbolicpaintable.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
 #define GTK_TYPE_SYMBOLIC_PAINTABLE       (gtk_symbolic_paintable_get_type ())
 
 GDK_AVAILABLE_IN_ALL
-G_DECLARE_INTERFACE (GtkSymbolicPaintable, gtk_symbolic_paintable, GTK, SYMBOLIC_PAINTABLE, GListModel)
+G_DECLARE_INTERFACE (GtkSymbolicPaintable, gtk_symbolic_paintable, GTK, SYMBOLIC_PAINTABLE, GdkPaintable)
 
 /**
  * GtkSymbolicPaintableInterface:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]