Author: heuermh
Date: Thu Jul 16 13:05:41 2009
New Revision: 481

Modified:
     
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
     
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java

Log:
Issue 69 ; adding render quality parameter

Modified:  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
==============================================================================
---  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
      
(original)
+++  
piccolo2d.java/trunk/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java
      
Thu Jul 16 13:05:41 2009
@@ -49,6 +49,12 @@
      /** Camera for this offscreen canvas. */
      private PCamera camera;

+    /** Render quality. */
+    private int renderQuality = DEFAULT_RENDER_QUALITY;
+
+    /** Default render quality,  
<code>PPaintContext.HIGH_QUALITY_RENDERING</code>. */
+    static final int DEFAULT_RENDER_QUALITY =  
PPaintContext.HIGH_QUALITY_RENDERING;
+

      /**
       * Create a new offscreen canvas the specified width and height.
@@ -78,7 +84,7 @@
              throw new IllegalArgumentException("graphics must not be  
null");
          }
          PPaintContext paintContext = new PPaintContext(graphics);
-         
paintContext.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
+        paintContext.setRenderQuality(renderQuality);
          camera.fullPaint(paintContext);
      }

@@ -105,6 +111,31 @@
       */
      public PCamera getCamera() {
          return camera;
+    }
+
+    /**
+     * Set the render quality hint for this offscreen canvas to  
<code>renderQuality</code>.
+     *
+     * @param renderQuality render quality hint, must be one of  
<code>PPaintContext.HIGH_QUALITY_RENDERING</code>
+     *    or <code>PPaintContext.LOW_QUALITY_RENDERING</code>
+     */
+    public void setRenderQuality(final int renderQuality) {
+        if ((renderQuality == PPaintContext.HIGH_QUALITY_RENDERING)
+                || (renderQuality == PPaintContext.LOW_QUALITY_RENDERING))  
{
+            this.renderQuality = renderQuality;
+        } else {
+            throw new IllegalArgumentException("renderQuality must be one  
of PPaintContext.HIGH_QUALITY_RENDERING"
+                    + " or PPaintContext.LOW_QUALITY_RENDERING, was " +  
renderQuality);
+        }
+    }
+
+    /**
+     * Return the render quality hint for this offscreen canvas.
+     *
+     * @return the render quality hint for this offscreen canvas
+     */
+    public int getRenderQuality() {
+        return renderQuality;
      }

      /*...@inheritdoc} */

Modified:  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java
==============================================================================
---  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java
  
(original)
+++  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java
  
Thu Jul 16 13:05:41 2009
@@ -37,8 +37,7 @@
  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;

  import junit.framework.TestCase;

@@ -58,21 +57,21 @@
          assertNotNull(canvas3);

          try {
-            POffscreenCanvas canvas = new POffscreenCanvas(-1, 100);
+            new POffscreenCanvas(-1, 100);
              fail("ctr(-1, 100) expected IllegalArgumentException");
          }
          catch (IllegalArgumentException e) {
              // expected
          }
          try {
-            POffscreenCanvas canvas = new POffscreenCanvas(100, -1);
+            new POffscreenCanvas(100, -1);
              fail("ctr(100, -1) expected IllegalArgumentException");
          }
          catch (IllegalArgumentException e) {
              // expected
          }
          try {
-            POffscreenCanvas canvas = new POffscreenCanvas(-1, -1);
+            new POffscreenCanvas(-1, -1);
              fail("ctr(-1, -1) expected IllegalArgumentException");
          }
          catch (IllegalArgumentException e) {
@@ -135,6 +134,22 @@
              POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
              canvas.render(null);
              fail("render(null) expected IllegalArgumentException");
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testRenderQuality() {
+        POffscreenCanvas canvas = new POffscreenCanvas(100, 200);
+        assertEquals(POffscreenCanvas.DEFAULT_RENDER_QUALITY,  
canvas.getRenderQuality());
+        canvas.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
+        assertEquals(PPaintContext.HIGH_QUALITY_RENDERING,  
canvas.getRenderQuality());
+        canvas.setRenderQuality(PPaintContext.LOW_QUALITY_RENDERING);
+        assertEquals(PPaintContext.LOW_QUALITY_RENDERING,  
canvas.getRenderQuality());
+
+        try {
+            canvas.setRenderQuality(-1);
          }
          catch (IllegalArgumentException e) {
              // expected

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

Reply via email to