group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
HudContext.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "HudTypes.hpp"
7
8#include <array>
9#include <vector>
10
11class SdfAtlas;
12class HudSvgAtlas;
13
19{
20public:
22 void init(const SdfAtlas* atlas, HudSvgAtlas* svgAtlas = nullptr);
23
25 void beginFrame();
26
27 // ── Primitives ──────────────────────────────────────────────────────
28
29 void rect(float x, float y, float w, float h, HudColor color);
30 void rectOutline(float x, float y, float w, float h, float thickness, HudColor color);
31 void roundedRect(float x, float y, float w, float h, float radius, HudColor color);
32 void rotatedRect(float cx, float cy, float w, float h, float angleDeg, HudColor color);
33
41 void gradientRect(float x, float y, float w, float h, HudColor leftColor, HudColor rightColor);
42
44 void triangle(float x0, float y0, float x1, float y1, float x2, float y2, HudColor color);
45
49 void
50 triangleColors(float x0, float y0, HudColor c0, float x1, float y1, HudColor c1, float x2, float y2, HudColor c2);
51
57 void polyline(const float* points, int numPoints, float thickness, HudColor color);
58
59 // ── Bars ────────────────────────────────────────────────────────────
60
61 void bar(float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg);
62
63 // ── Text ────────────────────────────────────────────────────────────
64
71 void text(const char* str,
72 float x,
73 float y,
74 float size,
75 HudColor color,
77 bool outlined = false);
78 void knockoutText(const char* str, float x, float y, float size, HudAlign align = HudAlign::Left);
79 float measureText(const char* str, float size) const;
80 void measureTextVerticalBounds(const char* str, float size, float& outTop, float& outBottom) const;
81
82 // ── Icons ───────────────────────────────────────────────────────────
83
84 bool icon(HudIcon id, float x, float y, float size, HudColor tint = HudColor::white());
85 bool svg(HudIcon id, float x, float y, float w, float h, HudColor tint = HudColor::white());
86 bool svgFlipped(HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor tint = HudColor::white());
87 bool svgPartialX(HudIcon id, float x, float y, float w, float h, float fraction, HudColor tint = HudColor::white());
88 bool svgMask(HudIcon id, float x, float y, float w, float h, HudColor color);
89 bool svgMaskFlipped(HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor color);
90 bool svgMaskPartialX(HudIcon id, float x, float y, float w, float h, float fraction, HudColor color);
91 bool svgMaskRangeX(HudIcon id, float x, float y, float w, float h, float startFraction, float endFraction, HudColor color);
93 float x,
94 float y,
95 float w,
96 float h,
97 float fraction,
98 bool fromRight,
99 bool flipX,
100 bool flipY,
101 HudColor color);
102
103 // ── Crosshair ───────────────────────────────────────────────────────
104
105 void crosshair(const CrosshairStyle& style, float screenW, float screenH);
106
107 // ── Vignette ────────────────────────────────────────────────────────
108
113 void vignette(float screenW, float screenH, HudColor color);
114
120 void scopeMask(float screenW, float screenH, float radiusPx, HudColor color);
121
122 // ── Clipping ────────────────────────────────────────────────────────
123
124 void pushClipRect(float x, float y, float w, float h);
125 void popClipRect();
126
129 void endFrame();
130
132 void tintVertices(std::size_t startVertex, HudColor tint);
133
135 void rotateVertices(std::size_t startVertex, float cx, float cy, float angleDeg);
136
137 // ── Access for HudRenderer ──────────────────────────────────────────
138
139 [[nodiscard]] const std::vector<HudVertex>& vertices() const { return vertices_; }
140
143 [[nodiscard]] const std::vector<std::array<float, 6>>& clipSpans() const { return clipSpans_; }
144
145private:
146 const SdfAtlas* sdfAtlas_ = nullptr;
148 std::vector<HudVertex> vertices_;
149 std::vector<std::array<float, 6>> clipSpans_;
150
151 // Clip stack: each entry is {x, y, w, h}. Empty = no clip.
152 std::vector<std::array<float, 4>> clipStack_;
153 uint32_t spanStartVertex_ = 0;
154 bool spanDirty_ = false;
155
157 void emitQuad(float x,
158 float y,
159 float w,
160 float h,
161 float u0,
162 float v0,
163 float u1,
164 float v1,
165 HudColor color,
166 float texMode,
167 float sd0 = 0.f,
168 float sd1 = 0.f,
169 float sd2 = 0.f);
170
172 void flushClipSpan();
173};
Shared types for the HUD system.
HudAlign
Definition HudTypes.hpp:55
@ Left
Definition HudTypes.hpp:56
HudIcon
Icon identifiers for the HUD icon atlas.
Definition HudTypes.hpp:63
Accumulates HUD geometry during a frame for batch rendering.
Definition HudContext.hpp:19
void beginFrame()
Clear all geometry for a new frame.
Definition HudContext.cpp:21
void bar(float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg)
Definition HudContext.cpp:268
bool svgMaskFlipped(HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor color)
Definition HudContext.cpp:484
bool svg(HudIcon id, float x, float y, float w, float h, HudColor tint=HudColor::white())
Definition HudContext.cpp:434
const SdfAtlas * sdfAtlas_
Definition HudContext.hpp:146
bool svgMaskRangeX(HudIcon id, float x, float y, float w, float h, float startFraction, float endFraction, HudColor color)
Definition HudContext.cpp:524
bool svgFlipped(HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor tint=HudColor::white())
Definition HudContext.cpp:439
const std::vector< std::array< float, 6 > > & clipSpans() const
Clip rect spans: {startVertex, vertexCount, x, y, w, h}.
Definition HudContext.hpp:143
bool svgMaskPartialX(HudIcon id, float x, float y, float w, float h, float fraction, HudColor color)
Definition HudContext.cpp:503
void rotateVertices(std::size_t startVertex, float cx, float cy, float angleDeg)
Rotate vertices emitted since startVertex around a screen-space point.
Definition HudContext.cpp:53
void flushClipSpan()
Flush the current clip span before changing scissor state.
Definition HudContext.cpp:106
void pushClipRect(float x, float y, float w, float h)
Definition HudContext.cpp:626
void rotatedRect(float cx, float cy, float w, float h, float angleDeg, HudColor color)
Definition HudContext.cpp:141
HudSvgAtlas * svgAtlas_
Definition HudContext.hpp:147
void knockoutText(const char *str, float x, float y, float size, HudAlign align=HudAlign::Left)
Definition HudContext.cpp:345
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
void vignette(float screenW, float screenH, HudColor color)
Draw a full-screen radial vignette overlay.
Definition HudContext.cpp:611
void polyline(const float *points, int numPoints, float thickness, HudColor color)
Stroke a polyline with sharp-mitred corners using rotated rects.
Definition HudContext.cpp:226
std::vector< std::array< float, 6 > > clipSpans_
Definition HudContext.hpp:149
bool svgMaskPartialXFlipped(HudIcon id, float x, float y, float w, float h, float fraction, bool fromRight, bool flipX, bool flipY, HudColor color)
Definition HudContext.cpp:549
void triangleColors(float x0, float y0, HudColor c0, float x1, float y1, HudColor c1, float x2, float y2, HudColor c2)
Triangle with per-vertex colors — the rasteriser interpolates across the surface.
Definition HudContext.cpp:214
uint32_t spanStartVertex_
Vertex index where current clip span started.
Definition HudContext.hpp:153
std::vector< HudVertex > vertices_
Definition HudContext.hpp:148
void tintVertices(std::size_t startVertex, HudColor tint)
Multiply already-emitted vertex colors by a tint.
Definition HudContext.cpp:37
bool svgMask(HudIcon id, float x, float y, float w, float h, HudColor color)
Definition HudContext.cpp:479
void init(const SdfAtlas *atlas, HudSvgAtlas *svgAtlas=nullptr)
Bind the SDF atlas for text layout (glyph metrics).
Definition HudContext.cpp:15
float measureText(const char *str, float size) const
Definition HudContext.cpp:382
void triangle(float x0, float y0, float x1, float y1, float x2, float y2, HudColor color)
Emit a single solid-colored triangle (3 vertices).
Definition HudContext.cpp:203
bool svgPartialX(HudIcon id, float x, float y, float w, float h, float fraction, HudColor tint=HudColor::white())
Definition HudContext.cpp:458
void rectOutline(float x, float y, float w, float h, float thickness, HudColor color)
Definition HudContext.cpp:173
bool icon(HudIcon id, float x, float y, float size, HudColor tint=HudColor::white())
Definition HudContext.cpp:429
void emitQuad(float x, float y, float w, float h, float u0, float v0, float u1, float v1, HudColor color, float texMode, float sd0=0.f, float sd1=0.f, float sd2=0.f)
Emit 6 vertices for a textured quad.
Definition HudContext.cpp:71
const std::vector< HudVertex > & vertices() const
Definition HudContext.hpp:139
void measureTextVerticalBounds(const char *str, float size, float &outTop, float &outBottom) const
Definition HudContext.cpp:397
void scopeMask(float screenW, float screenH, float radiusPx, HudColor color)
Draw a full-screen scope mask with a transparent circular cut-out.
Definition HudContext.cpp:617
void crosshair(const CrosshairStyle &style, float screenW, float screenH)
Definition HudContext.cpp:589
bool spanDirty_
Definition HudContext.hpp:154
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 endFrame()
Flush any remaining unflushed vertices into a final clip span.
Definition HudContext.cpp:30
void roundedRect(float x, float y, float w, float h, float radius, HudColor color)
Definition HudContext.cpp:247
void rect(float x, float y, float w, float h, HudColor color)
Definition HudContext.cpp:136
std::vector< std::array< float, 4 > > clipStack_
Definition HudContext.hpp:152
void popClipRect()
Definition HudContext.cpp:633
Definition HudSvgAtlas.hpp:26
Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.
Definition SdfAtlas.hpp:18
Crosshair appearance parameters.
Definition HudTypes.hpp:133
RGBA color for HUD elements (linear space, straight alpha).
Definition HudTypes.hpp:24
static constexpr HudColor white()
Definition HudTypes.hpp:30