APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g2d

public Class NinePatch

extends Object
Class Inheritance
Imports
com.badlogic.gdx.graphics.Color, .Texture, .Texture.TextureFilter, com.badlogic.gdx.math.MathUtils, com.badlogic.gdx.utils.GdxRuntimeException

A 3x3 grid of texture regions. Any of the regions may be omitted. Padding may be set as a hint on how to inset content on top of the ninepatch (by default the eight "edge" textures of the ninepatch define the padding). When drawn, the four corner patches will not be scaled, the interior patch will be scaled in both directions, and the middle patch for each edge will be scaled in only one direction.

Note this class does not accept ".9.png" textures that include the metadata border pixels describing the splits (and padding) for the ninepatch. That information is either passed to a constructor or defined implicitly by the size of the individual patch textures. TextureAtlas is one way to generate a postprocessed ninepatch texture regions from ".9.png" files.

Field Summary

Modifier and TypeField and Description
public static final int
BOTTOM_CENTER

Indices for the NinePatch(TextureRegion...) constructor.

public static final int
public static final int
private int
private float
private int
private int
private final Color
private int
private float
public static final int
public static final int
public static final int
private int
private float
private int
private int
private float
private float
private float
private float
private float
private float
private Texture
private static final Color
public static final int
public static final int
public static final int
private int
private float
private int
private int
private float[]

Constructor Summary

AccessConstructor and Description
public
NinePatch(Texture texture, int
Pixels from left edge.
left
,
int
Pixels from right edge.
right
,
int
Pixels from top edge.
top
,
int
Pixels from bottom edge.
bottom
)

Create a ninepatch by cutting up the given texture into nine patches.

public
NinePatch(TextureRegion region, int
Pixels from left edge.
left
,
int
Pixels from right edge.
right
,
int
Pixels from top edge.
top
,
int
Pixels from bottom edge.
bottom
)

Create a ninepatch by cutting up the given texture region into nine patches.

public
NinePatch(Texture texture, Color color)

Construct a degenerate "nine" patch with only a center component.

public
NinePatch(Texture texture)

Construct a degenerate "nine" patch with only a center component.

public
NinePatch(TextureRegion region, Color color)

Construct a degenerate "nine" patch with only a center component.

public
NinePatch(TextureRegion region)

Construct a degenerate "nine" patch with only a center component.

public
NinePatch(TextureRegion... patches)

Construct a nine patch from the given nine texture regions.

public
NinePatch(NinePatch ninePatch)

public
NinePatch(NinePatch ninePatch, Color color)

Method Summary

Modifier and TypeMethod and Description
private int
add(TextureRegion region, boolean isStretchW, boolean isStretchH)

public void
draw(Batch batch, float x, float y, float width, float height)

public void
draw(Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)

public float
public Color
public float
public float
public float
public float
getPadBottom()

Returns the bottom padding if set, else returns getBottomHeight().

public float
getPadLeft()

Returns the left padding if set, else returns getLeftWidth().

public float
getPadRight()

Returns the right padding if set, else returns getRightWidth().

public float
getPadTop()

Returns the top padding if set, else returns getTopHeight().

public float
public Texture
public float
public float
public float
private void
load(TextureRegion[] patches)

private void
prepareVertices(Batch batch, float x, float y, float width, float height)

public void
scale(float scaleX, float scaleY)

Multiplies the top/left/bottom/right sizes and padding by the specified amount.

private void
set(int idx, float x, float y, float width, float height, float color)

Set the coordinates and color of a ninth of the patch.

public void
setBottomHeight(float bottomHeight)

Set the draw-time height of the three bottom edge patches

public void
setColor(Color color)

Copy given color.

public void
setLeftWidth(float leftWidth)

Set the draw-time width of the three left edge patches

public void
setMiddleHeight(float middleHeight)

Set the height of the middle row of the patch.

public void
setMiddleWidth(float middleWidth)

Set the width of the middle column of the patch.

public void
public void
setPadding(float left, float right, float top, float bottom)

Set the padding for content inside this ninepatch.

public void
public void
public void
public void
setRightWidth(float rightWidth)

Set the draw-time width of the three right edge patches

public void
setTopHeight(float topHeight)

Set the draw-time height of the three top edge patches

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BOTTOM_CENTERback to summary
public static final int BOTTOM_CENTER

Indices for the NinePatch(TextureRegion...) constructor.

BOTTOM_LEFTback to summary
public static final int BOTTOM_LEFT
BOTTOM_RIGHTback to summary
public static final int BOTTOM_RIGHT
bottomCenterback to summary
private int bottomCenter
bottomHeightback to summary
private float bottomHeight
bottomLeftback to summary
private int bottomLeft
bottomRightback to summary
private int bottomRight
colorback to summary
private final Color color
idxback to summary
private int idx
leftWidthback to summary
private float leftWidth
MIDDLE_CENTERback to summary
public static final int MIDDLE_CENTER
MIDDLE_LEFTback to summary
public static final int MIDDLE_LEFT
MIDDLE_RIGHTback to summary
public static final int MIDDLE_RIGHT
middleCenterback to summary
private int middleCenter
middleHeightback to summary
private float middleHeight
middleLeftback to summary
private int middleLeft
middleRightback to summary
private int middleRight
middleWidthback to summary
private float middleWidth
padBottomback to summary
private float padBottom
padLeftback to summary
private float padLeft
padRightback to summary
private float padRight
padTopback to summary
private float padTop
rightWidthback to summary
private float rightWidth
textureback to summary
private Texture texture
tmpDrawColorback to summary
private static final Color tmpDrawColor
TOP_CENTERback to summary
public static final int TOP_CENTER
TOP_LEFTback to summary
public static final int TOP_LEFT
TOP_RIGHTback to summary
public static final int TOP_RIGHT
topCenterback to summary
private int topCenter
topHeightback to summary
private float topHeight
topLeftback to summary
private int topLeft
topRightback to summary
private int topRight
verticesback to summary
private float[] vertices

