group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
HudContext Class Reference

Accumulates HUD geometry during a frame for batch rendering. More...

#include <HudContext.hpp>

Collaboration diagram for HudContext:
[legend]

Public Member Functions

void init (const SdfAtlas *atlas, HudSvgAtlas *svgAtlas=nullptr)
 Bind the SDF atlas for text layout (glyph metrics).
void beginFrame ()
 Clear all geometry for a new frame.
void rect (float x, float y, float w, float h, HudColor color)
void rectOutline (float x, float y, float w, float h, float thickness, HudColor color)
void roundedRect (float x, float y, float w, float h, float radius, HudColor color)
void rotatedRect (float cx, float cy, float w, float h, float angleDeg, HudColor color)
void gradientRect (float x, float y, float w, float h, HudColor leftColor, HudColor rightColor)
 Filled rect with a horizontal color gradient.
void triangle (float x0, float y0, float x1, float y1, float x2, float y2, HudColor color)
 Emit a single solid-colored triangle (3 vertices).
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.
void polyline (const float *points, int numPoints, float thickness, HudColor color)
 Stroke a polyline with sharp-mitred corners using rotated rects.
void bar (float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg)
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.
void knockoutText (const char *str, float x, float y, float size, HudAlign align=HudAlign::Left)
float measureText (const char *str, float size) const
void measureTextVerticalBounds (const char *str, float size, float &outTop, float &outBottom) const
bool icon (HudIcon id, float x, float y, float size, HudColor tint=HudColor::white())
bool svg (HudIcon id, float x, float y, float w, float h, HudColor tint=HudColor::white())
bool svgFlipped (HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor tint=HudColor::white())
bool svgPartialX (HudIcon id, float x, float y, float w, float h, float fraction, HudColor tint=HudColor::white())
bool svgMask (HudIcon id, float x, float y, float w, float h, HudColor color)
bool svgMaskFlipped (HudIcon id, float x, float y, float w, float h, bool flipX, bool flipY, HudColor color)
bool svgMaskPartialX (HudIcon id, float x, float y, float w, float h, float fraction, HudColor color)
bool svgMaskRangeX (HudIcon id, float x, float y, float w, float h, float startFraction, float endFraction, HudColor color)
bool svgMaskPartialXFlipped (HudIcon id, float x, float y, float w, float h, float fraction, bool fromRight, bool flipX, bool flipY, HudColor color)
void crosshair (const CrosshairStyle &style, float screenW, float screenH)
void vignette (float screenW, float screenH, HudColor color)
 Draw a full-screen radial vignette overlay.
void scopeMask (float screenW, float screenH, float radiusPx, HudColor color)
 Draw a full-screen scope mask with a transparent circular cut-out.
void pushClipRect (float x, float y, float w, float h)
void popClipRect ()
void endFrame ()
 Flush any remaining unflushed vertices into a final clip span.
void tintVertices (std::size_t startVertex, HudColor tint)
 Multiply already-emitted vertex colors by a tint.
void rotateVertices (std::size_t startVertex, float cx, float cy, float angleDeg)
 Rotate vertices emitted since startVertex around a screen-space point.
const std::vector< HudVertex > & vertices () const
const std::vector< std::array< float, 6 > > & clipSpans () const
 Clip rect spans: {startVertex, vertexCount, x, y, w, h}.

Private Member Functions

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.
void flushClipSpan ()
 Flush the current clip span before changing scissor state.

Private Attributes

const SdfAtlassdfAtlas_ = nullptr
HudSvgAtlassvgAtlas_ = nullptr
std::vector< HudVertexvertices_
std::vector< std::array< float, 6 > > clipSpans_
std::vector< std::array< float, 4 > > clipStack_
uint32_t spanStartVertex_ = 0
 Vertex index where current clip span started.
bool spanDirty_ = false

Detailed Description

Accumulates HUD geometry during a frame for batch rendering.

Widgets call rect(), text(), bar(), etc. to emit quads. At the end of the frame, HudRenderer consumes the vertex buffer and clip rect list.

Member Function Documentation

◆ bar()

void HudContext::bar ( float x,
float y,
float w,
float h,
float fill01,
HudColor fg,
HudColor bg )
Here is the call graph for this function:

◆ beginFrame()

void HudContext::beginFrame ( )

Clear all geometry for a new frame.

◆ clipSpans()

const std::vector< std::array< float, 6 > > & HudContext::clipSpans ( ) const
inlinenodiscard

Clip rect spans: {startVertex, vertexCount, x, y, w, h}.

Negative w means "full viewport" (no scissor).

◆ crosshair()

void HudContext::crosshair ( const CrosshairStyle & style,
float screenW,
float screenH )
Here is the call graph for this function:

◆ emitQuad()

void HudContext::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 )
private

Emit 6 vertices for a textured quad.

Here is the caller graph for this function:

◆ endFrame()

void HudContext::endFrame ( )

Flush any remaining unflushed vertices into a final clip span.

Must be called after all draw() calls, before accessing vertices/clipSpans.

Here is the call graph for this function:

◆ flushClipSpan()

void HudContext::flushClipSpan ( )
private

Flush the current clip span before changing scissor state.

Here is the caller graph for this function:

◆ gradientRect()

void HudContext::gradientRect ( float x,
float y,
float w,
float h,
HudColor leftColor,
HudColor rightColor )

Filled rect with a horizontal color gradient.

