Revision: 1013
Author: allain.lalonde
Date: Sat Apr 17 08:14:43 2010
Log: Fixing Issue 172
http://code.google.com/p/piccolo2d/source/detail?r=1013

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

=======================================
--- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java Mon Jan 18 16:07:38 2010 +++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/POffscreenCanvas.java Sat Apr 17 08:14:43 2010
@@ -28,6 +28,7 @@
  */
 package edu.umd.cs.piccolo;

+import java.awt.Color;
 import java.awt.Cursor;
 import java.awt.Graphics2D;

@@ -42,6 +43,9 @@
  */
 public final class POffscreenCanvas implements PComponent {

+ /** Default render quality, <code>PPaintContext.HIGH_QUALITY_RENDERING</code>. */ + static final int DEFAULT_RENDER_QUALITY = PPaintContext.HIGH_QUALITY_RENDERING;
+
     /** Bounds of this offscreen canvas. */
     private final PBounds bounds;

@@ -51,9 +55,11 @@
     /** 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;
-
+ /** Whether this node's background color should be drawn when rendering. */
+    private boolean opaque;
+
+ /** Background color to paint before the contents of the scene are rendered. */
+    private Color backgroundColor;

     /**
      * Create a new offscreen canvas the specified width and height.
@@ -70,6 +76,9 @@
         }
         bounds = new PBounds(0.0d, 0.0d, width, height);
         setCamera(PUtil.createBasicScenegraph());
+
+        opaque = false;
+        backgroundColor = null;
     }

     /**
@@ -82,6 +91,12 @@
         if (graphics == null) {
throw new IllegalArgumentException("graphics must not be null");
         }
+
+        if (opaque && backgroundColor != null) {
+            graphics.setBackground(backgroundColor);
+ graphics.clearRect(0, 0, (int)bounds.getWidth(), (int)bounds.getHeight());
+        }
+
         final PPaintContext paintContext = new PPaintContext(graphics);
         paintContext.setRenderQuality(renderQuality);
         camera.fullPaint(paintContext);
@@ -164,4 +179,29 @@
     public void setInteracting(final boolean interacting) {
         // empty
     }
-}
+
+    /**
+     * Return the root of the scene this POffscreenCanvas is viewing.
+     *
+     * @return root element of the scene being viewed
+     */
+    public PRoot getRoot() {
+        return camera.getRoot();
+    }
+
+    public boolean isOpaque() {
+        return opaque;
+    }
+
+    public void setOpaque(boolean opaque) {
+        this.opaque = opaque;
+    }
+
+    public Color getBackground() {
+        return backgroundColor;
+    }
+
+    public void setBackground(Color backgroundColor) {
+        this.backgroundColor = backgroundColor;
+    }
+}

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

Reply via email to