Move a few methods
This commit is contained in:
parent
b4b137560c
commit
60bf5377cd
|
@ -6,7 +6,14 @@ import com.mojang.blaze3d.vertex.Tesselator
|
|||
import com.mojang.blaze3d.vertex.VertexConsumer
|
||||
import fr.username404.snowygui.Snowy
|
||||
|
||||
fun interface Renderable { fun render(poseStack: PoseStack?) }
|
||||
fun interface Renderable {
|
||||
companion object Rendering {
|
||||
@JvmStatic val tessellator: Tesselator = Tesselator.getInstance()
|
||||
@JvmStatic val buffer: BufferBuilder = tessellator.builder
|
||||
}
|
||||
fun render(poseStack: PoseStack?)
|
||||
}
|
||||
|
||||
abstract class Element(
|
||||
@JvmField val xOrigin: Double, @JvmField val yOrigin: Double,
|
||||
val width: Int, val height: Int
|
||||
|
@ -14,10 +21,13 @@ abstract class Element(
|
|||
var x = xOrigin; var y = yOrigin
|
||||
internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean =
|
||||
((coordinateX >= this.x) && (coordinateX <= (this.x + this.width))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height)))
|
||||
companion object Rendering {
|
||||
companion object {
|
||||
private var caughtError: Boolean = false
|
||||
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()
|
||||
@JvmStatic protected val buffer: BufferBuilder = tessellator.builder
|
||||
fun fromRenderable(r: Renderable, x: Int, y: Int, width: Int, height: Int): Element {
|
||||
return object: Element(x.toDouble(), y.toDouble(), width, height) {
|
||||
override fun render(poseStack: PoseStack?) = r.render(poseStack)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun display(stack: PoseStack? = null) {
|
||||
if (!hidden && !caughtError) try {
|
||||
|
|
|
@ -6,13 +6,6 @@ import net.minecraft.network.chat.TranslatableComponent
|
|||
import kotlin.properties.Delegates
|
||||
|
||||
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
|
||||
companion object {
|
||||
fun fromRenderable(r: Renderable, x: Int, y: Int, width: Int, height: Int): Element {
|
||||
return object: Element(x.toDouble(), y.toDouble(), width, height) {
|
||||
override fun render(poseStack: PoseStack?) = r.render(poseStack)
|
||||
}
|
||||
}
|
||||
}
|
||||
open val components: MutableSet<Element> by Delegates.notNull()
|
||||
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||
if (poseStack != null) {
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.mojang.blaze3d.systems.RenderSystem
|
|||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import fr.username404.snowygui.gui.ColoredElement
|
||||
import fr.username404.snowygui.gui.Renderable.Rendering.buffer
|
||||
import fr.username404.snowygui.gui.Renderable.Rendering.tessellator
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import org.lwjgl.opengl.GL20
|
||||
|
|
Loading…
Reference in New Issue