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 00b6253..ea50c43 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt @@ -16,23 +16,25 @@ class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? = RenderSystem.enableBlend() RenderSystem.defaultBlendFunc() with(buffer) { - begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) + begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION) // Render the header: - 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() + 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() // Render the box: val fullHeight = (y + height) + 80 - vertex(x, fullHeight, 0.0).colorEnd() - vertex(x + width + inclination, fullHeight, 0.0).colorEnd() - vertex(x + width + inclination, y + height, 0.0).colorEnd() + vertex(x, fullHeight, 0.0).endVertex() + vertex(x + width + inclination, fullHeight, 0.0).endVertex() + vertex(x + width + inclination, y + height, 0.0).endVertex() tessellator.end() - 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() + 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() 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 bfb3399..3c0b42f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -1,5 +1,6 @@ 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 @@ -29,6 +30,7 @@ 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 { @@ -37,7 +39,6 @@ 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 {