package fr.username404.snowygui.gui import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.Tesselator import com.mojang.blaze3d.vertex.VertexConsumer fun interface Renderable { fun render(poseStack: PoseStack?) } abstract class Element( var x: Double, var y: Double, val width: Int, val height: Int ): Renderable { companion object Rendering { @JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance() @JvmStatic protected val buffer: BufferBuilder = tessellator.builder } fun display(stack: PoseStack? = null) { if (!hidden) render(stack) } var hidden: Boolean = false } abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val color: Int, val opacity: Float) : Element(x, y, width, height) { companion object { const val TransparentColor: Int = -0x1 @JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer { with(hextoRGB(color)) { return this@colorIt.color(get(0), get(1), get(2), opacity) } } } protected fun VertexConsumer.colorEnd() = colorIt(color, opacity).endVertex() } fun hextoRGB(hex: Int): MutableList { val returnedColorList = mutableListOf() for (i in 2 downTo 0) { returnedColorList.add( (hex shr (i * 8) and 255) / 255.0F ) } return returnedColorList }