t3.hrd.state
Class Tile

java.lang.Object
  extended by t3.hrd.state.OrderedElement
      extended by t3.hrd.state.Tile

public class Tile
extends OrderedElement

A Tile is a rectangular image with a width and height that is drawn on the desk with a specific width, height and orientation, and at a specific location. Create new Tiles by calling the appropriate method on the a StateManager object. A Tile can be backed, split or unbacked.

A backed tile is the simplest tile. It has a BufferedImage that stores its contents.

An unbacked tile has no BufferedImage, and if you call the method to get the image then the system will create an empty bufferedimage, call callback_repaintUnbackedTile to paint into the empty image, and then return the result. You can set up the StateManager to always produce unbacked tiles rather than backed tiles.

A split tile is created if you create a tile with a large number of pixels (depending on how you set up your StateManager). It has no bufferedImage itself but refers to several smaller backed tiles.

A Tile uses the bufferedimage format TYPE_INT_ARGB (i.e. 32 bits per pixel) by default but you can specify a flag to change this to TYPE_USHORT_565RGB (i.e. 16 bits per pixel). Pixel data is sent to the graphics card via OpenGL in the same format as the BufferedImage.

When stored as a texture for rendering, the texture has format RGBA8 (i.e. 32 bits per pixel) by default but you can specify a flag to change this to RGB4 (i.e. 12 bits per pixel).

TILE space is a 2D homogenous coordinate space corresponding to the coordinate space of the tile's image. There are methods to obtain the corner points, outline and bounding box of the tile in TILE space and also in DESK space (i.e. once the tile has been affine-transformed).

Threading notes: this class is not thread-safe. You must use some kind of locking scheme if you use it in a multithreaded environment.

Author:
pjt40

Field Summary
static int FLAG_BI_USHORT565RGB_NOT_INTARGB
           
static int FLAG_NO_TRANSFORM
          Tile not transformed - draw texture pixel for pixel into frame buffer
static int FLAG_TEXTUREALWAYSRESIDENTEVENWHENTILEINVISIBLE
           
static int FLAG_TEXTUREALWAYSRESIDENTWHENTILEVISIBLE
           
 int flags
           
 int imageH
          As imageW
 int imageW
          Width of the tile's buffered image in pixels.
 int tileHeight
          Height of the usable tile image in pixels.
static boolean TILEtoDESKflipsHoriz
           
static boolean TILEtoDESKflipsVert
           
 int tileType
           
static int TILETYPE_BACKED
           
static int TILETYPE_SPLIT
           
static int TILETYPE_UNBACKED
           
 int tileWidth
          Width of the usable tile image in pixels.
 java.util.List<UnwarpedRect> unwarpedRectsLinesReadOnly
          UnwarpedRects associated with this tile, for reading only.
 java.util.List<UnwarpedRect> unwarpedRectsWordsReadOnly
           
 
Fields inherited from class t3.hrd.state.OrderedElement
elementId, stateManager
 
