84 if (surface == NULL) { |
84 if (surface == NULL) { |
85 asc_error("Rendering TTF surface failed: %s", SDL_GetError()); |
85 asc_error("Rendering TTF surface failed: %s", SDL_GetError()); |
86 return; |
86 return; |
87 } |
87 } |
88 if (asc_test_flag(text->base.flags, ASC_TEXT_CENTERED_FLAG)) { |
88 if (asc_test_flag(text->base.flags, ASC_TEXT_CENTERED_FLAG)) { |
89 unsigned short newoffx = surface->w / 2; |
89 asc_node_set_origin(node, ASC_VEC3F(surface->w / 2, 0, 0)); |
90 asc_transform_translate2f(node->transform, ASC_VEC2F(text->offx - newoffx, 0)); |
|
91 text->offx = newoffx; |
|
92 } |
90 } |
93 |
91 |
94 // Transfer Image Data |
92 // Transfer Image Data |
95 asc_texture_from_surface(text->texture, surface); |
93 asc_texture_from_surface(text->texture, surface); |
96 |
94 |
149 asc_scene_node_name(node, args.name); |
147 asc_scene_node_name(node, args.name); |
150 node->render_group = ASC_RENDER_GROUP_2D_BLEND; |
148 node->render_group = ASC_RENDER_GROUP_2D_BLEND; |
151 node->destroy_func = asc_text_destroy; |
149 node->destroy_func = asc_text_destroy; |
152 node->update_func = asc_text_update; |
150 node->update_func = asc_text_update; |
153 node->draw_func = asc_text_draw; |
151 node->draw_func = asc_text_draw; |
154 asc_transform_identity(node->transform); |
152 node->position = ASC_VEC3F(args.x, args.y, ASC_SCENE_2D_DEPTH_OFFSET); |
155 asc_transform_translate3f(node->transform, |
153 node->scale = ASC_VEC3F_1; |
156 ASC_VEC3F(args.x, args.y, ASC_SCENE_2D_DEPTH_OFFSET)); |
154 asc_mat4f_unit(node->rotation); |
157 |
155 |
158 // text properties |
156 // text properties |
159 node->flags = args.alignment; // use flags variable to save some space |
157 node->flags = args.alignment; // use flags variable to save some space |
160 text->max_width = args.max_width; |
158 text->max_width = args.max_width; |
161 text->font = asc_active_font; |
159 text->font = asc_active_font; |
162 text->color = asc_context.ink; |
160 text->color = asc_context.ink; |
163 if (args.text == NULL) { |
161 if (args.text == NULL) { |
164 text->text = cx_mutstr(strdup(" ")); |
162 text->text = cx_mutstr(strdup(" ")); |
165 } else { |
163 } else { |
166 text->text = cx_mutstr(strdup(args.text)); |
164 text->text = cx_mutstr(strdup(args.text)); |
|
165 } |
|
166 if (args.centered) { |
|
167 asc_set_flag(node->flags, ASC_TEXT_CENTERED_FLAG); |
167 } |
168 } |
168 |
169 |
169 // initialize texture |
170 // initialize texture |
170 // mesh will be created in the update func |
171 // mesh will be created in the update func |
171 text->texture = cxMallocDefault(sizeof(AscTexture)); |
172 text->texture = cxMallocDefault(sizeof(AscTexture)); |