diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/gui/MessageUi.kt | 9 | ||||
-rw-r--r-- | src/main/kotlin/util/render/ScreenRenderUtils.kt | 65 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/main/kotlin/gui/MessageUi.kt b/src/main/kotlin/gui/MessageUi.kt index f3feeb7..5f337f3 100644 --- a/src/main/kotlin/gui/MessageUi.kt +++ b/src/main/kotlin/gui/MessageUi.kt @@ -2,6 +2,7 @@ package moe.nea.ultranotifier.gui import gg.essential.universal.UMatrixStack import gg.essential.universal.UScreen +import juuxel.libninepatch.NinePatch import moe.nea.ultranotifier.util.render.ScreenRenderUtils import moe.nea.ultranotifier.util.ultraIdentifier import java.awt.Color @@ -15,5 +16,13 @@ class MessageUi : UScreen() { matrixStack, 200.0, 0.0, 300.0, 100.0 ) + ScreenRenderUtils.renderNineSlice( + NinePatch.builder(ultraIdentifier("textures/gui/square_panel.png")) + .cornerSize(10) + .mode(NinePatch.Mode.STRETCHING) + .cornerUv(0.1F, 0.1F).build(), + matrixStack, + 225.0, 25.0, 275.0, 75.0 + ) } } 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() + } + } |