X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Ftext.h;fp=source%2Frender%2Ftext.h;h=40c9b8500097d1591f8be68b1ad6b3234870729b;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/render/text.h b/source/render/text.h new file mode 100644 index 00000000..40c9b850 --- /dev/null +++ b/source/render/text.h @@ -0,0 +1,87 @@ +#ifndef MSP_GL_TEXT_H_ +#define MSP_GL_TEXT_H_ + +#include "font.h" +#include "mesh.h" +#include "object.h" +#include "technique.h" + +namespace Msp { +namespace GL { + +/** +Creates an object consisting of the visual representation of a string. Can be +used with an ObjectInstance to further customize the appearance. +*/ +class Text: public Renderable +{ +public: + enum HorizontalAlign + { + LEFT, + CENTER, + RIGHT + }; + + enum VerticalAlign + { + DESCENT, + BASELINE, + MIDLINE, + ASCENT + }; + +private: + const Font &font; + Mesh mesh; + Object object; + Technique technique; + float horz_align; + float vert_offset; + float width; + +public: + Text(const Font &, const Technique * = 0); + + const Mesh *get_mesh() const { return &mesh; } + + /** Sets technique to render with. It should have a texture slot named + "diffuse_map", which will be replaced with the font's texture. */ + void set_technique(const Technique *); + + const Technique *get_technique() const { return object.get_technique(); } + + /// Sets the string to be displayed. + void set_text(const std::string &, StringCodec::Decoder &); + + template + void set_text(const std::string &t) + { + typename C::Decoder dec; + set_text(t, dec); + } + + void set_text(const std::string &t) + { set_text(t); } + + /// Clears the object's contents. + void clear(); + + /// Sets horizontal and vertical alignment with predefined anchors. + void set_alignment(HorizontalAlign, VerticalAlign = BASELINE); + + /** Sets horizontal and vertical alignment. 0.0 means left or baseline, + 1.0 means right or top. */ + void set_alignment(float, float = 0.0f); + + float get_width() const { return width; } + + virtual void render(Renderer &, const Tag & = Tag()) const; + + operator const Object &() const { return object; } +}; + +} // namespace GL +} // namespace Msp + +#endif