[gtk+/rendering-cleanup-next: 8/153] API: ruler: Change draw_ticks vfunc



commit c4eaf0710abcb6fd6a4890c4e05141fc84360e67
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 2 14:47:02 2010 +0200

    API: ruler: Change draw_ticks vfunc
    
    We now pass in a cairo_t of the backbuffer and the width and height of
    the widget/backbuffer, so the vfunc has a place to draw to.

 gtk/gtkruler.c |   51 ++++++++++++++++++++++++++++++++-------------------
 gtk/gtkruler.h |    5 ++++-
 2 files changed, 36 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkruler.c b/gtk/gtkruler.c
index 72693f5..bd1e071 100644
--- a/gtk/gtkruler.c
+++ b/gtk/gtkruler.c
@@ -88,7 +88,10 @@ static gboolean gtk_ruler_motion_notify   (GtkWidget      *widget,
 static gboolean gtk_ruler_expose          (GtkWidget      *widget,
                                            GdkEventExpose *event);
 static void     gtk_ruler_make_pixmap     (GtkRuler       *ruler);
-static void     gtk_ruler_real_draw_ticks (GtkRuler       *ruler);
+static void     gtk_ruler_real_draw_ticks (GtkRuler       *ruler,
+                                           cairo_t        *cr,
+                                           int             width,
+                                           int             height);
 static void     gtk_ruler_real_draw_pos   (GtkRuler       *ruler);
 
 
@@ -437,10 +440,25 @@ gtk_ruler_get_range (GtkRuler *ruler,
 void
 gtk_ruler_draw_ticks (GtkRuler *ruler)
 {
+  GtkRulerPrivate *priv = ruler->priv;
+  GtkAllocation allocation;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_RULER (ruler));
 
+  if (priv->backing_store == NULL)
+    return;
+  
+  gtk_widget_get_allocation (GTK_WIDGET (ruler), &allocation);
+  cr = cairo_create (priv->backing_store);
+
   if (GTK_RULER_GET_CLASS (ruler)->draw_ticks)
-    GTK_RULER_GET_CLASS (ruler)->draw_ticks (ruler);
+    GTK_RULER_GET_CLASS (ruler)->draw_ticks (ruler,
+                                             cr,
+                                             allocation.width,
+                                             allocation.height);
+
+  cairo_destroy (cr);
 }
 
 void
@@ -633,13 +651,14 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
 }
 
 static void
-gtk_ruler_real_draw_ticks (GtkRuler *ruler)
+gtk_ruler_real_draw_ticks (GtkRuler *ruler,
+                           cairo_t  *cr,
+                           int       w,
+                           int       h)
 {
-  GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (ruler);
   GtkRulerPrivate *priv = ruler->priv;
   GtkStyle *style;
-  cairo_t *cr;
   gint i, j;
   gint width, height;
   gint xthickness;
@@ -659,11 +678,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
   PangoLayout *layout;
   PangoRectangle logical_rect, ink_rect;
 
-  if (!gtk_widget_is_drawable (widget))
-    return;
-
   style = gtk_widget_get_style (widget);
-  gtk_widget_get_allocation (widget, &allocation);
 
   xthickness = style->xthickness;
   ythickness = style->ythickness;
@@ -676,18 +691,17 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      width = allocation.width;
-      height = allocation.height - ythickness * 2;
+      width = w;
+      height = h - ythickness * 2;
     }
   else
     {
-      width = allocation.height;
-      height = allocation.width - ythickness * 2;
+      width = h;
+      height = w - ythickness * 2;
     }
 
 #define DETAILE(private) (priv->orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler");
 
-  cr = cairo_create (priv->backing_store);
   gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
 
   gtk_cairo_paint_box (style, cr,
@@ -696,14 +710,14 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
                        priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
                        "hruler" : "vruler",
                        0, 0,
-                       allocation.width, allocation.height);
+                       w, h);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       cairo_rectangle (cr,
                        xthickness,
                        height + ythickness,
-                       allocation.width - 2 * xthickness,
+                       w - 2 * xthickness,
                        1);
     }
   else
@@ -712,7 +726,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
                        height + xthickness,
                        ythickness,
                        1,
-                       allocation.height - 2 * ythickness);
+                       h - 2 * ythickness);
     }
 
   upper = priv->upper / priv->metric->pixels_per_unit;
@@ -842,9 +856,8 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
     }
 
   cairo_fill (cr);
-out:
-  cairo_destroy (cr);
 
+out:
   g_object_unref (layout);
 }
 
diff --git a/gtk/gtkruler.h b/gtk/gtkruler.h
index f3ebf0c..8d6989e 100644
--- a/gtk/gtkruler.h
+++ b/gtk/gtkruler.h
@@ -75,7 +75,10 @@ struct _GtkRulerClass
 {
   GtkWidgetClass parent_class;
 
-  void (* draw_ticks) (GtkRuler *ruler);
+  void (* draw_ticks) (GtkRuler *ruler,
+                       cairo_t  *cr,
+                       int       width,
+                       int       height);
   void (* draw_pos)   (GtkRuler *ruler);
 
   /* Padding for future expansion */



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