]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/text.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / render / text.h
index 916d6d7b8d1c02e74dfa2dfca8dfd054c77e79ef..b4fc8f52e9aae3ddc2aae3344dce51b3e567804e 100644 (file)
@@ -4,16 +4,21 @@
 #include "font.h"
 #include "mesh.h"
 #include "object.h"
-#include "technique.h"
+#include "objectinstance.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.
+Creates a Mesh and an Object for rendering text.
+
+The mesh is created with a font size of 1 unit.  Set the Text's model matrix to
+scale it to the desired size.
+
+If you derive from Text to customize it, make sure you call Text::setup_render
+or otherwise set the appropriate texture to the Renderer.
 */
-class Text: public Renderable
+class Text: public ObjectInstance
 {
 public:
        enum HorizontalAlign
@@ -35,24 +40,24 @@ private:
        const Font &font;
        Mesh mesh;
        Object object;
-       Technique technique;
-       float horz_align;
-       float vert_offset;
-       float width;
+       Tag texture_slot;
+       float horz_align = 0.0f;
+       float vert_offset = 0.0f;
+       float width = 0.0f;
 
 public:
-       Text(const Font &, const Technique * = 0, const std::string & = std::string());
+       Text(const Font &, const Technique * = 0, Tag = Tag());
 
        const Mesh *get_mesh() const { return &mesh; }
 
-       /** Sets technique to render with, replacing the given texture slot with
+       /** Sets technique to render with, along with the texture slot to use for
        the font texture.  If no texture slot is specified, heuristics are used to
        choose a suitable one. */
-       void set_technique(const Technique *, const std::string & = std::string());
+       void set_technique(const Technique *, Tag = Tag());
 
        const Technique *get_technique() const { return object.get_technique(); }
 
-       /// Sets the string to be displayed.
+       /** Sets the string to be displayed, with an explicit character encoding. */
        void set_text(const std::string &, StringCodec::Decoder &);
 
        template<typename C>
@@ -62,13 +67,14 @@ public:
                set_text(t, dec);
        }
 
+       /** Sets the string to be displayed, with UTF-8 encoding. */
        void set_text(const std::string &t)
        { set_text<StringCodec::Utf8>(t); }
 
-       /// Clears the object's contents.
+       /** Clears any previous contents. */
        void clear();
 
-       /// Sets horizontal and vertical alignment with predefined anchors.
+       /** 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,
@@ -77,9 +83,9 @@ public:
 
        float get_width() const { return width; }
 
-       virtual void render(Renderer &, Tag = Tag()) const;
+       virtual void setup_render(Renderer &, Tag) const;
 
-       operator const Object &() const { return object; }
+       DEPRECATED operator const Object &() const { return object; }
 };
 
 } // namespace GL