Skip to content

Commit 65f0be4

Browse files
committed
setSize() method for offscreen surface
1 parent af5dbd9 commit 65f0be4

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

core/src/processing/core/PSurfaceAWT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public class PSurfaceAWT extends PSurfaceNone {
6161

6262

6363
public PSurfaceAWT(PGraphics graphics) {
64-
this.graphics = graphics;
64+
//this.graphics = graphics;
65+
super(graphics);
6566

6667
if (checkRetina()) {
6768
// System.out.println("retina in use");

core/src/processing/core/PSurfaceNone.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222

2323
package processing.core;
2424

25-
//import java.awt.Color;
26-
//import java.awt.Component;
27-
2825

2926
/**
3027
* Surface that's not really visible. Used for PDF and friends, or as a base
3128
* class for other drawing surfaces. It includes the standard rendering loop.
3229
*/
3330
public class PSurfaceNone implements PSurface {
3431
PApplet sketch;
32+
PGraphics graphics;
3533

3634
Thread thread;
3735
boolean paused;
@@ -41,7 +39,9 @@ public class PSurfaceNone implements PSurface {
4139
protected long frameRatePeriod = 1000000000L / 60L;
4240

4341

44-
public PSurfaceNone() { }
42+
public PSurfaceNone(PGraphics graphics) {
43+
this.graphics = graphics;
44+
}
4545

4646

4747
@Override
@@ -98,9 +98,27 @@ public void setupExternalMessages() { }
9898
//
9999

100100

101-
public void setSize(int width, int height) {
102-
// TODO Auto-generated method stub
101+
@Override
102+
public void setSize(int wide, int high) {
103+
if (PApplet.DEBUG) {
104+
//System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
105+
new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
106+
}
107+
108+
//if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
109+
if (wide == sketch.width && high == sketch.height) {
110+
if (PApplet.DEBUG) {
111+
new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
112+
}
113+
return; // unchanged, don't rebuild everything
114+
}
115+
116+
//throw new RuntimeException("implement me, see readme.md");
117+
sketch.width = wide;
118+
sketch.height = high;
103119

120+
// set PGraphics variables for width/height/pixelWidth/pixelHeight
121+
graphics.setSize(wide, high);
104122
}
105123

106124

java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected void allocate() {
104104

105105
@Override
106106
public PSurface createSurface() {
107-
return surface = new PSurfaceNone();
107+
return surface = new PSurfaceNone(this);
108108
}
109109

110110

0 commit comments

Comments
 (0)