Package arc.graphics.g2d
Class NinePatch
java.lang.Object
arc.graphics.g2d.NinePatch
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 nine-patch define the padding). When drawn the eight "edge"
patches will not be scaled, only the interior patch will be scaled.
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)
.
A correctly created TextureAtlas
is one way to generate a post-processed nine-patch from a ".9.png" file.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Indices forNinePatch(TextureRegion...)
constructorstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionNinePatch
(TextureRegion region) Construct a degenerate "nine" patch with only a center component.NinePatch
(TextureRegion... patches) Construct a nine patch from the given nine texture regions.NinePatch
(TextureRegion region, int left, int right, int top, int bottom) Create a ninepatch by cutting up the given texture region into nine patches.NinePatch
(TextureRegion region, Color color) Construct a degenerate "nine" patch with only a center component.Construct a degenerate "nine" patch with only a center component.Create a ninepatch by cutting up the given texture into nine patches.Construct a degenerate "nine" patch with only a center component. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(float x, float y, float width, float height) void
draw
(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) float
getColor()
float
float
float
float
Returns the bottom padding if set, else returnsgetBottomHeight()
.float
Returns the left padding if set, else returnsgetLeftWidth()
.float
Returns the right padding if set, else returnsgetRightWidth()
.float
Returns the top padding if set, else returnsgetTopHeight()
.float
float
float
float
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 patchesvoid
Copy given color.void
setLeftWidth
(float leftWidth) Set the draw-time width of the three left edge patchesvoid
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 patchesvoid
setTopHeight
(float topHeight) Set the draw-time height of the three top edge patches
-
Field Details
-
TOP_LEFT
public static final int TOP_LEFT- See Also:
-
TOP_CENTER
public static final int TOP_CENTER- See Also:
-
TOP_RIGHT
public static final int TOP_RIGHT- See Also:
-
MIDDLE_LEFT
public static final int MIDDLE_LEFT- See Also:
-
MIDDLE_CENTER
public static final int MIDDLE_CENTER- See Also:
-
MIDDLE_RIGHT
public static final int MIDDLE_RIGHT- See Also:
-
BOTTOM_LEFT
public static final int BOTTOM_LEFT- See Also:
-
BOTTOM_CENTER
public static final int BOTTOM_CENTERIndices forNinePatch(TextureRegion...)
constructor- See Also:
-
BOTTOM_RIGHT
public static final int BOTTOM_RIGHT- See Also:
-
-
Constructor Details
-
NinePatch
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
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.
-
NinePatch
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
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.
-
NinePatch
Construct a degenerate "nine" patch with only a center component. -
NinePatch
Construct a degenerate "nine" patch with only a center component. -
NinePatch
Construct a degenerate "nine" patch with only a center component. -
NinePatch
Construct a degenerate "nine" patch with only a center component. -
NinePatch
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 benull
. Patch indices are specified via the public membersTOP_LEFT
,TOP_CENTER
, etc. -
NinePatch
-
NinePatch
-
-
Method Details
-
draw
public void draw(float x, float y, float width, float height) -
draw
public void draw(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) -
getColor
-
setColor
Copy given color. The color will be blended with the batch color, then combined with the texture colors at draw time. Default isColor.white
. -
getLeftWidth
public float getLeftWidth() -
setLeftWidth
public void setLeftWidth(float leftWidth) Set the draw-time width of the three left edge patches -
getRightWidth
public float getRightWidth() -
setRightWidth
public void setRightWidth(float rightWidth) Set the draw-time width of the three right edge patches -
getTopHeight
public float getTopHeight() -
setTopHeight
public void setTopHeight(float topHeight) Set the draw-time height of the three top edge patches -
getBottomHeight
public float getBottomHeight() -
setBottomHeight
public void setBottomHeight(float bottomHeight) Set the draw-time height of the three bottom edge patches -
getMiddleWidth
public float getMiddleWidth() -
setMiddleWidth
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 thedefault total width
. -
getMiddleHeight
public float getMiddleHeight() -
setMiddleHeight
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 thedefault total height
. -
getTotalWidth
public float getTotalWidth() -
getTotalHeight
public float getTotalHeight() -
setPadding
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. -
getPadLeft
public float getPadLeft()Returns the left padding if set, else returnsgetLeftWidth()
. -
setPadLeft
public void setPadLeft(float left) -
getPadRight
public float getPadRight()Returns the right padding if set, else returnsgetRightWidth()
. -
setPadRight
public void setPadRight(float right) -
getPadTop
public float getPadTop()Returns the top padding if set, else returnsgetTopHeight()
. -
setPadTop
public void setPadTop(float top) -
getPadBottom
public float getPadBottom()Returns the bottom padding if set, else returnsgetBottomHeight()
. -
setPadBottom
public void setPadBottom(float bottom) -
scale
public void scale(float scaleX, float scaleY) Multiplies the top/left/bottom/right sizes and padding by the specified amount. -
getTexture
-