[gtk+/rendering-cleanup-next: 144/154] widget: Clip drawing to the widget's allocation.



commit 2e1a05606c2fde19b6cd89100e70f1e337746a31
Author: Benjamin Otte <otte redhat com>
Date:   Tue Sep 14 16:35:12 2010 +0200

    widget: Clip drawing to the widget's allocation.
    
    I've seen (and written) quite some widgets (and theme engines) that use
    cairo_paint() to draw the background. So avoiding overdraw makes sense.
    
    Also move all that setup into a _gtk_widget_draw_internal() function
    that will be used by all functions that can be used by other functions
    that draw widgets.

 gtk/gtkwidget.c |   30 +++++++++++++++++++++++++++---
 gtk/gtkwidget.h |    4 +++-
 2 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 4f0d66f..aefc38a 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5115,6 +5115,32 @@ gtk_cairo_should_draw_window (cairo_t *cr,
          event->window == window;
 }
 
+/* code shared by gtk_container_propagate_draw() and
+ * gtk_widget_draw()
+ */
+void
+_gtk_widget_draw_internal (GtkWidget *widget,
+                           cairo_t   *cr)
+{
+  if (!gtk_widget_is_drawable (widget))
+    return;
+
+  cairo_rectangle (cr, 
+                   0, 0,
+                   widget->priv->allocation.width,
+                   widget->priv->allocation.height);
+  cairo_clip (cr);
+
+  if (gdk_cairo_get_clip_rectangle (cr, NULL))
+    {
+      gboolean result;
+
+      g_signal_emit (widget, widget_signals[DRAW], 
+                     0, cr,
+                     &result);
+    }
+}
+
 static gboolean
 gtk_widget_real_expose_event (GtkWidget      *widget,
 			      GdkEventExpose *expose)
@@ -5162,9 +5188,7 @@ gtk_widget_real_expose_event (GtkWidget      *widget,
                        widget->priv->allocation.y);
     }
 
-  g_signal_emit (widget, widget_signals[DRAW], 
-                 0, cr,
-                 &result);
+  _gtk_widget_draw_internal (widget, cr);
 
   /* unset here, so if someone keeps a reference to cr we
    * don't leak the window. */
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 41e5ac0..990ced8 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -924,8 +924,10 @@ GtkRequisition *gtk_requisition_new      (void) G_GNUC_MALLOC;
 GtkRequisition *gtk_requisition_copy     (const GtkRequisition *requisition);
 void            gtk_requisition_free     (GtkRequisition       *requisition);
 
-GdkEventExpose *  _gtk_cairo_get_event                    (cairo_t     *cr);
+GdkEventExpose *  _gtk_cairo_get_event                    (cairo_t      *cr);
 
+void              _gtk_widget_draw_internal               (GtkWidget    *widget,
+                                                           cairo_t      *cr);
 void              _gtk_widget_set_has_default             (GtkWidget    *widget,
                                                            gboolean      has_default);
 void              _gtk_widget_set_has_grab                (GtkWidget    *widget,



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