diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-05-27 21:27:10 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2021-05-27 21:27:10 +0300 |
commit | 0da8b453600577aa2519b9e9427733d9bf4da99d (patch) | |
tree | 07fa43e327239fcfbd1939ac4f646014386a4fa9 | |
parent | dc48a30a3205967bdc1bcdea33a155ee4a3ddc87 (diff) | |
download | LibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.tar.gz LibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.tar.bz2 LibGui-0da8b453600577aa2519b9e9427733d9bf4da99d.zip |
Update LibNinePatch to 1.1.0, use ContextualTextureRenderer
4 files changed, 12 insertions, 31 deletions
diff --git a/gradle.properties b/gradle.properties index a9a2d81..f714d88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,4 @@ org.gradle.jvmargs=-Xmx1G fabric_version=0.34.5+1.17 jankson_version=3.0.1+j1.2.0 modmenu_version=1.14.15 - libninepatch_version=1.0.0 + libninepatch_version=1.1.0 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": "*" |