[gtk+/cairo-style: 5/21] style: Convert draw_arrow vfunc to Cairo version



commit 891c3cbc62a752750e6a8b20a7548eb06eaf37b0
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 16:15:59 2010 +0200

    style: Convert draw_arrow vfunc to Cairo version

 gtk/gtkstyle.c |   79 +++++++++++++++++++++++++++++++++++++++++--------------
 gtk/gtkstyle.h |   41 ++++++++++++++++++----------
 2 files changed, 85 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 36ddba9..5fc420b 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -127,10 +127,9 @@ static void gtk_default_draw_shadow     (GtkStyle        *style,
 					 gint             width,
 					 gint             height);
 static void gtk_default_draw_arrow      (GtkStyle        *style,
-					 GdkWindow       *window,
+					 cairo_t         *cr,
 					 GtkStateType     state_type,
 					 GtkShadowType    shadow_type,
-					 GdkRectangle    *area,
 					 GtkWidget       *widget,
 					 const gchar     *detail,
 					 GtkArrowType     arrow_type,
@@ -2288,10 +2287,9 @@ calculate_arrow_geometry (GtkArrowType  arrow_type,
 
 static void
 gtk_default_draw_arrow (GtkStyle      *style,
-			GdkWindow     *window,
+			cairo_t       *cr,
 			GtkStateType   state,
 			GtkShadowType  shadow,
-			GdkRectangle  *area,
 			GtkWidget     *widget,
 			const gchar   *detail,
 			GtkArrowType   arrow_type,
@@ -2301,30 +2299,16 @@ gtk_default_draw_arrow (GtkStyle      *style,
 			gint           width,
 			gint           height)
 {
-  cairo_t *cr;
-
-  sanitize_size (window, &width, &height);
-
   calculate_arrow_geometry (arrow_type, &x, &y, &width, &height);
 
   if (detail && strcmp (detail, "menu_scroll_arrow_up") == 0)
     y++;
 
-  cr = gdk_cairo_create (window);
-
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-
   if (state == GTK_STATE_INSENSITIVE)
     draw_arrow (cr, &style->white, arrow_type,
 		x + 1, y + 1, width, height);
   draw_arrow (cr, &style->fg[state], arrow_type,
 	      x, y, width, height);
-
-  cairo_destroy (cr);
 }
 
 static void
@@ -5033,13 +5017,68 @@ gtk_paint_arrow (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type,
-                                           (GdkRectangle *) area, widget, detail,
+  sanitize_size (window, &width, &height);
+
+  cr = gtk_style_cairo_create (window, area);
+
+  gtk_cairo_paint_arrow (style, cr, state_type, shadow_type,
+                         widget, detail,
+                         arrow_type, fill, x, y, width, height);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_arrow:
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @widget: (allow-none): the widget
+ * @detail: (allow-none): a style detail
+ * @arrow_type: the type of arrow to draw
+ * @fill: %TRUE if the arrow tip should be filled
+ * @x: x origin of the rectangle to draw the arrow in
+ * @y: y origin of the rectangle to draw the arrow in
+ * @width: width of the rectangle to draw the arrow in
+ * @height: height of the rectangle to draw the arrow in
+ * 
+ * Draws an arrow in the given rectangle on @cr using the given 
+ * parameters. @arrow_type determines the direction of the arrow.
+ */
+void
+gtk_cairo_paint_arrow (GtkStyle           *style,
+                       cairo_t            *cr,
+                       GtkStateType        state_type,
+                       GtkShadowType       shadow_type,
+                       GtkWidget          *widget,
+                       const gchar        *detail,
+                       GtkArrowType        arrow_type,
+                       gboolean            fill,
+                       gint                x,
+                       gint                y,
+                       gint                width,
+                       gint                height)
+{
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (width >= 0);
+  g_return_if_fail (height >= 0);
+
+  cairo_save (cr);
+
+  GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
+                                           widget, detail,
                                            arrow_type, fill, x, y, width, height);
+
+  cairo_restore (cr);
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 6ffe514..705f414 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -192,10 +192,9 @@ struct _GtkStyleClass
 				 gint			 width,
 				 gint			 height);
   void (*draw_arrow)		(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
 				 GtkShadowType		 shadow_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 GtkArrowType		 arrow_type,
@@ -506,19 +505,31 @@ void gtk_cairo_paint_shadow      (GtkStyle           *style,
                                   gint                y,
                                   gint                width,
                                   gint                height);
-void gtk_paint_arrow       (GtkStyle           *style,
-			    GdkWindow          *window,
-			    GtkStateType        state_type,
-			    GtkShadowType       shadow_type,
-			    const GdkRectangle *area,
-			    GtkWidget          *widget,
-			    const gchar        *detail,
-			    GtkArrowType        arrow_type,
-			    gboolean            fill,
-			    gint                x,
-			    gint                y,
-			    gint                width,
-			    gint                height);
+void gtk_paint_arrow             (GtkStyle           *style,
+                                  GdkWindow          *window,
+                                  GtkStateType        state_type,
+                                  GtkShadowType       shadow_type,
+                                  const GdkRectangle *area,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  GtkArrowType        arrow_type,
+                                  gboolean            fill,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
+void gtk_cairo_paint_arrow       (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkShadowType       shadow_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  GtkArrowType        arrow_type,
+                                  gboolean            fill,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
 void gtk_paint_diamond     (GtkStyle           *style,
 			    GdkWindow          *window,
 			    GtkStateType        state_type,



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