aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java10
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java29
-rw-r--r--src/main/resources/fabric.mod.json2
3 files changed, 11 insertions, 30 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 47b106f..46b5061 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
@@ -155,12 +155,10 @@ public interface BackgroundPainter {
configurator.accept(builder);
var ninePatch = builder.build();
return (matrices, left, top, panel) -> {
- try (NinePatchTextureRendererImpl renderer = NinePatchTextureRendererImpl.bind(matrices)) {
- matrices.push();
- matrices.translate(left, top, 0);
- ninePatch.draw(renderer, panel.getWidth(), panel.getHeight());
- matrices.pop();
- }
+ matrices.push();
+ matrices.translate(left, top, 0);
+ ninePatch.draw(NinePatchTextureRendererImpl.INSTANCE, matrices, panel.getWidth(), panel.getHeight());
+ matrices.pop();
};
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java
index 9395c5f..7161373 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java
@@ -4,33 +4,16 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
-import juuxel.libninepatch.TextureRenderer;
-
-import java.util.ArrayDeque;
-import java.util.Deque;
+import juuxel.libninepatch.ContextualTextureRenderer;
/**
- * An implementation of LibNinePatch's {@link TextureRenderer} for identifiers.
+ * An implementation of LibNinePatch's {@link ContextualTextureRenderer} for identifiers.
*/
-public final class NinePatchTextureRendererImpl implements TextureRenderer<Identifier>, AutoCloseable {
- private static final NinePatchTextureRendererImpl INSTANCE = new NinePatchTextureRendererImpl();
- private final Deque<MatrixStack> matrixStackStack = new ArrayDeque<>();
-
- private NinePatchTextureRendererImpl() {}
-
- // TODO: Replace this with a context system in LNP
- public static NinePatchTextureRendererImpl bind(MatrixStack matrices) {
- INSTANCE.matrixStackStack.push(matrices);
- return INSTANCE;
- }
-
- @Override
- public void draw(Identifier texture, int x, int y, int width, int height, float u1, float v1, float u2, float v2) {
- ScreenDrawing.texturedRect(matrixStackStack.peek(), x, y, width, height, texture, u1, v1, u2, v2, 0xFF_FFFFFF);
- }
+public enum NinePatchTextureRendererImpl implements ContextualTextureRenderer<Identifier, MatrixStack> {
+ INSTANCE;
@Override
- public void close() {
- matrixStackStack.pop();
+ public void draw(Identifier texture, MatrixStack matrices, int x, int y, int width, int height, float u1, float v1, float u2, float v2) {
+ ScreenDrawing.texturedRect(matrices, x, y, width, height, texture, u1, v1, u2, v2, 0xFF_FFFFFF);
}
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 6b2cc35..c6e1b4d 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -31,7 +31,7 @@
"minecraft": ">=1.16.5",
"jankson": "^3.0.0",
"fabric-networking-api-v1": "^1.0.0",
- "libninepatch": "^1.0.0"
+ "libninepatch": "^1.1.0"
},
"suggests": {
"flamingo": "*"