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_primary{0.168627f, 0.694118f, 0.741176f, 1.0f}; // #2BB1BD
27constexpr HudColor k_secondary{0.250980f, 0.478431f, 0.501961f, 1.0f}; // #407A80
28constexpr HudColor k_tertiary{0.615686f, 0.858824f, 0.882353f, 1.0f}; // #9DDBE1
29constexpr HudColor k_quaternary{0.070588f, 0.270588f, 0.290196f, 1.0f}; // #12454A
30
41
48
57
59constexpr HudColor k_amber{k_primary.r, k_primary.g, k_primary.b, 1.0f};
66
68constexpr HudColor k_red{k_primary.r, k_primary.g, k_primary.b, 1.0f};
73constexpr HudColor k_health{0.92f, 0.96f, 0.97f, 1.0f};
74constexpr HudColor k_healthBright{1.0f, 1.0f, 1.0f, 1.0f};
75
80
83
86
87// ── Weapon-type accent colors (Apex convention) ───────────────────────────
88//
89// Each weapon class has its own bright accent: AR teal, sniper purple,
90// pistol green, SMG amber, shotgun red. Used for the weapon-panel
91// underline, fire-mode tag border, slot-tab top-edge, and slot-index pill
92// background — so the player parses *what* they're holding by color
93// before reading the name.
99
103constexpr HudColor weaponTypeAccent(int weaponId)
104{
105 switch (weaponId) {
106 case 0: // Rifle — full-auto AR
107 return k_typeAr;
108 case 1: // Rocket — explosive, treat as shotgun-class
109 return k_typeShotgun;
110 case 2: // RailGun — single-shot precision
111 return k_typeSniper;
112 case 3: // EnergyGun — beam SMG-class
113 return k_typeSmg;
114 default: // grenades / unknown — fall back to generic amber
115 return k_amber;
116 }
117}
118
120constexpr HudColor withAlpha(HudColor c, float alpha)
121{
122 return HudColor{c.r, c.g, c.b, c.a * alpha};
123}
124
125// ── Mil-spec bracket corners ────────────────────────────────────────────────
126
132 float x,
133 float y,
134 float w,
135 float h,
136 float armLen = 10.f,
137 float thickness = 1.f,
138 float outset = 0.f,
139 HudColor color = k_amber)
140{
141 const float bx = x - outset;
142 const float by = y - outset;
143 const float bw = w + outset * 2.f;
144 const float bh = h + outset * 2.f;
145
146 // Top-left.
147 ctx.rect(bx, by, armLen, thickness, color);
148 ctx.rect(bx, by, thickness, armLen, color);
149 // Top-right.
150 ctx.rect(bx + bw - armLen, by, armLen, thickness, color);
151 ctx.rect(bx + bw - thickness, by, thickness, armLen, color);
152 // Bottom-left.
153 ctx.rect(bx, by + bh - thickness, armLen, thickness, color);
154 ctx.rect(bx, by + bh - armLen, thickness, armLen, color);
155 // Bottom-right.
156 ctx.rect(bx + bw - armLen, by + bh - thickness, armLen, thickness, color);
157 ctx.rect(bx + bw - thickness, by + bh - armLen, thickness, armLen, color);
158}
159
161inline void drawPanel(HudContext& ctx,
162 float x,
163 float y,
164 float w,
165 float h,
166 HudColor fill = k_bgPanel,
167 HudColor border = k_line,
168 float thickness = 1.f)
169{
170 ctx.rect(x, y, w, h, fill);
171 ctx.rectOutline(x, y, w, h, thickness, border);
172}
173
179inline void drawTrailBar(HudContext& ctx,
180 float x,
181 float y,
182 float w,
183 float h,
184 float fill01,
185 float trail01,
186 HudColor fillColor,
187 HudColor trailColor = HudColor{k_tertiary.r, k_tertiary.g, k_tertiary.b, 0.45f},
188 HudColor bgColor = k_bgInset,
189 HudColor borderColor = k_lineDim)
190{
191 // Background.
192 ctx.rect(x, y, w, h, bgColor);
193 // Ghost trail (drained portion drawn first, so live fill overlays it).
194 if (trail01 > fill01)
195 ctx.rect(x, y, w * trail01, h, trailColor);
196 // Live fill.
197 if (fill01 > 0.f)
198 ctx.rect(x, y, w * fill01, h, fillColor);
199 // Hairline border.
200 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
201}
202
207constexpr HudColor lerpColor(HudColor a, HudColor b, float t)
208{
209 return HudColor{
210 a.r + (b.r - a.r) * t,
211 a.g + (b.g - a.g) * t,
212 a.b + (b.b - a.b) * t,
213 a.a + (b.a - a.a) * t,
214 };
215}
216
226 float x,
227 float y,
228 float w,
229 float h,
230 float fill01,
231 float trail01,
232 HudColor fillLeft,
233 HudColor fillRight,
234 HudColor trailColor = HudColor{k_tertiary.r, k_tertiary.g, k_tertiary.b, 0.45f},
235 HudColor bgColor = k_bgInset,
236 HudColor borderColor = k_lineDim)
237{
238 ctx.rect(x, y, w, h, bgColor);
239 if (trail01 > fill01)
240 ctx.rect(x, y, w * trail01, h, trailColor);
241 if (fill01 > 0.f) {
242 // Right endpoint of the visible fill = same point in the underlying
243 // gradient, so the bar drains cleanly without color compression.
244 const HudColor visibleRight = lerpColor(fillLeft, fillRight, fill01);
245 ctx.gradientRect(x, y, w * fill01, h, fillLeft, visibleRight);
246 }
247 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
248}
249
254inline void drawKeyTab(HudContext& ctx,
255 const char* key,
256 float x,
257 float y,
258 float fontSize,
259 float padX = 3.f,
260 float padY = 1.f,
261 HudColor bgColor = HudColor{k_quaternary.r, k_quaternary.g, k_quaternary.b, 0.45f},
262 HudColor borderColor = k_lineBright,
263 HudColor textColor = k_textDim)
264{
265 const float capH = fontSize * 0.72f;
266 const float w = ctx.measureText(key, fontSize) + padX * 2.f;
267 const float h = capH + padY * 2.f;
268 ctx.rect(x, y, w, h, bgColor);
269 ctx.rectOutline(x, y, w, h, 1.f, borderColor);
270 ctx.text(key, x + w * 0.5f, y - fontSize * 0.28f + padY, fontSize, textColor, HudAlign::Center);
271}
272
273} // namespace voidfall
Immediate-mode draw API for HUD widgets.
Shared types for the HUD system.
@ Center
Definition HudTypes.hpp:57
Accumulates HUD geometry during a frame for batch rendering.
Definition HudContext.hpp:19
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:278
float measureText(const char *str, float size) const
Definition HudContext.cpp:382
void rectOutline(float x, float y, float w, float h, float thickness, HudColor color)
Definition HudContext.cpp:173
void gradientRect(float x, float y, float w, float h, HudColor leftColor, HudColor rightColor)
Filled rect with a horizontal color gradient.
Definition HudContext.cpp:181
void rect(float x, float y, float w, float h, HudColor color)
Definition HudContext.cpp:136
Definition HudIcons.cpp:14
constexpr HudColor k_typePistol
Definition VoidfallStyle.hpp:96
constexpr HudColor k_textBright
Brightest text — kept near-white for hero readouts.
Definition VoidfallStyle.hpp:56
constexpr HudColor k_line
Standard hairline — oklch(0.40 0.018 60).
Definition VoidfallStyle.hpp:45
constexpr HudColor k_typeSmg
Definition VoidfallStyle.hpp:97
constexpr HudColor weaponTypeAccent(int weaponId)
Map a weapon-type id (matching WeaponType integer order in ecs/components/WeaponState....
Definition VoidfallStyle.hpp:103
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:131
constexpr HudColor k_bgPanel
Standard panel fill — bumped to 0.92α (was 0.78).
Definition VoidfallStyle.hpp:36
constexpr HudColor k_health
Definition VoidfallStyle.hpp:73
constexpr HudColor k_green
Status green — oklch(0.78 0.16 145).
Definition VoidfallStyle.hpp:82
constexpr HudColor k_amberGlow
Amber glow tint — oklch(0.80 0.165 75 / 0.15).
Definition VoidfallStyle.hpp:65
constexpr HudColor k_secondary
Definition VoidfallStyle.hpp:27
constexpr HudColor k_redDim
Dim red — oklch(0.50 0.15 28).
Definition VoidfallStyle.hpp:72
constexpr HudColor k_lineDim
Dim hairline — oklch(0.32 0.015 60 / 0.6).
Definition VoidfallStyle.hpp:43
constexpr HudColor k_quaternary
Definition VoidfallStyle.hpp:29
constexpr HudColor k_bgInset
Inset bar background.
Definition VoidfallStyle.hpp:40
constexpr HudColor k_cyan
Shield cyan — oklch(0.80 0.10 220).
Definition VoidfallStyle.hpp:77
constexpr HudColor k_primary
Deep panel background — opaque so HUD chrome doesn't pick up sky tint.
Definition VoidfallStyle.hpp:26
constexpr HudColor k_bgPanelSolid
Solid panel — used for hero callouts.
Definition VoidfallStyle.hpp:38
constexpr HudColor k_textDim
Dim text — bumped luminance from ~0.55 to ~0.78 so secondary readouts (fire mode, "+reserve",...
Definition VoidfallStyle.hpp:52
constexpr HudColor k_amber
Primary amber — oklch(0.80 0.165 75).
Definition VoidfallStyle.hpp:59
constexpr HudColor k_amberDeep
Deep amber — oklch(0.45 0.10 70).
Definition VoidfallStyle.hpp:63
constexpr HudColor k_typeShotgun
Definition VoidfallStyle.hpp:98
void drawGradientTrailBar(HudContext &ctx, float x, float y, float w, float h, float fill01, float trail01, HudColor fillLeft, HudColor fillRight, HudColor trailColor=HudColor{k_tertiary.r, k_tertiary.g, k_tertiary.b, 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:225
constexpr HudColor withAlpha(HudColor c, float alpha)
Apply alpha to a palette color (for fade-out).
Definition VoidfallStyle.hpp:120
constexpr HudColor k_lineBright
Bright hairline — oklch(0.55 0.02 60).
Definition VoidfallStyle.hpp:47
constexpr HudColor k_tertiary
Definition VoidfallStyle.hpp:28
void drawKeyTab(HudContext &ctx, const char *key, float x, float y, float fontSize, float padX=3.f, float padY=1.f, HudColor bgColor=HudColor{k_quaternary.r, k_quaternary.g, k_quaternary.b, 0.45f}, HudColor borderColor=k_lineBright, HudColor textColor=k_textDim)
Draw a bordered "key tab" pill with a single character inside.
Definition VoidfallStyle.hpp:254
constexpr HudColor k_red
Health red — oklch(0.65 0.20 28).
Definition VoidfallStyle.hpp:68
constexpr HudColor k_typeAr
Definition VoidfallStyle.hpp:94
constexpr HudColor k_healthBright
Definition VoidfallStyle.hpp:74
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:161
void drawTrailBar(HudContext &ctx, float x, float y, float w, float h, float fill01, float trail01, HudColor fillColor, HudColor trailColor=HudColor{k_tertiary.r, k_tertiary.g, k_tertiary.b, 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:179
constexpr HudColor k_pickupBg
Pickup amber-trim background.
Definition VoidfallStyle.hpp:85
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:207
constexpr HudColor k_redBright
Bright tail of HP gradient — oklch(0.72 0.18 35).
Definition VoidfallStyle.hpp:70
constexpr HudColor k_typeSniper
Definition VoidfallStyle.hpp:95
constexpr HudColor k_amberDim
Dimmer amber — oklch(0.65 0.13 75).
Definition VoidfallStyle.hpp:61
constexpr HudColor k_cyanDim
Dim cyan — oklch(0.55 0.08 220).
Definition VoidfallStyle.hpp:79
constexpr HudColor k_text
Standard text — bumped slightly toward white for body chrome.
Definition VoidfallStyle.hpp:54
constexpr HudColor k_bgVoid
Definition VoidfallStyle.hpp:31
RGBA color for HUD elements (linear space, straight alpha).
Definition HudTypes.hpp:24
float r
Definition HudTypes.hpp:25
float g
Definition HudTypes.hpp:25
float b
Definition HudTypes.hpp:25
float a
Definition HudTypes.hpp:25