diff --git a/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java b/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java index 3166efc..56d864c 100755 --- a/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/POffscreenCanvas.java @@ -49,6 +49,12 @@ /** Camera for this offscreen canvas. */ private PCamera camera; + /** Render quality. */ + private int renderQuality = DEFAULT_RENDER_QUALITY; + + /** Default render quality, PPaintContext.HIGH_QUALITY_RENDERING. */ + 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); } @@ -107,6 +113,31 @@ return camera; } + /** + * Set the render quality hint for this offscreen canvas to renderQuality. + * + * @param renderQuality render quality hint, must be one of PPaintContext.HIGH_QUALITY_RENDERING + * or PPaintContext.LOW_QUALITY_RENDERING + */ + 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} */ public final void paintImmediately() { // empty diff --git a/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java b/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java index 8e51185..4e06937 100755 --- a/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java +++ b/extras/src/test/java/edu/umd/cs/piccolox/POffscreenCanvasTest.java @@ -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) { @@ -141,6 +140,22 @@ } } + 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 + } + } + public void testPaintImmediately() { POffscreenCanvas canvas = new POffscreenCanvas(100, 200); canvas.paintImmediately();