diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 14:07:20 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 14:07:20 +0300 |
commit | b5ab318efb559da0e7b8d3272fd18a2c38655c7d (patch) | |
tree | 42491b362d760f3089759ec326316047ae490494 | |
parent | 2a05170b93d9522cc9d54d954a783dd6a7f01c1c (diff) | |
download | LibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.tar.gz LibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.tar.bz2 LibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.zip |
Add BackgroundPainter.createGuiSprite
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index f3df523..7831f33 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -10,6 +10,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Texture; import juuxel.libninepatch.NinePatch; import juuxel.libninepatch.TextureRegion; +import java.util.Objects; import java.util.function.Consumer; /** @@ -158,4 +159,19 @@ public interface BackgroundPainter { else light.paintBackground(context, left, top, panel); }; } + + /** + * Creates a background painter that uses a texture from the GUI atlas. + * + * <p>This method can be used to draw tiled or nine-slice GUI sprites from resource packs + * as a simpler and more data-driven alternative to {@link #createNinePatch(Identifier)}. + * + * @param texture the texture ID + * @return a new background painter that uses a GUI sprite + * @since 9.0.0 + */ + static BackgroundPainter createGuiSprite(Identifier texture) { + Objects.requireNonNull(texture, "Texture cannot be null"); + return (context, left, top, panel) -> context.drawGuiTexture(texture, left, top, panel.getWidth(), panel.getHeight()); + } } |