FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #5011 from JakubValtar/blow-up · pippinbarr/processing@514d420 · GitHub

Repository navigation

Commit 514d420

Browse files
authored
Merge pull request processing#5011 from JakubValtar/blow-up
Window placement and pixel density cleanup
2 parents 6919bef + 8f31289 commit 514d420

9 files changed

Lines changed: 292 additions & 313 deletions

File tree

‎core/src/processing/awt/PGraphicsJava2D.java‎

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ public void beginDraw() {
409409
checkSettings();
410410
resetMatrix(); // reset model matrix
411411
vertexCount = 0;
412-
413-
g2.scale(pixelDensity, pixelDensity);
414412
}
415413

416414

@@ -1573,8 +1571,8 @@ protected void imageImpl(PImage who,
15731571

15741572
// Nuke the cache if the image was resized
15751573
if (cash != null) {
1576-
if (who.width != cash.image.getWidth() ||
1577-
who.height != cash.image.getHeight()) {
1574+
if (who.pixelWidth != cash.image.getWidth() ||
1575+
who.pixelHeight != cash.image.getHeight()) {
15781576
cash = null;
15791577
}
15801578
}
@@ -1601,12 +1599,17 @@ protected void imageImpl(PImage who,
16011599
// This might be a PGraphics that hasn't been drawn to yet.
16021600
// Can't just bail because the cache has been created above.
16031601
// https://github.com/processing/processing/issues/2208
1604-
who.pixels = new int[who.width * who.height];
1602+
who.pixels = new int[who.pixelWidth * who.pixelHeight];
16051603
}
16061604
cash.update(who, tint, tintColor);
16071605
who.setModified(false);
16081606
}
16091607

1608+
u1 *= who.pixelDensity;
1609+
v1 *= who.pixelDensity;
1610+
u2 *= who.pixelDensity;
1611+
v2 *= who.pixelDensity;
1612+
16101613
g2.drawImage(((ImageCache) getCache(who)).image,
16111614
(int) x1, (int) y1, (int) x2, (int) y2,
16121615
u1, v1, u2, v2, null);
@@ -1674,14 +1677,14 @@ public void update(PImage source, boolean tint, int tintColor) {
16741677
// in the alpha channel when drawn to the screen.
16751678
// https://github.com/processing/processing/issues/2030
16761679
if (image == null) {
1677-
image = new BufferedImage(source.width, source.height,
1680+
image = new BufferedImage(source.pixelWidth, source.pixelHeight,
16781681
BufferedImage.TYPE_INT_ARGB);
16791682
}
16801683

16811684
WritableRaster wr = image.getRaster();
16821685
if (tint) {
1683-
if (tintedTemp == null || tintedTemp.length != source.width) {
1684-
tintedTemp = new int[source.width];
1686+
if (tintedTemp == null || tintedTemp.length != source.pixelWidth) {
1687+
tintedTemp = new int[source.pixelHeight];
16851688
}
16861689
int a2 = (tintColor >> 24) & 0xff;
16871690
// System.out.println("tint color is " + a2);
@@ -1695,8 +1698,8 @@ public void update(PImage source, boolean tint, int tintColor) {
16951698
// The target image is opaque, meaning that the source image has no
16961699
// alpha (is not ARGB), and the tint has no alpha.
16971700
int index = 0;
1698-
for (int y = 0; y < source.height; y++) {
1699-
for (int x = 0; x < source.width; x++) {
1701+
for (int y = 0; y < source.pixelHeight; y++) {
1702+
for (int x = 0; x < source.pixelWidth; x++) {
17001703
int argb1 = source.pixels[index++];
17011704
int r1 = (argb1 >> 16) & 0xff;
17021705
int g1 = (argb1 >> 8) & 0xff;
@@ -1710,7 +1713,7 @@ public void update(PImage source, boolean tint, int tintColor) {
17101713
((g2 * g1) & 0xff00) |
17111714
(((b2 * b1) & 0xff00) >> 8);
17121715
}
1713-
wr.setDataElements(0, y, source.width, 1, tintedTemp);
1716+
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
17141717
}
17151718
// could this be any slower?
17161719
// float[] scales = { tintR, tintG, tintB };
@@ -1724,18 +1727,18 @@ public void update(PImage source, boolean tint, int tintColor) {
17241727
(tintColor & 0xffffff) == 0xffffff) {
17251728
int hi = tintColor & 0xff000000;
17261729
int index = 0;
1727-
for (int y = 0; y < source.height; y++) {
1728-
for (int x = 0; x < source.width; x++) {
1730+
for (int y = 0; y < source.pixelHeight; y++) {
1731+
for (int x = 0; x < source.pixelWidth; x++) {
17291732
tintedTemp[x] = hi | (source.pixels[index++] & 0xFFFFFF);
17301733
}
1731-
wr.setDataElements(0, y, source.width, 1, tintedTemp);
1734+
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
17321735
}
17331736
} else {
17341737
int index = 0;
1735-
for (int y = 0; y < source.height; y++) {
1738+
for (int y = 0; y < source.pixelHeight; y++) {
17361739
if (source.format == RGB) {
17371740
int alpha = tintColor & 0xFF000000;
1738-
for (int x = 0; x < source.width; x++) {
1741+
for (int x = 0; x < source.pixelWidth; x++) {
17391742
int argb1 = source.pixels[index++];
17401743
int r1 = (argb1 >> 16) & 0xff;
17411744
int g1 = (argb1 >> 8) & 0xff;
@@ -1746,7 +1749,7 @@ public void update(PImage source, boolean tint, int tintColor) {
17461749
(((b2 * b1) & 0xff00) >> 8);
17471750
}
17481751
} else if (source.format == ARGB) {
1749-
for (int x = 0; x < source.width; x++) {
1752+
for (int x = 0; x < source.pixelWidth; x++) {
17501753
int argb1 = source.pixels[index++];
17511754
int a1 = (argb1 >> 24) & 0xff;
17521755
int r1 = (argb1 >> 16) & 0xff;
@@ -1760,13 +1763,13 @@ public void update(PImage source, boolean tint, int tintColor) {
17601763
}
17611764
} else if (source.format == ALPHA) {
17621765
int lower = tintColor & 0xFFFFFF;
1763-
for (int x = 0; x < source.width; x++) {
1766+
for (int x = 0; x < source.pixelWidth; x++) {
17641767
int a1 = source.pixels[index++];
17651768
tintedTemp[x] =
17661769
(((a2 * a1) & 0xff00) << 16) | lower;
17671770
}
17681771
}
1769-
wr.setDataElements(0, y, source.width, 1, tintedTemp);
1772+
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
17701773
}
17711774
}
17721775
// Not sure why ARGB images take the scales in this order...
@@ -1786,7 +1789,7 @@ public void update(PImage source, boolean tint, int tintColor) {
17861789
// in a PImage and how the high bits will be set.
17871790
}
17881791
// If no tint, just shove the pixels on in there verbatim
1789-
wr.setDataElements(0, 0, source.width, source.height, source.pixels);
1792+
wr.setDataElements(0, 0, source.pixelWidth, source.pixelHeight, source.pixels);
17901793
}
17911794
this.tinted = tint;
17921795
this.tintedColor = tintColor;
@@ -2232,6 +2235,7 @@ public void shearY(float angle) {
22322235
@Override
22332236
public void resetMatrix() {
22342237
g2.setTransform(new AffineTransform());
2238+
g2.scale(pixelDensity, pixelDensity);
22352239
}
22362240

22372241

@@ -2793,7 +2797,7 @@ public void updatePixels(int x, int y, int c, int d) {
27932797
if (pixels != null) {
27942798
getRaster().setDataElements(0, 0, pixelWidth, pixelHeight, pixels);
27952799
}
2796-
modified = true;
2800+
modified = false;
27972801
}
27982802

27992803

@@ -2836,12 +2840,6 @@ public int get(int x, int y) {
28362840
//public PImage get(int x, int y, int w, int h)
28372841

28382842

2839-
@Override
2840-
public PImage get() {
2841-
return get(0, 0, width, height);
2842-
}
2843-
2844-
28452843
@Override
28462844
protected void getImpl(int sourceX, int sourceY,
28472845
int sourceWidth, int sourceHeight,
@@ -2852,7 +2850,7 @@ protected void getImpl(int sourceX, int sourceY,
28522850
// ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
28532851
WritableRaster raster = getRaster();
28542852

2855-
if (sourceWidth == target.width && sourceHeight == target.height) {
2853+
if (sourceWidth == target.pixelWidth && sourceHeight == target.pixelHeight) {
28562854
raster.getDataElements(sourceX, sourceY, sourceWidth, sourceHeight, target.pixels);
28572855
// https://github.com/processing/processing/issues/2030
28582856
if (raster.getNumBands() == 3) {
@@ -2866,7 +2864,7 @@ protected void getImpl(int sourceX, int sourceY,
28662864

28672865
// Copy the temporary output pixels over to the outgoing image
28682866
int sourceOffset = 0;
2869-
int targetOffset = targetY*target.width + targetX;
2867+
int targetOffset = targetY*target.pixelWidth + targetX;
28702868
for (int y = 0; y < sourceHeight; y++) {
28712869
if (raster.getNumBands() == 3) {
28722870
for (int i = 0; i < sourceWidth; i++) {
@@ -2878,15 +2876,15 @@ protected void getImpl(int sourceX, int sourceY,
28782876
System.arraycopy(temp, sourceOffset, target.pixels, targetOffset, sourceWidth);
28792877
}
28802878
sourceOffset += sourceWidth;
2881-
targetOffset += target.width;
2879+
targetOffset += target.pixelWidth;
28822880
}
28832881
}
28842882
}
28852883

28862884

28872885
@Override
28882886
public void set(int x, int y, int argb) {
2889-
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
2887+
if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) return;
28902888
// ((BufferedImage) image).setRGB(x, y, argb);
28912889
getset[0] = argb;
28922890
// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
@@ -2907,18 +2905,18 @@ protected void setImpl(PImage sourceImage,
29072905
// ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
29082906

29092907
if ((sourceX == 0) && (sourceY == 0) &&
2910-
(sourceWidth == sourceImage.width) &&
2911-
(sourceHeight == sourceImage.height)) {
2908+
(sourceWidth == sourceImage.pixelWidth) &&
2909+
(sourceHeight == sourceImage.pixelHeight)) {
29122910
// System.out.format("%d %d %dx%d %d%n", targetX, targetY,
29132911
// sourceImage.width, sourceImage.height,
29142912
// sourceImage.pixels.length);
29152913
raster.setDataElements(targetX, targetY,
2916-
sourceImage.width, sourceImage.height,
2914+
sourceImage.pixelWidth, sourceImage.pixelHeight,
29172915
sourceImage.pixels);
29182916
} else {
29192917
// TODO optimize, incredibly inefficient to reallocate this much memory
29202918
PImage temp = sourceImage.get(sourceX, sourceY, sourceWidth, sourceHeight);
2921-
raster.setDataElements(targetX, targetY, temp.width, temp.height, temp.pixels);
2919+
raster.setDataElements(targetX, targetY, temp.pixelWidth, temp.pixelHeight, temp.pixels);
29222920
}
29232921
}
29242922

‎core/src/processing/awt/PSurfaceAWT.java‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public class PSurfaceAWT extends PSurfaceNone {
9090
int sketchWidth;
9191
int sketchHeight;
9292

93+
int windowScaleFactor;
94+
9395

9496
public PSurfaceAWT(PGraphics graphics) {
9597
//this.graphics = graphics;
@@ -224,7 +226,7 @@ public void validate() {
224226
if (!oldSize.equals(newSize)) {
225227
// System.out.println("validate() render old=" + oldSize + " -> new=" + newSize);
226228
oldSize = newSize;
227-
sketch.setSize(newSize.width, newSize.height);
229+
sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
228230
// try {
229231
render();
230232
// } catch (IllegalStateException ise) {
@@ -423,8 +425,11 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor,
423425
sketch.displayWidth = screenRect.width;
424426
sketch.displayHeight = screenRect.height;
425427

426-
sketchWidth = sketch.sketchWidth();
427-
sketchHeight = sketch.sketchHeight();
428+
windowScaleFactor = PApplet.platform == PConstants.MACOSX ?
429+
1 : sketch.pixelDensity;
430+
431+
sketchWidth = sketch.sketchWidth() * windowScaleFactor;
432+
sketchHeight = sketch.sketchHeight() * windowScaleFactor;
428433

429434
boolean fullScreen = sketch.sketchFullScreen();
430435
// Removing the section below because sometimes people want to do the
@@ -481,7 +486,7 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor,
481486
// http://dev.processing.org/bugs/show_bug.cgi?id=908
482487

483488
frame.add(canvas);
484-
setSize(sketchWidth, sketchHeight);
489+
setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
485490

486491
/*
487492
if (fullScreen) {
@@ -954,8 +959,8 @@ public void setSize(int wide, int high) {
954959
return; // unchanged, don't rebuild everything
955960
}
956961

957-
sketchWidth = wide;
958-
sketchHeight = high;
962+
sketchWidth = wide * windowScaleFactor;
963+
sketchHeight = high * windowScaleFactor;
959964

960965
// canvas.setSize(wide, high);
961966
// frame.setSize(wide, high);
@@ -1142,8 +1147,9 @@ public void componentResized(ComponentEvent e) {
11421147
// overall size of the window. Perhaps JFrame sets its coord
11431148
// system so that (0, 0) is always the upper-left of the content
11441149
// area. Which seems nice, but breaks any f*ing AWT-based code.
1145-
setSize(windowSize.width - currentInsets.left - currentInsets.right,
1146-
windowSize.height - currentInsets.top - currentInsets.bottom);
1150+
int w = windowSize.width - currentInsets.left - currentInsets.right;
1151+
int h = windowSize.height - currentInsets.top - currentInsets.bottom;
1152+
setSize(w / windowScaleFactor, h / windowScaleFactor);
11471153

11481154
// correct the location when inset size changes
11491155
setLocation(x - currentInsets.left, y - currentInsets.top);
@@ -1312,7 +1318,8 @@ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
13121318

13131319
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
13141320
peAction, peModifiers,
1315-
nativeEvent.getX(), nativeEvent.getY(),
1321+
nativeEvent.getX() / windowScaleFactor,
1322+
nativeEvent.getY() / windowScaleFactor,
13161323
peButton,
13171324
peCount));
13181325
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL