Class NinePatch
- All Implemented Interfaces:
BackgroundPainter
Nine-patch textures are separated into nine sections: four corners, four edges and a center part.
The edges and the center are either tiled or stretched, depending on the mode,
to fill the area between the corners. By default, the texture mode is loaded from the texture metadata.
The default mode for that is NinePatch.Mode.STRETCHING.
NinePatch painters have a customizable padding that can be applied.
For example, a GUI panel for a container block might have a padding of 8 pixels, like BackgroundPainter.VANILLA.
You can set the padding using setPadding(int).
Nine-patch metadata
You can specify metadata for a nine-patch texture in a resource pack by creating a metadata file. Metadata files can currently specify the filling mode of the painter that paints the texture.The metadata file for a texture has to be placed in the same directory as the texture.
The file name must be X.9patch where X is the texture file name (including .png).
Metadata files use the .properties format with the following keys:
| Key | Value | Description |
|---|---|---|
mode |
stretching | tiling |
The texture filling mode |
- Since:
- 1.5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe mode of a nine-patch painter defines how it fills the area between the corners. -
Field Summary
Fields inherited from interface io.github.cottonmc.cotton.gui.client.BackgroundPainter
SLOT, VANILLA -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintintint@Nullable NinePatch.ModegetMode()intnet.minecraft.util.IdentifierintvoidpaintBackground(net.minecraft.client.util.math.MatrixStack matrices, int left, int top, WWidget panel)Paint the specified panel to the screen.setBottomPadding(int bottomPadding)setLeftPadding(int leftPadding)setMode(@Nullable NinePatch.Mode mode)Sets the mode of this painter to the specified mode.setPadding(int padding)setPadding(int vertical, int horizontal)setPadding(int topPadding, int leftPadding, int bottomPadding, int rightPadding)setRightPadding(int rightPadding)setTopPadding(int topPadding)
-
Constructor Details
-
NinePatch
public NinePatch(net.minecraft.util.Identifier texture)Creates a nine-patch background painter with 4 px corners and a 0.25 corner UV.- Parameters:
texture- the texture ID
-
NinePatch
public NinePatch(net.minecraft.util.Identifier texture, int cornerSize, float cornerUv)Creates a nine-patch background painter.- Parameters:
texture- the texture IDcornerSize- the size of the corners on the screencornerUv- the fraction of the corners from the whole texture
-
-
Method Details
-
getTopPadding
public int getTopPadding() -
setTopPadding
-
getLeftPadding
public int getLeftPadding() -
setLeftPadding
-
getBottomPadding
public int getBottomPadding() -
setBottomPadding
-
getRightPadding
public int getRightPadding() -
setRightPadding
-
setPadding
-
setPadding
-
setPadding
-
getTexture
public net.minecraft.util.Identifier getTexture() -
getCornerSize
public int getCornerSize() -
getMode
-
setMode
Sets the mode of this painter to the specified mode.If the
modeis not null, it will override the one specified in the texture metadata. A null mode uses the texture metadata. -
paintBackground
public void paintBackground(net.minecraft.client.util.math.MatrixStack matrices, int left, int top, WWidget panel)Description copied from interface:BackgroundPainterPaint the specified panel to the screen.- Specified by:
paintBackgroundin interfaceBackgroundPainterleft- The absolute position of the left of the panel, in gui-screen coordinatestop- The absolute position of the top of the panel, in gui-screen coordinatespanel- The panel being painted
-