adding clear() method

This commit is contained in:
benfry
2012-09-02 21:26:20 +00:00
parent ff85026bd9
commit 55e29aed39
3 changed files with 40 additions and 21 deletions
+5
View File
@@ -6637,6 +6637,11 @@ public class PGraphics extends PImage implements PConstants {
// BACKGROUND
public void clear() {
showMethodWarning("clear");
}
/**
* ( begin auto-generated from background.xml )
*
+29 -17
View File
@@ -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
View File
@@ -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