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 {
|
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
components.forEach {
|
components.forEach {
|
||||||
if (it.withinBounds(d, e) and !GuiDragging) {
|
if (it.isWithinBounds(d, e) and !GuiDragging) {
|
||||||
GuiDragging = true
|
GuiDragging = true
|
||||||
it.x = d.minus(f) + (d - (it.x + it.width))
|
it.x = d.minus(f) + (d - (it.x + it.width))
|
||||||
it.y = e.minus(g) + (e - (it.y + it.height))
|
it.y = e.minus(g) + (e - (it.y + it.height))
|
||||||
|
@ -30,8 +30,8 @@ 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 withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
|
internal fun isWithinBounds(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)))
|
(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
|
||||||
fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element {
|
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
|
var barStage: Int = 1; private set
|
||||||
fun scroll(d: Double, e: Double, supplied: Double) {
|
fun scroll(d: Double, e: Double, supplied: Double) {
|
||||||
if (withinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) {
|
if (isWithinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) {
|
||||||
with(buttonsProgressBar) {
|
with(buttonsProgressBar) {
|
||||||
if ((height > 8 || (supplied < 0)) && (((height < (buttons.size * 8)) && (height < originalHeight)) || (supplied > 0))) {
|
if ((height > 8 || (supplied < 0)) && (((height < (buttons.size * 8)) && (height < originalHeight)) || (supplied > 0))) {
|
||||||
height -= supplied.toInt()
|
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 lightUp() { opacity += ButtonInfo.lightningFactor }
|
||||||
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
||||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
||||||
wasWithinBounds = withinBounds(d, e).also {
|
wasWithinBounds = isWithinBounds(d, e).also {
|
||||||
if (it) {
|
if (it) {
|
||||||
if (info.kind == Type.TOGGLE) {
|
if (info.kind == Type.TOGGLE) {
|
||||||
toggled = !toggled
|
toggled = !toggled
|
||||||
|
Loading…
Reference in New Issue
Block a user