Skip to content

Commit 7c7f57a

Browse files
committed
Fix z fighting of drag state
1 parent 391a5fb commit 7c7f57a

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

src/main/kotlin/com/lambda/gui/MenuBar.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.lambda.graphics.texture.TextureOwner.upload
2828
import com.lambda.gui.DearImGui.EXTERNAL_LINK
2929
import com.lambda.gui.components.HudGuiLayout
3030
import com.lambda.gui.components.QuickSearch
31+
import com.lambda.gui.components.SettingsWidget.buildConfigSettingsContext
3132
import com.lambda.gui.dsl.ImGuiBuilder
3233
import com.lambda.module.ModuleRegistry
3334
import com.lambda.module.tag.ModuleTag
@@ -198,6 +199,10 @@ object MenuBar {
198199
menuItem(if (HudGuiLayout.isShownInGUI) "Hide" else "Show") {
199200
HudGuiLayout.isShownInGUI = !HudGuiLayout.isShownInGUI
200201
}
202+
separator()
203+
menu("HUD Settings") {
204+
buildConfigSettingsContext(HudGuiLayout)
205+
}
201206
}
202207

203208
private fun ImGuiBuilder.buildModulesMenu() {

src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
5252

5353
// Snapping
5454
val snapEnabled by setting("Enable Snapping", true, "Master toggle for HUD snapping").group(Group.Snapping)
55-
val gridSize by setting("Grid Size", 16f, 2f..128f, 1f, "Grid step in pixels") { snapEnabled }.group(Group.Snapping)
55+
val gridSize by setting("Grid Size", 25f, 2f..128f, 1f, "Grid step in pixels") { snapEnabled }.group(Group.Snapping)
5656
val snapToEdges by setting("Snap To Element Edges", true) { snapEnabled }.group(Group.Snapping)
5757
val snapToCenters by setting("Snap To Element Centers", true) { snapEnabled }.group(Group.Snapping)
5858
val snapToScreenCenter by setting("Snap To Screen Center", true) { snapEnabled }.group(Group.Snapping)
@@ -82,6 +82,7 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
8282
private val lastBounds = mutableMapOf<String, RectF>()
8383
private val pendingPositions = mutableMapOf<String, Pair<Float, Float>>()
8484
private val snapOverlays = mutableMapOf<String, SnapVisual>()
85+
private var mousePressedThisFrameGlobal = false
8586

8687
var isShownInGUI = true
8788
var isLocked = false
@@ -121,6 +122,7 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
121122
val mousePressedThisFrame = mouseDown && !mouseWasDown
122123
val mouseReleasedThisFrame = !mouseDown && mouseWasDown
123124
mouseWasDown = mouseDown
125+
mousePressedThisFrameGlobal = mousePressedThisFrame
124126

125127
if (mouseReleasedThisFrame || !ClickGui.isEnabled || isLocked) {
126128
activeDragHudName = null
@@ -138,9 +140,8 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
138140
registerContextMenu(notShown)
139141

140142
if (ClickGui.isEnabled && !isLocked) {
141-
if (activeDragHudName == null && mousePressedThisFrame) { tryBeginDrag(huds) }
142-
if (activeDragHudName != null && mouseDown) updateDragAndSnapping()
143-
if (activeDragHudName != null) drawDragGrid()
143+
if (activeDragHudName != null && mouseDown) updateDragAndSnapping()
144+
if (activeDragHudName != null) drawDragGrid()
144145
}
145146

146147
huds.forEach { hud ->
@@ -176,6 +177,14 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
176177
val outlineWidth = if (hud.outline) hud.outlineWidth else 0f
177178
withStyleVar(ImGuiStyleVar.WindowBorderSize, outlineWidth) {
178179
window("##${hud.name}", flags = hudFlags) {
180+
if (ClickGui.isEnabled && !isLocked && activeDragHudName == null && mousePressedThisFrameGlobal && ImGui.isWindowHovered()) {
181+
val mx = io.mousePos.x
182+
val my = io.mousePos.y
183+
activeDragHudName = hud.name
184+
dragOffsetX = mx - windowPos.x
185+
dragOffsetY = my - windowPos.y
186+
}
187+
179188
val vis = snapOverlays[hud.name]
180189
if (vis != null) {
181190
SnapManager.drawSnapLines(
@@ -218,10 +227,6 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
218227
isShownInGUI = !isShownInGUI
219228
}
220229
separator()
221-
menu("HUD Settings") {
222-
buildConfigSettingsContext(this@HudGuiLayout)
223-
}
224-
separator()
225230
if (notShown.isEmpty()) {
226231
textDisabled("No hidden HUD elements")
227232
} else {
@@ -236,20 +241,9 @@ object HudGuiLayout : Loadable, Configurable(HudConfig) {
236241
}
237242
}
238243
}
239-
}
240-
}
241-
242-
private fun ImGuiBuilder.tryBeginDrag(huds: List<HudModule>) {
243-
val mx = io.mousePos.x
244-
val my = io.mousePos.y
245-
huds.forEach { hud ->
246-
val r = lastBounds[hud.name] ?: return@forEach
247-
val inside = mx >= r.x && mx <= r.x + r.w && my >= r.y && my <= r.y + r.h
248-
if (inside) {
249-
activeDragHudName = hud.name
250-
dragOffsetX = mx - r.x
251-
dragOffsetY = my - r.y
252-
return
244+
separator()
245+
menu("HUD Settings") {
246+
buildConfigSettingsContext(this@HudGuiLayout)
253247
}
254248
}
255249
}

0 commit comments

Comments
 (0)