1 #include "meshbuilder.h"
10 Text::Text(const Font &f, const Technique *tech):
12 mesh((TEXCOORD2, VERTEX2)),
17 object.set_mesh(&mesh);
22 void Text::set_technique(const Technique *tech)
27 technique.replace_texture("diffuse_map", font.get_texture());
28 object.set_technique(&technique);
31 object.set_technique(0);
34 void Text::set_text(const string &text, StringCodec::Decoder &dec)
37 width = font.get_string_width(text, dec);
38 MeshBuilder bld(mesh);
39 bld.matrix() *= Matrix::translation(Vector3(-horz_align*width, vert_offset, 0.0f));
40 font.build_string(text, dec, bld);
49 void Text::set_alignment(HorizontalAlign ha, VerticalAlign va)
54 case LEFT: h = 0.0f; break;
55 case CENTER: h = 0.5f; break;
56 case RIGHT: h = 1.0f; break;
57 default: throw invalid_argument("Text::set_alignment");
63 case DESCENT: v = -font.get_descent(); break;
64 case BASELINE: v = 0.0f; break;
65 case MIDLINE: v = font.get_cap_height()/2; break;
66 case ASCENT: v = font.get_ascent(); break;
67 default: throw invalid_argument("Text::set_alignment");
73 void Text::set_alignment(float h, float v)
75 if(h==horz_align && -v==vert_offset)
78 float horz_adjust = (horz_align-h)*width;
79 float vert_adjust = -v-vert_offset;
83 unsigned pos_offset = mesh.get_vertices().get_format().offset(VERTEX2);
84 unsigned n_vertices = mesh.get_n_vertices();
85 for(unsigned i=0; i<n_vertices; ++i)
87 float *pos = mesh.modify_vertex(i)+pos_offset;
88 pos[0] += horz_adjust;
89 pos[1] += vert_adjust;
93 void Text::render(Renderer &renderer, const Tag &tag) const
95 object.render(renderer, tag);