[gtk+/rendering-cleanup-next: 141/155] test: Port offscreen test to draw vfunc



commit 5f6ca2f739b016d6658532f9049a03a9c1789eb9
Author: Benjamin Otte <otte redhat com>
Date:   Sat Sep 11 00:08:54 2010 +0200

    test: Port offscreen test to draw vfunc

 tests/gtkoffscreenbox.c |  145 +++++++++++++++++++++--------------------------
 1 files changed, 65 insertions(+), 80 deletions(-)
---
diff --git a/tests/gtkoffscreenbox.c b/tests/gtkoffscreenbox.c
index 49e1aa7..7573dd3 100644
--- a/tests/gtkoffscreenbox.c
+++ b/tests/gtkoffscreenbox.c
@@ -17,8 +17,8 @@ static void        gtk_offscreen_box_size_allocate (GtkWidget       *widget,
                                                     GtkAllocation   *allocation);
 static gboolean    gtk_offscreen_box_damage        (GtkWidget       *widget,
                                                     GdkEventExpose  *event);
-static gboolean    gtk_offscreen_box_expose        (GtkWidget       *widget,
-                                                    GdkEventExpose  *offscreen);
+static gboolean    gtk_offscreen_box_draw          (GtkWidget       *widget,
+                                                    cairo_t         *cr);
 
 static void        gtk_offscreen_box_add           (GtkContainer    *container,
                                                     GtkWidget       *child);
@@ -117,7 +117,7 @@ gtk_offscreen_box_class_init (GtkOffscreenBoxClass *klass)
   widget_class->unrealize = gtk_offscreen_box_unrealize;
   widget_class->size_request = gtk_offscreen_box_size_request;
   widget_class->size_allocate = gtk_offscreen_box_size_allocate;
-  widget_class->expose_event = gtk_offscreen_box_expose;
+  widget_class->draw = gtk_offscreen_box_draw;
 
   g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
                                    GTK_TYPE_OFFSCREEN_BOX,
@@ -584,88 +584,73 @@ gtk_offscreen_box_damage (GtkWidget      *widget,
 }
 
 static gboolean
-gtk_offscreen_box_expose (GtkWidget      *widget,
-			  GdkEventExpose *event)
+gtk_offscreen_box_draw (GtkWidget *widget,
+                        cairo_t   *cr)
 {
   GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget);
   GdkWindow *window;
 
-  if (gtk_widget_is_drawable (widget))
+  window = gtk_widget_get_window (widget);
+  if (gtk_cairo_should_draw_window (cr, window))
     {
-      window = gtk_widget_get_window (widget);
-      if (event->window == window)
-	{
-          cairo_surface_t *surface;
-          GtkAllocation child_area;
-          cairo_t *cr;
-	  int start_y = 0;
-
-	  if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
-	    {
-	      surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
-              gtk_widget_get_allocation (offscreen_box->child1, &child_area);
-
-	      cr = gdk_cairo_create (window);
-
-              cairo_set_source_surface (cr, surface, 0, 0);
-              cairo_paint (cr);
-
-              cairo_destroy (cr);
-
-              start_y += child_area.height;
-	    }
-
-	  if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
-	    {
-              gint w, h;
-
-	      surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
-              gtk_widget_get_allocation (offscreen_box->child2, &child_area);
-
-	      cr = gdk_cairo_create (window);
-
-              /* transform */
-	      cairo_translate (cr, 0, start_y);
-	      cairo_translate (cr, child_area.width / 2, child_area.height / 2);
-	      cairo_rotate (cr, offscreen_box->angle);
-	      cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
-
-              /* clip */
-              gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
-              cairo_rectangle (cr, 0, 0, w, h);
-              cairo_clip (cr);
-
-              /* paint */
-	      cairo_set_source_surface (cr, surface, 0, 0);
-	      cairo_paint (cr);
-
-              cairo_destroy (cr);
-	    }
-	}
-      else if (event->window == offscreen_box->offscreen_window1)
-	{
-	  gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
-			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
-			      &event->area, widget, "blah",
-			      0, 0, -1, -1);
-
-	  if (offscreen_box->child1)
-	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
-					    offscreen_box->child1,
-                                            event);
-	}
-      else if (event->window == offscreen_box->offscreen_window2)
-	{
-	  gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
-			      GTK_STATE_NORMAL, GTK_SHADOW_NONE,
-			      &event->area, widget, "blah",
-			      0, 0, -1, -1);
-
-	  if (offscreen_box->child2)
-	    gtk_container_propagate_expose (GTK_CONTAINER (widget),
-					    offscreen_box->child2,
-                                            event);
-	}
+      cairo_surface_t *surface;
+      GtkAllocation child_area;
+
+      if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
+        {
+          surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
+
+          cairo_set_source_surface (cr, surface, 0, 0);
+          cairo_paint (cr);
+
+          gtk_widget_get_allocation (offscreen_box->child1, &child_area);
+          cairo_translate (cr, 0, child_area.height);
+        }
+
+      if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2))
+        {
+          surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
+          gtk_widget_get_allocation (offscreen_box->child2, &child_area);
+
+          /* transform */
+          cairo_translate (cr, child_area.width / 2, child_area.height / 2);
+          cairo_rotate (cr, offscreen_box->angle);
+          cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
+
+          /* paint */
+          cairo_set_source_surface (cr, surface, 0, 0);
+          cairo_paint (cr);
+        }
+    }
+  else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1))
+    {
+      gint w, h;
+
+      gdk_drawable_get_size (offscreen_box->offscreen_window1, &w, &h);
+      gtk_cairo_paint_flat_box (gtk_widget_get_style (widget), cr,
+                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                          widget, "blah",
+                          0, 0, w, h);
+
+      if (offscreen_box->child1)
+        gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                      offscreen_box->child1,
+                                      cr);
+    }
+  else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2))
+    {
+      gint w, h;
+
+      gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
+      gtk_cairo_paint_flat_box (gtk_widget_get_style (widget), cr,
+                          GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+                          widget, "blah",
+                          0, 0, w, h);
+
+      if (offscreen_box->child2)
+        gtk_container_propagate_draw (GTK_CONTAINER (widget),
+                                      offscreen_box->child2,
+                                      cr);
     }
 
   return FALSE;



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