public class NinePatch extends Object
NOTE: This class expects a "post-processed" nine-patch, and not a raw ".9.png" texture. That is, the textures given to
this class should not include the meta-data pixels from a ".9.png" that describe the layout of the ninepatch over the
interior of the graphic. That information should be passed into the constructor either implicitly as the size of the individual
patch textures, or via the left, right, top, bottom
parameters to NinePatch(Texture, int, int, int, int)
or NinePatch(TextureRegion, int, int, int, int)
.
TextureAtlas
is one way to generate a post-processed nine-patch from a ".9.png" file.
Modifier and Type | Field and Description |
---|---|
static int |
BOTTOM_CENTER
Indices for
NinePatch(TextureRegion...) constructor |
static int |
BOTTOM_LEFT |
static int |
BOTTOM_RIGHT |
static int |
MIDDLE_CENTER |
static int |
MIDDLE_LEFT |
static int |
MIDDLE_RIGHT |
static int |
TOP_CENTER |
static int |
TOP_LEFT |
static int |
TOP_RIGHT |
Constructor and Description |
---|
NinePatch(NinePatch ninePatch) |
NinePatch(NinePatch ninePatch,
Color color) |
NinePatch(Texture texture)
Construct a degenerate "nine" patch with only a center component.
|
NinePatch(Texture texture,
Color color)
Construct a degenerate "nine" patch with only a center component.
|
NinePatch(Texture texture,
int left,
int right,
int top,
int bottom)
Create a ninepatch by cutting up the given texture into nine patches.
|
NinePatch(TextureRegion... patches)
Construct a nine patch from the given nine texture regions.
|
NinePatch(TextureRegion region)
Construct a degenerate "nine" patch with only a center component.
|
NinePatch(TextureRegion region,
Color color)
Construct a degenerate "nine" patch with only a center component.
|
NinePatch(TextureRegion region,
int left,
int right,
int top,
int bottom)
Create a ninepatch by cutting up the given texture region into nine patches.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Batch batch,
float x,
float y,
float width,
float height) |
void |
draw(Batch batch,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation) |
float |
getBottomHeight() |
Color |
getColor() |
float |
getLeftWidth() |
float |
getMiddleHeight() |
float |
getMiddleWidth() |
float |
getPadBottom()
Returns the bottom padding if set, else returns
getBottomHeight() . |
float |
getPadLeft()
Returns the left padding if set, else returns
getLeftWidth() . |
float |
getPadRight()
Returns the right padding if set, else returns
getRightWidth() . |
float |
getPadTop()
Returns the top padding if set, else returns
getTopHeight() . |
float |
getRightWidth() |
Texture |
getTexture() |
float |
getTopHeight() |
float |
getTotalHeight() |
float |
getTotalWidth() |
void |
scale(float scaleX,
float scaleY)
Multiplies the top/left/bottom/right sizes and padding by the specified amount.
|
void |
setBottomHeight(float bottomHeight)
Set the draw-time height of the three bottom edge patches
|
void |
setColor(Color color)
Copy given color.
|
void |
setLeftWidth(float leftWidth)
Set the draw-time width of the three left edge patches
|
void |
setMiddleHeight(float middleHeight)
Set the height of the middle row of the patch.
|
void |
setMiddleWidth(float middleWidth)
Set the width of the middle column of the patch.
|
void |
setPadBottom(float bottom)
|
void |
setPadding(float left,
float right,
float top,
float bottom)
Set the padding for content inside this ninepatch.
|
void |
setPadLeft(float left)
|
void |
setPadRight(float right)
|
void |
setPadTop(float top)
|
void |
setRightWidth(float rightWidth)
Set the draw-time width of the three right edge patches
|
void |
setTopHeight(float topHeight)
Set the draw-time height of the three top edge patches
|
public static final int TOP_LEFT
public static final int TOP_CENTER
public static final int TOP_RIGHT
public static final int MIDDLE_LEFT
public static final int MIDDLE_CENTER
public static final int MIDDLE_RIGHT
public static final int BOTTOM_LEFT
public static final int BOTTOM_CENTER
NinePatch(TextureRegion...)
constructorpublic static final int BOTTOM_RIGHT
public NinePatch(Texture texture, int left, int right, int top, int bottom)
left
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.public NinePatch(TextureRegion region, int left, int right, int top, int bottom)
left
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.public NinePatch(Texture texture, Color color)
public NinePatch(Texture texture)
public NinePatch(TextureRegion region, Color color)
public NinePatch(TextureRegion region)
public NinePatch(TextureRegion... patches)
null
. Patch indices are specified via the public
members TOP_LEFT
, TOP_CENTER
, etc.public NinePatch(NinePatch ninePatch)
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 void setColor(Color color)
draw
time. Default is Color.WHITE
.public Color getColor()
public float getLeftWidth()
public void setLeftWidth(float leftWidth)
public float getRightWidth()
public void setRightWidth(float rightWidth)
public float getTopHeight()
public void setTopHeight(float topHeight)
public float getBottomHeight()
public void setBottomHeight(float bottomHeight)
public float getMiddleWidth()
public void setMiddleWidth(float middleWidth)
default
total width
.public float getMiddleHeight()
public void setMiddleHeight(float middleHeight)
default
total height
.public float getTotalWidth()
public float getTotalHeight()
public void setPadding(float left, float right, float top, float bottom)
public float getPadLeft()
getLeftWidth()
.public void setPadLeft(float left)
public float getPadRight()
getRightWidth()
.public void setPadRight(float right)
public float getPadTop()
getTopHeight()
.public void setPadTop(float top)
public float getPadBottom()
getBottomHeight()
.public void setPadBottom(float bottom)
public void scale(float scaleX, float scaleY)
public Texture getTexture()
Copyright © 2019. All rights reserved.