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



commit d71e06d41b845597edb89a84f481ef8d03045143
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 10 14:23:39 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 |   34 +++++++++++++++++++++++++++++-----
 gtk/gtkwidget.h |    4 +++-
 2 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 687cbe2..d67a67e 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4729,6 +4729,34 @@ 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,
+                     widget->priv->allocation.width,
+                     widget->priv->allocation.height,
+                     &result);
+    }
+}
+
 static gboolean
 gtk_widget_real_expose_event (GtkWidget      *widget,
 			      GdkEventExpose *expose)
@@ -4776,11 +4804,7 @@ gtk_widget_real_expose_event (GtkWidget      *widget,
                        widget->priv->allocation.y);
     }
 
-  g_signal_emit (widget, widget_signals[DRAW], 
-                 0, cr,
-                 widget->priv->allocation.width,
-                 widget->priv->allocation.height,
-                 &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 67bec89..8524c72 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -885,8 +885,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]