GameCanvasLFImplpublic class GameCanvasLFImpl extends Object This is the look & feel implementation for GameCanvas. |
Fields Summary |
---|
javax.microedition.lcdui.game.GameCanvas | ownerThe owner of this view. | private javax.microedition.lcdui.Image | offscreenBufferCurrently every GameCanvas has one offscreen buffer
Can be optimized so that we put a limit on number of
offscreen buffers an application can have | private GraphicsAccess | graphicsAccessCached reference to GraphicsAccess instance |
Constructors Summary |
---|
public GameCanvasLFImpl(javax.microedition.lcdui.game.GameCanvas c)Create new implementation instance for the given GameCanvas
owner = c;
graphicsAccess = GameMap.getGraphicsAccess();
/* IMPL_NOTE: The initial off-screen buffer has the same width
* and height as the entire screen. Further resizing will not
* cause memory reallocation until new geometry is bigger than
* the current one. Screen rotation is one of the cases the
* reallocation is needed.
*
* User can override the methods getWidth() and getHeight() of
* GameCanvas, so they should not be used for off-screen buffer
* initial allocation.
*/
offscreenBuffer = Image.createImage(
graphicsAccess.getScreenWidth(),
graphicsAccess.getScreenHeight());
|
Methods Summary |
---|
public void | drawBuffer(javax.microedition.lcdui.Graphics g)Render the off-screen buffer content to the Graphics object
// NullPointerException will be thrown in drawImage if g == null
if (offscreenBuffer != null) {
g.drawImage(offscreenBuffer, 0, 0,
Graphics.TOP | Graphics.LEFT);
}
| public void | flushGraphics()Flushes the off-screen buffer to the display. The size
of the flushed area is equal to the size of the GameCanvas.
DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
if (displayAccess != null && offscreenBuffer != null) {
displayAccess.flush(owner, offscreenBuffer,
0, 0, owner.getWidth(), owner.getHeight());
}
| public void | flushGraphics(int x, int y, int width, int height)Flushes the specified region of the off-screen buffer to the display.
if (width < 1 || height < 1) {
return;
}
DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
if (displayAccess != null && offscreenBuffer != null) {
displayAccess.flush(owner, offscreenBuffer,
x, y, width, height);
}
| public javax.microedition.lcdui.Graphics | getGraphics()Obtains the Graphics object for rendering a GameCanvas. The returned
Graphics object renders to the off-screen buffer belonging to this
GameCanvas.
IMPL_NOTE: The dimensions of the Graphics object are explicitly
set to GameCanvas size, since off-screen buffer larger than
GameCanvas can be used, while some JSR clients need to translate
the coordinates regarding the GameCanvas size.
Anyway if GameCanvas has zero width or height, the Graphics
dimensions are set to entire off-screen buffer.
if (offscreenBuffer != null) {
int w = owner.getWidth();
int h = owner.getHeight();
Graphics g = ((w <= 0) || (h <= 0)) ?
offscreenBuffer.getGraphics() :
graphicsAccess.getImageGraphics(offscreenBuffer, w, h);
graphicsAccess.setGraphicsCreator(g, owner);
return g;
}
return null;
| public int | getKeyStates()Gets the states of the physical game keys.
DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
if (displayAccess != null) {
return displayAccess.getKeyMask();
}
return 0;
| public void | lCallSizeChanged(int w, int h)Handle screen size change event to update internal
state of the GameCanvas accordingly
// Resize off-screen buffer in the case it is not big enough only
if (w > offscreenBuffer.getWidth() ||
h > offscreenBuffer.getHeight()) {
// OutOfMemoryError can be thrown
graphicsAccess.resizeImage(
offscreenBuffer, w, h, true);
}
|
|