Thu, 18 Jan 2024 21:53:16 +0100
don't force the use of CxBuffer in AscTextNode
src/ascension/text.h | file | annotate | diff | comparison | revisions | |
src/text.c | file | annotate | diff | comparison | revisions | |
test/sandbox.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/ascension/text.h Mon Dec 18 19:05:30 2023 +0100 1.2 +++ b/src/ascension/text.h Thu Jan 18 21:53:16 2024 +0100 1.3 @@ -33,7 +33,7 @@ 1.4 #include <cx/buffer.h> 1.5 1.6 typedef struct AscTextNode { 1.7 - CxBuffer text; 1.8 + char *text; 1.9 AscFont const *font; 1.10 asc_vec2i position; 1.11 asc_col4i color;
2.1 --- a/src/text.c Mon Dec 18 19:05:30 2023 +0100 2.2 +++ b/src/text.c Thu Jan 18 21:53:16 2024 +0100 2.3 @@ -42,9 +42,7 @@ 2.4 node->position = (asc_vec2i) {x, y}; 2.5 node->font = asc_context.active_font; 2.6 node->color = asc_context.ink; 2.7 - cxBufferInit(&node->text, NULL, strlen(text)+8, 2.8 - cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); 2.9 - cxBufferPutString(&node->text, text); 2.10 + node->text = strdup(text); 2.11 2.12 return node; 2.13 } 2.14 @@ -64,15 +62,10 @@ 2.15 asc_dprintf("Generated new texture for text node: %u", node->internal.tex_id); 2.16 } 2.17 2.18 - // ensure the text is zero-terminated 2.19 - CxBuffer* text = &(node->text); 2.20 - cxBufferMinimumCapacity(text, text->size+1); 2.21 - text->space[text->size] = '\0'; 2.22 - 2.23 // Render text onto a surface 2.24 SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped( 2.25 asc_font_cache_validate(node->font)->ptr, 2.26 - text->space, 2.27 + node->text, 2.28 asc_col_sdl(node->color), 2.29 node->max_width 2.30 ); 2.31 @@ -136,6 +129,6 @@ 2.32 void asc_text_free(AscTextNode *node) { 2.33 asc_dprintf("Release text node texture: %u", node->internal.tex_id); 2.34 glDeleteTextures(1, &node->internal.tex_id); 2.35 - cxBufferDestroy(&node->text); 2.36 + free(node->text); 2.37 free(node); 2.38 } 2.39 \ No newline at end of file
3.1 --- a/test/sandbox.c Mon Dec 18 19:05:30 2023 +0100 3.2 +++ b/test/sandbox.c Thu Jan 18 21:53:16 2024 +0100 3.3 @@ -54,7 +54,7 @@ 3.4 3.5 asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); 3.6 asc_ink_rgb(255, 0, 0); 3.7 - AscTextNode *fps_counter = asc_text(50, 50, "60 FPS"); 3.8 + AscTextNode *fps_counter = asc_text(50, 50, "9999 FPS"); 3.9 unsigned last_fps = 0; 3.10 3.11 while (asc_loop_next()) { 3.12 @@ -67,8 +67,7 @@ 3.13 unsigned fps = 1000u / asc_context.elapsed_millis; 3.14 if (fps != last_fps) { 3.15 last_fps = fps; 3.16 - cxBufferReset(&fps_counter->text); 3.17 - cx_bprintf(&fps_counter->text, "%u FPS", fps); 3.18 + snprintf(fps_counter->text, 9, "%u FPS", fps); 3.19 asc_text_update(fps_counter); 3.20 } 3.21 }