Skip to content

Commit 11237ca

Browse files
committed
Clamped position
1 parent 5d74559 commit 11237ca

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

common/src/main/kotlin/com/lambda/gui/impl/AbstractClickGui.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ abstract class AbstractClickGui(name: String, owner: Module? = null) : LambdaGui
7272
windows.onEvent(e)
7373
}
7474

75-
fun showWindow(window: WindowComponent<*>) {
76-
// we have to wait some time to place this window over other ones
77-
recordRenderCall {
78-
windows.children.add(window)
79-
}
80-
}
81-
8275
fun unfocusSettings() {
8376
windows.children.filterIsInstance<ModuleWindow>().forEach { moduleWindow ->
8477
moduleWindow.contentComponents.children.forEach { moduleButton ->

common/src/main/kotlin/com/lambda/module/HudModule.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,30 @@ abstract class HudModule(
2020
protected abstract val width: Double
2121
protected abstract val height: Double
2222

23-
private var px by setting("Position X", 10.0, 0.0..10000.0, 1.0) { false }
24-
private var py by setting("Position Y", 10.0, 0.0..10000.0, 1.0) { false }
23+
private var px by setting("Position X", 0.0, -10000.0..10000.0, 0.1) { false }
24+
private var py by setting("Position Y", 0.0, -10000.0..10000.0, 0.1) { false }
2525

26-
var position get() = Vec2d(px, py); set(value) { px = value.x; py = value.y }
26+
private var screenSize = Vec2d.ZERO
27+
var position get() = Vec2d(px, py); set(value) { setPos(value.x, value.y) }
2728
val rect get() = Rect.basedOn(position, width, height)
2829

2930
private val renderer = RenderLayer()
3031

3132
protected fun onRender(block: RenderLayer.() -> Unit) =
3233
renderCallables.add(block)
3334

35+
private fun setPos(x: Double, y: Double) {
36+
val xRange = 0.0..screenSize.x - width
37+
val yRange = 0.0..screenSize.y - height
38+
39+
px = x.coerceIn(xRange)
40+
py = y.coerceIn(yRange)
41+
}
42+
3443
init {
3544
listener<RenderEvent.GUI.HUD> { event ->
45+
screenSize = event.screenSize
46+
3647
renderCallables.forEach { function ->
3748
function.invoke(renderer)
3849
}

0 commit comments

Comments
 (0)