Patch for gtkimage.c (fixes resize and redraw problems)




This is my first patch submission, so please let me know if I'm doing
something wrong.

This patch fixes problems with redraws and resizes when a gtkimage is
within a container that might give it an allocation larger than the
actual image.  It fixes both screen glitches and actual crashes (the
crashes generally only occurred when using xshm).

The basic problem was that the old code really needed to be doing a
full rectangle intersection instead of more limited checks.

I don't know if it's a violation of the Gtk coding standard, but I
moved some variables inside the if's local scope so they wouldn't take
up stack space when not needed (assuming that the optimizer doesn't
kill them anyway in that situation), and so that you can't
accidentally refer to them when you didn't mean to.  Please let me
know, and change it back if that's not OK.

--- gtk+971025/gtk/gtkimage.c	Wed Sep 24 20:21:46 1997
+++ gtk+971025-patched/gtk/gtkimage.c	Tue Oct 28 15:53:58 1997
@@ -127,17 +127,17 @@
 gtk_image_expose (GtkWidget      *widget,
 		  GdkEventExpose *event)
 {
-  GtkImage *image;
-  GtkMisc *misc;
-  GdkRectangle area;
-  gint x, y;
-
   g_return_val_if_fail (widget != NULL, FALSE);
   g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
   g_return_val_if_fail (event != NULL, FALSE);
 
   if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget))
     {
+      GtkImage *image;
+      GtkMisc *misc;
+      GdkRectangle area, image_bound, intersection;
+      gint x, y;
+      
       image = GTK_IMAGE (widget);
       misc = GTK_MISC (widget);
 
@@ -156,20 +156,23 @@
 	  gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
 	}
 
-      area = event->area;
-      if ((area.x < 0) || (area.y < 0))
-	{
-	  area.x = area.y = 0;
-	  area.width = image->image->width;
-	  area.height = image->image->height;
-	}
-
-      gdk_draw_image (widget->window,
-		      widget->style->black_gc,
-		      image->image,
-		      area.x, area.y, x+area.x, y+area.y,
-		      area.width, area.height);
+      image_bound.x = x;
+      image_bound.y = y;      
+      image_bound.width = image->image->width;
+      image_bound.height = image->image->height;      
 
+      area = event->area;
+      
+      if(gdk_rectangle_intersect(&image_bound, &area, &intersection))
+        {
+          gdk_draw_image (widget->window,
+                          widget->style->black_gc,
+                          image->image,
+                          image_bound.x - x, image_bound.y - y,
+                          image_bound.x, image_bound.y,
+                          image_bound.width, image_bound.height);
+        }
+      
       if (image->mask)
 	{
 	  gdk_gc_set_clip_mask (widget->style->black_gc, NULL);



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