From 0da8b453600577aa2519b9e9427733d9bf4da99d Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Thu, 27 May 2021 21:27:10 +0300 Subject: Update LibNinePatch to 1.1.0, use ContextualTextureRenderer --- .../cotton/gui/client/BackgroundPainter.java | 10 +++----- .../impl/client/NinePatchTextureRendererImpl.java | 29 +++++----------------- 2 files changed, 10 insertions(+), 29 deletions(-) (limited to 'src/main/java') 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, AutoCloseable { - private static final NinePatchTextureRendererImpl INSTANCE = new NinePatchTextureRendererImpl(); - private final Deque 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 { + 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); } } -- cgit