src/text.c

changeset 23
ab07757004b4
parent 19
d0e88022e209
child 24
7183b4ae9b20
--- 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

mercurial