aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-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
2 files changed, 10 insertions, 29 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);
}
}