diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt index ea50c43..00b6253 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt @@ -16,25 +16,23 @@ class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? = RenderSystem.enableBlend() RenderSystem.defaultBlendFunc() with(buffer) { - begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION) + begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) // Render the header: - setColor() - vertex(x, y + height, 0.0).endVertex() - vertex(x + width + inclination, y + height, 0.0).endVertex() - vertex(x + width, y, 0.0).endVertex() - vertex(x + inclination, y, 0.0).endVertex() + vertex(x, y + height, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() + vertex(x + width, y, 0.0).colorEnd() + vertex(x + inclination, y, 0.0).colorEnd() // Render the box: val fullHeight = (y + height) + 80 - vertex(x, fullHeight, 0.0).endVertex() - vertex(x + width + inclination, fullHeight, 0.0).endVertex() - vertex(x + width + inclination, y + height, 0.0).endVertex() + vertex(x, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() tessellator.end() - begin(GL20.GL_LINES, DefaultVertexFormat.POSITION) - setColor(0xF2F2FC, o = 1F) - vertex(x + inclination, y + height, 0.0).endVertex() - vertex(x + width, y + height, 0.0).endVertex() + begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR) + vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex() + vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex() tessellator.end() } RenderSystem.enableTexture() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 3c0b42f..bfb3399 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.gui -import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.Tesselator @@ -30,7 +29,6 @@ abstract class Element( } abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val color: Int, val opacity: Float) : Element(x, y, width, height) { - protected fun setColor(c: Int = color, o: Float = opacity): Unit = hextoRGB(c).run { @Suppress("DEPRECATION") RenderSystem.color4f(get(0), get(1), get(2), o) } companion object { const val TransparentColor: Int = -0x1 @JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer { @@ -39,6 +37,7 @@ abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val } } } + protected fun VertexConsumer.colorEnd() = colorIt(color, opacity).endVertex() } fun hextoRGB(hex: Int): MutableList {