# HG changeset patch # User Mike Becker # Date 1705611196 -3600 # Node ID ab07757004b4ce5c9c4c63a77003fd86bdd147f6 # Parent 30b12e88fd846d410ca76353f1dea4b815a07031 don't force the use of CxBuffer in AscTextNode diff -r 30b12e88fd84 -r ab07757004b4 src/ascension/text.h --- a/src/ascension/text.h Mon Dec 18 19:05:30 2023 +0100 +++ b/src/ascension/text.h Thu Jan 18 21:53:16 2024 +0100 @@ -33,7 +33,7 @@ #include typedef struct AscTextNode { - CxBuffer text; + char *text; AscFont const *font; asc_vec2i position; asc_col4i color; diff -r 30b12e88fd84 -r ab07757004b4 src/text.c --- a/src/text.c Mon Dec 18 19:05:30 2023 +0100 +++ b/src/text.c Thu Jan 18 21:53:16 2024 +0100 @@ -42,9 +42,7 @@ node->position = (asc_vec2i) {x, y}; node->font = asc_context.active_font; node->color = asc_context.ink; - cxBufferInit(&node->text, NULL, strlen(text)+8, - cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); - cxBufferPutString(&node->text, text); + node->text = strdup(text); return node; } @@ -64,15 +62,10 @@ asc_dprintf("Generated new texture for text node: %u", node->internal.tex_id); } - // ensure the text is zero-terminated - CxBuffer* text = &(node->text); - cxBufferMinimumCapacity(text, text->size+1); - text->space[text->size] = '\0'; - // Render text onto a surface SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped( asc_font_cache_validate(node->font)->ptr, - text->space, + node->text, asc_col_sdl(node->color), node->max_width ); @@ -136,6 +129,6 @@ void asc_text_free(AscTextNode *node) { asc_dprintf("Release text node texture: %u", node->internal.tex_id); glDeleteTextures(1, &node->internal.tex_id); - cxBufferDestroy(&node->text); + free(node->text); free(node); } \ No newline at end of file diff -r 30b12e88fd84 -r ab07757004b4 test/sandbox.c --- a/test/sandbox.c Mon Dec 18 19:05:30 2023 +0100 +++ b/test/sandbox.c Thu Jan 18 21:53:16 2024 +0100 @@ -54,7 +54,7 @@ asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); asc_ink_rgb(255, 0, 0); - AscTextNode *fps_counter = asc_text(50, 50, "60 FPS"); + AscTextNode *fps_counter = asc_text(50, 50, "9999 FPS"); unsigned last_fps = 0; while (asc_loop_next()) { @@ -67,8 +67,7 @@ unsigned fps = 1000u / asc_context.elapsed_millis; if (fps != last_fps) { last_fps = fps; - cxBufferReset(&fps_counter->text); - cx_bprintf(&fps_counter->text, "%u FPS", fps); + snprintf(fps_counter->text, 9, "%u FPS", fps); asc_text_update(fps_counter); } }