[gtk+/gtk-style-context: 216/260] GtkThemingEngine: use background-image in render_background()



commit 7c58c090420de319da0b98e972dbbb008b8195d7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Sep 2 02:14:10 2010 +0200

    GtkThemingEngine: use background-image in render_background()

 gtk/gtkthemingengine.c |   52 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index b37a388..5a2285a 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -892,28 +892,47 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
                                       gdouble           width,
                                       gdouble           height)
 {
+  GdkColor *bg_color, *base_color;
+  cairo_pattern_t *pattern;
   GtkStateFlags flags;
-  GdkColor *color;
 
-  cairo_save (cr);
   flags = gtk_theming_engine_get_state (engine);
-
-  if (gtk_theming_engine_has_class (engine, "entry"))
-    gtk_theming_engine_get (engine, flags,
-                            "base-color", &color,
-                            NULL);
-  else
-    gtk_theming_engine_get (engine, flags,
-                            "background-color", &color,
-                            NULL);
-
-  gdk_cairo_set_source_color (cr, color);
+  cairo_save (cr);
 
   if (gtk_theming_engine_has_class (engine, "spinbutton") &&
       gtk_theming_engine_has_class (engine, "button"))
-    cairo_rectangle (cr, x + 2, y + 2, width - 4, height - 4);
+    {
+      x += 2;
+      y += 2;
+      width -= 4;
+      height -= 4;
+    }
+
+  gtk_theming_engine_get (engine, flags,
+                          "background-image", &pattern,
+                          "background-color", &bg_color,
+                          "base-color", &base_color,
+                          NULL);
+
+  if (pattern)
+    {
+      cairo_translate (cr, x, y);
+      cairo_scale (cr, width, height);
+
+      cairo_rectangle (cr, 0, 0, 1, 1);
+      cairo_set_source (cr, pattern);
+
+      cairo_pattern_destroy (pattern);
+    }
   else
-    cairo_rectangle (cr, x, y, width, height);
+    {
+      if (gtk_theming_engine_has_class (engine, "entry"))
+        gdk_cairo_set_source_color (cr, base_color);
+      else
+        gdk_cairo_set_source_color (cr, bg_color);
+
+      cairo_rectangle (cr, x, y, width, height);
+    }
 
   if (gtk_theming_engine_has_class (engine, "tooltip"))
     {
@@ -927,7 +946,8 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
 
   cairo_restore (cr);
 
-  gdk_color_free (color);
+  gdk_color_free (base_color);
+  gdk_color_free (bg_color);
 }
 
 static void



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