setSize() method for offscreen surface

This commit is contained in:
Ben Fry
2015-05-16 08:01:15 -04:00
parent 498b6c626b
commit e52be3f71b
3 changed files with 27 additions and 8 deletions

View File

@@ -61,7 +61,8 @@ public class PSurfaceAWT extends PSurfaceNone {
public PSurfaceAWT(PGraphics graphics) {
this.graphics = graphics;
//this.graphics = graphics;
super(graphics);
if (checkRetina()) {
// System.out.println("retina in use");

View File

@@ -22,9 +22,6 @@
package processing.core;
//import java.awt.Color;
//import java.awt.Component;
/**
* Surface that's not really visible. Used for PDF and friends, or as a base
@@ -32,6 +29,7 @@ package processing.core;
*/
public class PSurfaceNone implements PSurface {
PApplet sketch;
PGraphics graphics;
Thread thread;
boolean paused;
@@ -41,7 +39,9 @@ public class PSurfaceNone implements PSurface {
protected long frameRatePeriod = 1000000000L / 60L;
public PSurfaceNone() { }
public PSurfaceNone(PGraphics graphics) {
this.graphics = graphics;
}
@Override
@@ -98,9 +98,27 @@ public class PSurfaceNone implements PSurface {
//
public void setSize(int width, int height) {
// TODO Auto-generated method stub
@Override
public void setSize(int wide, int high) {
if (PApplet.DEBUG) {
//System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
}
//if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
if (wide == sketch.width && high == sketch.height) {
if (PApplet.DEBUG) {
new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
}
return; // unchanged, don't rebuild everything
}
//throw new RuntimeException("implement me, see readme.md");
sketch.width = wide;
sketch.height = high;
// set PGraphics variables for width/height/pixelWidth/pixelHeight
graphics.setSize(wide, high);
}

View File

@@ -104,7 +104,7 @@ public class PGraphicsPDF extends PGraphicsJava2D {
@Override
public PSurface createSurface() {
return surface = new PSurfaceNone();
return surface = new PSurfaceNone(this);
}