Revision: 653
Author: allain.lalonde
Date: Wed Aug 5 13:17:16 2009
Log: Fixed Issue 66; made printing the canvas print the entire scene,
regardless of what's visible.
http://code.google.com/p/piccolo2d/source/detail?r=653
Modified:
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java
=======================================
---
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java
Sun Aug 2 19:48:01 2009
+++
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java
Wed Aug 5 13:17:16 2009
@@ -136,16 +136,16 @@
private PZoomEventHandler zoomEventHandler;
private boolean paintingImmediately;
-
+
/** Used to track whether the last paint operation was during an
animation. */
private boolean animatingOnLastPaint;
-
+
/** The mouse listener that is registered for large scale mouse
events. */
private transient MouseListener mouseListener;
-
+
/** Remembers the key processor. */
private transient KeyEventPostProcessor keyEventPostProcessor;
-
+
/** The mouse wheel listeners that's registered to receive wheel
events. */
private transient MouseWheelListener mouseWheelListener;
/**
@@ -388,8 +388,8 @@
* when it is not interacting or animating. The default value is
* PPaintContext. HIGH_QUALITY_RENDERING.
*
- * @param normalRenderQuality supports
PPaintContext.HIGH_QUALITY_RENDERING or
- * PPaintContext.LOW_QUALITY_RENDERING
+ * @param normalRenderQuality supports
PPaintContext.HIGH_QUALITY_RENDERING
+ * or PPaintContext.LOW_QUALITY_RENDERING
*/
public void setDefaultRenderQuality(final int normalRenderQuality) {
this.normalRenderQuality = normalRenderQuality;
@@ -401,7 +401,8 @@
* when it is animating. The default value is
* PPaintContext.LOW_QUALITY_RENDERING.
*
- * @param animatingRenderQuality supports
PPaintContext.HIGH_QUALITY_RENDERING or
+ * @param animatingRenderQuality supports
+ * PPaintContext.HIGH_QUALITY_RENDERING or
* PPaintContext.LOW_QUALITY_RENDERING
*/
public void setAnimatingRenderQuality(final int
animatingRenderQuality) {
@@ -416,7 +417,8 @@
* when it is interacting. The default value is
* PPaintContext.LOW_QUALITY_RENDERING.
*
- * @param interactingRenderQuality supports
PPaintContext.HIGH_QUALITY_RENDERING or
+ * @param interactingRenderQuality supports
+ * PPaintContext.HIGH_QUALITY_RENDERING or
* PPaintContext.LOW_QUALITY_RENDERING
*/
public void setInteractingRenderQuality(final int
interactingRenderQuality) {
@@ -866,4 +868,38 @@
public PInputEventListener[] getInputEventListeners() {
return camera.getInputEventListeners();
}
-}
+
+ /**
+ * Prints the entire scene regardless of what the viewable area is.
+ *
+ * @param g Graphics context onto which to paint the scene for printing
+ */
+ public void printAll(final Graphics g) {
+ final Graphics2D g2 = (Graphics2D) g;
+
+ final PBounds clippingRect = new PBounds(g.getClipBounds());
+ clippingRect.expandNearestIntegerDimensions();
+
+ final PBounds originalCameraBounds = getCamera().getBounds();
+ final PBounds layerBounds =
getCamera().getUnionOfLayerFullBounds();
+ getCamera().setBounds(layerBounds);
+
+ final double clipRatio = clippingRect.getWidth() /
clippingRect.getHeight();
+ final double nodeRatio = getWidth() / getHeight();
+ final double scale;
+ if (nodeRatio <= clipRatio) {
+ scale = clippingRect.getHeight() / getCamera().getHeight();
+ }
+ else {
+ scale = clippingRect.getWidth() / getCamera().getWidth();
+ }
+ g2.scale(scale, scale);
+ g2.translate(-clippingRect.x, -clippingRect.y);
+
+ final PPaintContext pc = new PPaintContext(g2);
+ pc.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
+ getCamera().fullPaint(pc);
+
+ getCamera().setBounds(originalCameraBounds);
+ }
+}
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---