]> git.tdb.fi Git - libs/gl.git/blob - source/text.h
Visit the rest of an iteration statement in NodeRemover
[libs/gl.git] / source / text.h
1 #ifndef MSP_GL_TEXT_H_
2 #define MSP_GL_TEXT_H_
3
4 #include "font.h"
5 #include "mesh.h"
6 #include "object.h"
7 #include "technique.h"
8
9 namespace Msp {
10 namespace GL {
11
12 /**
13 Creates an object consisting of the visual representation of a string.  Can be
14 used with an ObjectInstance to further customize the appearance.
15 */
16 class Text: public Renderable
17 {
18 public:
19         enum HorizontalAlign
20         {
21                 LEFT,
22                 CENTER,
23                 RIGHT
24         };
25
26         enum VerticalAlign
27         {
28                 DESCENT,
29                 BASELINE,
30                 MIDLINE,
31                 ASCENT
32         };
33
34 private:
35         const Font &font;
36         Mesh mesh;
37         Object object;
38         Technique technique;
39         float horz_align;
40         float vert_offset;
41         float width;
42
43 public:
44         Text(const Font &, const Technique * = 0);
45
46         const Mesh *get_mesh() const { return &mesh; }
47
48         /** Sets technique to render with.  It should have a texture slot named
49         "diffuse_map", which will be replaced with the font's texture. */
50         void set_technique(const Technique *);
51
52         const Technique *get_technique() const { return object.get_technique(); }
53
54         /// Sets the string to be displayed.
55         void set_text(const std::string &, StringCodec::Decoder &);
56
57         template<typename C>
58         void set_text(const std::string &t)
59         {
60                 typename C::Decoder dec;
61                 set_text(t, dec);
62         }
63
64         void set_text(const std::string &t)
65         { set_text<StringCodec::Utf8>(t); }
66
67         /// Clears the object's contents.
68         void clear();
69
70         /// Sets horizontal and vertical alignment with predefined anchors.
71         void set_alignment(HorizontalAlign, VerticalAlign = BASELINE);
72
73         /** Sets horizontal and vertical alignment.  0.0 means left or baseline,
74         1.0 means right or top. */
75         void set_alignment(float, float = 0.0f);
76
77         float get_width() const { return width; }
78
79         virtual void render(Renderer &, const Tag & = Tag()) const;
80
81         operator const Object &() const { return object; }
82 };
83
84 } // namespace GL
85 } // namespace Msp
86
87 #endif