Revision: 1014
Author: heuermh
Date: Sun Apr 18 19:57:39 2010
Log: Issue 172 ; increasing test coverage, javadoc improvements, checkstyle fixes
http://code.google.com/p/piccolo2d/source/detail?r=1014

Modified:
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/POffscreenCanvasTest.java

=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java Sat Apr 17 08:14:43 2010 +++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java Sun Apr 18 19:57:39 2010
@@ -55,12 +55,13 @@
     /** Render quality. */
     private int renderQuality = DEFAULT_RENDER_QUALITY;

- /** Whether this node's background color should be drawn when rendering. */
+    /** True if this offscreen canvas is opaque. */
     private boolean opaque;

- /** Background color to paint before the contents of the scene are rendered. */
+    /** Background color for this offscreen canvas. */
     private Color backgroundColor;

+
     /**
      * Create a new offscreen canvas the specified width and height.
      *
@@ -80,12 +81,12 @@
         opaque = false;
         backgroundColor = null;
     }
+

     /**
      * Render this offscreen canvas to the specified graphics.
-     *
- * @param graphics graphics to render this offscreen canvas to, must not be
-     *            null
+     *
+ * @param graphics graphics to render this offscreen canvas to, must not be null
      */
     public void render(final Graphics2D graphics) {
         if (graphics == null) {
@@ -94,7 +95,7 @@

         if (opaque && backgroundColor != null) {
             graphics.setBackground(backgroundColor);
- graphics.clearRect(0, 0, (int)bounds.getWidth(), (int)bounds.getHeight()); + graphics.clearRect(0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
         }

         final PPaintContext paintContext = new PPaintContext(graphics);
@@ -181,27 +182,54 @@
     }

     /**
-     * Return the root of the scene this POffscreenCanvas is viewing.
+ * Return the root node of the scene graph for this offscreen canvas. The + * root node will be null if the camera for this offscreen canvas is null.
      *
-     * @return root element of the scene being viewed
+     * @return the root node of the scene graph for this offscreen canvas
      */
     public PRoot getRoot() {
-        return camera.getRoot();
+        return camera == null ? null : camera.getRoot();
     }

+    /**
+ * Return true if this offscreen canvas is opaque. Defaults to <code>false</code>.
+     *
+     * @return true if this offscreen canvas is opaque
+     */
     public boolean isOpaque() {
         return opaque;
     }

-    public void setOpaque(boolean opaque) {
+    /**
+     * Set to true if this offscreen canvas is opaque.
+     *
+     * @param opaque true if this offscreen canvas is opaque
+     */
+    public void setOpaque(final boolean opaque) {
         this.opaque = opaque;
     }

+    /**
+     * Return the background color for this offscreen canvas.  If this
+     * offscreen canvas is opaque, the background color will be painted
+     * before the contents of the scene are rendered.
+     *
+     * @see #isOpaque
+     * @return the background color for this offscreen canvas
+     */
     public Color getBackground() {
         return backgroundColor;
     }

-    public void setBackground(Color backgroundColor) {
+    /**
+ * Set the background color for this offscreen canvas to <code>backgroundColor</code>. + * If this offscreen canvas is opaque, the background color will be painted
+     * before the contents of the scene are rendered.
+     *
+     * @see #isOpaque
+     * @param backgroundColor background color for this offscreen canvas
+     */
+    public void setBackground(final Color backgroundColor) {
         this.backgroundColor = backgroundColor;
     }
 }
=======================================
--- /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/POffscreenCanvasTest.java Mon Jan 18 16:07:38 2010 +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/POffscreenCanvasTest.java Sun Apr 18 19:57:39 2010
@@ -36,6 +36,7 @@
 import junit.framework.TestCase;
 import edu.umd.cs.piccolo.PCamera;
 import edu.umd.cs.piccolo.nodes.PPath;
+import edu.umd.cs.piccolo.util.PBounds;
 import edu.umd.cs.piccolo.util.PPaintContext;

 /**
@@ -103,6 +104,34 @@
             }
         }
     }
+
+    public void testRenderEmptyOpaqueNullBackgroundColor() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+ final BufferedImage image = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB);
+        final Graphics2D graphics = image.createGraphics();
+        canvas.setOpaque(true);
+        canvas.render(graphics);
+        for (int x = 0; x < 100; x++) {
+            for (int y = 0; y < 200; y++) {
+                assertEquals(0, image.getRGB(x, y));
+            }
+        }
+    }
+
+    public void testRenderEmptyOpaque() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+ final BufferedImage image = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB);
+        final Graphics2D graphics = image.createGraphics();
+        canvas.setOpaque(true);
+        canvas.setBackground(Color.RED);
+        canvas.render(graphics);
+        for (int x = 0; x < 100; x++) {
+            for (int y = 0; y < 200; y++) {
+                // red pixel, RGBA is 255, 0, 0, 255
+                assertEquals(-65536, image.getRGB(x, y));
+            }
+        }
+    }

     public void testRenderFull() {
         final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
@@ -148,6 +177,12 @@
             // expected
         }
     }
+
+    public void testRepaint() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.repaint(null);
+        canvas.repaint(new PBounds(0.0, 0.0, 50.0, 50.0));
+    }

     public void testPaintImmediately() {
         final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
@@ -170,4 +205,29 @@
         canvas.setInteracting(true);
         canvas.setInteracting(false);
     }
-}
+
+    public void testRoot() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertNotNull(canvas.getRoot());
+    }
+
+    public void testRootIsNullWhenCameraIsNull() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        canvas.setCamera(null);
+        assertEquals(null, canvas.getRoot());
+    }
+
+    public void testOpaque() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertFalse(canvas.isOpaque());
+        canvas.setOpaque(true);
+        assertTrue(canvas.isOpaque());
+    }
+
+    public void testBackground() {
+        final POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertEquals(null, canvas.getBackground());
+        canvas.setBackground(Color.RED);
+        assertEquals(Color.RED, canvas.getBackground());
+    }
+}

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to