[gtk+/gtk-2-22] test: Convert testinput to Cairo



commit 8e537f94ac91e02cccbcd229d58969ae08520d33
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jul 15 18:37:08 2010 +0200

    test: Convert testinput to Cairo
    
    The test is broken though as it draws onto windows outside of expose
    events.
    And we all know you shouldn't do that.

 tests/testinput.c |   39 ++++++++++++++++++++++-----------------
 1 files changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/tests/testinput.c b/tests/testinput.c
index 1336b7c..695bdfe 100644
--- a/tests/testinput.c
+++ b/tests/testinput.c
@@ -52,16 +52,14 @@ update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
 
   if (pixmap != NULL)
     {
+      cairo_t *cr = gdk_cairo_create (widget->window);
+
       if (cursor_present && (cursor_present != state ||
 			     x != cursor_x || y != cursor_y))
 	{
-          cairo_t *cr = gdk_cairo_create (widget->window);
-
           gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
           cairo_rectangle (cr, cursor_x - 5, cursor_y - 5, 10, 10);
           cairo_fill (cr);
-
-          cairo_destroy (cr);
 	}
 
       cursor_present = state;
@@ -70,12 +68,14 @@ update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
 
       if (cursor_present)
 	{
-	  gdk_draw_rectangle (widget->window,
-			      widget->style->black_gc,
-			      TRUE,
-			      cursor_x - 5, cursor_y -5,
-			      10, 10);
+          cairo_set_source_rgb (cr, 0, 0, 0);
+          cairo_rectangle (cr, 
+                           cursor_x - 5, cursor_y -5,
+			   10, 10);
+          cairo_fill (cr);
 	}
+
+      cairo_destroy (cr);
     }
 }
 
@@ -122,31 +122,36 @@ static void
 draw_brush (GtkWidget *widget, GdkInputSource source,
 	    gdouble x, gdouble y, gdouble pressure)
 {
-  GdkGC *gc;
+  GdkColor color;
   GdkRectangle update_rect;
+  cairo_t *cr;
 
   switch (source)
     {
     case GDK_SOURCE_MOUSE:
-      gc = widget->style->dark_gc[gtk_widget_get_state (widget)];
+      color = widget->style->dark[gtk_widget_get_state (widget)];
       break;
     case GDK_SOURCE_PEN:
-      gc = widget->style->black_gc;
+      color.red = color.green = color.blue = 0;
       break;
     case GDK_SOURCE_ERASER:
-      gc = widget->style->white_gc;
+      color.red = color.green = color.blue = 65535;
       break;
     default:
-      gc = widget->style->light_gc[gtk_widget_get_state (widget)];
+      color = widget->style->light[gtk_widget_get_state (widget)];
     }
 
   update_rect.x = x - 10 * pressure;
   update_rect.y = y - 10 * pressure;
   update_rect.width = 20 * pressure;
   update_rect.height = 20 * pressure;
-  gdk_draw_rectangle (pixmap, gc, TRUE,
-		      update_rect.x, update_rect.y,
-		      update_rect.width, update_rect.height);
+
+  cr = gdk_cairo_create (pixmap);
+  gdk_cairo_set_source_color (cr, &color);
+  gdk_cairo_rectangle (cr, &update_rect);
+  cairo_fill (cr);
+  cairo_destroy (cr);
+
   gtk_widget_queue_draw_area (widget,
 			      update_rect.x, update_rect.y,
 			      update_rect.width, update_rect.height);



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