mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
adding clear() method
This commit is contained in:
@@ -6637,6 +6637,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
// BACKGROUND
|
||||
|
||||
|
||||
public void clear() {
|
||||
showMethodWarning("clear");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from background.xml )
|
||||
*
|
||||
|
||||
@@ -1817,6 +1817,33 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
|
||||
|
||||
// BACKGROUND
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
clearPixels(0);
|
||||
}
|
||||
|
||||
|
||||
int[] clearPixels;
|
||||
|
||||
protected void clearPixels(int color) {
|
||||
// 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();
|
||||
// WritableRaster raster = image.getRaster();
|
||||
if ((clearPixels == null) || (clearPixels.length < width)) {
|
||||
clearPixels = new int[width];
|
||||
}
|
||||
Arrays.fill(clearPixels, backgroundColor);
|
||||
for (int i = 0; i < height; i++) {
|
||||
raster.setDataElements(0, i, width, 1, clearPixels);
|
||||
}
|
||||
}
|
||||
|
||||
// background() methods inherited from PGraphics, along with the
|
||||
// PImage version of backgroundImpl(), since it just calls set().
|
||||
|
||||
@@ -1824,26 +1851,11 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
|
||||
//public void backgroundImpl(PImage image)
|
||||
|
||||
|
||||
int[] clearPixels;
|
||||
|
||||
@Override
|
||||
public void backgroundImpl() {
|
||||
if (backgroundAlpha) {
|
||||
// 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();
|
||||
// WritableRaster raster = image.getRaster();
|
||||
if ((clearPixels == null) || (clearPixels.length < width)) {
|
||||
clearPixels = new int[width];
|
||||
}
|
||||
Arrays.fill(clearPixels, backgroundColor);
|
||||
for (int i = 0; i < height; i++) {
|
||||
raster.setDataElements(0, i, width, 1, clearPixels);
|
||||
}
|
||||
clearPixels(backgroundColor);
|
||||
|
||||
} else {
|
||||
Color bgColor = new Color(backgroundColor);
|
||||
// seems to fire an additional event that causes flickering,
|
||||
|
||||
+6
-4
@@ -36,10 +36,12 @@ _ delete()/dispose() being used in the movie
|
||||
_ buffer sink methods in movie
|
||||
_ 'newFrame' is 'available', and ready() is part of that
|
||||
|
||||
_ loadShape() mess
|
||||
_ get things out of PGraphics
|
||||
_ separate PShape2/3D from OpenGL
|
||||
_ incorporate SVG loader into the 2D class
|
||||
_ loadShape() cleanup
|
||||
_ remove PShape2D/3D
|
||||
_ make PShapeOpenGL a cache object
|
||||
_ make PShapeOBJ the 3D loader
|
||||
o separate PShape2/3D from OpenGL
|
||||
o incorporate SVG loader into the 2D class
|
||||
|
||||
_ loadPixels() implementation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user