$darkmode
#include "ui.h"#include "glad/glad.h"#include "io.h"#include "log.h"#include "render_utils.h"#include "shader.h"#include "utils.h"#include <cglm/affine.h>#include <cglm/cam.h>#include <cglm/mat4.h>#include <cglm/types.h>#include <cglm/vec3.h>#include <stb_truetype.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>Data Structures | |
| struct | UIQuad |
Enumerations | |
| enum | FontAtlasConfig { FONT_ATLAS_SIZE = 512 , FONT_FIRST_CHAR = 32 , FONT_CHAR_COUNT = 96 } |
| enum | VertexConfig { QUAD_VERTICES_COUNT = 6 , VERTEX_COMPONENTS = 12 , VERTICES_PER_QUAD = 6 , FLOATS_PER_VERTEX = 12 } |
Functions | |
| static void | setup_ui_render_state (void) |
| static int | create_font_atlas (unsigned char *font_buffer, float font_size, UIContext *ui_context) |
| static int | setup_vertex_buffers (UIContext *ui_context) |
| static void | prepare_batch (UIContext *ui_context, GLuint texture) |
| static UIQuad | make_glyph_quad (const GlyphInfo *glyph, float render_x, float render_y, float scale, const vec3 color, float alpha) |
| int | ui_init (UIContext *ui_context, const char *font_path, float font_size) |
| Initializes the UI system. More... | |
| void | ui_begin (UIContext *ui_context, int screen_width, int screen_height) |
| Begins a new UI batch. More... | |
| void | ui_flush (UIContext *ui_context) |
| Flushes the current UI batch to the GPU. More... | |
| void | ui_end (UIContext *ui_context) |
| Ends the current UI batch and restores OpenGL state. More... | |
| void | ui_draw_text (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, int screen_width, int screen_height) |
| Draws a single text string at a specific coordinate. More... | |
| float | ui_measure_text (const UIContext *ui_context, const char *text) |
| Measures the width of a text string in pixels. More... | |
| void | ui_draw_text_ex (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, float alpha, int screen_width, int screen_height) |
| Draws text with custom alpha transparency. More... | |
| void | ui_draw_text_scaled (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, float alpha, float scale, int screen_width, int screen_height) |
| Draws text with custom alpha transparency and a scale factor. More... | |
| void | ui_draw_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, const vec3 color, int screen_width, int screen_height) |
| Draws a solid color rectangle. More... | |
| void | ui_draw_rect_ex (UIContext *ui_context, float rect_x, float rect_y, float width, float height, const vec3 color, float alpha, int screen_width, int screen_height) |
| Draws a solid color rectangle with custom alpha transparency. More... | |
| void | ui_destroy (UIContext *ui_context) |
| Releases UI resources. More... | |
| void | ui_layout_init (UILayout *layout, UIContext *ui_ctx, float pos_x, float pos_y, float padding, int screen_width, int screen_height) |
| Initializes a layout helper for a frame. More... | |
| void | ui_layout_text (UILayout *layout, const char *text, const vec3 color) |
| Draws text and advances the layout cursor. More... | |
| void | ui_layout_separator (UILayout *layout, float space) |
| Adds vertical space to the layout. More... | |
| void | ui_draw_spinner (UIContext *ui_context, float center_x, float center_y, float size, float angle, const vec3 color, int screen_width, int screen_height) |
| Draws a rotating loading spinner. More... | |
| void | ui_draw_rounded_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, float radius, const vec3 color, float alpha, int screen_width, int screen_height) |
| Draws a rounded rectangle with custom alpha. More... | |
| void | ui_draw_textured_quad (UIContext *ui_context, GLuint texture, float rect_x, float rect_y, float width, float height, const vec3 tint, float alpha, int screen_width, int screen_height) |
| Draws a textured quad tinted by a color (mode 3). More... | |
| void | ui_draw_bloom_quad (UIContext *ui_context, GLuint texture, float rect_x, float rect_y, float width, float height, const vec3 tint, float intensity, int screen_width, int screen_height) |
| Draws a textured quad with additive blending for bloom effects (mode 4). More... | |
| void | ui_draw_glow_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, float radius, const vec3 color, float alpha, int screen_width, int screen_height) |
| Draws an SDF neon glow border around a rounded rectangle area. More... | |
Variables | |
| static const float | FONT_ATLAS_SIZE_F = 512.0F |
| static const float | FONT_BASELINE_OFFSET = 30.0F |
| static const size_t | MAX_FONT_FILE_SIZE = 10 * 1024 * 1024 |
| static const float | UI_QUAD_POS_HALF = 0.5F |
| static const float | UI_QUAD_TEX_MAX = 1.0F |
| static const float | UI_QUAD_MIN = 0.0F |
| static GLStateBackup | g_ui_saved_state |
| enum FontAtlasConfig |
| enum VertexConfig |
|
static |
|
static |
|
static |
|
static |
|
static |
| void ui_begin | ( | UIContext * | ui_context, |
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Begins a new UI batch.
| ui_context | Pointer to the UI context. |
| screen_width | Current window width. |
| screen_height | Current window height. |
| void ui_destroy | ( | UIContext * | ui_context | ) |
Releases UI resources.
| ui_context | Pointer to the struct. |
| void ui_draw_bloom_quad | ( | UIContext * | ui_context, |
| GLuint | texture, | ||
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| const vec3 | tint, | ||
| float | intensity, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a textured quad with additive blending for bloom effects (mode 4).
Uses GL_ONE, GL_ONE blending so dark pixels are invisible and bright pixels add light on top of existing content. The texture should be a radial bloom (bright center, black surround). The tint parameter allows coloring the bloom.
| texture | OpenGL texture handle (bloom PNG, black background). |
| tint | Color of the bloom light (e.g. white or cyan). |
| intensity | Bloom brightness (0.0 = invisible, 1.0 = full). |
| void ui_draw_glow_rect | ( | UIContext * | ui_context, |
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| float | radius, | ||
| const vec3 | color, | ||
| float | alpha, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws an SDF neon glow border around a rounded rectangle area.
| void ui_draw_rect | ( | UIContext * | ui_context, |
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| const vec3 | color, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a solid color rectangle.
| void ui_draw_rect_ex | ( | UIContext * | ui_context, |
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| const vec3 | color, | ||
| float | alpha, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a solid color rectangle with custom alpha transparency.
| void ui_draw_rounded_rect | ( | UIContext * | ui_context, |
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| float | radius, | ||
| const vec3 | color, | ||
| float | alpha, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a rounded rectangle with custom alpha.
| void ui_draw_spinner | ( | UIContext * | ui_context, |
| float | center_x, | ||
| float | center_y, | ||
| float | size, | ||
| float | angle, | ||
| const vec3 | color, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a rotating loading spinner.
| void ui_draw_text | ( | UIContext * | ui_context, |
| const char * | text, | ||
| float | pos_x, | ||
| float | pos_y, | ||
| const vec3 | color, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a single text string at a specific coordinate.
| void ui_draw_text_ex | ( | UIContext * | ui_context, |
| const char * | text, | ||
| float | pos_x, | ||
| float | pos_y, | ||
| const vec3 | color, | ||
| float | alpha, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws text with custom alpha transparency.
| void ui_draw_text_scaled | ( | UIContext * | ui_context, |
| const char * | text, | ||
| float | pos_x, | ||
| float | pos_y, | ||
| const vec3 | color, | ||
| float | alpha, | ||
| float | scale, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws text with custom alpha transparency and a scale factor.
| void ui_draw_textured_quad | ( | UIContext * | ui_context, |
| GLuint | texture, | ||
| float | rect_x, | ||
| float | rect_y, | ||
| float | width, | ||
| float | height, | ||
| const vec3 | tint, | ||
| float | alpha, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Draws a textured quad tinted by a color (mode 3).
The PNG texture's RGB is multiplied by the tint color, and its alpha channel is scaled by the alpha parameter. Use for keycaps and panel frame.
| texture | OpenGL texture handle (RGBA PNG). |
| tint | Tint color multiplied against the texture RGB. |
| alpha | Overall opacity. |
| void ui_end | ( | UIContext * | ui_context | ) |
Ends the current UI batch and restores OpenGL state.
| ui_context | Pointer to the UI context. |
| void ui_flush | ( | UIContext * | ui_context | ) |
Flushes the current UI batch to the GPU.
| ui_context | Pointer to the UI context. |
| int ui_init | ( | UIContext * | ui_context, |
| const char * | font_path, | ||
| float | font_size | ||
| ) |
Initializes the UI system.
| ui_context | Pointer to the struct. |
| font_path | Path to the binary font metrics/texture. |
| font_size | Default scale. |
| void ui_layout_init | ( | UILayout * | layout, |
| UIContext * | ui_ctx, | ||
| float | pos_x, | ||
| float | pos_y, | ||
| float | padding, | ||
| int | screen_width, | ||
| int | screen_height | ||
| ) |
Initializes a layout helper for a frame.
| void ui_layout_separator | ( | UILayout * | layout, |
| float | space | ||
| ) |
Adds vertical space to the layout.
| void ui_layout_text | ( | UILayout * | layout, |
| const char * | text, | ||
| const vec3 | color | ||
| ) |
Draws text and advances the layout cursor.
| float ui_measure_text | ( | const UIContext * | ui_context, |
| const char * | text | ||
| ) |
Measures the width of a text string in pixels.
| ui_context | Pointer to the context. |
| text | The text to measure. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |