public class BufferedGraphics extends Object
This facility is necessary because some platforms (e.g. Qtopia on the Sharp Zaurus) do not support reading bits from a Window surface. This makes certain drawing operations impossible directly on this surface. e.g. XOR'ing of images and the drawing of transparent images. However all platforms support reading bits from an Image and therefore these operations are possible using images.
You will generally create a BufferedGraphics in the doPaint() method of your control. You then call getGraphics() to get the Graphics object that you should use for your drawing and when you are done call release() on the BufferedGraphics to transfer what has been drawn to the original Graphics.
Note that you can construct the BufferedGraphics conditionally, which means that if the original Graphics was already drawing on an Image, that same graphics will be used and no temporary image will be created. In fact, when created conditionally, the canCopyFrom() method is called on the original Graphics, and if it returns true, then that original Graphics is used.
Modifier and Type | Field and Description |
---|---|
boolean |
cacheWhenDone
Set this true if you want the BufferedGraphics to cache itself on flush.
|
boolean |
dontFree
Set this true if you want the BufferedGraphics to not free itself on completion.
|
boolean |
freeOriginal
Set this true if you want the BufferedGraphics to free the original Graphics
when done.
|
static int |
OPTION_ALWAYS_BUFFER |
static int |
OPTION_DONT_ACCEPT_UNBUFFERED |
static int |
OPTION_DONT_BUFFER |
static int |
OPTION_DONT_COPY_FROM_ORIGINAL |
static int |
OPTION_EXACT_SIZE |
Constructor and Description |
---|
BufferedGraphics()
Create an empty BufferedGraphics.
|
BufferedGraphics(Graphics original,
Rect drawingAreaNeeded)
Create a new BufferedGraphics from the original if the original does not support copying.
|
BufferedGraphics(Graphics original,
Rect drawingAreaNeeded,
boolean unconditionally)
Create a new BufferedGraphics from the original.
|
Modifier and Type | Method and Description |
---|---|
boolean |
bufferedToSurface()
This returns true if the BufferedGraphics is buffering directly onto
an ISurface instead of to another Graphics.
|
void |
cache() |
void |
cached() |
void |
cancel()
Cancel drawing, free resources and do not update the original graphics.
|
boolean |
canCopyFrom()
Returns if the Graphics returned by getGraphics() can be copied from.
|
boolean |
canCopyFromOriginal() |
void |
clipSurface(int x,
int y,
int width,
int height) |
boolean |
copyFromOriginal()
This attempts to copy the data from the original graphics.
|
void |
createAlphaLayer(double layerAlpha) |
protected Image |
createNewImage(int width,
int height) |
boolean |
drawingToImage()
Returns if the Graphics returned by getGraphics() is drawing to an Image.
|
void |
finalize()
This method (when overriden), will be called when the VM determines that the Object can be
garbage collected.
|
void |
flush()
Copy the data already drawn on this surface, to the destination surface.
|
void |
flushOriginal() |
protected void |
free() |
static BufferedGraphics |
getCached() |
Graphics |
getGraphics()
Get the graphics that you should use to draw on.
|
Graphics |
getOriginal() |
void |
release()
Copy the drawn image to the original graphics and free all temporary resources.
|
Graphics |
setFor(Graphics g,
int targetX,
int targetY,
int width,
int height,
int options) |
Graphics |
setFor(ISurface surf,
int xoffset,
int yoffset,
int targetX,
int targetY,
int width,
int height,
int options) |
void |
translateToZero()
This translates the graphics so that the co-ordinates (0,0)
now refer to targetX and targetY.
|
public static final int OPTION_DONT_COPY_FROM_ORIGINAL
public static final int OPTION_DONT_ACCEPT_UNBUFFERED
public static final int OPTION_DONT_BUFFER
public static final int OPTION_ALWAYS_BUFFER
public static final int OPTION_EXACT_SIZE
public boolean freeOriginal
public boolean dontFree
public boolean cacheWhenDone
public BufferedGraphics()
public BufferedGraphics(Graphics original, Rect drawingAreaNeeded, boolean unconditionally)
original
- The original graphics.drawingAreaNeeded
- A non-null rectangle specifying the area needed.unconditionally
- If this is true then a temporary image will always be created. If it
is false, then a temporary image will only be created if original.canCopyFrom() returns false.protected Image createNewImage(int width, int height) throws SystemResourceException, OutOfMemoryError
public Graphics setFor(ISurface surf, int xoffset, int yoffset, int targetX, int targetY, int width, int height, int options)
public Graphics setFor(Graphics g, int targetX, int targetY, int width, int height, int options)
public static BufferedGraphics getCached()
public void cache()
public void clipSurface(int x, int y, int width, int height)
public boolean bufferedToSurface()
public Graphics getOriginal()
public void translateToZero()
public boolean drawingToImage()
public boolean canCopyFrom()
public boolean canCopyFromOriginal()
public boolean copyFromOriginal()
public Graphics getGraphics()
public void flush()
bufferedGraphics.flushOriginal();
public void createAlphaLayer(double layerAlpha)
public void flushOriginal()
public void release()
protected void free()
public void cancel()
public void cached()
public void finalize()
Object
The finalize() method of a Class is only called if it overrides finalize() - the finalize() method java.lang.Object is never called by the Eve VM.