[gtk+/rendering-cleanup-next: 136/199] testgtk: Use draw signal in cursors example



commit 98e2bd46f1325980fa16c60123e1d2dc8c5ce9c1
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 9 03:12:51 2010 +0200

    testgtk: Use draw signal in cursors example

 tests/testgtk.c |   38 +++++++++++---------------------------
 1 files changed, 11 insertions(+), 27 deletions(-)
---
diff --git a/tests/testgtk.c b/tests/testgtk.c
index b18b52f..14db373 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -4951,43 +4951,27 @@ create_spins (GtkWidget *widget)
  */
 
 static gint
-cursor_expose_event (GtkWidget *widget,
-		     GdkEvent  *event,
-		     gpointer   user_data)
+cursor_draw (GtkWidget *widget,
+	     cairo_t   *cr,
+	     gpointer   user_data)
 {
-  GtkAllocation allocation;
-  GtkDrawingArea *darea;
-  GdkDrawable *drawable;
-  guint max_width;
-  guint max_height;
-  cairo_t *cr;
-
-  g_return_val_if_fail (widget != NULL, TRUE);
-  g_return_val_if_fail (GTK_IS_DRAWING_AREA (widget), TRUE);
-
-  darea = GTK_DRAWING_AREA (widget);
-  drawable = gtk_widget_get_window (widget);
-
-  gtk_widget_get_allocation (widget, &allocation);
-  max_width = allocation.width;
-  max_height = allocation.height;
+  int width, height;
 
-  cr = gdk_cairo_create (drawable);
+  width = gtk_widget_get_allocated_width (widget);
+  height = gtk_widget_get_allocated_height (widget);
 
   cairo_set_source_rgb (cr, 1, 1, 1);
-  cairo_rectangle (cr, 0, 0, max_width, max_height / 2);
+  cairo_rectangle (cr, 0, 0, width, height / 2);
   cairo_fill (cr);
 
   cairo_set_source_rgb (cr, 0, 0, 0);
-  cairo_rectangle (cr, 0, max_height / 2, max_width, max_height / 2);
+  cairo_rectangle (cr, 0, height / 2, width, height / 2);
   cairo_fill (cr);
 
   gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->bg[GTK_STATE_NORMAL]);
-  cairo_rectangle (cr, max_width / 3, max_height / 3, max_width / 3, max_height / 3);
+  cairo_rectangle (cr, width / 3, height / 3, width / 3, height / 3);
   cairo_fill (cr);
 
-  cairo_destroy (cr);
-
   return TRUE;
 }
 
@@ -5158,8 +5142,8 @@ create_cursors (GtkWidget *widget)
       gtk_widget_set_size_request (darea, 80, 80);
       gtk_container_add (GTK_CONTAINER (frame), darea);
       g_signal_connect (darea,
-			"expose_event",
-			G_CALLBACK (cursor_expose_event),
+			"draw",
+			G_CALLBACK (cursor_draw),
 			NULL);
       gtk_widget_set_events (darea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
       g_signal_connect (darea,



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