moving to pixelDensity()

This commit is contained in:
Ben Fry
2015-06-08 12:00:33 -04:00
parent 4a016306d1
commit a4a87f8633
10 changed files with 50 additions and 28 deletions
+19 -1
View File
@@ -810,6 +810,7 @@ public class PApplet implements PConstants {
boolean fullScreen;
int display = -1; // use default
GraphicsDevice[] displayDevices;
int pixelDensity = 1;
String outputPath;
OutputStream outputStream;
@@ -967,6 +968,14 @@ public class PApplet implements PConstants {
}
final public int sketchPixelDensity() {
return pixelDensity;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public int displayDensity() {
if (display == SPAN) {
// walk through all displays, use lowest common denominator
@@ -1029,6 +1038,15 @@ public class PApplet implements PConstants {
}
public void pixelDensity(int density) {
if (density != this.pixelDensity) {
if (insideSettings("pixelDensity", density)) {
this.pixelDensity = density;
}
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -5237,7 +5255,7 @@ public class PApplet implements PConstants {
vessel.pixelWidth = actual.width;
vessel.pixelHeight = actual.height;
vessel.pixelFactor = 1;
vessel.pixelDensity = 1;
}
requestImageCount--;
}
+5 -3
View File
@@ -698,9 +698,11 @@ public class PGraphics extends PImage implements PConstants {
public void setParent(PApplet parent) { // ignore
this.parent = parent;
// Some renderers (OpenGL) need to know what smoothing level will be used
// before the rendering surface is even created.
smooth = parent.sketchSmooth();
pixelDensity = parent.sketchPixelDensity();
}
@@ -747,8 +749,8 @@ public class PGraphics extends PImage implements PConstants {
height = h;
/** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */
pixelWidth = width * pixelFactor;
pixelHeight = height * pixelFactor;
pixelWidth = width * pixelDensity;
pixelHeight = height * pixelDensity;
// if (surface != null) {
// allocate();
@@ -8064,6 +8066,6 @@ public class PGraphics extends PImage implements PConstants {
public boolean is2X() {
return pixelFactor == 2;
return pixelDensity == 2;
}
}
+3 -3
View File
@@ -1900,8 +1900,8 @@ public class PGraphicsFX2D extends PGraphics {
@Override
public void loadPixels() {
// pixelFactor = 2;
int wide = width * pixelFactor;
int high = height * pixelFactor;
int wide = width * pixelDensity;
int high = height * pixelDensity;
if ((pixels == null) || (pixels.length != wide*high)) {
pixels = new int[wide * high];
@@ -1917,7 +1917,7 @@ public class PGraphicsFX2D extends PGraphics {
// }
// }
SnapshotParameters sp = new SnapshotParameters();
if (pixelFactor == 2) {
if (pixelDensity == 2) {
sp.setTransform(Transform.scale(2, 2));
}
WritableImage wi = ((PSurfaceFX) surface).canvas.snapshot(sp, null);
@@ -25,6 +25,6 @@ package processing.core;
public class PGraphicsFX2D2X extends PGraphics {
public PGraphicsFX2D2X() {
pixelFactor = 2;
pixelDensity = 2;
}
}
@@ -272,8 +272,8 @@ public class PGraphicsJava2D extends PGraphics {
public Graphics2D checkImage() {
if (image == null ||
((BufferedImage) image).getWidth() != width*pixelFactor ||
((BufferedImage) image).getHeight() != height*pixelFactor) {
((BufferedImage) image).getWidth() != width*pixelDensity ||
((BufferedImage) image).getHeight() != height*pixelDensity) {
// ((VolatileImage) image).getWidth() != width ||
// ((VolatileImage) image).getHeight() != height) {
// image = new BufferedImage(width * pixelFactor, height * pixelFactor
@@ -299,8 +299,8 @@ public class PGraphicsJava2D extends PGraphics {
// Formerly this was broken into separate versions based on offscreen or
// not, but we may as well create a compatible image; it won't hurt, right?
int wide = width * pixelFactor;
int high = height * pixelFactor;
int wide = width * pixelDensity;
int high = height * pixelDensity;
// System.out.println("re-creating image");
image = gc.createCompatibleImage(wide, high);
// image = gc.createCompatibleVolatileImage(wide, high);
@@ -375,6 +375,8 @@ public class PGraphicsJava2D extends PGraphics {
checkSettings();
resetMatrix(); // reset model matrix
vertexCount = 0;
g2.scale(pixelDensity, pixelDensity);
}
@@ -13,7 +13,7 @@ public class PGraphicsJava2D2X extends PGraphicsJava2D {
public PGraphicsJava2D2X() {
pixelFactor = 2;
pixelDensity = 2;
// retina = new PImage();
// retina.format = RGB;
}
+12 -12
View File
@@ -95,7 +95,7 @@ public class PImage implements PConstants, Cloneable {
public int[] pixels;
/** 1 for most images, 2 for hi-dpi/retina */
public int pixelFactor;
public int pixelDensity = 1;
/** Actual dimensions of pixels array, taking into account the 2x setting. */
public int pixelWidth;
@@ -210,7 +210,7 @@ public class PImage implements PConstants, Cloneable {
*/
public PImage() {
format = ARGB; // default to ARGB images for release 0116
pixelFactor = 1;
pixelDensity = 1;
}
@@ -266,10 +266,10 @@ public class PImage implements PConstants, Cloneable {
this.width = width;
this.height = height;
this.format = format;
this.pixelFactor = factor;
this.pixelDensity = factor;
pixelWidth = width * pixelFactor;
pixelHeight = height * pixelFactor;
pixelWidth = width * pixelDensity;
pixelHeight = height * pixelDensity;
this.pixels = new int[pixelWidth * pixelHeight];
}
@@ -330,7 +330,7 @@ public class PImage implements PConstants, Cloneable {
pg.grabPixels();
} catch (InterruptedException e) { }
}
pixelFactor = 1;
pixelDensity = 1;
pixelWidth = width;
pixelHeight = height;
}
@@ -632,7 +632,7 @@ public class PImage implements PConstants, Cloneable {
}
BufferedImage img =
shrinkImage((BufferedImage) getNative(), w*pixelFactor, h*pixelFactor);
shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity);
PImage temp = new PImage(img);
this.pixelWidth = temp.width;
@@ -641,8 +641,8 @@ public class PImage implements PConstants, Cloneable {
// Get the resized pixel array
this.pixels = temp.pixels;
this.width = pixelWidth / pixelFactor;
this.height = pixelHeight / pixelFactor;
this.width = pixelWidth / pixelDensity;
this.height = pixelHeight / pixelDensity;
// Mark the pixels array as altered
updatePixels();
@@ -858,9 +858,9 @@ public class PImage implements PConstants, Cloneable {
targetFormat = ARGB;
}
PImage target = new PImage(targetWidth / pixelFactor,
targetHeight / pixelFactor,
targetFormat, pixelFactor);
PImage target = new PImage(targetWidth / pixelDensity,
targetHeight / pixelDensity,
targetFormat, pixelDensity);
target.parent = parent; // parent may be null so can't use createImage()
if (w > 0 && h > 0) {
getImpl(x, y, w, h, target, targetX, targetY);
@@ -26,6 +26,6 @@ public class PGraphics2D2X extends PGraphics2D {
public PGraphics2D2X() {
super();
pixelFactor = 2;
pixelDensity = 2;
}
}
@@ -26,6 +26,6 @@ public class PGraphics3D2X extends PGraphics3D {
public PGraphics3D2X() {
super();
pixelFactor = 2;
pixelDensity = 2;
}
}
@@ -706,7 +706,7 @@ public class PGraphicsOpenGL extends PGraphics {
public float getPixelScale() {
if (surfaceJOGL == null) return pixelFactor;
if (surfaceJOGL == null) return pixelDensity;
else return surfaceJOGL.getPixelScale();
}