Make Element.isWithinBounds() public, make SnowyScreen.components a MutableCollection & use GLFW.GLFW_MOUSE_BUTTON_LEFT in ClickGui.kt
This commit is contained in:
parent
ce52119458
commit
d315737321
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue