Skip to content

Commit

Permalink
fix scale blob
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Nov 13, 2024
1 parent 88725d9 commit 2fed725
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kotlin = "2.0.20"
kotlinx-coroutines = "1.8.1"
kotlinx-atomicfu = "0.24.0"
fabric-language-kotlin = "1.12.2+kotlin.2.0.20"
polyui = "1.7.25"
polyui = "1.7.26"
annotations = "24.1.0"
hypixel-modapi = "1.0"
hypixel-data = "0.1.2" # Dep of hypixel-modapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ open class ConfigVisualizer {
if (!initialized) {
this.afterParentInit(Int.MAX_VALUE) {
layoutIgnored = true
x = -100f
y = -100f
x = 1000000f
y = 1000000f
parent.position()
renders = false
}
} else {
layoutIgnored = true
x = -100f
y = -100f
x = 1000000f
y = 1000000f
parent.position()
renders = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.polyfrost.polyui.event.Event
import org.polyfrost.polyui.unit.Point
import org.polyfrost.polyui.unit.by
import org.polyfrost.polyui.utils.fastEach
import kotlin.math.sqrt

private val LOGGER = LogManager.getLogger("OneConfig/HUD")

Expand All @@ -53,18 +54,21 @@ private val scaleBlob by lazy {
).radius(10f).draggable().onDragStart {
sx = polyUI.mouseX
sy = polyUI.mouseY
st = scaleX
}.onDragEnd {
st = cur?.scaleX ?: 1f
}.onDrag {
cur?.let {
val dx = polyUI.mouseX - sx
val dy = polyUI.mouseY - sy
val s = st + (((dx + dy) / (it.width + it.height))).coerceIn(0.5f, 3f)
val dst = sqrt(dx * dx + dy * dy)
val init = sqrt(it.width * it.width + it.height * it.height)
val sign = if(dx + dy < 0f) -1f else 1f
val s = (st + sign * (dst / init)).coerceIn(0.5f, 3f)

it.scaleX = s
it.scaleY = s
x = it.x + (it.width * s) - (width / 2f)
y = it.y + (it.height * s) - (height / 2f)
}
true
}.apply {
// addEventHandler(Event.Mouse.Pressed(0)) {
// if(!polyUI.inputManager.hasFocused) polyUI.focus(this)
Expand Down Expand Up @@ -261,6 +265,13 @@ private fun Drawable.trySnapY(ly: Float): Boolean {
* Method to be used as the `onDrag` handler for HUD elements.
*/
fun Drawable.snapHandler() {
if (cur === this) {
val vs = visibleSize
scaleBlob.let {
it.x = x + vs.x - (it.width / 2f)
it.y = y + vs.y - (it.height / 2f)
}
}
HudManager.slinex = -1f
HudManager.sliney = -1f
if (HudManager.panelOpen) return
Expand All @@ -281,7 +292,7 @@ fun Drawable.snapHandler() {
// expensive!
polyUI.master.children?.fastEach {
if (it === this) return@fastEach
if (it === HudManager.panel) return@fastEach
if (it === HudManager.panel || it === scaleBlob) return@fastEach
if (!it.renders) return@fastEach

if (!hran) {
Expand Down

0 comments on commit 2fed725

Please sign in to comment.