From ac6ef66cc8f60ecc9d7ee8691bf7a73fcc24f4b7 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sun, 16 Feb 2025 21:13:58 -0500 Subject: renderer: set font size functions on init --- renderer.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'renderer.c') diff --git a/renderer.c b/renderer.c index 4720ac0..5bbfbcb 100644 --- a/renderer.c +++ b/renderer.c @@ -12,6 +12,10 @@ enum window { HEIGHT = 600, }; +enum text { + TEXT_HEIGHT = 18, +}; + static const mu_Color COLOR_BG = {0, 0, 0, 255}; static const char button_map[256] = { @@ -42,6 +46,27 @@ static int buf_idx; static SDL_Window *window; +static int text_width(mu_Font font, const char *text, int len) { + if (len < 0) { + len = strlen(text); + } + + int res = 0; + for (const char *p = text; *p && len--; p++) { + if ((*p & 0xc0) == 0x80) { continue; } + int chr = mu_min((unsigned char) *p, 127); + res += atlas[ATLAS_FONT + chr].w; + } + return res; +} + + +static int +text_height(mu_Font font) { + return TEXT_HEIGHT; +} + + static void flush(void) { if (buf_idx == 0) { return; } @@ -211,7 +236,7 @@ static void render_command(mu_Command *cmd) { } -void r_init(void) { +void r_init(mu_Context *ctx) { /* init SDL window */ SDL_Init(SDL_INIT_EVERYTHING); window = SDL_CreateWindow( @@ -239,6 +264,10 @@ void r_init(void) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); assert(glGetError() == 0); + + /* init microui */ + ctx->text_width = text_width; + ctx->text_height = text_height; } @@ -266,22 +295,6 @@ void r_present(void) { } -int r_get_text_width(const char *text, int len) { - int res = 0; - for (const char *p = text; *p && len--; p++) { - if ((*p & 0xc0) == 0x80) { continue; } - int chr = mu_min((unsigned char) *p, 127); - res += atlas[ATLAS_FONT + chr].w; - } - return res; -} - - -int r_get_text_height(void) { - return 18; -} - - void r_get_window_size(int *w, int *h) { SDL_GetWindowSize(window, w, h); } -- cgit v1.2.3