JSR-184 Public Review Draft - Apr. 30, 2003.

javax.microedition.m3d
Class Background

java.lang.Object
  |
  +--javax.microedition.m3d.Object3D
        |
        +--javax.microedition.m3d.Background

public class Background
extends Object3D

Attributes for clearing the color buffer. The color buffer can be cleared with a solid color or a background image. The image can be scaled to fit the screen, repeated, or centered separately in each of the horizontal and vertical directions. The image can also be further positioned by an offset.

Background image data

The Background image is stored as a reference to an Image2D. The image may be in any of the formats defined in Image2D, with or without a palette. The width and height of the image are not limited in any way; in particular, they need not be powers of two.

If the referenced Image2D is modified by the application (by rendering into it), or a new Image2D is bound as the background image, the modifications are immediately reflected in the Background object.

See Also:
Binary format

Field Summary
static int CENTER
          Specifies that the background image be centered in the viewport in the X or Y direction.
static int FIT
          Specifies that the background image be scaled to fit the viewport in the X or Y direction.
static int TILE
          Specifies that the background image be repeated (tiled) indefinitely in the X or Y direction.
 
Fields inherited from class javax.microedition.m3d.Object3D
userObject
 
Constructor Summary
Background()
          Constructs a new Background with default values.
 
Method Summary
 int getColor()
          Retrieves the current background color.
 Image2D getImage()
          Gets the current background image.
 int getImageModeX()
          Gets the current X background image scaling mode.
 int getImageModeY()
          Gets the current Y background image scaling mode.
 float getImageOffsetX()
          Gets the X offset of the background image.
 float getImageOffsetY()
          Gets the Y offset of the background image.
 void setColor(int ARGB)
          Sets the background color.
 void setImage(Image2D image)
          Sets the background image, or switches from background image mode to background color mode.
 void setImageMode(int modeX, int modeY)
          Sets the background image scaling modes for the X and Y directions.
 void setImageOffset(float offsetX, float offsetY)
          Sets the background image offset.
 
Methods inherited from class javax.microedition.m3d.Object3D
addAnimationTrack, animate, clone, find, getAnimationTrack, getAnimationTrackCount, getReferences, getUserID, removeAnimationTrack, setUserID
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER

Specifies that the background image be centered in the viewport in the X or Y direction.

See Also:
Constant Field Values

TILE

public static final int TILE

Specifies that the background image be repeated (tiled) indefinitely in the X or Y direction.

See Also:
Constant Field Values

FIT

public static final int FIT

Specifies that the background image be scaled to fit the viewport in the X or Y direction. NOTE: It is currently not possible to scale the image without distortion if its aspect ratio differs from the aspect ratio of the screen.

The image offset in this mode is calculated as fractions of the scaled image size. The image also repeats to fill the screen as in the TILE mode.

See Also:
Constant Field Values
Constructor Detail

Background

public Background()

Constructs a new Background with default values. The default values are:

Method Detail

setColor

public void setColor(int ARGB)

Sets the background color. The parts of the viewport that are not covered by the background image are cleared to the background color when Graphics3D.clear(BUF_COLOR, Background) or Graphics3D.render(World) is called.

Parameters:
ARGB - the new background color in 0xAARRGGBB format
See Also:
getColor()

getColor

public int getColor()

Retrieves the current background color.

Returns:
the current background color in 0xAARRGGBB format
See Also:
setColor(int)

setImage

public void setImage(Image2D image)

Sets the background image, or switches from background image mode to background color mode.

Parameters:
image - the background image, or null to disable the current background image (if any) and clear with background color instead
See Also:
getImage()

getImage

public Image2D getImage()

Gets the current background image.

Returns:
the current background image; null if there is no image
See Also:
setImage(javax.microedition.m3d.Image2D)

setImageMode

public void setImageMode(int modeX,
                         int modeY)

Sets the background image scaling modes for the X and Y directions.

Parameters:
modeX - one of CENTER, TILE, FIT
modeY - one of CENTER, TILE, FIT
Throws:
java.lang.IllegalArgumentException - if modeX or modeY is not a legal scaling mode

getImageModeX

public int getImageModeX()

Gets the current X background image scaling mode.

Returns:
the X scaling mode integer constant
See Also:
setImageMode

getImageModeY

public int getImageModeY()

Gets the current Y background image scaling mode.

Returns:
the Y scaling mode integer constant
See Also:
setImageMode

setImageOffset

public void setImageOffset(float offsetX,
                           float offsetY)

Sets the background image offset. This is specified as the position of the center of the viewport with respect to the top left corner of the background image, in fractions of (scaled) image size. The default value of (0.5, 0.5) places the center of the viewport at the center of the image; that is, centers the image in the viewport.

Parameters:
offsetX - background image X offset
offsetY - background image Y offset

getImageOffsetX

public float getImageOffsetX()

Gets the X offset of the background image.

Returns:
the background image X offset in floating point
See Also:
setImageOffset

getImageOffsetY

public float getImageOffsetY()

Gets the Y offset of the background image.

Returns:
the background image Y offset in floating point
See Also:
setImageOffset

JSR-184 Public Review Draft - Apr. 30, 2003.

Copyright © 2003 Nokia Corporation. See the Copyright Notice for details.