Rename the Element.withinBounds method to isWithinBounds and simplify it

This commit is contained in:
Username404 2021-06-19 17:55:17 +02:00
parent 9a2a78a3a3
commit fd4a380acb
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 5 additions and 5 deletions

View File

@ -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))

View File

@ -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 {

View File

@ -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()

View File

@ -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