CVSROOT: /cvsroot/classpath Module name: classpath Changes by: Roman Kennke <rabbit78> 06/06/12 21:10:11
Modified files: . : ChangeLog gnu/java/awt/peer/gtk: CairoGraphics2D.java CairoSurfaceGraphics.java ComponentGraphics.java VolatileImageGraphics.java Log message: 2006-06-12 Roman Kennke <[EMAIL PROTECTED]> * gnu/java/awt/peer/gtk/CairoGraphics2D.java (copy): Use getClip() to copy the clip. Make copied transform null when original transform is null. Set clip here. (setTransform): Correctly update the clip. (setTransformImpl): New method. Updates the actual transform for Cairo. (transform): Correctly update the clip. (translate): Correctly update the clip. (clip): Handle null clip and argument correctly. (clipRect): Avoid creating new Rectangle objects. (getClip): Get the correct copy of the clip. (setClip): Correctly handle null argument. * gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java (CairoSurfaceGraphics): Don't set the clip here. The clip can either be null or whatever has been set in copy(). * gnu/java/awt/peer/gtk/ComponentGraphics.java (drawImage): Add translation to the image coordinates. * gnu/java/awt/peer/gtk/VolatileImageGraphics.java (VolatileImageGraphics): Don't set clip here. The clip can either be null or whatever has been set in copy(). CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7787&r2=1.7788 http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java?cvsroot=classpath&r1=1.20&r2=1.21 http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java?cvsroot=classpath&r1=1.5&r2=1.6 http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java?cvsroot=classpath&r1=1.14&r2=1.15 http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java?cvsroot=classpath&r1=1.4&r2=1.5 Patches: Index: ChangeLog =================================================================== RCS file: /cvsroot/classpath/classpath/ChangeLog,v retrieving revision 1.7787 retrieving revision 1.7788 diff -u -b -r1.7787 -r1.7788 --- ChangeLog 12 Jun 2006 20:39:15 -0000 1.7787 +++ ChangeLog 12 Jun 2006 21:10:10 -0000 1.7788 @@ -1,3 +1,26 @@ +2006-06-12 Roman Kennke <[EMAIL PROTECTED]> + + * gnu/java/awt/peer/gtk/CairoGraphics2D.java + (copy): Use getClip() to copy the clip. Make copied transform + null when original transform is null. Set clip here. + (setTransform): Correctly update the clip. + (setTransformImpl): New method. Updates the actual transform for + Cairo. + (transform): Correctly update the clip. + (translate): Correctly update the clip. + (clip): Handle null clip and argument correctly. + (clipRect): Avoid creating new Rectangle objects. + (getClip): Get the correct copy of the clip. + (setClip): Correctly handle null argument. + * gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java + (CairoSurfaceGraphics): Don't set the clip here. The clip can either + be null or whatever has been set in copy(). + * gnu/java/awt/peer/gtk/ComponentGraphics.java + (drawImage): Add translation to the image coordinates. + * gnu/java/awt/peer/gtk/VolatileImageGraphics.java + (VolatileImageGraphics): Don't set clip here. The clip can either + be null or whatever has been set in copy(). + 2006-06-12 Keith Seitz <[EMAIL PROTECTED]> From Kyle Galloway <[EMAIL PROTECTED]>: Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -b -r1.20 -r1.21 --- gnu/java/awt/peer/gtk/CairoGraphics2D.java 12 Jun 2006 10:32:44 -0000 1.20 +++ gnu/java/awt/peer/gtk/CairoGraphics2D.java 12 Jun 2006 21:10:11 -0000 1.21 @@ -238,13 +238,10 @@ bg = new Color(g.bg.getRGB()); } - if (g.clip == null) - clip = null; - else - clip = new Rectangle(g.getClipBounds()); + clip = g.getClip(); if (g.transform == null) - transform = new AffineTransform(); + transform = null; else transform = new AffineTransform(g.transform); @@ -254,7 +251,8 @@ setBackground(bg); setPaint(paint); setStroke(stroke); - setTransform(transform); + setTransformImpl(transform); + setClip(clip); } /** @@ -435,6 +433,29 @@ */ public void setTransform(AffineTransform tx) { + // Transform clip into target space using the old transform. + updateClip(transform); + + // Update the native transform. + setTransformImpl(tx); + + // Transform the clip back into user space using the inverse new transform. + try + { + updateClip(transform.createInverse()); + } + catch (NoninvertibleTransformException ex) + { + // TODO: How can we deal properly with this? + ex.printStackTrace(); + } + + if (clip != null) + setClip(clip); + } + + private void setTransformImpl(AffineTransform tx) + { transform = tx; if (transform != null) { @@ -450,28 +471,22 @@ transform = new AffineTransform(tx); else transform.concatenate(tx); - setTransform(transform); + if (clip != null) { - // FIXME: this should actuall try to transform the shape - // rather than degrade to bounds. - Rectangle2D r = clip.getBounds2D(); - double[] coords = new double[] - { - r.getX(), r.getY(), r.getX() + r.getWidth(), - r.getY() + r.getHeight() - }; try { - tx.createInverse().transform(coords, 0, coords, 0, 2); - r.setRect(coords[0], coords[1], coords[2] - coords[0], - coords[3] - coords[1]); - clip = r; + AffineTransform clipTransform = tx.createInverse(); + updateClip(clipTransform); } - catch (java.awt.geom.NoninvertibleTransformException e) + catch (NoninvertibleTransformException ex) { + // TODO: How can we deal properly with this? + ex.printStackTrace(); } } + + setTransformImpl(transform); } public void rotate(double theta) @@ -504,18 +519,21 @@ { // FIXME: this should actuall try to transform the shape // rather than degrade to bounds. - Rectangle2D r; - if (clip instanceof Rectangle2D) - r = (Rectangle2D) clip; + { + Rectangle2D r = (Rectangle2D) clip; + r.setRect(r.getX() - tx, r.getY() - ty, r.getWidth(), + r.getHeight()); + } else - r = clip.getBounds2D(); - - r.setRect(r.getX() - tx, r.getY() - ty, r.getWidth(), r.getHeight()); - clip = r; + { + AffineTransform clipTransform = + AffineTransform.getTranslateInstance(-tx, -ty); + updateClip(clipTransform); + } } - setTransform(transform); + setTransformImpl(transform); } public void translate(int x, int y) @@ -534,11 +552,20 @@ { // Do not touch clip when s == null. if (s == null) + { + // The spec says this should clear the clip. The reference + // implementation throws a NullPointerException instead. I think, + // in this case we should conform to the specs, as it shouldn't + // affect compatibility. + setClip(null); return; + } // If the current clip is still null, initialize it. if (clip == null) - clip = originalClip; + { + clip = getRealBounds(); + } // This is so common, let's optimize this. if (clip instanceof Rectangle2D && s instanceof Rectangle2D) @@ -546,7 +573,6 @@ Rectangle2D clipRect = (Rectangle2D) clip; Rectangle2D r = (Rectangle2D) s; Rectangle2D.intersect(clipRect, r, clipRect); - // Call setClip so that subclasses get notified. setClip(clipRect); } else @@ -691,6 +717,14 @@ public void clipRect(int x, int y, int width, int height) { + if (clip == null) + setClip(new Rectangle(x, y, width, height)); + else if (clip instanceof Rectangle) + { + computeIntersection(x, y, width, height, (Rectangle) clip); + setClip(clip); + } + else clip(new Rectangle(x, y, width, height)); } @@ -698,8 +732,15 @@ { if (clip == null) return null; - else + else if (clip instanceof Rectangle2D) return clip.getBounds2D(); //getClipInDevSpace(); + else + { + GeneralPath p = new GeneralPath(); + PathIterator pi = clip.getPathIterator(new AffineTransform()); + p.append(pi, false); + return p; + } } public Rectangle getClipBounds() @@ -750,12 +791,11 @@ firstClip = false; } - if (s == null) - clip = originalClip; - else clip = s; cairoResetClip(nativePointer); + if (clip != null) + { cairoNewPath(nativePointer); if (clip instanceof Rectangle2D) { @@ -768,6 +808,7 @@ cairoClip(nativePointer); } + } public void setBackground(Color c) { @@ -1626,4 +1667,47 @@ return db.getData(); } + + /** + * Helper method to transform the clip. This is called by the various + * transformation-manipulation methods to update the clip (which is in + * userspace) accordingly. + * + * The transform usually is the inverse transform that was applied to the + * graphics object. + * + * @param t the transform to apply to the clip + */ + private void updateClip(AffineTransform t) + { + if (clip == null) + return; + + if (! (clip instanceof GeneralPath)) + clip = new GeneralPath(clip); + + GeneralPath p = (GeneralPath) clip; + p.transform(t); + } + + private static 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; + } } Index: gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java 10 Jun 2006 10:33:18 -0000 1.5 +++ gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java 12 Jun 2006 21:10:11 -0000 1.6 @@ -64,7 +64,6 @@ this.surface = surface; cairo_t = surface.newCairoContext(); setup( cairo_t ); - setClip(0, 0, surface.width, surface.height); } /** @@ -76,7 +75,6 @@ surface = copyFrom.surface; cairo_t = surface.newCairoContext(); copy( copyFrom, cairo_t ); - setClip(0, 0, surface.width, surface.height); } public Graphics create() Index: gnu/java/awt/peer/gtk/ComponentGraphics.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -b -r1.14 -r1.15 --- gnu/java/awt/peer/gtk/ComponentGraphics.java 12 Jun 2006 12:25:03 -0000 1.14 +++ gnu/java/awt/peer/gtk/ComponentGraphics.java 12 Jun 2006 21:10:11 -0000 1.15 @@ -277,11 +277,14 @@ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { - if( img instanceof GtkVolatileImage ) + if (img instanceof GtkVolatileImage + && transform.getType() == AffineTransform.TYPE_TRANSLATION) { + x += transform.getTranslateX(); + y += transform.getTranslateY(); GtkVolatileImage vimg = (GtkVolatileImage) img; drawVolatile( component, vimg.nativePointer, - x, y - 20, vimg.width, vimg.height ); + x, y, vimg.width, vimg.height ); return true; } return super.drawImage( img, x, y, observer ); @@ -290,10 +293,13 @@ public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { - if( img instanceof GtkVolatileImage ) + if( img instanceof GtkVolatileImage + && transform.getType() == AffineTransform.TYPE_TRANSLATION) { + x += transform.getTranslateX(); + y += transform.getTranslateY(); GtkVolatileImage vimg = (GtkVolatileImage) img; - drawVolatile( component, vimg.nativePointer, x, y - 20, + drawVolatile( component, vimg.nativePointer, x, y, width, height ); return true; } Index: gnu/java/awt/peer/gtk/VolatileImageGraphics.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- gnu/java/awt/peer/gtk/VolatileImageGraphics.java 10 Jun 2006 14:06:23 -0000 1.4 +++ gnu/java/awt/peer/gtk/VolatileImageGraphics.java 12 Jun 2006 21:10:11 -0000 1.5 @@ -67,7 +67,6 @@ this.owner = img; cairo_t = initFromVolatile( owner.nativePointer, img.width, img.height ); setup( cairo_t ); - setClip( new Rectangle( 0, 0, img.width, img.height) ); } private VolatileImageGraphics(VolatileImageGraphics copy) @@ -75,7 +74,6 @@ this.owner = copy.owner; cairo_t = initFromVolatile(owner.nativePointer, owner.width, owner.height); copy( copy, cairo_t ); - clipRect(0, 0, owner.width, owner.height); } public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)