fix a pixelDensity() issue w/ default display

This commit is contained in:
Ben Fry
2022-10-30 18:38:00 -04:00
parent f681ae31ba
commit b0cd253dad
2 changed files with 33 additions and 7 deletions

View File

@@ -129,16 +129,34 @@ public class ShimAWT implements PConstants {
private int displayDensityImpl(int display) {
if (display > 0 && display <= displayDevices.length) {
GraphicsConfiguration graphicsConfig =
displayDevices[display - 1].getDefaultConfiguration();
GraphicsConfiguration graphicsConfig = null;
if (display == -1) { // the default display
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsConfig = ge.getDefaultScreenDevice().getDefaultConfiguration();
} else if (display == SPAN) {
// walk through all displays, go with lowest common denominator
for (int i = 0; i < displayDevices.length; i++) {
if (displayDensityImpl(i) == 1) {
return 1;
}
}
return 2; // everyone is density 2
} else if (display <= displayDevices.length) {
graphicsConfig = displayDevices[display - 1].getDefaultConfiguration();
}
if (graphicsConfig == null) {
System.err.println("Display " + display + " does not exist, " +
"returning 1 for displayDensity(" + display + ")");
return 1; // not the end of the world, so don't throw a RuntimeException
} else {
AffineTransform tx = graphicsConfig.getDefaultTransform();
return (int) Math.round(tx.getScaleX());
}
System.err.println("Display " + display + " does not exist, " +
"returning 1 for displayDensity(" + display + ")");
return 1; // not the end of the world, so don't throw a RuntimeException
}

View File

@@ -3,8 +3,16 @@ X Updating PApplet to use Java 17 (switch statements, etc)
X XxxList bug with random() if there are zero elements in the array
X now throws ArrayIndexOutOfBoundsException
X kinda want to return null, but later getting an NPE is more confusing
X can't do pixelDensity 2 with fullScreen and Java2D
X when using fullScreen(), shows error:
X "Display -1 does not exist, returning 1 for displayDensity(-1)"
X maybe https://github.com/processing/processing4/issues/487
_ need alphabetical ordering for json serialization
_ use choice() instead of random() for list classes
_ add choice() as a PApplet method for int values of random()?
_ concurrent StringDict et al
_ why no concurrent TreemMap? https://stackoverflow.com/a/17656453
_ https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html