Method Summary
 java.awt.image.BufferedImage createCompatibleBufferedImage(int w, int h)
          Creates a BufferedImage compatible with the tile's image.
 java.awt.Graphics2D createGraphics2DForTileUpdate(java.awt.Rectangle r, java.awt.image.BufferedImage tileUpdateImage)
          Creates a Graphics2D from a Rectangle and a BufferedImage such that (r.x,r.y) in Graphics2D corresponds to (0,0) in the BufferedImage and the clip area of the Graphics2D is exactly the size of the BufferedImage.
 double getDESKcentreX()
           
 double getDESKcentreY()
           
 double getDESKheight()
           
 double getDESKwidth()
           
 java.awt.geom.GeneralPath getGpDESKoutline()
           
 java.awt.image.BufferedImage getImageForReadingOnlyNoPainting()
          For a backed tile only.
 java.awt.image.BufferedImage getImageForReadingOnlyPaintIfNecessary()
          For a backed tile, this returns the backed tile's BufferedImage that contains the tile's pixel data.
 boolean getIntegerTileSpaceCoordsFromDESK(int[] intTileSpaceCoords, double[] dDESK)
          Translates DESK space coordinates into TILE space coordinates and then rounds to integers.
 Jama.Matrix[] getmDESKcornersClockwise()
           
 Jama.Matrix getmDESKtoTILE()
           
 Jama.Matrix[] getmTILEcornersClockwise()
           
 Jama.Matrix getmTILEtoDESK()
           
 java.awt.geom.Rectangle2D getrDESKboundingBox()
           
 Tile[][] getSplitComponentsPackedByColForReadOnly()
          For a split tile, this returns its component backed Tiles, packed by column.
 double getTILEtoDESKrotationClockwise()
           
 boolean isDestroyed()
           
 boolean isFlagSet(int f)
           
 boolean isVisible()
           
 void opCreateUnwarpedRect(UnwarpedRect r)
          Creates a new unwarped rectangle.
 void opDestroyAllUnwarpedRectsIntersecting(java.awt.Rectangle r)
          Destroys all unwarped rectangles intersecting a specified rectangle.
 void opSetAff(double DESKcentreX, double DESKcentreY, double DESKwidth, double DESKheight, double thetaClockwise)
          Sets the centre, width, height and rotation of the tile on the display surface.
 void opSetVisibility(boolean v)
          Set tile visibility.
 void opUpdateContents(int x, int y, java.awt.image.BufferedImage update, int compressionHint)
          Pastes a supplied image into part of the tile's contents.
 void opUpdateContentsByCopyingFromOtherTile(int sx, int sy, int dx, int dy, int w, int h, Tile source)
          Updates the contents of this tile by copying data from another tile.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FLAG_NO_TRANSFORM

public static final int FLAG_NO_TRANSFORM
Tile not transformed - draw texture pixel for pixel into frame buffer

See Also:
Constant Field Values

FLAG_BI_USHORT565RGB_NOT_INTARGB

public static final int FLAG_BI_USHORT565RGB_NOT_INTARGB
See Also:
Constant Field Values

FLAG_TEXTUREALWAYSRESIDENTWHENTILEVISIBLE

public static final int FLAG_TEXTUREALWAYSRESIDENTWHENTILEVISIBLE
See Also:
Constant Field Values

FLAG_TEXTUREALWAYSRESIDENTEVENWHENTILEINVISIBLE

public static final int FLAG_TEXTUREALWAYSRESIDENTEVENWHENTILEINVISIBLE
See Also:
Constant Field Values

TILEtoDESKflipsVert

public static final boolean TILEtoDESKflipsVert
See Also:
Constant Field Values

TILEtoDESKflipsHoriz

public static final boolean TILEtoDESKflipsHoriz
See Also:
Constant Field Values

TILETYPE_BACKED

public static final int TILETYPE_BACKED
See Also:
Constant Field Values

TILETYPE_SPLIT

public static final int TILETYPE_SPLIT
See Also:
Constant Field Values

TILETYPE_UNBACKED

public static final int TILETYPE_UNBACKED
See Also:
Constant Field Values

tileWidth

public final int tileWidth
Width of the usable tile image in pixels.


tileHeight

public final int tileHeight
Height of the usable tile image in pixels.


imageW

public final int imageW
Width of the tile's buffered image in pixels. Not set if the tile is unbacked or split. May differ from tileWidth because some systems must use on powers of two for image dimensions


imageH

public final int imageH
As imageW


flags

public final int flags

tileType

public final int tileType

unwarpedRectsLinesReadOnly

public final java.util.List<UnwarpedRect> unwarpedRectsLinesReadOnly
UnwarpedRects associated with this tile, for reading only.


unwarpedRectsWordsReadOnly

public final java.util.List<UnwarpedRect> unwarpedRectsWordsReadOnly
Method Detail

isVisible

public boolean isVisible()

isFlagSet

public boolean isFlagSet(int f)

getTILEtoDESKrotationClockwise

public double getTILEtoDESKrotationClockwise()

getDESKcentreX

public double getDESKcentreX()

getDESKcentreY

public double getDESKcentreY()

getDESKwidth

public double getDESKwidth()

getDESKheight

public double getDESKheight()

getmTILEcornersClockwise

public Jama.Matrix[] getmTILEcornersClockwise()

getmDESKcornersClockwise

public Jama.Matrix[] getmDESKcornersClockwise()

getrDESKboundingBox

public java.awt.geom.Rectangle2D getrDESKboundingBox()

getmTILEtoDESK

