From 5d98234d397a19b9e1c0e3c5fcc755f1862adc48 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 16 Apr 2025 04:41:17 +0200 Subject: [PATCH] Fix and improve UI rendering Signed-off-by: Username404-59 --- .../snowygui/gui/elements/ClickBox.kt | 31 +++++++++---------- .../snowygui/utils/RenderingUtil.kt | 7 ++--- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 38d9dbf..c9d4b8a 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -81,26 +81,25 @@ class ClickBox( val currentHeight = y + (height + clickboxHeightOffset) prepareDraw() renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_TRIANGLE_FAN) { - with(it) { - // Render the header: - addVertex(x, y + height, 0.0F).colorEnd() - addVertex(x + width + inclination, y + height, 0.0F).colorEnd() - addVertex(x + width, y, 0.0F).colorEnd() - addVertex(x + inclination, y, 0.0F).colorEnd() + // Render the header: + addVertex(x, y + height, 0.0F).colorEnd() + addVertex(x + width + inclination, y + height, 0.0F).colorEnd() + addVertex(x + width, y, 0.0F).colorEnd() + addVertex(x + inclination, y, 0.0F).colorEnd() + } - // Render the box: - addVertex(x, currentHeight, 0.0F).colorEnd() - addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd() - addVertex(x + width + inclination, y + height, 0.0F).colorEnd() - } + renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_TRIANGLE_FAN) { + // Render the box: + addVertex(x, currentHeight, 0.0F).colorEnd() + addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd() + addVertex(x + width + inclination, y + height, 0.0F).colorEnd() + addVertex(x, y + height, 0.0F).colorEnd() } renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) { - with(it) { - colorShader() - addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) - addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) - } + colorShader() + addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) + addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) } endDraw() diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt index da30e20..abb3e59 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt @@ -18,7 +18,6 @@ import java.util.OptionalInt import java.util.OptionalDouble object RenderingUtil { - @JvmField val tessellator: Tesselator = Tesselator.getInstance() @JvmStatic fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer = hextoRGB(color).run { setColor(get(0), get(1), get(2), opacity) @@ -36,21 +35,21 @@ object RenderingUtil { fun drawRectangle( x: Double, y: Double, height: Int, width: Int, color: Int = Colors.TRANSPARENT(), opacity: Float = 1F - ): Unit = renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_QUADS) { buffer -> buffer.run { + ): Unit = renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_QUADS) { fun VertexConsumer.colorIt() = colorIt(color, opacity) val x = x.toFloat() ; val y = y.toFloat() addVertex(x, y + height, 0.0F).colorIt() addVertex(x + width, y + height, 0.0F).colorIt() addVertex(x + width, y, 0.0F).colorIt() addVertex(x, y, 0.0F).colorIt() - } } + } fun renderBufferWithPipeline( name: String? = "Dynamic vertex buffer", renderPipeline: RenderPipeline, renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget, uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null, - bufferBuilderConsumer: (BufferBuilder) -> Unit, + bufferBuilderConsumer: BufferBuilder.() -> Unit, ) { val mode = renderPipeline.vertexFormatMode val builder = Tesselator.getInstance().begin(mode, renderPipeline.vertexFormat)