check display size

This commit is contained in:
Ben Fry
2014-02-06 22:32:59 -05:00
parent 3fa176cc64
commit 206d489b3c
+32 -11
View File
@@ -914,6 +914,11 @@ public class PApplet extends Applet
}
} catch (Exception e) { } // may be a security problem
// Figure out the available display width and height.
// No major problem if this fails, we have to try again anyway in
// handleDraw() on the first (== 0) frame.
checkDisplaySize();
Dimension size = getSize();
if ((size.width != 0) && (size.height != 0)) {
// When this PApplet is embedded inside a Java application with other
@@ -967,6 +972,21 @@ public class PApplet extends Applet
}
private void checkDisplaySize() {
if (getGraphicsConfiguration() != null) {
GraphicsDevice displayDevice = getGraphicsConfiguration().getDevice();
if (displayDevice != null) {
Rectangle screenRect =
displayDevice.getDefaultConfiguration().getBounds();
displayWidth = screenRect.width;
displayHeight = screenRect.height;
}
}
}
private boolean checkRetina() {
if (platform == MACOSX) {
// This should probably be reset each time there's a display change.
@@ -2278,17 +2298,18 @@ public class PApplet extends Applet
long now = System.nanoTime();
if (frameCount == 0) {
GraphicsConfiguration gc = getGraphicsConfiguration();
if (gc == null) return;
GraphicsDevice displayDevice =
getGraphicsConfiguration().getDevice();
if (displayDevice == null) return;
Rectangle screenRect =
displayDevice.getDefaultConfiguration().getBounds();
// screenX = screenRect.x;
// screenY = screenRect.y;
displayWidth = screenRect.width;
displayHeight = screenRect.height;
// GraphicsConfiguration gc = getGraphicsConfiguration();
// if (gc == null) return;
// GraphicsDevice displayDevice =
// getGraphicsConfiguration().getDevice();
// if (displayDevice == null) return;
// Rectangle screenRect =
// displayDevice.getDefaultConfiguration().getBounds();
//// screenX = screenRect.x;
//// screenY = screenRect.y;
// displayWidth = screenRect.width;
// displayHeight = screenRect.height;
checkDisplaySize();
try {
//println("Calling setup()");