mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 18:10:43 +01:00
Merge pull request #5011 from JakubValtar/blow-up
Window placement and pixel density cleanup
This commit is contained in:
@@ -409,8 +409,6 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
checkSettings();
|
||||
resetMatrix(); // reset model matrix
|
||||
vertexCount = 0;
|
||||
|
||||
g2.scale(pixelDensity, pixelDensity);
|
||||
}
|
||||
|
||||
|
||||
@@ -1573,8 +1571,8 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
// Nuke the cache if the image was resized
|
||||
if (cash != null) {
|
||||
if (who.width != cash.image.getWidth() ||
|
||||
who.height != cash.image.getHeight()) {
|
||||
if (who.pixelWidth != cash.image.getWidth() ||
|
||||
who.pixelHeight != cash.image.getHeight()) {
|
||||
cash = null;
|
||||
}
|
||||
}
|
||||
@@ -1601,12 +1599,17 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// This might be a PGraphics that hasn't been drawn to yet.
|
||||
// Can't just bail because the cache has been created above.
|
||||
// https://github.com/processing/processing/issues/2208
|
||||
who.pixels = new int[who.width * who.height];
|
||||
who.pixels = new int[who.pixelWidth * who.pixelHeight];
|
||||
}
|
||||
cash.update(who, tint, tintColor);
|
||||
who.setModified(false);
|
||||
}
|
||||
|
||||
u1 *= who.pixelDensity;
|
||||
v1 *= who.pixelDensity;
|
||||
u2 *= who.pixelDensity;
|
||||
v2 *= who.pixelDensity;
|
||||
|
||||
g2.drawImage(((ImageCache) getCache(who)).image,
|
||||
(int) x1, (int) y1, (int) x2, (int) y2,
|
||||
u1, v1, u2, v2, null);
|
||||
@@ -1674,14 +1677,14 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// in the alpha channel when drawn to the screen.
|
||||
// https://github.com/processing/processing/issues/2030
|
||||
if (image == null) {
|
||||
image = new BufferedImage(source.width, source.height,
|
||||
image = new BufferedImage(source.pixelWidth, source.pixelHeight,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
WritableRaster wr = image.getRaster();
|
||||
if (tint) {
|
||||
if (tintedTemp == null || tintedTemp.length != source.width) {
|
||||
tintedTemp = new int[source.width];
|
||||
if (tintedTemp == null || tintedTemp.length != source.pixelWidth) {
|
||||
tintedTemp = new int[source.pixelHeight];
|
||||
}
|
||||
int a2 = (tintColor >> 24) & 0xff;
|
||||
// System.out.println("tint color is " + a2);
|
||||
@@ -1695,8 +1698,8 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// The target image is opaque, meaning that the source image has no
|
||||
// alpha (is not ARGB), and the tint has no alpha.
|
||||
int index = 0;
|
||||
for (int y = 0; y < source.height; y++) {
|
||||
for (int x = 0; x < source.width; x++) {
|
||||
for (int y = 0; y < source.pixelHeight; y++) {
|
||||
for (int x = 0; x < source.pixelWidth; x++) {
|
||||
int argb1 = source.pixels[index++];
|
||||
int r1 = (argb1 >> 16) & 0xff;
|
||||
int g1 = (argb1 >> 8) & 0xff;
|
||||
@@ -1710,7 +1713,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
((g2 * g1) & 0xff00) |
|
||||
(((b2 * b1) & 0xff00) >> 8);
|
||||
}
|
||||
wr.setDataElements(0, y, source.width, 1, tintedTemp);
|
||||
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
|
||||
}
|
||||
// could this be any slower?
|
||||
// float[] scales = { tintR, tintG, tintB };
|
||||
@@ -1724,18 +1727,18 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
(tintColor & 0xffffff) == 0xffffff) {
|
||||
int hi = tintColor & 0xff000000;
|
||||
int index = 0;
|
||||
for (int y = 0; y < source.height; y++) {
|
||||
for (int x = 0; x < source.width; x++) {
|
||||
for (int y = 0; y < source.pixelHeight; y++) {
|
||||
for (int x = 0; x < source.pixelWidth; x++) {
|
||||
tintedTemp[x] = hi | (source.pixels[index++] & 0xFFFFFF);
|
||||
}
|
||||
wr.setDataElements(0, y, source.width, 1, tintedTemp);
|
||||
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
|
||||
}
|
||||
} else {
|
||||
int index = 0;
|
||||
for (int y = 0; y < source.height; y++) {
|
||||
for (int y = 0; y < source.pixelHeight; y++) {
|
||||
if (source.format == RGB) {
|
||||
int alpha = tintColor & 0xFF000000;
|
||||
for (int x = 0; x < source.width; x++) {
|
||||
for (int x = 0; x < source.pixelWidth; x++) {
|
||||
int argb1 = source.pixels[index++];
|
||||
int r1 = (argb1 >> 16) & 0xff;
|
||||
int g1 = (argb1 >> 8) & 0xff;
|
||||
@@ -1746,7 +1749,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
(((b2 * b1) & 0xff00) >> 8);
|
||||
}
|
||||
} else if (source.format == ARGB) {
|
||||
for (int x = 0; x < source.width; x++) {
|
||||
for (int x = 0; x < source.pixelWidth; x++) {
|
||||
int argb1 = source.pixels[index++];
|
||||
int a1 = (argb1 >> 24) & 0xff;
|
||||
int r1 = (argb1 >> 16) & 0xff;
|
||||
@@ -1760,13 +1763,13 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
}
|
||||
} else if (source.format == ALPHA) {
|
||||
int lower = tintColor & 0xFFFFFF;
|
||||
for (int x = 0; x < source.width; x++) {
|
||||
for (int x = 0; x < source.pixelWidth; x++) {
|
||||
int a1 = source.pixels[index++];
|
||||
tintedTemp[x] =
|
||||
(((a2 * a1) & 0xff00) << 16) | lower;
|
||||
}
|
||||
}
|
||||
wr.setDataElements(0, y, source.width, 1, tintedTemp);
|
||||
wr.setDataElements(0, y, source.pixelWidth, 1, tintedTemp);
|
||||
}
|
||||
}
|
||||
// Not sure why ARGB images take the scales in this order...
|
||||
@@ -1786,7 +1789,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// in a PImage and how the high bits will be set.
|
||||
}
|
||||
// If no tint, just shove the pixels on in there verbatim
|
||||
wr.setDataElements(0, 0, source.width, source.height, source.pixels);
|
||||
wr.setDataElements(0, 0, source.pixelWidth, source.pixelHeight, source.pixels);
|
||||
}
|
||||
this.tinted = tint;
|
||||
this.tintedColor = tintColor;
|
||||
@@ -2232,6 +2235,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
@Override
|
||||
public void resetMatrix() {
|
||||
g2.setTransform(new AffineTransform());
|
||||
g2.scale(pixelDensity, pixelDensity);
|
||||
}
|
||||
|
||||
|
||||
@@ -2793,7 +2797,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
if (pixels != null) {
|
||||
getRaster().setDataElements(0, 0, pixelWidth, pixelHeight, pixels);
|
||||
}
|
||||
modified = true;
|
||||
modified = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2836,12 +2840,6 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
//public PImage get(int x, int y, int w, int h)
|
||||
|
||||
|
||||
@Override
|
||||
public PImage get() {
|
||||
return get(0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void getImpl(int sourceX, int sourceY,
|
||||
int sourceWidth, int sourceHeight,
|
||||
@@ -2852,7 +2850,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
|
||||
WritableRaster raster = getRaster();
|
||||
|
||||
if (sourceWidth == target.width && sourceHeight == target.height) {
|
||||
if (sourceWidth == target.pixelWidth && sourceHeight == target.pixelHeight) {
|
||||
raster.getDataElements(sourceX, sourceY, sourceWidth, sourceHeight, target.pixels);
|
||||
// https://github.com/processing/processing/issues/2030
|
||||
if (raster.getNumBands() == 3) {
|
||||
@@ -2866,7 +2864,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
// Copy the temporary output pixels over to the outgoing image
|
||||
int sourceOffset = 0;
|
||||
int targetOffset = targetY*target.width + targetX;
|
||||
int targetOffset = targetY*target.pixelWidth + targetX;
|
||||
for (int y = 0; y < sourceHeight; y++) {
|
||||
if (raster.getNumBands() == 3) {
|
||||
for (int i = 0; i < sourceWidth; i++) {
|
||||
@@ -2878,7 +2876,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
System.arraycopy(temp, sourceOffset, target.pixels, targetOffset, sourceWidth);
|
||||
}
|
||||
sourceOffset += sourceWidth;
|
||||
targetOffset += target.width;
|
||||
targetOffset += target.pixelWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2886,7 +2884,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int argb) {
|
||||
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
|
||||
if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) return;
|
||||
// ((BufferedImage) image).setRGB(x, y, argb);
|
||||
getset[0] = argb;
|
||||
// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
|
||||
@@ -2907,18 +2905,18 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
|
||||
|
||||
if ((sourceX == 0) && (sourceY == 0) &&
|
||||
(sourceWidth == sourceImage.width) &&
|
||||
(sourceHeight == sourceImage.height)) {
|
||||
(sourceWidth == sourceImage.pixelWidth) &&
|
||||
(sourceHeight == sourceImage.pixelHeight)) {
|
||||
// System.out.format("%d %d %dx%d %d%n", targetX, targetY,
|
||||
// sourceImage.width, sourceImage.height,
|
||||
// sourceImage.pixels.length);
|
||||
raster.setDataElements(targetX, targetY,
|
||||
sourceImage.width, sourceImage.height,
|
||||
sourceImage.pixelWidth, sourceImage.pixelHeight,
|
||||
sourceImage.pixels);
|
||||
} else {
|
||||
// TODO optimize, incredibly inefficient to reallocate this much memory
|
||||
PImage temp = sourceImage.get(sourceX, sourceY, sourceWidth, sourceHeight);
|
||||
raster.setDataElements(targetX, targetY, temp.width, temp.height, temp.pixels);
|
||||
raster.setDataElements(targetX, targetY, temp.pixelWidth, temp.pixelHeight, temp.pixels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,8 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
int sketchWidth;
|
||||
int sketchHeight;
|
||||
|
||||
int windowScaleFactor;
|
||||
|
||||
|
||||
public PSurfaceAWT(PGraphics graphics) {
|
||||
//this.graphics = graphics;
|
||||
@@ -224,7 +226,7 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
if (!oldSize.equals(newSize)) {
|
||||
// System.out.println("validate() render old=" + oldSize + " -> new=" + newSize);
|
||||
oldSize = newSize;
|
||||
sketch.setSize(newSize.width, newSize.height);
|
||||
sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
|
||||
// try {
|
||||
render();
|
||||
// } catch (IllegalStateException ise) {
|
||||
@@ -423,8 +425,11 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
sketch.displayWidth = screenRect.width;
|
||||
sketch.displayHeight = screenRect.height;
|
||||
|
||||
sketchWidth = sketch.sketchWidth();
|
||||
sketchHeight = sketch.sketchHeight();
|
||||
windowScaleFactor = PApplet.platform == PConstants.MACOSX ?
|
||||
1 : sketch.pixelDensity;
|
||||
|
||||
sketchWidth = sketch.sketchWidth() * windowScaleFactor;
|
||||
sketchHeight = sketch.sketchHeight() * windowScaleFactor;
|
||||
|
||||
boolean fullScreen = sketch.sketchFullScreen();
|
||||
// Removing the section below because sometimes people want to do the
|
||||
@@ -481,7 +486,7 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=908
|
||||
|
||||
frame.add(canvas);
|
||||
setSize(sketchWidth, sketchHeight);
|
||||
setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
|
||||
|
||||
/*
|
||||
if (fullScreen) {
|
||||
@@ -954,8 +959,8 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
return; // unchanged, don't rebuild everything
|
||||
}
|
||||
|
||||
sketchWidth = wide;
|
||||
sketchHeight = high;
|
||||
sketchWidth = wide * windowScaleFactor;
|
||||
sketchHeight = high * windowScaleFactor;
|
||||
|
||||
// canvas.setSize(wide, high);
|
||||
// frame.setSize(wide, high);
|
||||
@@ -1142,8 +1147,9 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
// overall size of the window. Perhaps JFrame sets its coord
|
||||
// system so that (0, 0) is always the upper-left of the content
|
||||
// area. Which seems nice, but breaks any f*ing AWT-based code.
|
||||
setSize(windowSize.width - currentInsets.left - currentInsets.right,
|
||||
windowSize.height - currentInsets.top - currentInsets.bottom);
|
||||
int w = windowSize.width - currentInsets.left - currentInsets.right;
|
||||
int h = windowSize.height - currentInsets.top - currentInsets.bottom;
|
||||
setSize(w / windowScaleFactor, h / windowScaleFactor);
|
||||
|
||||
// correct the location when inset size changes
|
||||
setLocation(x - currentInsets.left, y - currentInsets.top);
|
||||
@@ -1312,7 +1318,8 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
|
||||
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
|
||||
peAction, peModifiers,
|
||||
nativeEvent.getX(), nativeEvent.getY(),
|
||||
nativeEvent.getX() / windowScaleFactor,
|
||||
nativeEvent.getY() / windowScaleFactor,
|
||||
peButton,
|
||||
peCount));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user