[gtk+/wip/css: 118/143] themingbackground: Convert to GtkCssImage



commit f7f9782263ada06fd6680855d202cdb2a63dd89e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 3 02:40:50 2012 +0100

    themingbackground: Convert to GtkCssImage
    
    The conversion is incomplete and requires some work to account for
    all the CSS crazies, like repeat modes and background-size.

 gtk/gtkthemingbackground.c        |   63 +++++++++++-------------------------
 gtk/gtkthemingbackgroundprivate.h |    4 +-
 2 files changed, 21 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 2a00228..972c47c 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -106,57 +106,34 @@ static void
 _gtk_theming_background_paint (GtkThemingBackground *bg,
                                cairo_t              *cr)
 {
+  cairo_save (cr);
+
   _gtk_rounded_box_path (&bg->clip_box, cr);
+  cairo_clip (cr);
+
   gdk_cairo_set_source_rgba (cr, &bg->bg_color);
+  cairo_paint (cr);
 
-  if (bg->pattern)
+  if (bg->image)
     {
       GtkCssBackgroundRepeat *repeat;
-      cairo_surface_t *surface;
-      int scale_width, scale_height;
+      double image_width, image_height;
 
       gtk_theming_engine_get (bg->engine, bg->flags,
                               "background-repeat", &repeat,
                               NULL);
 
-      if (cairo_pattern_get_surface (bg->pattern, &surface) != CAIRO_STATUS_SUCCESS)
-        surface = NULL;
-
-      if (surface && repeat)
-        {
-          scale_width = cairo_image_surface_get_width (surface);
-          scale_height = cairo_image_surface_get_height (surface);
-          if (repeat->repeat == GTK_CSS_BACKGROUND_REPEAT_STYLE_REPEAT)
-            cairo_pattern_set_extend (bg->pattern, CAIRO_EXTEND_REPEAT);
-          else if (repeat->repeat == GTK_CSS_BACKGROUND_REPEAT_STYLE_NO_REPEAT)
-            cairo_pattern_set_extend (bg->pattern, CAIRO_EXTEND_NONE);
-        }
-      else
-        {
-          cairo_pattern_set_extend (bg->pattern, CAIRO_EXTEND_PAD);
-          scale_width = bg->image_rect.width;
-          scale_height = bg->image_rect.height;
-        }
-
-      if (scale_width && scale_height)
-        {
-          /* Fill background color first */
-          cairo_fill_preserve (cr);
-
-          cairo_translate (cr, bg->image_rect.x, bg->image_rect.y);
-          cairo_scale (cr, scale_width, scale_height);
-          cairo_set_source (cr, bg->pattern);
-          cairo_scale (cr, 1.0 / scale_width, 1.0 / scale_height);
-          cairo_translate (cr, -bg->image_rect.x, -bg->image_rect.y);
-
-          g_free (repeat);
-
-          cairo_pattern_destroy (bg->pattern);
-          bg->pattern = NULL;
-        }
+      _gtk_css_image_get_concrete_size (bg->image,
+                                        0, 0, /* XXX: needs background-size support */
+                                        bg->image_rect.width, bg->image_rect.height,
+                                        &image_width, &image_height);
+
+      cairo_translate (cr, bg->image_rect.x, bg->image_rect.y);
+      /* XXX: repeat flags */
+      _gtk_css_image_draw (bg->image, cr, image_width, image_height);
     }
 
-  cairo_fill (cr);
+  cairo_restore (cr);
 }
 
 static void
@@ -204,9 +181,7 @@ _gtk_theming_background_init_engine (GtkThemingBackground *bg)
   _gtk_theming_background_apply_clip (bg);
   _gtk_theming_background_apply_origin (bg);
 
-  gtk_theming_engine_get (bg->engine, bg->flags,
-                          "background-image", &bg->pattern,
-                          NULL);
+  bg->image = g_value_get_object (_gtk_theming_engine_peek_property (bg->engine, "background-image"));
 }
 
 void
@@ -227,7 +202,7 @@ _gtk_theming_background_init (GtkThemingBackground *bg,
   bg->paint_area.width = width;
   bg->paint_area.height = height;
 
-  bg->pattern = NULL;
+  bg->image = NULL;
   bg->junction = junction;
 
   _gtk_theming_background_init_engine (bg);
@@ -250,5 +225,5 @@ _gtk_theming_background_render (GtkThemingBackground *bg,
 gboolean
 _gtk_theming_background_has_background_image (GtkThemingBackground *bg)
 {
-  return (bg->pattern != NULL) ? TRUE : FALSE;
+  return (bg->image != NULL) ? TRUE : FALSE;
 }
diff --git a/gtk/gtkthemingbackgroundprivate.h b/gtk/gtkthemingbackgroundprivate.h
index 540613d..27dbc82 100644
--- a/gtk/gtkthemingbackgroundprivate.h
+++ b/gtk/gtkthemingbackgroundprivate.h
@@ -25,7 +25,7 @@
 #include <glib-object.h>
 #include <cairo.h>
 
-#include "gtkstylecontext.h"
+#include "gtkcssimageprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "gtkroundedboxprivate.h"
 #include "gtkshadowprivate.h"
@@ -41,7 +41,7 @@ struct _GtkThemingBackground {
   cairo_rectangle_t image_rect;
 
   GtkJunctionSides junction;
-  cairo_pattern_t *pattern;
+  GtkCssImage *image;
 
   GtkRoundedBox padding_box;
   GtkRoundedBox clip_box;



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