]> git.tdb.fi Git - libs/gl.git/blob - source/render/text.h
Add support for integer vertex attributes
[libs/gl.git] / source / render / 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 "objectinstance.h"
8 #include "technique.h"
9
10 namespace Msp {
11 namespace GL {
12
13 /**
14 Creates an object consisting of the visual representation of a string.  If you
15 derive from Text to customize it, make sure you call Text::setup_render or
16 otherwise bind the appropriate texture.
17 */
18 class Text: public ObjectInstance
19 {
20 public:
21         enum HorizontalAlign
22         {
23                 LEFT,
24                 CENTER,
25                 RIGHT
26         };
27
28         enum VerticalAlign
29         {
30                 DESCENT,
31                 BASELINE,
32                 MIDLINE,
33                 ASCENT
34         };
35
36 private:
37         const Font &font;
38         Mesh mesh;
39         Object object;
40         Tag texture_slot;
41         float horz_align;
42         float vert_offset;
43         float width;
44
45 public:
46         Text(const Font &, const Technique * = 0, Tag = Tag());
47
48         const Mesh *get_mesh() const { return &mesh; }
49
50         /** Sets technique to render with, replacing the given texture slot with
51         the font texture.  If no texture slot is specified, heuristics are used to
52         choose a suitable one. */
53         void set_technique(const Technique *, Tag = Tag());
54
55         const Technique *get_technique() const { return object.get_technique(); }
56
57         /// Sets the string to be displayed.
58         void set_text(const std::string &, StringCodec::Decoder &);
59
60         template<typename C>
61         void set_text(const std::string &t)
62         {
63                 typename C::Decoder dec;
64                 set_text(t, dec);
65         }
66
67         void set_text(const std::string &t)
68         { set_text<StringCodec::Utf8>(t); }
69
70         /// Clears the object's contents.
71         void clear();
72
73         /// Sets horizontal and vertical alignment with predefined anchors.
74         void set_alignment(HorizontalAlign, VerticalAlign = BASELINE);
75
76         /** Sets horizontal and vertical alignment.  0.0 means left or baseline,
77         1.0 means right or top. */
78         void set_alignment(float, float = 0.0f);
79
80         float get_width() const { return width; }
81
82         virtual void setup_render(Renderer &, Tag) const;
83
84         DEPRECATED operator const Object &() const { return object; }
85 };
86
87 } // namespace GL
88 } // namespace Msp
89
90 #endif