2 // Copyright (C) 2008 by Martin Moracek
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.
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
30 #include <boost/utility.hpp>
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"
66 TextStyle(uint s
, FontStyle t
, const Vector4f
& c
)
67 : size(s
), fstyle(t
), colour(c
) {}
70 class Text
: private boost::noncopyable
{
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_
;}
101 // structures for text parsing and mesh creation
103 const GlyphInfo
* glyph
;
108 GlyphPrep(const GlyphInfo
* g
, TextStyle
* ts
, int o
)
109 : glyph(g
), style(ts
), offset(o
) {}
112 typedef std::vector
<GlyphPrep
> GlyphPrepVector
;
115 typedef std::pair
<const GlyphPrep
*, Vector2i
> PagePrepPair
;
116 typedef std::deque
<PagePrepPair
> PagePrepQueue
;
119 IndexBuffer
* indices
;
122 // used for refilling
126 typedef std::vector
<MeshPage
> PageVector
;
133 // determines, whether font will be rendered via blending or alpha testing
141 Vector4i textRect_
; // [left, top, right, bottom]
143 // scale factor - for matching different resolutions
144 Vector2f scaleFactor_
;
146 // render batch related info
148 const Matrix4x4f
* trans_
;
150 GeometryBatch batch_
; // pre-built batch
153 virtual void RedrawText(bool reset
) = 0;
155 void ResetPages(void);
156 MeshPage
& GetPageByTexture(const TexturePtr
& texture
);
159 // geometry information
160 AttribBufferSet
* abuffers_
;
161 PageVector pages_
; // pages in texture cache