Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextRenderer.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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  * 0 A.D. 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_TEXTRENDERER
19 #define INCLUDED_TEXTRENDERER
20 
21 #include "graphics/ShaderProgram.h"
22 #include "maths/Matrix3D.h"
23 #include "ps/CStr.h"
24 #include "ps/Overlay.h"
25 
26 class CFont;
27 
29 {
30 public:
31  CTextRenderer(const CShaderProgramPtr& shader);
32 
33  /**
34  * Reset the text transform to the default, with (0,0) in the top-left of the screen.
35  */
36  void ResetTransform();
37 
39 
40  void SetTransform(const CMatrix3D& transform);
41 
42  void Translate(float x, float y, float z);
43 
44  /**
45  * Set the color for subsequent print calls.
46  */
47  void Color(const CColor& color);
48 
49  /**
50  * Set the color for subsequent print calls.
51  */
52  void Color(float r, float g, float b, float a = 1.0);
53 
54  /**
55  * Set the font for subsequent print calls.
56  */
57  void Font(const CStrW& font);
58 
59  /**
60  * Print formatted text at (0,0) under the current transform,
61  * and advance the transform by the width of the text.
62  */
63  void PrintfAdvance(const wchar_t* fmt, ...);
64 
65  /**
66  * Print formatted text at (x,y) under the current transform.
67  * Does not alter the current transform.
68  */
69  void PrintfAt(float x, float y, const wchar_t* fmt, ...);
70 
71  /**
72  * Print text at (0,0) under the current transform,
73  * and advance the transform by the width of the text.
74  */
75  void PutAdvance(const wchar_t* buf);
76 
77  /**
78  * Print text at (x,y) under the current transform,
79  * and advance the transform by the width of the text.
80  */
81  void Put(float x, float y, const wchar_t* buf);
82 
83  /**
84  * Render all of the previously printed text calls.
85  */
86  void Render();
87 
88 private:
89  struct SBatch
90  {
93  shared_ptr<CFont> font;
94  std::wstring text;
95  };
96 
98 
100 
102  shared_ptr<CFont> m_Font;
103 
104  std::map<CStrW, shared_ptr<CFont> > m_Fonts;
105 
106  std::vector<SBatch> m_Batches;
107 };
108 
109 #endif // INCLUDED_TEXTRENDERER
shared_ptr< CFont > m_Font
Definition: TextRenderer.h:102
void PrintfAt(float x, float y, const wchar_t *fmt,...)
Print formatted text at (x,y) under the current transform.
void Translate(float x, float y, float z)
void Render()
Render all of the previously printed text calls.
CMatrix3D GetTransform()
void PutAdvance(const wchar_t *buf)
Print text at (0,0) under the current transform, and advance the transform by the width of the text...
Definition: Overlay.h:34
CTextRenderer(const CShaderProgramPtr &shader)
CMatrix3D m_Transform
Definition: TextRenderer.h:99
shared_ptr< CFont > font
Definition: TextRenderer.h:93
CShaderProgramPtr m_Shader
Definition: TextRenderer.h:97
void Put(float x, float y, const wchar_t *buf)
Print text at (x,y) under the current transform, and advance the transform by the width of the text...
void Color(const CColor &color)
Set the color for subsequent print calls.
void PrintfAdvance(const wchar_t *fmt,...)
Print formatted text at (0,0) under the current transform, and advance the transform by the width of ...
void ResetTransform()
Reset the text transform to the default, with (0,0) in the top-left of the screen.
Definition: Font.h:28
std::vector< SBatch > m_Batches
Definition: TextRenderer.h:106
void SetTransform(const CMatrix3D &transform)
void Font(const CStrW &font)
Set the font for subsequent print calls.
shared_ptr< CShaderProgram > CShaderProgramPtr
std::map< CStrW, shared_ptr< CFont > > m_Fonts
Definition: TextRenderer.h:104