leftColor is at the left edge, rightColor at the right. The rasteriser perspective-correct-interpolates per-vertex colors across the quad, so the gradient is exact at any size and any rotation (though we only emit axis-aligned gradients here — the design's HP / shield bars are horizontal).

◆ icon()

bool HudContext::icon ( HudIcon id,
float x,
float y,
float size,
HudColor tint = HudColor::white() )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void HudContext::init ( const SdfAtlas * atlas,
HudSvgAtlas * svgAtlas = nullptr )

Bind the SDF atlas for text layout (glyph metrics).

◆ knockoutText()

void HudContext::knockoutText ( const char * str,
float x,
float y,
float size,
HudAlign align = HudAlign::Left )
Here is the call graph for this function:

◆ measureText()

float HudContext::measureText ( const char * str,
float size ) const
Here is the caller graph for this function:

◆ measureTextVerticalBounds()

void HudContext::measureTextVerticalBounds ( const char * str,
float size,
float & outTop,
float & outBottom ) const
Here is the caller graph for this function:

◆ polyline()

void HudContext::polyline ( const float * points,
int numPoints,
float thickness,
HudColor color )

Stroke a polyline with sharp-mitred corners using rotated rects.

Parameters
points2*N pairs (x0,y0,x1,y1,...) — N >= 2.
numPointsNumber of (x,y) points.
thicknessLine width in pixels.
colorStroke color.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ popClipRect()

void HudContext::popClipRect ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushClipRect()

void HudContext::pushClipRect ( float x,
float y,
float w,
float h )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect()

void HudContext::rect ( float x,
float y,
float w,
float h,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rectOutline()

void HudContext::rectOutline ( float x,
float y,
float w,
float h,
float thickness,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotatedRect()

void HudContext::rotatedRect ( float cx,
float cy,
float w,
float h,
float angleDeg,
HudColor color )
Here is the caller graph for this function:

◆ rotateVertices()

void HudContext::rotateVertices ( std::size_t startVertex,
float cx,
float cy,
float angleDeg )

Rotate vertices emitted since startVertex around a screen-space point.

Here is the caller graph for this function:

◆ roundedRect()

void HudContext::roundedRect ( float x,
float y,
float w,
float h,
float radius,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scopeMask()

void HudContext::scopeMask ( float screenW,
float screenH,
float radiusPx,
HudColor color )

Draw a full-screen scope mask with a transparent circular cut-out.

Parameters
screenWViewport width in pixels.
screenHViewport height in pixels.
radiusPxRadius of the clear scope glass in pixels.
colorMask tint; alpha controls opacity outside the cut-out.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svg()

bool HudContext::svg ( HudIcon id,
float x,
float y,
float w,
float h,
HudColor tint = HudColor::white() )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svgFlipped()

bool HudContext::svgFlipped ( HudIcon id,
float x,
float y,
float w,
float h,
bool flipX,
bool flipY,
HudColor tint = HudColor::white() )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svgMask()

bool HudContext::svgMask ( HudIcon id,
float x,
float y,
float w,
float h,
HudColor color )
Here is the call graph for this function:

◆ svgMaskFlipped()

bool HudContext::svgMaskFlipped ( HudIcon id,
float x,
float y,
float w,
float h,
bool flipX,
bool flipY,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svgMaskPartialX()

bool HudContext::svgMaskPartialX ( HudIcon id,
float x,
float y,
float w,
float h,
float fraction,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svgMaskPartialXFlipped()

bool HudContext::svgMaskPartialXFlipped ( HudIcon id,
float x,
float y,
float w,
float h,
float fraction,
bool fromRight,
bool flipX,
bool flipY,
HudColor color )
Here is the call graph for this function:

◆ svgMaskRangeX()

bool HudContext::svgMaskRangeX ( HudIcon id,
float x,
float y,
float w,
float h,
float startFraction,
float endFraction,
HudColor color )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ svgPartialX()

bool HudContext::svgPartialX ( HudIcon id,
float x,
float y,
float w,
float h,
float fraction,
HudColor tint = HudColor::white() )
Here is the call graph for this function:

◆ text()

void HudContext::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.

Parameters
outlinedWhen true the glyph picks up a 1-px dark outline for legibility against bright/varied backgrounds (damage numbers over the world, etc.). Defaults to off so text rendered onto the dark Voidfall panel chrome stays clean and doesn't gain a "sticker" look.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tintVertices()

void HudContext::tintVertices ( std::size_t startVertex,
HudColor tint )

Multiply already-emitted vertex colors by a tint.

◆ triangle()

void HudContext::triangle ( float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
HudColor color )

Emit a single solid-colored triangle (3 vertices).

Here is the caller graph for this function:

◆ triangleColors()

void HudContext::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.

Used by chamfered / pentagon panels that need a horizontal or radial gradient.

◆ vertices()

const std::vector< HudVertex > & HudContext::vertices ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ vignette()

void HudContext::vignette ( float screenW,
float screenH,
HudColor color )

Draw a full-screen radial vignette overlay.

Parameters
screenWViewport width in pixels.
screenHViewport height in pixels.
colorTint color with alpha controlling intensity.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ clipSpans_

std::vector<std::array<float, 6> > HudContext::clipSpans_
private

◆ clipStack_

std::vector<std::array<float, 4> > HudContext::clipStack_
private

◆ sdfAtlas_

const SdfAtlas* HudContext::sdfAtlas_ = nullptr
private

◆ spanDirty_

bool HudContext::spanDirty_ = false
private

◆ spanStartVertex_

uint32_t HudContext::spanStartVertex_ = 0
private

Vertex index where current clip span started.

◆ svgAtlas_

HudSvgAtlas* HudContext::svgAtlas_ = nullptr
private

◆ vertices_

std::vector<HudVertex> HudContext::vertices_
private

The documentation for this class was generated from the following files: