aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2021-05-27 21:27:10 +0300
committerJuuz <6596629+Juuxel@users.noreply.github.com>2021-05-27 21:27:10 +0300
commit0da8b453600577aa2519b9e9427733d9bf4da99d (patch)
tree07fa43e327239fcfbd1939ac4f646014386a4fa9 /src/main/java
parentdc48a30a3205967bdc1bcdea33a155ee4a3ddc87 (diff)
downloadLibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.tar.gz
LibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.tar.bz2
LibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.zip
Update LibNinePatch to 1.1.0, use ContextualTextureRenderer
Diffstat (limited to 'src/main/java')
-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);
}
}