aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2023-09-09 14:07:20 +0300
committerJuuz <6596629+Juuxel@users.noreply.github.com>2023-09-09 14:07:20 +0300
commitb5ab318efb559da0e7b8d3272fd18a2c38655c7d (patch)
tree42491b362d760f3089759ec326316047ae490494 /src/main
parent2a05170b93d9522cc9d54d954a783dd6a7f01c1c (diff)
downloadLibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.tar.gz
LibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.tar.bz2
LibGui-b5ab318efb559da0e7b8d3272fd18a2c38655c7d.zip
Add BackgroundPainter.createGuiSprite
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java16
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());
+ }
}