public Jama.Matrix getmTILEtoDESK()

getmDESKtoTILE

public Jama.Matrix getmDESKtoTILE()

isDestroyed

public boolean isDestroyed()

getGpDESKoutline

public java.awt.geom.GeneralPath getGpDESKoutline()

getSplitComponentsPackedByColForReadOnly

public Tile[][] getSplitComponentsPackedByColForReadOnly()
For a split tile, this returns its component backed Tiles, packed by column.

Returns:

getImageForReadingOnlyNoPainting

public java.awt.image.BufferedImage getImageForReadingOnlyNoPainting()
For a backed tile only.

Returns:
The backed tile's BufferedImage that contains the tile's pixel data.

getImageForReadingOnlyPaintIfNecessary

public java.awt.image.BufferedImage getImageForReadingOnlyPaintIfNecessary()
For a backed tile, this returns the backed tile's BufferedImage that contains the tile's pixel data.

For an unbacked tile, this creates a new empty BufferedImage, calls callback_repaintUnbackedTile to paint into the empty image and returns the result.

For a split tile this results in an IllegalStateException.

Returns:

opSetAff

public void opSetAff(double DESKcentreX,
                     double DESKcentreY,
                     double DESKwidth,
                     double DESKheight,
                     double thetaClockwise)
Sets the centre, width, height and rotation of the tile on the display surface.

Parameters:
DESKcentreX -
DESKcentreY -
DESKwidth -
DESKheight -
thetaClockwise -

opSetVisibility

public void opSetVisibility(boolean v)
Set tile visibility.

Parameters:
v -

createCompatibleBufferedImage

public java.awt.image.BufferedImage createCompatibleBufferedImage(int w,
                                                                  int h)
Creates a BufferedImage compatible with the tile's image.

Parameters:
w -
h -
Returns:

createGraphics2DForTileUpdate

public java.awt.Graphics2D createGraphics2DForTileUpdate(java.awt.Rectangle r,
                                                         java.awt.image.BufferedImage tileUpdateImage)
Creates a Graphics2D from a Rectangle and a BufferedImage such that (r.x,r.y) in Graphics2D corresponds to (0,0) in the BufferedImage and the clip area of the Graphics2D is exactly the size of the BufferedImage.

Parameters:
r -
tileUpdateImage -
Returns:

opUpdateContentsByCopyingFromOtherTile

public void opUpdateContentsByCopyingFromOtherTile(int sx,
                                                   int sy,
                                                   int dx,
                                                   int dy,
                                                   int w,
                                                   int h,
                                                   Tile source)
Updates the contents of this tile by copying data from another tile. Neither tile may be split.

Parameters:
sx -
sy -
dx -
dy -
w -
h -
source -

opUpdateContents

public void opUpdateContents(int x,
                             int y,
                             java.awt.image.BufferedImage update,
                             int compressionHint)
Pastes a supplied image into part of the tile's contents. This works for all types of tile.

Typical usage: Say you want to update an area r of the tile. Create a new BufferedImage with same dimensions as r using createCompatibleBufferedImage. Create a Graphics2D using createGraphics2DForTileUpdate. Now draw into the Graphics2D. (0,0) will correspond to the origin in TILE space, but only things that you draw into the area of r will appear in the update. Now call opUpdateContents.

Parameters:
x - x coordinate of update in TILE
y - y coordinate of update in TILE
update - contents of update

opCreateUnwarpedRect

public void opCreateUnwarpedRect(UnwarpedRect r)
Creates a new unwarped rectangle. Not to be confused with split tiles.


opDestroyAllUnwarpedRectsIntersecting

public void opDestroyAllUnwarpedRectsIntersecting(java.awt.Rectangle r)
Destroys all unwarped rectangles intersecting a specified rectangle.

Parameters:
r -

getIntegerTileSpaceCoordsFromDESK

public boolean getIntegerTileSpaceCoordsFromDESK(int[] intTileSpaceCoords,
                                                 double[] dDESK)
Translates DESK space coordinates into TILE space coordinates and then rounds to integers.

Parameters:
intTileSpaceCoords - array of two ints, which are set to the x and y integer coordinates.
dDESK - array of three doubles, the DESK space coordinates.
Returns:
true iff the coordinates lie within the tile.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object