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.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
|
import org.lwjgl.glfw.GLFW
|
||||||
|
|
||||||
object ClickGui: SnowyScreen() {
|
object ClickGui: SnowyScreen() {
|
||||||
private var GuiDragging: Boolean = false
|
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 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 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 {
|
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 {
|
components.forEach {
|
||||||
if (it.isWithinBounds(d, e) && !GuiDragging) {
|
if (it.isWithinBounds(d, e) && !GuiDragging) {
|
||||||
GuiDragging = true
|
GuiDragging = true
|
||||||
|
|
|
@ -30,7 +30,7 @@ abstract class Element(
|
||||||
): Renderable, GuiEventListener {
|
): Renderable, GuiEventListener {
|
||||||
open var width = originalWidth; open var height = originalHeight
|
open var width = originalWidth; open var height = originalHeight
|
||||||
open var x = xOrigin; open var y = yOrigin
|
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))
|
(coordinateX in x..(x + width + offsetWidth)) && (coordinateY in y..(y + height + offsetHeight))
|
||||||
companion object {
|
companion object {
|
||||||
private var caughtError: Boolean = false
|
private var caughtError: Boolean = false
|
||||||
|
|
|
@ -5,7 +5,7 @@ import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
|
||||||
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
|
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) {
|
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||||
if (poseStack != null) {
|
if (poseStack != null) {
|
||||||
components.forEach {
|
components.forEach {
|
||||||
|
|
Loading…
Reference in New Issue