org.jrabbit.base.graphics.skins.image
Class SubImageSkin

java.lang.Object
  extended by org.jrabbit.base.data.cache.CachePointer<Image>
      extended by org.jrabbit.base.graphics.image.ImagePointer
          extended by org.jrabbit.base.graphics.skins.image.ImageSkin
              extended by org.jrabbit.base.graphics.skins.image.SubImageSkin
All Implemented Interfaces:
Renderable, Referenced, Retriever<Image>, Skin, Dimensioned

public class SubImageSkin
extends ImageSkin

Much like an ImageSkin, a SubImageSkin renders an Image it retrieves from the ImageCache; however, it renders a particular section of the Image, instead of the whole thing. This section can either be a small portion of it (like a single image on a Sprite sheet), or it can be larger than the source Image, in which case the resulting render is tiled. When using a SubImageSkin, remember that the textures used are Power-Of-Two textures; if an image is not PoT, its coordinates will need to be adjusted accordingly.

Author:
Chris Molini

Field Summary
private  float[] coordinates
          The Image coordinates that correspond to what section of the image to draw.
private  int ID
          Images use an array to manage their accelerated sub-sections for rendering; this is the ID of the current sub-image in that array.
 
Fields inherited from class org.jrabbit.base.graphics.skins.image.ImageSkin
height, width
 
Fields inherited from class org.jrabbit.base.data.cache.CachePointer
object, reference
 
Constructor Summary
SubImageSkin(java.lang.String reference, float[] coordinates)
          Creates a SubImageSkin that uses the indicated Image and renders the indicated section of it.
SubImageSkin(java.lang.String reference, int x, int y, int width, int height)
          Creates a SubImageSkin that uses the indicated Image and renders the indicated section of it.
 
Method Summary
 float[] coordinates()
          Accesses the coordinate values.
 void refresh()
          Refreshes the cached Image reference; this does not need to be called manually unless the contents of the Cache are altered.
protected  void refreshSubImage()
          Refreshes the rendering and dimensional data based on the currently set coordinate values.
 void render()
          Renders the desired section of the source image.
 void setCoordinates(float[] coordinates)
          Redefines the coordinates to use for rendering.
 
Methods inherited from class org.jrabbit.base.graphics.skins.image.ImageSkin
height, width
 
Methods inherited from class org.jrabbit.base.graphics.image.ImagePointer
retrieve
 
Methods inherited from class org.jrabbit.base.data.cache.CachePointer
object, reference, setReference, valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coordinates

private float[] coordinates
The Image coordinates that correspond to what section of the image to draw. These values are proportional; 0.5f means halfway across the image, not half a pixel.


ID

private int ID
Images use an array to manage their accelerated sub-sections for rendering; this is the ID of the current sub-image in that array.

Constructor Detail

SubImageSkin

public SubImageSkin(java.lang.String reference,
                    float[] coordinates)
Creates a SubImageSkin that uses the indicated Image and renders the indicated section of it.

Parameters:
reference - The identifier of the target image.
coordinates - The proportional coordinate values to map to the image. The values to use should be in the format {x1, y1, x2, y2}.

SubImageSkin

public SubImageSkin(java.lang.String reference,
                    int x,
                    int y,
                    int width,
                    int height)
Creates a SubImageSkin that uses the indicated Image and renders the indicated section of it. The indicated values are in pixels; they are not proportional.

Parameters:
reference - The identifier of the target image.
x - The top-left x pixel of the section to render.
y - The top-left y pixel of the section to render.
width - The width of the section to render (in pixels).
height - The height of the section to render (in pixels).
Method Detail

render

public void render()
Renders the desired section of the source image.

Specified by:
render in interface Renderable
Overrides:
render in class ImageSkin

refresh

public void refresh()
Refreshes the cached Image reference; this does not need to be called manually unless the contents of the Cache are altered. Additionally, this updates the stored dimensional values (width and height), and updates the ID used to render the sub-image.

Overrides:
refresh in class ImageSkin

coordinates

public final float[] coordinates()
Accesses the coordinate values. The returned values are proportions; they indicated the percentage of the Image to render.

Returns:
The array of floats that defines the section of the Image to render. These are in the format {x1, y1, x2, y2}.

setCoordinates

public void setCoordinates(float[] coordinates)
Redefines the coordinates to use for rendering.

Parameters:
coordinates - The array of floats that defines the section of the Image to render. These are in the format {x1, y1, x2, y2}.

refreshSubImage

protected void refreshSubImage()
Refreshes the rendering and dimensional data based on the currently set coordinate values.