Skip to content

Commit 2fed725

Browse files
committed
fix scale blob
1 parent 88725d9 commit 2fed725

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kotlin = "2.0.20"
66
kotlinx-coroutines = "1.8.1"
77
kotlinx-atomicfu = "0.24.0"
88
fabric-language-kotlin = "1.12.2+kotlin.2.0.20"
9-
polyui = "1.7.25"
9+
polyui = "1.7.26"
1010
annotations = "24.1.0"
1111
hypixel-modapi = "1.0"
1212
hypixel-data = "0.1.2" # Dep of hypixel-modapi

modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ open class ConfigVisualizer {
319319
if (!initialized) {
320320
this.afterParentInit(Int.MAX_VALUE) {
321321
layoutIgnored = true
322-
x = -100f
323-
y = -100f
322+
x = 1000000f
323+
y = 1000000f
324324
parent.position()
325325
renders = false
326326
}
327327
} else {
328328
layoutIgnored = true
329-
x = -100f
330-
y = -100f
329+
x = 1000000f
330+
y = 1000000f
331331
parent.position()
332332
renders = false
333333
}

modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hud_utils.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.polyfrost.polyui.event.Event
4040
import org.polyfrost.polyui.unit.Point
4141
import org.polyfrost.polyui.unit.by
4242
import org.polyfrost.polyui.utils.fastEach
43+
import kotlin.math.sqrt
4344

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

@@ -53,18 +54,21 @@ private val scaleBlob by lazy {
5354
).radius(10f).draggable().onDragStart {
5455
sx = polyUI.mouseX
5556
sy = polyUI.mouseY
56-
st = scaleX
57-
}.onDragEnd {
57+
st = cur?.scaleX ?: 1f
58+
}.onDrag {
5859
cur?.let {
5960
val dx = polyUI.mouseX - sx
6061
val dy = polyUI.mouseY - sy
61-
val s = st + (((dx + dy) / (it.width + it.height))).coerceIn(0.5f, 3f)
62+
val dst = sqrt(dx * dx + dy * dy)
63+
val init = sqrt(it.width * it.width + it.height * it.height)
64+
val sign = if(dx + dy < 0f) -1f else 1f
65+
val s = (st + sign * (dst / init)).coerceIn(0.5f, 3f)
66+
6267
it.scaleX = s
6368
it.scaleY = s
6469
x = it.x + (it.width * s) - (width / 2f)
6570
y = it.y + (it.height * s) - (height / 2f)
6671
}
67-
true
6872
}.apply {
6973
// addEventHandler(Event.Mouse.Pressed(0)) {
7074
// if(!polyUI.inputManager.hasFocused) polyUI.focus(this)
@@ -261,6 +265,13 @@ private fun Drawable.trySnapY(ly: Float): Boolean {
261265
* Method to be used as the `onDrag` handler for HUD elements.
262266
*/
263267
fun Drawable.snapHandler() {
268+
if (cur === this) {
269+
val vs = visibleSize
270+
scaleBlob.let {
271+
it.x = x + vs.x - (it.width / 2f)
272+
it.y = y + vs.y - (it.height / 2f)
273+
}
274+
}
264275
HudManager.slinex = -1f
265276
HudManager.sliney = -1f
266277
if (HudManager.panelOpen) return
@@ -281,7 +292,7 @@ fun Drawable.snapHandler() {
281292
// expensive!
282293
polyUI.master.children?.fastEach {
283294
if (it === this) return@fastEach
284-
if (it === HudManager.panel) return@fastEach
295+
if (it === HudManager.panel || it === scaleBlob) return@fastEach
285296
if (!it.renders) return@fastEach
286297

287298
if (!hran) {

0 commit comments

Comments
 (0)