make pixelDensity(displayDensity()) work properly, fixes #3436

This commit is contained in:
Ben Fry
2015-06-26 08:47:00 -04:00
parent f04b908812
commit a052600d48
2 changed files with 14 additions and 1 deletions
+2 -1
View File
@@ -1120,6 +1120,7 @@ public class PApplet implements PConstants {
return 1;
}
}
// If nobody's density is 1 (or != 2, to be exact) then everyone is 2
return 2;
}
return displayDensity(display);
@@ -1153,7 +1154,7 @@ public class PApplet implements PConstants {
System.err.println("Only one display is currently known, use displayDensity(1).");
} else {
System.err.format("Your displays are numbered %d through %d, " +
"pass one of those numbers to displayDensity()", 1, devices.length);
"pass one of those numbers to displayDensity()%n", 1, devices.length);
}
throw new RuntimeException("Display " + display + " does not exist.");
}
@@ -329,6 +329,11 @@ public class PdePreprocessor {
String[] pixelDensityContents = matchMethod("pixelDensity", searchArea);
if (pixelDensityContents != null) {
extraStatements.append(pixelDensityContents[0]);
} else {
pixelDensityContents = matchDensityMess(searchArea);
if (pixelDensityContents != null) {
extraStatements.append(pixelDensityContents[0]);
}
}
String[] sizeContents = matchMethod("size", searchArea);
@@ -433,6 +438,13 @@ public class PdePreprocessor {
}
static protected String[] matchDensityMess(String searchArea) {
final String regexp =
"(?:^|\\s|;)pixelDensity\\s*\\(\\s*displayDensity\\s*\\([^\\)]*\\)\\s*\\)\\s*\\;";
return PApplet.match(searchArea, regexp);
}
/**
* Replace all commented portions of a given String as spaces.
* Utility function used here and in the preprocessor.