com.threerings.media.image
Class NinePatch

java.lang.Object
  extended by com.threerings.media.image.NinePatch

public class NinePatch
extends Object

The NinePatch class permits drawing a bitmap in nine sections. The four corners are unscaled; the four edges are scaled in one axis, and the middle is scaled in both axes. Normally, the middle is transparent so that the patch can provide a selection about a rectangle. Essentially, it allows the creation of custom graphics that will scale the way that you define, when content added within the image exceeds the normal bounds of the graphic. This is an AWT clone of the NinePatch functionality that exists in Google's Android graphic system. See http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch


Field Summary
protected  int _bottom
           
protected  int _bottomPad
           
protected  BufferedImage _img
           
protected  int _left
           
protected  int _leftPad
           
protected  int _right
           
protected  int _rightPad
           
protected  int _top
          The size of the non-stretchable regions on each side.
protected  int _topPad
          The amount of padding on each side until we're in the content area.
 
Constructor Summary
NinePatch(BufferedImage img)
          Builds a NinePatch based on the given image.
NinePatch(BufferedImage img, Rectangle center, Rectangle content)
          Builds a NinePatch based on the given image.
 
Method Summary
 Rectangle getBoundsSurrounding(Rectangle content)
          Returns a rectangle describing the bounds of this NinePatch when drawn such that it frames the given content rectangle.
protected static Rectangle getRectangle(BufferedImage img, boolean stretch)
          Parses the image to find the bounds of the rectangle defined by pixels on the outside.
 void paint(Graphics2D gfx, Rectangle location)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_img

protected final BufferedImage _img

_top

protected final int _top
The size of the non-stretchable regions on each side.


_bottom

protected final int _bottom

_left

protected final int _left

_right

protected final int _right

_topPad

protected final int _topPad
The amount of padding on each side until we're in the content area.


_bottomPad

protected final int _bottomPad

_leftPad

protected final int _leftPad

_rightPad

protected final int _rightPad
Constructor Detail

NinePatch

public NinePatch(BufferedImage img)
Builds a NinePatch based on the given image. Figures out the NinePatch bounds by parsing the image: Opaque pixels in the top row and left column show the stretchable center. Opaque pixels in the bottom row and right column show the content area.


NinePatch

public NinePatch(BufferedImage img,
                 Rectangle center,
                 Rectangle content)
Builds a NinePatch based on the given image.

Parameters:
center - specifies the stretchable center of the image.
content - if non-null, specifies the usable content area of the image
Method Detail

paint

public void paint(Graphics2D gfx,
                  Rectangle location)

getBoundsSurrounding

public Rectangle getBoundsSurrounding(Rectangle content)
Returns a rectangle describing the bounds of this NinePatch when drawn such that it frames the given content rectangle.


getRectangle

protected static Rectangle getRectangle(BufferedImage img,
                                        boolean stretch)
Parses the image to find the bounds of the rectangle defined by pixels on the outside.