[committed] Enabling Graphics2D functionalities in ImageGraphicsBaseImpl

I have needs to use setTransform() and I found it works well for now.

I guess throwing exception is because of the mipmap support. But now ImageGraphics doesn't use it anywhere.

Is there any other reasons to disable these methods?





Index: src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java
===================================================================
--- src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java   (revision 4337)
+++ src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java   (working copy)
@@ -673,13 +673,11 @@
     }
 
     public void rotate( double theta ) {
-        throw new UnsupportedOperationException();
-//        delegate.rotate( theta );
+        delegate.rotate( theta );
     }
 
     public void rotate( double theta, double x, double y ) {
-        throw new UnsupportedOperationException();
-//        delegate.rotate( theta, x, y );
+        delegate.rotate( theta, x, y );
     }
 
     public void scale( double sx, double sy ) {
@@ -692,18 +690,15 @@
     }
 
     public void shear( double shx, double shy ) {
-        throw new UnsupportedOperationException();
-//        delegate.shear( shx, shy );
+        delegate.shear( shx, shy );
     }
 
     public void transform( AffineTransform Tx ) {
-        throw new UnsupportedOperationException();
-//        delegate.transform( Tx );
+        delegate.transform( Tx );
     }
 
     public void setTransform( AffineTransform Tx ) {
-        throw new UnsupportedOperationException();
-//        delegate.setTransform( Tx );
+        delegate.setTransform( Tx );
     }
 
     public AffineTransform getTransform() {

I think the reason is that it would be difficult to track changes to the dirty rectangle if you do transforms like that. Have you tested it and verified it works with various types of input? Otherwise I wouldn't suggest enabling it.

Momoko_Fan said:

I think the reason is that it would be difficult to track changes to the dirty rectangle if you do transforms like that. Have you tested it and verified it works with various types of input? Otherwise I wouldn't suggest enabling it.

I have no idea how dirty region and AffineTransform is related.
But I think it is how Graphics2D works in java and ImageGraphics should work the same as Graphics2D because it is subclass of Graphics2D.
If it is not rational, please let me know again and I'll drop it.  :)

Now I see what you said.

Okay, I'll find a way to set dirty region according to the AffineTransform.

Computing dirty region when transform is set seems not to be easy.

I suggest a naive approach.

When transform is set, the whole image region is set to dirty.



Index: src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java
===================================================================
--- src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java   (revision 4337)
+++ src/com/jmex/awt/swingui/ImageGraphicsBaseImpl.java   (working copy)
@@ -81,6 +81,7 @@
     private Rectangle imageBounds;
     private Rectangle clip = new Rectangle();
     private Rectangle tmp_dirty = new Rectangle();
+    protected AffineTransform tx = new AffineTransform();
     protected float scaleX = 1;
     protected float scaleY = 1;
 
@@ -697,13 +698,13 @@
     }
 
     public void transform( AffineTransform Tx ) {
-        throw new UnsupportedOperationException();
-//        delegate.transform( Tx );
+        tx.setTransform(Tx);
+        delegate.transform( Tx );
     }
 
     public void setTransform( AffineTransform Tx ) {
-        throw new UnsupportedOperationException();
-//        delegate.setTransform( Tx );
+        tx.setTransform(Tx);
+        delegate.setTransform( Tx );
     }
 
     public AffineTransform getTransform() {
Index: src/com/jmex/awt/swingui/LWJGLImageGraphics.java
===================================================================
--- src/com/jmex/awt/swingui/LWJGLImageGraphics.java   (revision 4337)
+++ src/com/jmex/awt/swingui/LWJGLImageGraphics.java   (working copy)
@@ -83,7 +83,9 @@
     public void update( Texture texture, boolean clean ) {
         boolean updateChildren = false;
         synchronized ( dirty ) {
-            if ( !dirty.isEmpty() ) {
+            if (!tx.isIdentity()) {
+                dirty.setBounds(getImageBounds());
+            } else if ( !dirty.isEmpty()) {
                 dirty.grow( 2, 2 ); // to prevent antialiasing problems
             }
             Rectangle2D.intersect( dirty, getImageBounds(), dirty );
Index: src/com/jmex/awt/swingui/JOGLImageGraphics.java
===================================================================
--- src/com/jmex/awt/swingui/JOGLImageGraphics.java   (revision 4337)
+++ src/com/jmex/awt/swingui/JOGLImageGraphics.java   (working copy)
@@ -83,7 +83,9 @@
         final GLU glu = new GLU();
         boolean updateChildren = false;
         synchronized ( dirty ) {
-            if ( !dirty.isEmpty() ) {
+            if (!tx.isIdentity()) {
+                dirty.setBounds(getImageBounds());
+            } else if ( !dirty.isEmpty()) {
                 dirty.grow( 2, 2 ); // to prevent antialiasing problems
             }
             Rectangle2D.intersect( dirty, getImageBounds(), dirty );

I guess that works, not the best solution but at least these methods are usable now.