Make Element.isWithinBounds() public, make SnowyScreen.components a MutableCollection & use GLFW.GLFW_MOUSE_BUTTON_LEFT in ClickGui.kt

This commit is contained in:
Username404 2021-06-26 17:08:24 +02:00
parent ce52119458
commit d315737321
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 4 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import fr.username404.snowygui.gui.ColoredElement
import fr.username404.snowygui.gui.Element
import fr.username404.snowygui.gui.SnowyScreen
import fr.username404.snowygui.gui.elements.ClickBox
import org.lwjgl.glfw.GLFW
object ClickGui: SnowyScreen() {
private var GuiDragging: Boolean = false
@ -16,7 +17,7 @@ object ClickGui: SnowyScreen() {
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { buttonsContext { this.mouseReleased(d, e, i) }; return false }
override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { scroll(d, e, f) }; return false }
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
if (i == 0) {
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
components.forEach {
if (it.isWithinBounds(d, e) && !GuiDragging) {
GuiDragging = true

View File

@ -30,7 +30,7 @@ abstract class Element(
): Renderable, GuiEventListener {
open var width = originalWidth; open var height = originalHeight
open var x = xOrigin; open var y = yOrigin
internal fun isWithinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
fun isWithinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
(coordinateX in x..(x + width + offsetWidth)) && (coordinateY in y..(y + height + offsetHeight))
companion object {
private var caughtError: Boolean = false

View File

@ -5,7 +5,7 @@ import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.TranslatableComponent
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
abstract val components: MutableSet<Element>
abstract val components: MutableCollection<Element>
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
if (poseStack != null) {
components.forEach {