[gtk+/rendering-cleanup: 6/76] style: Convert draw_hline vfunc to Cairo version



commit 0a733579d808171ce37359b7cd646ea3a66d96d9
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 15:35:58 2010 +0200

    style: Convert draw_hline vfunc to Cairo version

 gtk/gtkstyle.c                       |   81 ++++++++++++++++++++++++++-------
 gtk/gtkstyle.h                       |   29 ++++++++-----
 modules/engines/pixbuf/pixbuf-draw.c |   12 ++---
 3 files changed, 86 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index f72462c..26b2e2e 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -101,9 +101,8 @@ static GdkPixbuf *gtk_default_render_icon      (GtkStyle            *style,
                                                 GtkWidget           *widget,
                                                 const gchar         *detail);
 static void gtk_default_draw_hline      (GtkStyle        *style,
-					 GdkWindow       *window,
+					 cairo_t         *cr,
 					 GtkStateType     state_type,
-					 GdkRectangle    *area,
 					 GtkWidget       *widget,
 					 const gchar     *detail,
 					 gint             x1,
@@ -1644,17 +1643,15 @@ _cairo_draw_point (cairo_t *cr,
 }
 
 static void
-gtk_default_draw_hline (GtkStyle     *style,
-                        GdkWindow    *window,
+gtk_default_draw_hline (GtkStyle      *style,
+                        cairo_t       *cr,
                         GtkStateType  state_type,
-                        GdkRectangle  *area,
                         GtkWidget     *widget,
                         const gchar   *detail,
                         gint          x1,
                         gint          x2,
                         gint          y)
 {
-  cairo_t *cr;
   gint thickness_light;
   gint thickness_dark;
   gint i;
@@ -1662,15 +1659,8 @@ gtk_default_draw_hline (GtkStyle     *style,
   thickness_light = style->ythickness / 2;
   thickness_dark = style->ythickness - thickness_light;
   
-  cr = gdk_cairo_create (window);
   cairo_set_line_width (cr, 1.0);
 
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-  
   if (detail && !strcmp (detail, "label"))
     {
       if (state_type == GTK_STATE_INSENSITIVE)
@@ -1692,8 +1682,6 @@ gtk_default_draw_hline (GtkStyle     *style,
           _cairo_draw_line (cr, &style->light[state_type], x1 + thickness_light - i, y + i, x2, y + i);
         }
     }
-
-  cairo_destroy (cr);
 }
 
 
@@ -4780,6 +4768,22 @@ hls_to_rgb (gdouble *h,
 }
 
 
+static cairo_t *
+gtk_style_cairo_create (GdkWindow *window, const GdkRectangle *area)
+{
+  cairo_t *cr;
+
+  cr = gdk_cairo_create (window);
+
+  if (area)
+    {
+      gdk_cairo_rectangle (cr, area);
+      cairo_clip (cr);
+    }
+
+  return cr;
+}
+
 /**
  * gtk_paint_hline:
  * @style: a #GtkStyle
@@ -4807,13 +4811,56 @@ gtk_paint_hline (GtkStyle           *style,
                  gint                x2,
                  gint                y)
 {
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type,
-                                           (GdkRectangle *) area, widget, detail,
+  cr = gtk_style_cairo_create (window, area);
+
+  gtk_cairo_paint_hline (style, cr, state_type,
+                         widget, detail,
+                         x1, x2, y);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_hline:
+ * @style: a #GtkStyle
+ * @cr: a #caio_t
+ * @state_type: a state
+ * @widget: (allow-none): the widget
+ * @detail: (allow-none): a style detail
+ * @x1: the starting x coordinate
+ * @x2: the ending x coordinate
+ * @y: the y coordinate
+ *
+ * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @cr
+ * using the given style and state.
+ **/ 
+void 
+gtk_cairo_paint_hline (GtkStyle           *style,
+                       cairo_t            *cr,
+                       GtkStateType        state_type,
+                       GtkWidget          *widget,
+                       const gchar        *detail,
+                       gint                x1,
+                       gint                x2,
+                       gint                y)
+{
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
+
+  cairo_save (cr);
+
+  GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
+                                           widget, detail,
                                            x1, x2, y);
+
+  cairo_restore (cr);
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 51e30a6..382c67a 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -166,9 +166,8 @@ struct _GtkStyleClass
    */
 
   void (*draw_hline)		(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 gint			 x1,
@@ -454,15 +453,23 @@ GdkPixbuf*  gtk_style_render_icon     (GtkStyle            *style,
                                        GtkWidget           *widget,
                                        const gchar         *detail);
 
-void gtk_paint_hline       (GtkStyle           *style,
-			    GdkWindow          *window,
-			    GtkStateType        state_type,
-			    const GdkRectangle *area,
-			    GtkWidget          *widget,
-			    const gchar        *detail,
-			    gint                x1,
-			    gint                x2,
-			    gint                y);
+void gtk_paint_hline             (GtkStyle           *style,
+                                  GdkWindow          *window,
+                                  GtkStateType        state_type,
+                                  const GdkRectangle *area,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x1,
+                                  gint                x2,
+                                  gint                y);
+void gtk_cairo_paint_hline       (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x1,
+                                  gint                x2,
+                                  gint                y);
 void gtk_paint_vline       (GtkStyle           *style,
 			    GdkWindow          *window,
 			    GtkStateType        state_type,
diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c
index 6920288..1c1dc39 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -388,9 +388,8 @@ draw_gap_image_no_cairo(GtkStyle       *style,
 
 static void
 draw_hline (GtkStyle     *style,
-	    GdkWindow    *window,
+	    cairo_t      *cr,
 	    GtkStateType  state,
-	    GdkRectangle *area,
 	    GtkWidget    *widget,
 	    const gchar  *detail,
 	    gint          x1,
@@ -400,9 +399,6 @@ draw_hline (GtkStyle     *style,
   ThemeImage *image;
   ThemeMatchData   match_data;
   
-  g_return_if_fail(style != NULL);
-  g_return_if_fail(window != NULL);
-
   match_data.function = TOKEN_D_HLINE;
   match_data.detail = (gchar *)detail;
   match_data.flags = THEME_MATCH_ORIENTATION | THEME_MATCH_STATE;
@@ -413,12 +409,12 @@ draw_hline (GtkStyle     *style,
   if (image)
     {
       if (image->background)
-	theme_pixbuf_render_no_cairo (image->background,
-			     window, area, COMPONENT_ALL, FALSE,
+	theme_pixbuf_render (image->background,
+			     cr, COMPONENT_ALL, FALSE,
 			     x1, y, (x2 - x1) + 1, 2);
     }
   else
-    parent_class->draw_hline (style, window, state, area, widget, detail,
+    parent_class->draw_hline (style, cr, state, widget, detail,
 			      x1, x2, y);
 }
 



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