Remove an useless part of the Util object, and add a poseStack argument to the render function of the Renderable interface.
This commit is contained in:
parent
03f2963486
commit
c50ce0696f
|
@ -1,9 +1,9 @@
|
|||
package fr.username404.snowygui.gui
|
||||
|
||||
import fr.username404.snowygui.rendering.Util
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
|
||||
class Box(x: Int, y: Int, scale: Int): Element(x, y, 20 * scale, 10 * scale) {
|
||||
override fun render() {
|
||||
Util.UIRect(x, y, this.width, this.height, opacity = 1F)
|
||||
override fun render(poseStack: PoseStack?) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package fr.username404.snowygui.gui
|
||||
|
||||
fun interface Renderable { fun render() }
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
|
||||
fun interface Renderable { fun render(poseStack: PoseStack?) }
|
||||
abstract class Element(
|
||||
var x: Int, var y: Int,
|
||||
val width: Int, val height: Int
|
||||
): Renderable {
|
||||
fun display() { if (!hidden) render() }
|
||||
fun display(stack: PoseStack? = null) { if (!hidden) render(stack) }
|
||||
var hidden: Boolean = false
|
||||
}
|
|
@ -9,7 +9,7 @@ abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", priv
|
|||
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||
if (poseStack != null) {
|
||||
components?.forEach {
|
||||
it.display()
|
||||
it.display(poseStack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,13 @@
|
|||
package fr.username404.snowygui.rendering
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.mojang.blaze3d.vertex.Tesselator
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
internal object Util {
|
||||
private val tessellator: Tesselator = Tesselator.getInstance()
|
||||
private val buffer: BufferBuilder = tessellator.builder
|
||||
fun UIRect(x: Int, y: Int, width: Int, height: Int, color: Int = -0x1, opacity: Float) {
|
||||
val r = (color shr 16 and 255) / 255.0f
|
||||
val g = (color shr 8 and 255) / 255.0f
|
||||
val b = (color and 255) / 255.0f
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.disableTexture()
|
||||
RenderSystem.blendFuncSeparate(
|
||||
GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
|
||||
GlStateManager.SourceFactor.ONE,
|
||||
GlStateManager.DestFactor.ZERO
|
||||
)
|
||||
with(buffer) {
|
||||
begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION_COLOR)
|
||||
vertex(x.toDouble(), y.toDouble() + height, 0.0).color(r, g, b, opacity).endVertex()
|
||||
vertex(x.toDouble() + width, y.toDouble() + height, 0.0).color(r, g, b, opacity).endVertex()
|
||||
vertex(x.toDouble() + width, y.toDouble(), 0.0).color(r, g, b, opacity).endVertex()
|
||||
vertex(x.toDouble(), y.toDouble(), 0.0).color(r, g, b, opacity).endVertex()
|
||||
tessellator.end()
|
||||
RenderSystem.enableTexture()
|
||||
RenderSystem.disableBlend()
|
||||
}
|
||||
}
|
||||
fun UIString(poseStack: PoseStack, string: String, i: Float, j: Float) {
|
||||
Minecraft.getInstance().font.draw(poseStack, string, i, j, 10)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue