Move ClickBox.kt to a new package (fr.username404.snowygui.gui.elements) and add a method to Element.kt

This commit is contained in:
Username404-59 2021-04-30 19:09:28 +02:00
parent c54ac5b1f8
commit b4b137560c
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 6 additions and 3 deletions

View File

@ -1,8 +1,8 @@
package fr.username404.snowygui
import fr.username404.snowygui.gui.ClickBox
import fr.username404.snowygui.gui.Element
import fr.username404.snowygui.gui.SnowyScreen
import fr.username404.snowygui.gui.elements.ClickBox
import net.minecraft.network.chat.TranslatableComponent
object ClickGui: SnowyScreen() {
@ -14,7 +14,7 @@ object ClickGui: SnowyScreen() {
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
if (i == 0) {
components.forEach {
if (((d >= it.x) && (d <= (it.x + it.width))) and ((e >= it.y) && (e <= (it.y + it.height))) and !GuiDragging) {
if (it.withinBounds(d, e) and !GuiDragging) {
GuiDragging = true
it.x = d.minus(f) + (d - (it.x + it.width))
it.y = e.minus(g) + (e - (it.y + it.height))

View File

@ -12,6 +12,8 @@ abstract class Element(
val width: Int, val height: Int
): Renderable {
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 {
private var caughtError: Boolean = false
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()

View File

@ -1,8 +1,9 @@
package fr.username404.snowygui.gui
package fr.username404.snowygui.gui.elements
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 net.minecraft.client.Minecraft
import net.minecraft.network.chat.TranslatableComponent
import org.lwjgl.opengl.GL20