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



commit d5d66aa42a49fd0c34751fd1d6e4fe84671a6702
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 7fbd008..14eadae 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5119,6 +5119,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)
@@ -5166,9 +5192,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 3c58cd7..3ab1bd4 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -947,8 +947,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]