Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / gui / text.h
blobb96cdcda0eeee5e2a7d719a61cec7c97691cffe6
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file text.h
22 * Ble.
25 #pragma once
27 #include <vector>
28 #include <deque>
29 #include <string>
30 #include <boost/utility.hpp>
32 #include "types.h"
33 #include "math/vector.h"
34 #include "math/matrix.h"
36 #include "font/font.h"
38 #include "renderer/renderer.h"
39 #include "renderer/buffers.h"
40 #include "renderer/effect.h"
42 namespace tre {
44 struct GlyphInfo;
45 class Font;
47 enum HorizAlign {
48 haLeft,
49 haCenter,
50 haRight,
51 haStretch
54 enum VertAlign {
55 vaTop,
56 vaMiddle,
57 vaBottom
60 struct TextStyle {
61 uint size;
62 FontStyle fstyle;
63 Vector4f colour;
65 TextStyle() {}
66 TextStyle(uint s, FontStyle t, const Vector4f & c)
67 : size(s), fstyle(t), colour(c) {}
70 class Text : private boost::noncopyable {
71 public:
72 Text();
73 virtual ~Text();
75 void SetRect(uint width, uint height);
76 void SetHAlign(HorizAlign align);
77 void SetVAlign(VertAlign align);
79 void SetFont(const std::string & font);
81 void SetEffect(const std::string & fx);
83 void SetAntialias(bool on);
84 void SetScaleFactor(const Vector2f scale);
86 virtual void SetStyle(const TextStyle & style) = 0;
87 virtual const TextStyle & GetStyle(void) const = 0;
89 virtual void SetText(const std::string & text) = 0;
90 virtual void SetText(const std::wstring & text) = 0;
92 virtual void ClearText(void) = 0;
93 virtual const std::wstring GetText(void) const {return text_;}
95 const Vector4i & GetTextRect(void) const {return textRect_;}
97 void SetTransform(const Matrix4x4f * mat);
98 GeometryBatch & GetGeometry(void) {return batch_;}
100 protected:
101 // structures for text parsing and mesh creation
102 struct GlyphPrep {
103 const GlyphInfo * glyph;
104 TextStyle * style;
105 int offset;
107 GlyphPrep() {}
108 GlyphPrep(const GlyphInfo * g, TextStyle * ts, int o)
109 : glyph(g), style(ts), offset(o) {}
112 typedef std::vector<GlyphPrep> GlyphPrepVector;
114 // geometry
115 typedef std::pair<const GlyphPrep*, Vector2i> PagePrepPair;
116 typedef std::deque<PagePrepPair> PagePrepQueue;
118 struct MeshPage {
119 IndexBuffer * indices;
120 EffectVars * vars;
122 // used for refilling
123 PagePrepQueue prep;
126 typedef std::vector<MeshPage> PageVector;
128 protected:
129 FontPtr font_;
131 std::wstring text_;
133 // determines, whether font will be rendered via blending or alpha testing
134 bool antialias_;
136 // alignment
137 Vector2u bounds_;
138 HorizAlign halign_;
139 VertAlign valign_;
141 Vector4i textRect_; // [left, top, right, bottom]
143 // scale factor - for matching different resolutions
144 Vector2f scaleFactor_;
146 // render batch related info
147 EffectPtr effect_;
148 const Matrix4x4f * trans_;
150 GeometryBatch batch_; // pre-built batch
152 protected:
153 virtual void RedrawText(bool reset) = 0;
155 void ResetPages(void);
156 MeshPage & GetPageByTexture(const TexturePtr & texture);
158 private:
159 // geometry information
160 AttribBufferSet * abuffers_;
161 PageVector pages_; // pages in texture cache