FileDocCategorySizeDatePackage
Tile.javaAPI DocphoneME MR2 API (J2ME)6068Wed May 02 18:00:34 BST 2007com.sun.perseus.j2d

Tile

public class Tile extends Object
This class is used to represent an area of the viewport. It supports both clipping areas, in viewport coordinates (which is why it uses integers), and dirty area management.
author
Kevin Wong
version
$Id: Tile.java,v 1.6 2006/04/21 06:35:19 st125089 Exp $

Fields Summary
public int
x
Start and end x tile coordinates.
public int
maxX
public int
y
Start and end y tile coordinates.
public int
maxY
Constructors Summary
public Tile()
Default constructor.

    
public Tile(Tile t)
Copy constructor

param
t the Tile to copy. Should not be null.

        this();
        setTile(t);
    
public Tile(int x, int y, int width, int height)
Constructor with the Tile's coordinates.

param
x the tile's origin along the x-axis
param
y the tile's origin along the y-axis
param
width the tile's width
param
height the tile's height

        setTile(x, y, width, height);
    
Methods Summary
public voidaddSnapBox(Box b)
Adds the input Box to the tile, after snapping it to the integer grid.

param
b the Box instance to snap to the grid and add to the tile. Should not be null.

        b.snap();
        addTile((int) b.x, 
                (int) b.y, 
                (int) (b.x + b.width - 1), 
                (int) (b.y + b.height - 1));
    
public voidaddTile(com.sun.perseus.j2d.Tile t)
Adds the input tile to this tile.

param
tile the Tile to add.

        addTile(t.x, t.y, t.maxX, t.maxY);
    
public voidaddTile(int tx, int ty, int tmaxX, int tmaxY)
Adds the input tile, defined by its x, y, maxX, maxY values, to this tile.

param
tx the tile's x-axis origin
param
ty the tile's y-axis origin
param
tmaxX the tile's x-axis bottom right coordinate.
param
tmaxY the tile's y-axis bottom right coordinate.

        if (tx < x) {
            x = tx;
        }
        if (ty < y) {
            y = ty;
        }
        if (tmaxX > maxX) {
            maxX = tmaxX;
        }
        if (tmaxY > maxY) {
            maxY = tmaxY;
        }
    
public booleanisHit(com.sun.perseus.j2d.Tile t)

return
true if the tile is hit by the input tile.
param
t the tile to check. Should not be null.

        return 
            (t.maxX >= x)  // Leave out tiles to the left of this tile
            &&
            (t.maxY >= y)  // Leave out tiles to the top of this tile
            &&
            (t.x <= maxX)  // Leave out tiles to the right of this tile
            &&
            (t.y <= maxY); // Leave out tiles to the bottom of this tile
    
public voidsetEmptyTile()
Sets this tile to be empty. Actually, this sets the tile to a one pixel tile in the top left corner of the integer coordinate grid (i.e, in Integer.MIN_VALUE, Integer.MIN_VALUE). This tile will never intersect with any other tile.

        this.x = Integer.MIN_VALUE;
        this.y = Integer.MIN_VALUE;
        this.maxX = Integer.MIN_VALUE;
        this.maxY = Integer.MIN_VALUE;
    
public voidsetTile(int x, int y, int width, int height)
Sets the tile's dimension and origin.

param
x the tile's origin along the x-axis
param
y the tile's origin along the y-axis
param
width the tile's width
param
height the tile's height

        this.x = x;
        this.y = y;
        this.maxX = x + width - 1;
        this.maxY = y + height - 1;
    
public voidsetTile(com.sun.perseus.j2d.Tile t)
Sets this tile to the same x/y/maxX/maxY as t.

param
t the Tile to copy.

        this.x = t.x;
        this.y = t.y;
        this.maxX = t.maxX;
        this.maxY = t.maxY;
    
public voidsnapBox(Box b)
Sets the tile so that it snaps to the smallest pixel grid which completely contains the input Box.

param
b the Box instance to snap to the grid. If null, the tile is set to have all its values set to Integer.MIN_VALUE.

        if (b == null) {
            x = Integer.MIN_VALUE;
            y = Integer.MIN_VALUE;
            maxX = Integer.MIN_VALUE;
            maxY = Integer.MIN_VALUE;
        } else {
            b.snap();
            x = (int) b.x;
            y = (int) b.y;
            maxX = (int) (b.x + b.width - 1);
            maxY = (int) (b.y + b.height - 1);
        }

        
    
public java.lang.StringtoString()
Debug.

        return "minX = " + x + " minY = " + y + " maxX = " + maxX + " maxY = " + maxY;