From fd4a380acbf0014e2c11d34ee276cea3b9144ad8 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 19 Jun 2021 17:55:17 +0200 Subject: [PATCH] Rename the Element.withinBounds method to isWithinBounds and simplify it --- common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt | 2 +- common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt | 4 ++-- .../kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt | 2 +- .../kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index 1dda75e..f2a9e0f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -18,7 +18,7 @@ object ClickGui: SnowyScreen() { override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean { if (i == 0) { components.forEach { - if (it.withinBounds(d, e) and !GuiDragging) { + if (it.isWithinBounds(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 98f5986..c5d6037 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -30,8 +30,8 @@ abstract class Element( ): Renderable, GuiEventListener { open var width = originalWidth; open var height = originalHeight open var x = xOrigin; open var y = yOrigin - internal fun withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean = - ((coordinateX >= this.x) && (coordinateX <= (this.x + this.width + offsetWidth))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height + offsetHeight))) + internal 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 fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index ab77c20..27b2e68 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -53,7 +53,7 @@ class ClickBox( } var barStage: Int = 1; private set fun scroll(d: Double, e: Double, supplied: Double) { - if (withinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) { + if (isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) { with(buttonsProgressBar) { if ((height > 8 || (supplied < 0)) && (((height < (buttons.size * 8)) && (height < originalHeight)) || (supplied > 0))) { height -= supplied.toInt() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index a3e05de..23188f9 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -76,7 +76,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { private fun lightUp() { opacity += ButtonInfo.lightningFactor } private fun lightDown() { opacity -= ButtonInfo.lightningFactor } override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { - wasWithinBounds = withinBounds(d, e).also { + wasWithinBounds = isWithinBounds(d, e).also { if (it) { if (info.kind == Type.TOGGLE) { toggled = !toggled