[gtk+/rendering-cleanup: 66/141] tests: Convert testinput to use cairo_surface_t



commit 7873ab9e83ed3c16a93c86de0779de72744d4210
Author: Benjamin Otte <otte redhat com>
Date:   Wed Aug 25 15:50:57 2010 +0200

    tests: Convert testinput to use cairo_surface_t

 tests/testinput.c |   40 +++++++++++++++++++---------------------
 1 files changed, 19 insertions(+), 21 deletions(-)
---
diff --git a/tests/testinput.c b/tests/testinput.c
index 1f00c18..aecdb5b 100644
--- a/tests/testinput.c
+++ b/tests/testinput.c
@@ -24,15 +24,13 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#undef GTK_DISABLE_DEPRECATED
-
 #include "config.h"
 #include <stdio.h>
 #include "gtk/gtk.h"
 
-/* Backing pixmap for drawing area */
+/* Backing surface for drawing area */
 
-static GdkPixmap *pixmap = NULL;
+static cairo_surface_t *surface = NULL;
 
 /* Information about cursor */
 
@@ -50,14 +48,14 @@ update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
   static gint cursor_present = 0;
   gint state = !current_device->has_cursor && cursor_proximity;
 
-  if (pixmap != NULL)
+  if (surface != NULL)
     {
       cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
 
       if (cursor_present && (cursor_present != state ||
 			     x != cursor_x || y != cursor_y))
 	{
-          gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+          cairo_set_source_surface (cr, surface, 0, 0);
           cairo_rectangle (cr, cursor_x - 5, cursor_y - 5, 10, 10);
           cairo_fill (cr);
 	}
@@ -79,23 +77,23 @@ update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
     }
 }
 
-/* Create a new backing pixmap of the appropriate size */
+/* Create a new backing surface of the appropriate size */
 static gint
 configure_event (GtkWidget *widget, GdkEventConfigure *event)
 {
   GtkAllocation allocation;
   cairo_t *cr;
 
-  if (pixmap)
-    g_object_unref (pixmap);
+  if (surface)
+    cairo_surface_destroy (surface);
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  pixmap = gdk_pixmap_new (gtk_widget_get_window (widget),
-			   allocation.width,
-			   allocation.height,
-			   -1);
-  cr = gdk_cairo_create (pixmap);
+  surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
+                                               CAIRO_CONTENT_COLOR,
+                                               allocation.width,
+                                               allocation.height);
+  cr = cairo_create (surface);
 
   cairo_set_source_rgb (cr, 1, 1, 1);
   cairo_paint (cr);
@@ -105,14 +103,14 @@ configure_event (GtkWidget *widget, GdkEventConfigure *event)
   return TRUE;
 }
 
-/* Refill the screen from the backing pixmap */
+/* Refill the screen from the backing surface */
 static gint
 expose_event (GtkWidget *widget, GdkEventExpose *event)
 {
   cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
 
-  gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
-  gdk_cairo_rectangle (cr, &event->area);
+  cairo_set_source_surface (cr, surface, 0, 0);
+  gdk_cairo_region (cr, event->region);
   cairo_fill (cr);
 
   cairo_destroy (cr);
@@ -153,7 +151,7 @@ draw_brush (GtkWidget *widget, GdkInputSource source,
   update_rect.width = 20 * pressure;
   update_rect.height = 20 * pressure;
 
-  cr = gdk_cairo_create (pixmap);
+  cr = cairo_create (surface);
   gdk_cairo_set_source_color (cr, &color);
   gdk_cairo_rectangle (cr, &update_rect);
   cairo_fill (cr);
@@ -189,7 +187,7 @@ button_press_event (GtkWidget *widget, GdkEventButton *event)
   current_device = event->device;
   cursor_proximity = TRUE;
 
-  if (event->button == 1 && pixmap != NULL)
+  if (event->button == 1 && surface != NULL)
     {
       gdouble pressure = 0.5;
 
@@ -226,7 +224,7 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
   current_device = event->device;
   cursor_proximity = TRUE;
 
-  if (event->state & GDK_BUTTON1_MASK && pixmap != NULL)
+  if (event->state & GDK_BUTTON1_MASK && surface != NULL)
     {
       if (gdk_device_get_history (event->device, event->window, 
 				  motion_time, event->time,
@@ -325,7 +323,7 @@ main (int argc, char *argv[])
 
   gtk_widget_show (drawing_area);
 
-  /* Signals used to handle backing pixmap */
+  /* Signals used to handle backing surface */
 
   g_signal_connect (drawing_area, "expose_event",
 		    G_CALLBACK (expose_event), NULL);



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