group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
VoidfallStyle.hpp
Go to the documentation of this file.
1
14
15#pragma once
16
17#include "HudContext.hpp"
18#include "HudTypes.hpp"
19
20namespace voidfall
21{
22
23// ── Palette (matches prototype's CSS custom properties) ─────────────────────
24
26constexpr HudColor k_bgVoid{0.08f, 0.075f, 0.07f, 0.96f};
31constexpr HudColor k_bgPanel{0.10f, 0.095f, 0.085f, 0.92f};
33constexpr HudColor k_bgPanelSolid{0.09f, 0.085f, 0.075f, 0.96f};
35constexpr HudColor k_bgInset{0.12f, 0.115f, 0.105f, 0.92f};
36
38constexpr HudColor k_lineDim{0.32f, 0.30f, 0.28f, 0.7f};
40constexpr HudColor k_line{0.42f, 0.40f, 0.37f, 0.95f};
42constexpr HudColor k_lineBright{0.62f, 0.59f, 0.56f, 1.0f};
43
47constexpr HudColor k_textDim{0.78f, 0.76f, 0.73f, 1.0f};
49constexpr HudColor k_text{0.92f, 0.90f, 0.87f, 1.0f};
51constexpr HudColor k_textBright{1.00f, 0.99f, 0.97f, 1.0f};
52
54constexpr HudColor k_amber{1.00f, 0.71f, 0.18f, 1.0f};
56constexpr HudColor k_amberDim{0.78f, 0.55f, 0.14f, 1.0f};
58constexpr HudColor k_amberDeep{0.50f, 0.35f, 0.10f, 1.0f};
60constexpr HudColor k_amberGlow{1.00f, 0.71f, 0.18f, 0.18f};
61
63constexpr HudColor k_red{0.92f, 0.30f, 0.20f, 1.0f};
65constexpr HudColor k_redBright{0.95f, 0.45f, 0.25f, 1.0f};
67constexpr HudColor k_redDim{0.65f, 0.20f, 0.15f, 1.0f};
68
70constexpr HudColor k_cyan{0.45f, 0.78f, 0.96f, 1.0f};
72constexpr HudColor k_cyanDim{0.20f, 0.50f, 0.70f, 1.0f};
73
75constexpr HudColor k_green{0.30f, 0.86f, 0.45f, 1.0f};
76
78constexpr HudColor k_pickupBg{0.13f, 0.12f, 0.11f, 0.82f};
79
80// ── Weapon-type accent colors (Apex convention) ───────────────────────────
81//
82// Each weapon class has its own bright accent: AR teal, sniper purple,
83// pistol green, SMG amber, shotgun red. Used for the weapon-panel
84// underline, fire-mode tag border, slot-tab top-edge, and slot-index pill
85// background — so the player parses *what* they're holding by color
86// before reading the name.
87constexpr HudColor k_typeAr{0.20f, 0.65f, 0.70f, 1.0f}; // teal
88constexpr HudColor k_typeSniper{0.40f, 0.30f, 0.75f, 1.0f}; // purple
89constexpr HudColor k_typePistol{0.20f, 0.75f, 0.45f, 1.0f}; // green
90constexpr HudColor k_typeSmg{0.95f, 0.65f, 0.18f, 1.0f}; // amber
91constexpr HudColor k_typeShotgun{0.85f, 0.30f, 0.20f, 1.0f}; // red
92
96constexpr HudColor weaponTypeAccent(int weaponId)
97{
98 switch (weaponId) {
99 case 0: // Rifle — full-auto AR
100 return k_typeAr;
101 case 1: // Rocket — explosive, treat as shotgun-class
102 return k_typeShotgun;
103 case 2: // RailGun — single-shot precision
104 return k_typeSniper;
105 case 3: // EnergyGun — beam SMG-class
106 return k_typeSmg;
107 default: // grenades / unknown — fall back to generic amber
108 return k_amber;
109 }
110}
111
113constexpr HudColor withAlpha(HudColor c, float alpha)
114{
115 return HudColor{c.r, c.g, c.b, c.a * alpha};
116}
117
118// ── Mil-spec bracket corners ────────────────────────────────────────────────
119
125 float x,
126 float y,
127 float w,
128 float h,
129 float armLen = 10.f,
130 float thickness = 1.f,
131 float outset = 0.f,
132 HudColor color = k_amber)
133{
134 const float bx = x - outset;
135 const float by = y - outset;
136 const float bw = w + outset * 2.f;
137 const float bh = h + outset * 2.f;
138
139 // Top-left.
140 ctx.rect(bx, by, armLen, thickness, color);
141 ctx.rect(bx, by, thickness, armLen, color);
142 // Top-right.
143 ctx.rect(bx + bw - armLen, by, armLen, thickness, color);
144 ctx.rect(bx + bw - thickness, by, thickness, armLen, color);
145 // Bottom-left.
146 ctx.rect(bx, by + bh - thickness, armLen, thickness, color);
147 ctx.rect(bx, by + bh - armLen, thickness, armLen, color);
148 // Bottom-right.
149 ctx.rect(bx + bw - armLen, by + bh - thickness, armLen, thickness, color);
150 ctx.rect(bx + bw - thickness, by + bh - armLen, thickness, armLen, color);
151}
152
154inline void drawPanel(HudContext& ctx,
155 float x,
156 float y,
157 float w,
158 float h,
159 HudColor fill = k_bgPanel,
160 HudColor border = k_line,
161 float thickness = 1.f)
162{
163 ctx.rect(x, y, w, h, fill);
164 ctx.rectOutline(x, y, w, h, thickness, border);
165}
166
172inline void drawTrailBar(HudContext& ctx,
173 float x,
174 float y,
175 float w,
176 float h,
177 float fill01,
178 float trail01,
179 HudColor fillColor,
180 HudColor trailColor = HudColor{0.95f, 0.95f, 0.95f, 0.45f},
181 HudColor bgColor = k_bgInset,
182 HudColor borderColor = k_lineDim)
183{
184 // Background.
185 ctx.rect(x, y, w, h, bgColor);
186 // Ghost trail (drained portion drawn first, so live fill overlays it).
187 if (trail01 > fill01)
188 ctx.rect(x, y, w * trail01, h, trailColor);
189 // Live fill.
190 if (fill01 > 0.f)
191 ctx.rect(x, y, w * fill01, h, fillColor);
192 // Hairline border.
193 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
194}
195
200constexpr HudColor lerpColor(HudColor a, HudColor b, float t)
201{
202 return HudColor{
203 a.r + (b.r - a.r) * t,
204 a.g + (b.g - a.g) * t,
205 a.b + (b.b - a.b) * t,
206 a.a + (b.a - a.a) * t,
207 };
208}
209
219 float x,
220 float y,
221 float w,
222 float h,
223 float fill01,
224 float trail01,
225 HudColor fillLeft,
226 HudColor fillRight,
227 HudColor trailColor = HudColor{0.95f, 0.95f, 0.95f, 0.45f},
228 HudColor bgColor = k_bgInset,
229 HudColor borderColor = k_lineDim)
230{
231 ctx.rect(x, y, w, h, bgColor);
232 if (trail01 > fill01)
233 ctx.rect(x, y, w * trail01, h, trailColor);
234 if (fill01 > 0.f) {
235 // Right endpoint of the visible fill = same point in the underlying
236 // gradient, so the bar drains cleanly without color compression.
237 const HudColor visibleRight = lerpColor(fillLeft, fillRight, fill01);
238 ctx.gradientRect(x, y, w * fill01, h, fillLeft, visibleRight);
239 }
240 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
241}
242
247inline void drawKeyTab(HudContext& ctx,
248 const char* key,
249 float x,
250 float y,
251 float fontSize,
252 float padX = 3.f,
253 float padY = 1.f,
254 HudColor bgColor = HudColor{0.f, 0.f, 0.f, 0.45f},
255 HudColor borderColor = k_lineBright,
256 HudColor textColor = k_textDim)
257{
258 const float capH = fontSize * 0.72f;
259 const float w = ctx.measureText(key, fontSize) + padX * 2.f;
260 const float h = capH + padY * 2.f;
261 ctx.rect(x, y, w, h, bgColor);
262 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
263 ctx.text(key, x + w * 0.5f, y - fontSize * 0.28f + padY, fontSize, textColor, HudAlign::Center);
264}
265
266} // namespace voidfall
Immediate-mode draw API for HUD widgets.
Shared types for the HUD system.
@ Center
Definition HudTypes.hpp:48
Accumulates HUD geometry during a frame for batch rendering.
Definition HudContext.hpp:18
void text(const char *str, float x, float y, float size, HudColor color, HudAlign align=HudAlign::Left, bool outlined=false)
Render a UTF-8 ASCII string via SDF.
Definition HudContext.cpp:243
float measureText(const char *str, float size) const
Definition HudContext.cpp:310
void rectOutline(float x, float y, float w, float h, float thickness, HudColor color)
Definition HudContext.cpp:138
void gradientRect(float x, float y, float w, float h, HudColor leftColor, HudColor rightColor)
Filled rect with a horizontal color gradient.
Definition HudContext.cpp:146
void rect(float x, float y, float w, float h, HudColor color)
Definition HudContext.cpp:101
Definition HudIcons.cpp:13
constexpr HudColor k_typePistol
Definition VoidfallStyle.hpp:89
constexpr HudColor k_textBright
Brightest text — kept near-white for hero readouts.
Definition VoidfallStyle.hpp:51
constexpr HudColor k_line
Standard hairline — oklch(0.40 0.018 60).
Definition VoidfallStyle.hpp:40
void drawGradientTrailBar(HudContext &ctx, float x, float y, float w, float h, float fill01, float trail01, HudColor fillLeft, HudColor fillRight, HudColor trailColor=HudColor{0.95f, 0.95f, 0.95f, 0.45f}, HudColor bgColor=k_bgInset, HudColor borderColor=k_lineDim)
Draw a horizontal stat bar whose live fill is a left→right gradient (e.g.
Definition VoidfallStyle.hpp:218
constexpr HudColor k_typeSmg
Definition VoidfallStyle.hpp:90
constexpr HudColor weaponTypeAccent(int weaponId)
Map a weapon-type id (matching WeaponType integer order in ecs/components/WeaponState....
Definition VoidfallStyle.hpp:96
void drawCornerBrackets(HudContext &ctx, float x, float y, float w, float h, float armLen=10.f, float thickness=1.f, float outset=0.f, HudColor color=k_amber)
Draw four mil-spec L-shaped corner brackets around a rect.
Definition VoidfallStyle.hpp:124
constexpr HudColor k_bgPanel
Standard panel fill — bumped to 0.92α (was 0.78).
Definition VoidfallStyle.hpp:31
constexpr HudColor k_green
Status green — oklch(0.78 0.16 145).
Definition VoidfallStyle.hpp:75
constexpr HudColor k_amberGlow
Amber glow tint — oklch(0.80 0.165 75 / 0.15).
Definition VoidfallStyle.hpp:60
constexpr HudColor k_redDim
Dim red — oklch(0.50 0.15 28).
Definition VoidfallStyle.hpp:67
void drawTrailBar(HudContext &ctx, float x, float y, float w, float h, float fill01, float trail01, HudColor fillColor, HudColor trailColor=HudColor{0.95f, 0.95f, 0.95f, 0.45f}, HudColor bgColor=k_bgInset, HudColor borderColor=k_lineDim)
Draw a horizontal stat bar with a damage-trail ghost (solid fill).
Definition VoidfallStyle.hpp:172
constexpr HudColor k_lineDim
Dim hairline — oklch(0.32 0.015 60 / 0.6).
Definition VoidfallStyle.hpp:38
constexpr HudColor k_bgInset
Inset bar background.
Definition VoidfallStyle.hpp:35
constexpr HudColor k_cyan
Shield cyan — oklch(0.80 0.10 220).
Definition VoidfallStyle.hpp:70
constexpr HudColor k_bgPanelSolid
Solid panel — used for hero callouts.
Definition VoidfallStyle.hpp:33
constexpr HudColor k_textDim
Dim text — bumped luminance from ~0.55 to ~0.78 so secondary readouts (fire mode, "+reserve",...
Definition VoidfallStyle.hpp:47
void drawKeyTab(HudContext &ctx, const char *key, float x, float y, float fontSize, float padX=3.f, float padY=1.f, HudColor bgColor=HudColor{0.f, 0.f, 0.f, 0.45f}, HudColor borderColor=k_lineBright, HudColor textColor=k_textDim)
Draw a bordered "key tab" pill with a single character inside.
Definition VoidfallStyle.hpp:247
constexpr HudColor k_amber
Primary amber — oklch(0.80 0.165 75).
Definition VoidfallStyle.hpp:54
constexpr HudColor k_amberDeep
Deep amber — oklch(0.45 0.10 70).
Definition VoidfallStyle.hpp:58
constexpr HudColor k_typeShotgun
Definition VoidfallStyle.hpp:91
constexpr HudColor withAlpha(HudColor c, float alpha)
Apply alpha to a palette color (for fade-out).
Definition VoidfallStyle.hpp:113
constexpr HudColor k_lineBright
Bright hairline — oklch(0.55 0.02 60).
Definition VoidfallStyle.hpp:42
constexpr HudColor k_red
Health red — oklch(0.65 0.20 28).
Definition VoidfallStyle.hpp:63
constexpr HudColor k_typeAr
Definition VoidfallStyle.hpp:87
void drawPanel(HudContext &ctx, float x, float y, float w, float h, HudColor fill=k_bgPanel, HudColor border=k_line, float thickness=1.f)
Draw a Voidfall panel: solid fill + 1 px outline.
Definition VoidfallStyle.hpp:154
constexpr HudColor k_pickupBg
Pickup amber-trim background.
Definition VoidfallStyle.hpp:78
constexpr HudColor lerpColor(HudColor a, HudColor b, float t)
Lerp between two HudColors — used to compute the visible gradient endpoint when the bar is partially ...
Definition VoidfallStyle.hpp:200
constexpr HudColor k_redBright
Bright tail of HP gradient — oklch(0.72 0.18 35).
Definition VoidfallStyle.hpp:65
constexpr HudColor k_typeSniper
Definition VoidfallStyle.hpp:88
constexpr HudColor k_amberDim
Dimmer amber — oklch(0.65 0.13 75).
Definition VoidfallStyle.hpp:56
constexpr HudColor k_cyanDim
Dim cyan — oklch(0.55 0.08 220).
Definition VoidfallStyle.hpp:72
constexpr HudColor k_text
Standard text — bumped slightly toward white for body chrome.
Definition VoidfallStyle.hpp:49
constexpr HudColor k_bgVoid
Deep panel background — opaque so HUD chrome doesn't pick up sky tint.
Definition VoidfallStyle.hpp:26
RGBA color for HUD elements (linear space, straight alpha).
Definition HudTypes.hpp:15
float r
Definition HudTypes.hpp:16
float g
Definition HudTypes.hpp:16
float b
Definition HudTypes.hpp:16
float a
Definition HudTypes.hpp:16