Class NinePatch
- java.lang.Object
-
- gaia.cu9.ari.gaiaorbit.util.gdx.g2d.NinePatch
-
public class NinePatch extends java.lang.Object
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 toNinePatch(Texture, int, int, int, int)
orNinePatch(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
Fields Modifier and Type Field Description static int
BOTTOM_CENTER
Indices forNinePatch(TextureRegion...)
constructorstatic 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 Summary
Constructors Constructor Description NinePatch(com.badlogic.gdx.graphics.Texture texture)
Construct a degenerate "nine" patch with only a center component.NinePatch(com.badlogic.gdx.graphics.Texture texture, int left, int right, int top, int bottom)
Create a ninepatch by cutting up the given texture into nine patches.NinePatch(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Color color)
Construct a degenerate "nine" patch with only a center component.NinePatch(NinePatch ninePatch)
NinePatch(NinePatch ninePatch, com.badlogic.gdx.graphics.Color color)
NinePatch(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, com.badlogic.gdx.graphics.Color color)
Construct a degenerate "nine" patch with only a center component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y, float width, float height)
void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
float
getBottomHeight()
com.badlogic.gdx.graphics.Color
getColor()
float
getLeftWidth()
float
getMiddleHeight()
float
getMiddleWidth()
float
getPadBottom()
Returns the bottom padding if set, else returnsgetBottomHeight()
.float
getPadLeft()
Returns the left padding if set, else returnsgetLeftWidth()
.float
getPadRight()
Returns the right padding if set, else returnsgetRightWidth()
.float
getPadTop()
Returns the top padding if set, else returnsgetTopHeight()
.float
getRightWidth()
com.badlogic.gdx.graphics.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 patchesvoid
setColor(com.badlogic.gdx.graphics.Color color)
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 Detail
-
TOP_LEFT
public static final int TOP_LEFT
- See Also:
- Constant Field Values
-
TOP_CENTER
public static final int TOP_CENTER
- See Also:
- Constant Field Values
-
TOP_RIGHT
public static final int TOP_RIGHT
- See Also:
- Constant Field Values
-
MIDDLE_LEFT
public static final int MIDDLE_LEFT
- See Also:
- Constant Field Values
-
MIDDLE_CENTER
public static final int MIDDLE_CENTER
- See Also:
- Constant Field Values
-
MIDDLE_RIGHT
public static final int MIDDLE_RIGHT
- See Also:
- Constant Field Values
-
BOTTOM_LEFT
public static final int BOTTOM_LEFT
- See Also:
- Constant Field Values
-
BOTTOM_CENTER
public static final int BOTTOM_CENTER
Indices forNinePatch(TextureRegion...)
constructor- See Also:
- Constant Field Values
-
BOTTOM_RIGHT
public static final int BOTTOM_RIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NinePatch
public NinePatch(com.badlogic.gdx.graphics.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
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.
-
NinePatch
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
- Pixels from left edge.right
- Pixels from right edge.top
- Pixels from top edge.bottom
- Pixels from bottom edge.
-
NinePatch
public NinePatch(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Color color)
Construct a degenerate "nine" patch with only a center component.
-
NinePatch
public NinePatch(com.badlogic.gdx.graphics.Texture texture)
Construct a degenerate "nine" patch with only a center component.
-
NinePatch
public NinePatch(TextureRegion region, com.badlogic.gdx.graphics.Color color)
Construct a degenerate "nine" patch with only a center component.
-
NinePatch
public NinePatch(TextureRegion region)
Construct a degenerate "nine" patch with only a center component.
-
NinePatch
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 benull
. Patch indices are specified via the public membersTOP_LEFT
,TOP_CENTER
, etc.
-
NinePatch
public NinePatch(NinePatch ninePatch)
-
NinePatch
public NinePatch(NinePatch ninePatch, com.badlogic.gdx.graphics.Color color)
-
-
Method Detail
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y, float width, float height)
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color color)
Copy given color. The color will be blended with the batch color, then combined with the texture colors atdraw
time. Default isColor.WHITE
.
-
getColor
public com.badlogic.gdx.graphics.Color getColor()
-
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
public com.badlogic.gdx.graphics.Texture getTexture()
-
-