Class NinePatch

java.lang.Object
io.github.cottonmc.cotton.gui.client.NinePatch
All Implemented Interfaces:
BackgroundPainter

@Environment(CLIENT) public class NinePatch extends Object implements BackgroundPainter
The nine-patch background painter paints rectangles using a nine-patch texture.

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:

Properties
Key Value Description
mode stretching | tiling The texture filling mode
Since:
1.5.0
  • 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 ID
      cornerSize - the size of the corners on the screen
      cornerUv - the fraction of the corners from the whole texture
  • Method Details

    • getTopPadding

      public int getTopPadding()
    • setTopPadding

      public NinePatch setTopPadding(int topPadding)
    • getLeftPadding

      public int getLeftPadding()
    • setLeftPadding

      public NinePatch setLeftPadding(int leftPadding)
    • getBottomPadding

      public int getBottomPadding()
    • setBottomPadding

      public NinePatch setBottomPadding(int bottomPadding)
    • getRightPadding

      public int getRightPadding()
    • setRightPadding

      public NinePatch setRightPadding(int rightPadding)
    • setPadding

      public NinePatch setPadding(int padding)
    • setPadding

      public NinePatch setPadding(int vertical, int horizontal)
    • setPadding

      public NinePatch setPadding(int topPadding, int leftPadding, int bottomPadding, int rightPadding)
    • getTexture

      public net.minecraft.util.Identifier getTexture()
    • getCornerSize

      public int getCornerSize()
    • getMode

      @Nullable public @Nullable NinePatch.Mode getMode()
    • setMode

      public NinePatch setMode(@Nullable @Nullable NinePatch.Mode mode)
      Sets the mode of this painter to the specified mode.

      If the mode is 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: BackgroundPainter
      Paint the specified panel to the screen.
      Specified by:
      paintBackground in interface BackgroundPainter
      left - The absolute position of the left of the panel, in gui-screen coordinates
      top - The absolute position of the top of the panel, in gui-screen coordinates
      panel - The panel being painted