Skip to content

Commit a4db32e

Browse files
committed
Background and outline settings for HUD elements
1 parent 294248b commit a4db32e

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

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

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import com.lambda.module.HudModule
2929
import com.lambda.module.ModuleRegistry
3030
import com.lambda.module.modules.client.GuiSettings
3131
import com.lambda.module.modules.client.ClickGui
32+
import imgui.ImColor
3233
import imgui.ImGui
3334
import imgui.ImDrawList
3435
import imgui.flag.ImDrawListFlags
3536
import imgui.flag.ImGuiWindowFlags
37+
import imgui.flag.ImGuiStyleVar
3638
import kotlin.math.PI
3739

3840
object HudGuiLayout : Loadable {
@@ -98,26 +100,46 @@ object HudGuiLayout : Loadable {
98100
ImGui.setNextWindowPos(override.first, override.second)
99101
}
100102

101-
val hudFlags = if (ClickGui.isEnabled) DEFAULT_HUD_FLAGS else {
102-
DEFAULT_HUD_FLAGS or ImGuiWindowFlags.NoMove
103+
val bg = hud.backgroundColor
104+
val hasBg = bg.alpha > 0
105+
val baseFlags = if (hasBg) {
106+
DEFAULT_HUD_FLAGS and ImGuiWindowFlags.NoBackground.inv()
107+
} else DEFAULT_HUD_FLAGS
108+
val hudFlags = if (!ClickGui.isEnabled) {
109+
baseFlags or ImGuiWindowFlags.NoMove
110+
} else baseFlags
111+
112+
val pushedColor = if (hasBg) {
113+
val packed = ImColor.rgba(bg.red, bg.green, bg.blue, bg.alpha)
114+
ImGui.pushStyleColor(imgui.flag.ImGuiCol.WindowBg, packed)
115+
true
116+
} else {
117+
false
103118
}
104119

105-
window("##${hud.name}", flags = hudFlags) {
106-
val vis = snapOverlays[hud.name]
107-
if (vis != null) {
108-
SnapManager.drawSnapLines(
109-
foregroundDrawList,
110-
vis.snapX, vis.kindX,
111-
vis.snapY, vis.kindY
112-
)
120+
val outlineWidth = if (hud.outline) hud.outlineWidth else 0f
121+
withStyleVar(ImGuiStyleVar.WindowBorderSize, outlineWidth) {
122+
window("##${hud.name}", flags = hudFlags) {
123+
val vis = snapOverlays[hud.name]
124+
if (vis != null) {
125+
SnapManager.drawSnapLines(
126+
foregroundDrawList,
127+
vis.snapX, vis.kindX,
128+
vis.snapY, vis.kindY
129+
)
130+
}
131+
with(hud) { buildLayout() }
132+
if (ClickGui.isEnabled) {
133+
drawHudCornerArcs(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
134+
}
135+
val rect = RectF(windowPos.x, windowPos.y, windowSize.x, windowSize.y)
136+
SnapManager.registerElement(hud.name, rect)
137+
lastBounds[hud.name] = rect
113138
}
114-
with(hud) { buildLayout() }
115-
if (ClickGui.isEnabled) {
116-
drawHudOutline(foregroundDrawList, windowPos.x, windowPos.y, windowSize.x, windowSize.y)
117-
}
118-
val rect = RectF(windowPos.x, windowPos.y, windowSize.x, windowSize.y)
119-
SnapManager.registerElement(hud.name, rect)
120-
lastBounds[hud.name] = rect
139+
}
140+
141+
if (pushedColor) {
142+
ImGui.popStyleColor()
121143
}
122144
}
123145
}
@@ -154,7 +176,7 @@ object HudGuiLayout : Loadable {
154176
snapOverlays[id] = SnapVisual(snap.snapX, snap.snapY, snap.kindX, snap.kindY)
155177
}
156178

157-
private fun ImGuiBuilder.drawHudOutline(draw: ImDrawList, x: Float, y: Float, w: Float, h: Float) {
179+
private fun ImGuiBuilder.drawHudCornerArcs(draw: ImDrawList, x: Float, y: Float, w: Float, h: Float) {
158180
val baseRadius = GuiSettings.hudOutlineCornerRadius
159181
val rounding = if (baseRadius > 0f) baseRadius else style.windowRounding
160182
val inflate = GuiSettings.hudOutlineCornerInflate

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.module
2020
import com.lambda.gui.Layout
2121
import com.lambda.module.tag.ModuleTag
2222
import com.lambda.util.KeyCode
23+
import java.awt.Color
2324

2425
abstract class HudModule(
2526
name: String,
@@ -28,4 +29,8 @@ abstract class HudModule(
2829
alwaysListening: Boolean = false,
2930
enabledByDefault: Boolean = false,
3031
defaultKeybind: KeyCode = KeyCode.UNBOUND,
31-
) : Module(name, description, tag, alwaysListening, enabledByDefault, defaultKeybind), Layout
32+
) : Module(name, description, tag, alwaysListening, enabledByDefault, defaultKeybind), Layout {
33+
val backgroundColor by setting("Background Color", Color(0, 0, 0, 0))
34+
val outline by setting("Show Outline", false)
35+
val outlineWidth by setting("Outline Width", 1f, 0f..10f, 0.1f) { outline }
36+
}

0 commit comments

Comments
 (0)