40 } |
40 } |
41 |
41 |
42 node->position = (asc_vec2i) {x, y}; |
42 node->position = (asc_vec2i) {x, y}; |
43 node->font = asc_context.active_font; |
43 node->font = asc_context.active_font; |
44 node->color = asc_context.ink; |
44 node->color = asc_context.ink; |
45 cxBufferInit(&node->text, NULL, strlen(text)+8, |
45 node->text = strdup(text); |
46 cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); |
|
47 cxBufferPutString(&node->text, text); |
|
48 |
46 |
49 return node; |
47 return node; |
50 } |
48 } |
51 |
49 |
52 void asc_text_update(AscTextNode *node) { |
50 void asc_text_update(AscTextNode *node) { |
62 glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
60 glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
63 glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
61 glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
64 asc_dprintf("Generated new texture for text node: %u", node->internal.tex_id); |
62 asc_dprintf("Generated new texture for text node: %u", node->internal.tex_id); |
65 } |
63 } |
66 |
64 |
67 // ensure the text is zero-terminated |
|
68 CxBuffer* text = &(node->text); |
|
69 cxBufferMinimumCapacity(text, text->size+1); |
|
70 text->space[text->size] = '\0'; |
|
71 |
|
72 // Render text onto a surface |
65 // Render text onto a surface |
73 SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped( |
66 SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped( |
74 asc_font_cache_validate(node->font)->ptr, |
67 asc_font_cache_validate(node->font)->ptr, |
75 text->space, |
68 node->text, |
76 asc_col_sdl(node->color), |
69 asc_col_sdl(node->color), |
77 node->max_width |
70 node->max_width |
78 ); |
71 ); |
79 if (surface == NULL) { |
72 if (surface == NULL) { |
80 asc_error(SDL_GetError()); |
73 asc_error(SDL_GetError()); |