71 TTF_HORIZONTAL_ALIGN_CENTER, |
71 TTF_HORIZONTAL_ALIGN_CENTER, |
72 TTF_HORIZONTAL_ALIGN_RIGHT |
72 TTF_HORIZONTAL_ALIGN_RIGHT |
73 }; |
73 }; |
74 TTF_SetFontWrapAlignment( |
74 TTF_SetFontWrapAlignment( |
75 font, alignments[text->base.flags & ASC_TEXT_ALIGNMENT_MASK]); |
75 font, alignments[text->base.flags & ASC_TEXT_ALIGNMENT_MASK]); |
76 // TODO: it looks like TTF_RenderText_Blended_Wrapped is broken in SDL 3 |
76 SDL_Surface *surface = TTF_RenderText_Blended_Wrapped( |
77 SDL_Surface *surface = TTF_RenderText_Blended( |
77 font, text->text.ptr, text->text.length, asc_col_sdl(text->color), text->max_width |
78 font, text->text.ptr, text->text.length, asc_col_sdl(text->color)//, text->max_width |
|
79 ); |
78 ); |
80 if (surface == NULL) { |
79 if (surface == NULL) { |
81 asc_error("Rendering TTF surface failed: %s", SDL_GetError()); |
80 asc_error("Rendering TTF surface failed: %s", SDL_GetError()); |
82 return; |
81 return; |
83 } |
82 } |
208 void asc_text_printf( |
207 void asc_text_printf( |
209 AscText *node, |
208 AscText *node, |
210 const char *format, |
209 const char *format, |
211 ... |
210 ... |
212 ) { |
211 ) { |
|
212 size_t buflen = node->text.length + 1; |
213 va_list ap; |
213 va_list ap; |
214 va_start(ap, format); |
214 va_start(ap, format); |
215 cx_vsprintf( |
215 int ret = cx_vsprintf( |
216 &node->text.ptr, |
216 &node->text.ptr, |
217 &node->text.length, |
217 &buflen, |
218 format, |
218 format, |
219 ap |
219 ap |
220 ); |
220 ); |
221 va_end(ap); |
221 va_end(ap); |
|
222 if (ret < 0) { |
|
223 asc_wprintf("Unexpected error code when formatting text: %d", ret); |
|
224 node->text.length = 0; |
|
225 } else { |
|
226 node->text.length = ret; |
|
227 } |
222 asc_scene_node_update((AscSceneNode*)node); |
228 asc_scene_node_update((AscSceneNode*)node); |
223 } |
229 } |
224 |
230 |