Skip to content

Commit ee68ac8

Browse files
committed
moving to pixelDensity()
1 parent 7df6b37 commit ee68ac8

File tree

10 files changed

+50
-28
lines changed

10 files changed

+50
-28
lines changed

core/src/processing/core/PApplet.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ public void init() {
810810
boolean fullScreen;
811811
int display = -1; // use default
812812
GraphicsDevice[] displayDevices;
813+
int pixelDensity = 1;
813814

814815
String outputPath;
815816
OutputStream outputStream;
@@ -967,6 +968,14 @@ final public int sketchWindowColor() {
967968
}
968969

969970

971+
final public int sketchPixelDensity() {
972+
return pixelDensity;
973+
}
974+
975+
976+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
977+
978+
970979
public int displayDensity() {
971980
if (display == SPAN) {
972981
// walk through all displays, use lowest common denominator
@@ -1029,6 +1038,15 @@ static public int displayDensity(int display) {
10291038
}
10301039

10311040

1041+
public void pixelDensity(int density) {
1042+
if (density != this.pixelDensity) {
1043+
if (insideSettings("pixelDensity", density)) {
1044+
this.pixelDensity = density;
1045+
}
1046+
}
1047+
}
1048+
1049+
10321050
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10331051

10341052

@@ -5237,7 +5255,7 @@ public void run() {
52375255

52385256
vessel.pixelWidth = actual.width;
52395257
vessel.pixelHeight = actual.height;
5240-
vessel.pixelFactor = 1;
5258+
vessel.pixelDensity = 1;
52415259
}
52425260
requestImageCount--;
52435261
}

core/src/processing/core/PGraphics.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,11 @@ public PGraphics() {
698698

699699
public void setParent(PApplet parent) { // ignore
700700
this.parent = parent;
701+
701702
// Some renderers (OpenGL) need to know what smoothing level will be used
702703
// before the rendering surface is even created.
703704
smooth = parent.sketchSmooth();
705+
pixelDensity = parent.sketchPixelDensity();
704706
}
705707

706708

@@ -747,8 +749,8 @@ public void setSize(int w, int h) { // ignore
747749
height = h;
748750

749751
/** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */
750-
pixelWidth = width * pixelFactor;
751-
pixelHeight = height * pixelFactor;
752+
pixelWidth = width * pixelDensity;
753+
pixelHeight = height * pixelDensity;
752754

753755
// if (surface != null) {
754756
// allocate();
@@ -8064,6 +8066,6 @@ public boolean isGL() { // ignore
80648066

80658067

80668068
public boolean is2X() {
8067-
return pixelFactor == 2;
8069+
return pixelDensity == 2;
80688070
}
80698071
}

core/src/processing/core/PGraphicsFX2D.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,8 +1900,8 @@ public void backgroundImpl() {
19001900
@Override
19011901
public void loadPixels() {
19021902
// pixelFactor = 2;
1903-
int wide = width * pixelFactor;
1904-
int high = height * pixelFactor;
1903+
int wide = width * pixelDensity;
1904+
int high = height * pixelDensity;
19051905

19061906
if ((pixels == null) || (pixels.length != wide*high)) {
19071907
pixels = new int[wide * high];
@@ -1917,7 +1917,7 @@ public void loadPixels() {
19171917
// }
19181918
// }
19191919
SnapshotParameters sp = new SnapshotParameters();
1920-
if (pixelFactor == 2) {
1920+
if (pixelDensity == 2) {
19211921
sp.setTransform(Transform.scale(2, 2));
19221922
}
19231923
WritableImage wi = ((PSurfaceFX) surface).canvas.snapshot(sp, null);

core/src/processing/core/PGraphicsFX2D2X.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525

2626
public class PGraphicsFX2D2X extends PGraphics {
2727
public PGraphicsFX2D2X() {
28-
pixelFactor = 2;
28+
pixelDensity = 2;
2929
}
3030
}

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ public boolean canDraw() {
272272

273273
public Graphics2D checkImage() {
274274
if (image == null ||
275-
((BufferedImage) image).getWidth() != width*pixelFactor ||
276-
((BufferedImage) image).getHeight() != height*pixelFactor) {
275+
((BufferedImage) image).getWidth() != width*pixelDensity ||
276+
((BufferedImage) image).getHeight() != height*pixelDensity) {
277277
// ((VolatileImage) image).getWidth() != width ||
278278
// ((VolatileImage) image).getHeight() != height) {
279279
// image = new BufferedImage(width * pixelFactor, height * pixelFactor
@@ -299,8 +299,8 @@ public Graphics2D checkImage() {
299299

300300
// Formerly this was broken into separate versions based on offscreen or
301301
// not, but we may as well create a compatible image; it won't hurt, right?
302-
int wide = width * pixelFactor;
303-
int high = height * pixelFactor;
302+
int wide = width * pixelDensity;
303+
int high = height * pixelDensity;
304304
// System.out.println("re-creating image");
305305
image = gc.createCompatibleImage(wide, high);
306306
// image = gc.createCompatibleVolatileImage(wide, high);
@@ -375,6 +375,8 @@ public void beginDraw() {
375375
checkSettings();
376376
resetMatrix(); // reset model matrix
377377
vertexCount = 0;
378+
379+
g2.scale(pixelDensity, pixelDensity);
378380
}
379381

380382

core/src/processing/core/PGraphicsJava2D2X.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PGraphicsJava2D2X extends PGraphicsJava2D {
1313

1414

1515
public PGraphicsJava2D2X() {
16-
pixelFactor = 2;
16+
pixelDensity = 2;
1717
// retina = new PImage();
1818
// retina.format = RGB;
1919
}

core/src/processing/core/PImage.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class PImage implements PConstants, Cloneable {
9595
public int[] pixels;
9696

9797
/** 1 for most images, 2 for hi-dpi/retina */
98-
public int pixelFactor;
98+
public int pixelDensity = 1;
9999

100100
/** Actual dimensions of pixels array, taking into account the 2x setting. */
101101
public int pixelWidth;
@@ -210,7 +210,7 @@ public class PImage implements PConstants, Cloneable {
210210
*/
211211
public PImage() {
212212
format = ARGB; // default to ARGB images for release 0116
213-
pixelFactor = 1;
213+
pixelDensity = 1;
214214
}
215215

216216

@@ -266,10 +266,10 @@ public void init(int width, int height, int format, int factor) { // ignore
266266
this.width = width;
267267
this.height = height;
268268
this.format = format;
269-
this.pixelFactor = factor;
269+
this.pixelDensity = factor;
270270

271-
pixelWidth = width * pixelFactor;
272-
pixelHeight = height * pixelFactor;
271+
pixelWidth = width * pixelDensity;
272+
pixelHeight = height * pixelDensity;
273273
this.pixels = new int[pixelWidth * pixelHeight];
274274
}
275275

@@ -330,7 +330,7 @@ public PImage(Image img) {
330330
pg.grabPixels();
331331
} catch (InterruptedException e) { }
332332
}
333-
pixelFactor = 1;
333+
pixelDensity = 1;
334334
pixelWidth = width;
335335
pixelHeight = height;
336336
}
@@ -632,7 +632,7 @@ public void resize(int w, int h) { // ignore
632632
}
633633

634634
BufferedImage img =
635-
shrinkImage((BufferedImage) getNative(), w*pixelFactor, h*pixelFactor);
635+
shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity);
636636

637637
PImage temp = new PImage(img);
638638
this.pixelWidth = temp.width;
@@ -641,8 +641,8 @@ public void resize(int w, int h) { // ignore
641641
// Get the resized pixel array
642642
this.pixels = temp.pixels;
643643

644-
this.width = pixelWidth / pixelFactor;
645-
this.height = pixelHeight / pixelFactor;
644+
this.width = pixelWidth / pixelDensity;
645+
this.height = pixelHeight / pixelDensity;
646646

647647
// Mark the pixels array as altered
648648
updatePixels();
@@ -858,9 +858,9 @@ public PImage get(int x, int y, int w, int h) {
858858
targetFormat = ARGB;
859859
}
860860

861-
PImage target = new PImage(targetWidth / pixelFactor,
862-
targetHeight / pixelFactor,
863-
targetFormat, pixelFactor);
861+
PImage target = new PImage(targetWidth / pixelDensity,
862+
targetHeight / pixelDensity,
863+
targetFormat, pixelDensity);
864864
target.parent = parent; // parent may be null so can't use createImage()
865865
if (w > 0 && h > 0) {
866866
getImpl(x, y, w, h, target, targetX, targetY);

core/src/processing/opengl/PGraphics2D2X.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public class PGraphics2D2X extends PGraphics2D {
2626

2727
public PGraphics2D2X() {
2828
super();
29-
pixelFactor = 2;
29+
pixelDensity = 2;
3030
}
3131
}

core/src/processing/opengl/PGraphics3D2X.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public class PGraphics3D2X extends PGraphics3D {
2626

2727
public PGraphics3D2X() {
2828
super();
29-
pixelFactor = 2;
29+
pixelDensity = 2;
3030
}
3131
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ public void removeCache(PImage image) {
706706

707707

708708
public float getPixelScale() {
709-
if (surfaceJOGL == null) return pixelFactor;
709+
if (surfaceJOGL == null) return pixelDensity;
710710
else return surfaceJOGL.getPixelScale();
711711
}
712712

0 commit comments

Comments
 (0)