diff options
Diffstat (limited to 'src/main/kotlin/util/render/ScreenRenderUtils.kt')
-rw-r--r-- | src/main/kotlin/util/render/ScreenRenderUtils.kt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/kotlin/util/render/ScreenRenderUtils.kt b/src/main/kotlin/util/render/ScreenRenderUtils.kt index 6a659bf..224ccb4 100644 --- a/src/main/kotlin/util/render/ScreenRenderUtils.kt +++ b/src/main/kotlin/util/render/ScreenRenderUtils.kt @@ -2,6 +2,8 @@ package moe.nea.ultranotifier.util.render import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack +import juuxel.libninepatch.NinePatch +import juuxel.libninepatch.TextureRenderer import net.minecraft.util.Identifier import java.awt.Color @@ -36,4 +38,67 @@ object ScreenRenderUtils { graphics.pos(matrixStack, right, top, 0.0).tex(1.0, 0.0).endVertex() graphics.drawDirect() } + + fun renderNineSlice( + ninePatch: NinePatch<Identifier>, + matrixStack: UMatrixStack, + left: Double, top: Double, + right: Double, bottom: Double, + ) { + class Saver : TextureRenderer<Identifier> { + override fun draw( + texture: Identifier?, + x: Int, + y: Int, + width: Int, + height: Int, + u1: Float, + v1: Float, + u2: Float, + v2: Float + ) { + this.texture = texture + } + + var texture: Identifier? = null + } + + val saver = Saver() + ninePatch.draw(saver, 1, 1) + UGraphics.bindTexture(0, saver.texture!!) + val graphics = UGraphics.getFromTessellator() + graphics.beginWithDefaultShader(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE) + ninePatch.draw(object : TextureRenderer<Identifier> { + override fun draw( + texture: Identifier, + x: Int, + y: Int, + width: Int, + height: Int, + u1: Float, + v1: Float, + u2: Float, + v2: Float + ) { + val x1 = left + x.toDouble() + val y1 = top + y.toDouble() + val x2 = x1+ width + val y2 = y1 + height + graphics.pos(matrixStack, x1, y1, 0.0) + .tex(u1.toDouble(), v1.toDouble()) + .endVertex() + graphics.pos(matrixStack, x1, y2, 0.0) + .tex(u1.toDouble(), v2.toDouble()) + .endVertex() + graphics.pos(matrixStack, x2, y2, 0.0) + .tex(u2.toDouble(), v2.toDouble()) + .endVertex() + graphics.pos(matrixStack, x2, y1, 0.0) + .tex(u2.toDouble(), v1.toDouble()) + .endVertex() + } + }, (right - left).toInt(), (bottom - top).toInt()) + graphics.drawDirect() + } + } |