Hi there again,

> > This is surely required, no doubt about this. The table must support 
> > variable row heights and it did not. But now when scrolling from top to 
> > bottom, the height of the repaint region occasionaly turns negative:
> > 
> > java.awt.Rectangle[x=0,y=465,width=34,height=-450]

Now that is really strange, here is what I get in
JViewport.paintSimple() before and after clipRect:

clip:java.awt.Rectangle[x=0,y=-129,width=56,height=31]
clipped:java.awt.Rectangle[x=0,y=0,width=56,height=-98]

It seems that the clipping is broken somehow. GdkGraphics.clipRect()
relies on Rectangle.intersection() which is inefficient anyway, so I
adapted the SwingUtilities.computeIntersection() method into
GdkGraphics, which both solves this strange clipping problem and makes
the clipping much more efficient by avoiding the creation of 2(!) new
Rectangles each time.

Now the remaining problem might be that it tries repaints the whole
table still. I still look into this.

2006-05-18  Roman Kennke <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/gtk/GdkGraphics.java
        (clipRect): Don't use Rectangle.intersection() to avoid creating
        2 unnecessary Rectangle instances and fix a clipping problem.
        (computeIntersection): New helper method, adapted from
SwingUtilities.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: gnu/java/awt/peer/gtk/GdkGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java,v
retrieving revision 1.55
diff -u -1 -0 -r1.55 GdkGraphics.java
--- gnu/java/awt/peer/gtk/GdkGraphics.java	30 Mar 2006 18:55:13 -0000	1.55
+++ gnu/java/awt/peer/gtk/GdkGraphics.java	18 May 2006 14:54:11 -0000
@@ -32,20 +32,21 @@
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package gnu.java.awt.peer.gtk;
 
 import gnu.classpath.Configuration;
+import gnu.java.awt.AWTUtilities;
 
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.awt.Toolkit;
@@ -153,21 +154,22 @@
 
   native void connectSignals (GtkComponentPeer component);
 
   public native void clearRect(int x, int y, int width, int height);
 
   public void clipRect (int x, int y, int width, int height)
   {
     if (component != null && ! component.isRealized ())
       return;
 
-    clip = clip.intersection (new Rectangle (x, y, width, height));
+    //computeIntersection(x, y, width, height, clip);
+    clip = clip.intersection(new Rectangle(x, y, width, height));
     setClipRectangle (clip.x, clip.y, clip.width, clip.height);
   }
 
   public native void copyArea(int x, int y, int width, int height, 
 			      int dx, int dy);
 
   /**
    * Creates a copy of this GdkGraphics instance. This implementation can
    * reuse a cached instance to avoid massive instantiation of Graphics objects
    * during painting.
@@ -486,11 +488,33 @@
   {
     color = g.color;
     xorColor = g.xorColor;
     font = g.font;
     if (font == null)
       font = new Font ("Dialog", Font.PLAIN, 12);
     clip = new Rectangle (g.clip);
     component = g.component;
     nativeCopyState(g);
   }
+
+  private Rectangle computeIntersection(int x, int y, int w, int h,
+                                        Rectangle rect)
+  {
+    int x2 = (int) rect.x;
+    int y2 = (int) rect.y;
+    int w2 = (int) rect.width;
+    int h2 = (int) rect.height;
+
+    int dx = (x > x2) ? x : x2;
+    int dy = (y > y2) ? y : y2;
+    int dw = (x + w < x2 + w2) ? (x + w - dx) : (x2 + w2 - dx);
+    int dh = (y + h < y2 + h2) ? (y + h - dy) : (y2 + h2 - dy);
+
+    if (dw >= 0 && dh >= 0)
+      rect.setBounds(dx, dy, dw, dh);
+    else
+      rect.setBounds(0, 0, 0, 0);
+
+    return rect;
+  }
+
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to