diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index bd75919..a4137ea 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -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)) 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 f51ee69..1a08bf0 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -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() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt similarity index 94% rename from common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt rename to common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 2853dc9..93372bb 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -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