@@ -36,6 +36,7 @@ import imgui.flag.ImDrawListFlags
3636import imgui.flag.ImGuiWindowFlags
3737import imgui.flag.ImGuiStyleVar
3838import kotlin.math.PI
39+ import kotlin.math.max
3940
4041object HudGuiLayout : Loadable {
4142 const val DEFAULT_HUD_FLAGS =
@@ -51,6 +52,9 @@ object HudGuiLayout : Loadable {
5152 private val pendingPositions = mutableMapOf<String , Pair <Float , Float >>()
5253 private val snapOverlays = mutableMapOf<String , SnapVisual >()
5354
55+ var isShownInGUI = true
56+ var isLocked = false
57+
5458 private data class SnapVisual (
5559 val snapX : Float? ,
5660 val snapY : Float? ,
@@ -65,6 +69,8 @@ object HudGuiLayout : Loadable {
6569
6670 init {
6771 listen<GuiEvent .NewFrame > {
72+ if (ClickGui .isEnabled && ! isShownInGUI) return @listen
73+
6874 buildLayout {
6975 val vp = ImGui .getMainViewport()
7076 SnapManager .beginFrame(vp.sizeX, vp.sizeY, io.fontGlobalScale)
@@ -73,7 +79,8 @@ object HudGuiLayout : Loadable {
7379 val mousePressedThisFrame = mouseDown && ! mouseWasDown
7480 val mouseReleasedThisFrame = ! mouseDown && mouseWasDown
7581 mouseWasDown = mouseDown
76- if (mouseReleasedThisFrame || ! ClickGui .isEnabled) {
82+
83+ if (mouseReleasedThisFrame || ! ClickGui .isEnabled || isLocked) {
7784 activeDragHudName = null
7885 }
7986
@@ -86,12 +93,11 @@ object HudGuiLayout : Loadable {
8693
8794 notShown.forEach { SnapManager .unregisterElement(it.name) }
8895
89- if (ClickGui .isEnabled && activeDragHudName == null && mousePressedThisFrame) {
90- tryBeginDrag(huds)
91- }
92-
93- if (ClickGui .isEnabled && activeDragHudName != null && mouseDown) {
94- updateDragAndSnapping()
96+ val canDrag = ClickGui .isEnabled && ! isLocked
97+ if (canDrag) {
98+ if (activeDragHudName == null && mousePressedThisFrame) { tryBeginDrag(huds) }
99+ if (activeDragHudName != null && mouseDown) updateDragAndSnapping()
100+ if (activeDragHudName != null ) drawDragGrid()
95101 }
96102
97103 huds.forEach { hud ->
@@ -105,7 +111,7 @@ object HudGuiLayout : Loadable {
105111 val baseFlags = if (hasBg) {
106112 DEFAULT_HUD_FLAGS and ImGuiWindowFlags .NoBackground .inv ()
107113 } else DEFAULT_HUD_FLAGS
108- val hudFlags = if (! ClickGui .isEnabled) {
114+ val hudFlags = if (! ClickGui .isEnabled || isLocked ) {
109115 baseFlags or ImGuiWindowFlags .NoMove
110116 } else baseFlags
111117
@@ -129,7 +135,7 @@ object HudGuiLayout : Loadable {
129135 )
130136 }
131137 with (hud) { buildLayout() }
132- if (ClickGui .isEnabled ) {
138+ if (canDrag ) {
133139 drawHudCornerArcs(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
134140 }
135141 val rect = RectF (windowPos.x, windowPos.y, windowSize.x, windowSize.y)
@@ -176,11 +182,38 @@ object HudGuiLayout : Loadable {
176182 snapOverlays[id] = SnapVisual (snap.snapX, snap.snapY, snap.kindX, snap.kindY)
177183 }
178184
185+ private fun ImGuiBuilder.drawDragGrid () {
186+ if (! GuiSettings .snapEnabled || ! GuiSettings .snapToGrid) return
187+ val vp = ImGui .getMainViewport()
188+ val step = max(4f , GuiSettings .gridSize * io.fontGlobalScale)
189+ if (step <= 0f ) return
190+
191+ val x0 = vp.posX
192+ val y0 = vp.posY
193+ val x1 = vp.posX + vp.sizeX
194+ val y1 = vp.posY + vp.sizeY
195+
196+ val draw = backgroundDrawList
197+ val col = ImColor .rgba(255 , 255 , 255 , 28 )
198+ val thickness = 1f
199+
200+ var x = x0
201+ while (x <= x1 + 0.5f ) {
202+ draw.addLine(x, y0, x, y1, col, thickness)
203+ x + = step
204+ }
205+ var y = y0
206+ while (y <= y1 + 0.5f ) {
207+ draw.addLine(x0, y, x1, y, col, thickness)
208+ y + = step
209+ }
210+ }
211+
179212 private fun ImGuiBuilder.drawHudCornerArcs (draw : ImDrawList , x : Float , y : Float , w : Float , h : Float ) {
180213 val baseRadius = GuiSettings .hudOutlineCornerRadius
181214 val rounding = if (baseRadius > 0f ) baseRadius else style.windowRounding
182215 val inflate = GuiSettings .hudOutlineCornerInflate
183- // Soft halo corners (gray, slightly smaller)
216+ // Soft halo corners
184217 drawCornerArcs(
185218 draw,
186219 x, y, w, h,
0 commit comments