mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 01:50:44 +01:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -58,6 +58,7 @@ another PSurfaceAWT variant could allow direct rendering to the canvas (no loadP
|
||||
inside main, will know the screen that's being used for the app
|
||||
|
||||
#### Questions/To Do
|
||||
- change size() command to check through renderer constants and give better error message when using one of the built-in renderers
|
||||
- bad idea, or worst idea, to have 'surface' var in PGraphics?
|
||||
- move getFontRenderContext(font) to PApplet? surface? elsewhere?
|
||||
_ do we need canDraw() anymore?
|
||||
|
||||
@@ -753,6 +753,7 @@ public class PApplet implements PConstants {
|
||||
// screenWidth = screen.width;
|
||||
// screenHeight = screen.height;
|
||||
|
||||
defaultSize = true;
|
||||
finished = false; // just for clarity
|
||||
|
||||
// this will be cleared by draw() if it is not overridden
|
||||
@@ -1480,7 +1481,7 @@ public class PApplet implements PConstants {
|
||||
if (!renderer.equals(sketchRenderer())) {
|
||||
System.err.println("Because you're not running from the PDE, add this to your code:");
|
||||
System.err.println("public String sketchRenderer() {");
|
||||
System.err.println(" return " + renderer + ";");
|
||||
System.err.println(" return \"" + renderer + "\";");
|
||||
System.err.println("}");
|
||||
throw new RuntimeException("The sketchRenderer() method is not implemented.");
|
||||
}
|
||||
@@ -1811,7 +1812,7 @@ public class PApplet implements PConstants {
|
||||
// // Give up, instead set the new renderer and re-attempt setup()
|
||||
// return;
|
||||
// }
|
||||
this.defaultSize = false;
|
||||
defaultSize = false;
|
||||
|
||||
} else { // frameCount > 0, meaning an actual draw()
|
||||
// update the current frameRate
|
||||
@@ -9470,7 +9471,7 @@ public class PApplet implements PConstants {
|
||||
// and the empty draw() has set "finished" to true.
|
||||
// TODO make sure this won't hang if the applet has an exception.
|
||||
while (defaultSize && !finished) {
|
||||
//System.out.println("default size");
|
||||
// System.out.println("default size");
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
|
||||
@@ -9478,11 +9479,22 @@ public class PApplet implements PConstants {
|
||||
//System.out.println("interrupt");
|
||||
}
|
||||
}
|
||||
System.out.println("out of default size loop, " + width + " " + height);
|
||||
// convenience to avoid another 'get' from the static main() method
|
||||
return surface;
|
||||
}
|
||||
|
||||
|
||||
// protected void createSurface() {
|
||||
// surface = g.createSurface();
|
||||
// if (surface == null) {
|
||||
// System.err.println("This renderer needs to be updated for Processing 3");
|
||||
// System.err.println("The createSurface() method returned null.");
|
||||
// System.exit(1);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Return a Canvas object that can be embedded into other Java GUIs.
|
||||
* This is necessary because PApplet no longer subclasses Component.
|
||||
|
||||
@@ -770,7 +770,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
|
||||
|
||||
public PSurface createSurface() { // ignore
|
||||
return null;
|
||||
return new PSurfaceAWT(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -533,7 +533,7 @@ public class PSurfaceAWT implements PSurface {
|
||||
if (fullScreen) {
|
||||
frame.invalidate();
|
||||
} else {
|
||||
frame.pack();
|
||||
// frame.pack();
|
||||
}
|
||||
|
||||
// insufficient, places the 100x100 sketches offset strangely
|
||||
@@ -616,10 +616,7 @@ public class PSurfaceAWT implements PSurface {
|
||||
|
||||
|
||||
public void placeWindow(int[] location) {
|
||||
calcFrameSize(sketchWidth, sketchHeight);
|
||||
|
||||
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
|
||||
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
|
||||
setFrameSize(); //sketchWidth, sketchHeight);
|
||||
|
||||
if (location != null) {
|
||||
// a specific location was received from the Runner
|
||||
@@ -643,9 +640,7 @@ public class PSurfaceAWT implements PSurface {
|
||||
// ((JFrame) frame).getContentPane().setBackground(backgroundColor);
|
||||
// }
|
||||
|
||||
canvas.setBounds((contentW - sketchWidth)/2,
|
||||
(contentH - sketchHeight)/2,
|
||||
sketchWidth, sketchHeight);
|
||||
setCanvasSize(); //sketchWidth, sketchHeight);
|
||||
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
@@ -664,7 +659,20 @@ public class PSurfaceAWT implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
private Dimension calcFrameSize(int sketchWidth, int sketchHeight) {
|
||||
private void setCanvasSize() {
|
||||
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
|
||||
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
|
||||
|
||||
canvas.setBounds((contentW - sketchWidth)/2,
|
||||
(contentH - sketchHeight)/2,
|
||||
sketchWidth, sketchHeight);
|
||||
}
|
||||
|
||||
|
||||
/** Resize frame for these sketch (canvas) dimensions. */
|
||||
private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
|
||||
System.out.format("setting frame size %d %d %n", sketchWidth, sketchHeight);
|
||||
new Exception().printStackTrace(System.out);
|
||||
Insets insets = frame.getInsets();
|
||||
int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH) +
|
||||
insets.left + insets.right;
|
||||
@@ -684,7 +692,8 @@ public class PSurfaceAWT implements PSurface {
|
||||
|
||||
|
||||
public void placeWindow(int[] location, int[] editorLocation) {
|
||||
Dimension window = calcFrameSize(sketchWidth, sketchHeight);
|
||||
//Dimension window = setFrameSize(sketchWidth, sketchHeight);
|
||||
Dimension window = setFrameSize(); //sketchWidth, sketchHeight);
|
||||
|
||||
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
|
||||
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
|
||||
@@ -806,6 +815,18 @@ public class PSurfaceAWT implements PSurface {
|
||||
|
||||
// needs to resize the frame, which will resize the canvas, and so on...
|
||||
public void setSize(int wide, int high) {
|
||||
System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
|
||||
new Exception().printStackTrace(System.out);
|
||||
|
||||
sketchWidth = wide;
|
||||
sketchHeight = high;
|
||||
|
||||
// canvas.setSize(wide, high);
|
||||
// frame.setSize(wide, high);
|
||||
setFrameSize(); //wide, high);
|
||||
setCanvasSize();
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
|
||||
// If not realized (off-screen, i.e the Color Selector Tool), gc will be null.
|
||||
if (gc == null) {
|
||||
@@ -820,8 +841,8 @@ public class PSurfaceAWT implements PSurface {
|
||||
graphics.image = gc.createCompatibleImage(wide * factor, high * factor);
|
||||
|
||||
//throw new RuntimeException("implement me, see readme.md");
|
||||
sketchWidth = sketch.width = wide;
|
||||
sketchHeight = sketch.height = high;
|
||||
sketch.width = wide;
|
||||
sketch.height = high;
|
||||
|
||||
// sets internal variables for width/height/pixelWidth/pixelHeight
|
||||
graphics.setSize(wide, high);
|
||||
@@ -1499,4 +1520,9 @@ public class PSurfaceAWT implements PSurface {
|
||||
canvas.setCursor(invisibleCursor);
|
||||
cursorVisible = false;
|
||||
}
|
||||
|
||||
|
||||
void debug(String format, Object ... args) {
|
||||
System.out.format(format + "%n", args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user