mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 01:50:44 +01:00
fix for background(0, 0, 0, 0) reset issue
This commit is contained in:
@@ -1037,20 +1037,42 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
int[] clearPixels;
|
||||
|
||||
public void clear() {
|
||||
// the only way to properly clear the screen is to re-allocate
|
||||
if (backgroundAlpha) {
|
||||
// clearRect() doesn't work because it just makes everything black.
|
||||
// instead, just wipe out the canvas to its transparent original
|
||||
allocate();
|
||||
//allocate();
|
||||
|
||||
// allocate also won't work, because all the settings
|
||||
// (like smooth) will be completely reset.
|
||||
// Instead, create a small array that can be used to set the pixels
|
||||
// several times. Using a single-pixel line of length 'width' is a
|
||||
// tradeoff between speed (setting each pixel individually is too slow)
|
||||
// and memory (an array for width*height would waste lots of memory
|
||||
// if it stayed resident, and would terrify the gc if it were
|
||||
// re-created on each trip to background().
|
||||
WritableRaster raster = ((BufferedImage) image).getRaster();
|
||||
if ((clearPixels == null) || (clearPixels.length < width)) {
|
||||
clearPixels = new int[width];
|
||||
}
|
||||
for (int i = 0; i < width; i++) {
|
||||
clearPixels[i] = backgroundColor;
|
||||
}
|
||||
for (int i = 0; i < height; i++) {
|
||||
raster.setDataElements(0, i, width, 1, clearPixels);
|
||||
}
|
||||
} else {
|
||||
// in case people do transformations before background(),
|
||||
// need to handle this with a push/reset/pop
|
||||
pushMatrix();
|
||||
resetMatrix();
|
||||
g2.setColor(new Color(backgroundColor, backgroundAlpha));
|
||||
g2.fillRect(0, 0, width, height);
|
||||
popMatrix();
|
||||
}
|
||||
// in case people do transformations before background(),
|
||||
// need to handle this with a push/reset/pop
|
||||
pushMatrix();
|
||||
resetMatrix();
|
||||
g2.setColor(new Color(backgroundColor, backgroundAlpha));
|
||||
g2.fillRect(0, 0, width, height);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ X with smooth() turned off, shouldn't be smoothing image on resize
|
||||
X but on osx, apple defaults the image smoothing to true
|
||||
X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1164753510
|
||||
X http://developer.apple.com/documentation/Java/Conceptual/JavaPropVMInfoRef/Articles/JavaSystemProperties.html#//apple_ref/doc/uid/TP40001975-DontLinkElementID_6
|
||||
X background(0, 0, 0, 0) was resetting stroke, smooth, etc.
|
||||
|
||||
_ loadImage() requires an extension, maybe add a second version?
|
||||
_ loadImage("blah", "jpg");
|
||||
|
||||
Reference in New Issue
Block a user