Constructor Detail

NinePatchback to summary
public NinePatch(Texture texture, int left, int right, int top, int bottom)

Create a ninepatch by cutting up the given texture into nine patches. The subsequent parameters define the 4 lines that will cut the texture region into 9 pieces.

Parameters
left:int

Pixels from left edge.

right:int

Pixels from right edge.

top:int

Pixels from top edge.

bottom:int

Pixels from bottom edge.

NinePatchback to summary
public NinePatch(TextureRegion region, int left, int right, int top, int bottom)

Create a ninepatch by cutting up the given texture region into nine patches. The subsequent parameters define the 4 lines that will cut the texture region into 9 pieces.

Parameters
left:int

Pixels from left edge.

right:int

Pixels from right edge.

top:int

Pixels from top edge.

bottom:int

Pixels from bottom edge.

NinePatchback to summary
public NinePatch(Texture texture, Color color)

Construct a degenerate "nine" patch with only a center component.

NinePatchback to summary
public NinePatch(Texture texture)

Construct a degenerate "nine" patch with only a center component.

NinePatchback to summary
public NinePatch(TextureRegion region, Color color)

Construct a degenerate "nine" patch with only a center component.

NinePatchback to summary
public NinePatch(TextureRegion region)

Construct a degenerate "nine" patch with only a center component.

NinePatchback to summary
public NinePatch(TextureRegion... patches)

Construct a nine patch from the given nine texture regions. The provided patches must be consistently sized (e.g., any left edge textures must have the same width, etc). Patches may be null. Patch indices are specified via the public members TOP_LEFT, TOP_CENTER, etc.

NinePatchback to summary
public NinePatch(NinePatch ninePatch)
NinePatchback to summary
public NinePatch(NinePatch ninePatch, Color color)

Method Detail

addback to summary
private int add(TextureRegion region, boolean isStretchW, boolean isStretchH)
drawback to summary
public void draw(Batch batch, float x, float y, float width, float height)
drawback to summary
public void draw(Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
getBottomHeightback to summary
public float getBottomHeight()
getColorback to summary
public Color getColor()
getLeftWidthback to summary
public float getLeftWidth()
getMiddleHeightback to summary
public float getMiddleHeight()
getMiddleWidthback to summary
public float getMiddleWidth()
getPadBottomback to summary
public float getPadBottom()

Returns the bottom padding if set, else returns getBottomHeight().

getPadLeftback to summary
public float getPadLeft()

Returns the left padding if set, else returns getLeftWidth().

getPadRightback to summary
public float getPadRight()

Returns the right padding if set, else returns getRightWidth().

getPadTopback to summary
public float getPadTop()

Returns the top padding if set, else returns getTopHeight().

getRightWidthback to summary
public float getRightWidth()
getTextureback to summary
public Texture getTexture()
getTopHeightback to summary
public float getTopHeight()
getTotalHeightback to summary
public float getTotalHeight()
getTotalWidthback to summary
public float getTotalWidth()
loadback to summary
private void load(TextureRegion[] patches)
prepareVerticesback to summary
private void prepareVertices(Batch batch, float x, float y, float width, float height)
scaleback to summary
public void scale(float scaleX, float scaleY)

Multiplies the top/left/bottom/right sizes and padding by the specified amount.

setback to summary
private void set(int idx, float x, float y, float width, float height, float color)

Set the coordinates and color of a ninth of the patch.

setBottomHeightback to summary
public void setBottomHeight(float bottomHeight)

Set the draw-time height of the three bottom edge patches

setColorback to summary
public void setColor(Color color)

Copy given color. The color will be blended with the batch color, then combined with the texture colors at draw time. Default is Color#WHITE.

setLeftWidthback to summary
public void setLeftWidth(float leftWidth)

Set the draw-time width of the three left edge patches

setMiddleHeightback to summary
public void setMiddleHeight(float middleHeight)

Set the height of the middle row of the patch. At render time, this is implicitly the requested render-height of the entire nine patch, minus the top and bottom height. This value is only used for computing the default total height.

setMiddleWidthback to summary
public void setMiddleWidth(float middleWidth)

Set the width of the middle column of the patch. At render time, this is implicitly the requested render-width of the entire nine patch, minus the left and right width. This value is only used for computing the default total width.

setPadBottomback to summary
public void setPadBottom(float bottom)

See setPadding(float, float, float, float)

setPaddingback to summary
public void setPadding(float left, float right, float top, float bottom)

Set the padding for content inside this ninepatch. By default the padding is set to match the exterior of the ninepatch, so the content should fit exactly within the middle patch.

setPadLeftback to summary
public void setPadLeft(float left)

See setPadding(float, float, float, float)

setPadRightback to summary
public void setPadRight(float right)

See setPadding(float, float, float, float)

setPadTopback to summary
public void setPadTop(float top)

See setPadding(float, float, float, float)

setRightWidthback to summary
public void setRightWidth(float rightWidth)

Set the draw-time width of the three right edge patches

setTopHeightback to summary
public void setTopHeight(float topHeight)

Set the draw-time height of the three top edge patches