Rename the Element.withinBounds method to isWithinBounds and simplify it
This commit is contained in:
parent
9a2a78a3a3
commit
fd4a380acb
|
@ -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))
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue