implement displayDensity(int), it's been returning the main display's value

This commit is contained in:
Ben Fry
2020-01-19 10:53:49 -05:00
parent 1f877eaf15
commit f1bced8d5f
2 changed files with 13 additions and 19 deletions
+10 -19
View File
@@ -1073,20 +1073,10 @@ public class PApplet implements PConstants {
final public boolean sketchFullScreen() {
//return false;
return fullScreen;
}
// // Could be named 'screen' instead of display since it's the people using
// // full screen who will be looking for it. On the other hand, screenX/Y/Z
// // makes things confusing, and if 'displayIndex' exists...
// public boolean sketchSpanDisplays() {
// //return false;
// return spanDisplays;
// }
// Numbered from 1, SPAN (0) means all displays, -1 means the default display
final public int sketchDisplay() {
return display;
@@ -1094,13 +1084,11 @@ public class PApplet implements PConstants {
final public String sketchOutputPath() {
//return null;
return outputPath;
}
final public OutputStream sketchOutputStream() {
//return null;
return outputStream;
}
@@ -1145,18 +1133,21 @@ public class PApplet implements PConstants {
return 1;
}
/**
* @param display the display number to check
* (1-indexed to match the Preferences dialog box)
*/
public int displayDensity(int display) {
GraphicsDevice graphicsDevice = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
GraphicsConfiguration graphicsConfig = graphicsDevice
.getDefaultConfiguration();
if (display > 0 && display <= displayDevices.length) {
GraphicsConfiguration graphicsConfig =
displayDevices[display - 1].getDefaultConfiguration();
AffineTransform tx = graphicsConfig.getDefaultTransform();
return (int) Math.round(tx.getScaleX());
}
AffineTransform tx = graphicsConfig.getDefaultTransform();
return (int) Math.round(tx.getScaleX());
System.err.println("Display " + display + " does not exist, returning ");
return 1; // not the end of the world, so don't throw a RuntimeException
}