Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUItext.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 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 /*
19 GUI text, handles text stuff
20 
21 --Overview--
22 
23  Mainly contains struct SGUIText and friends.
24  Actual text processing is made in CGUI::GenerateText()
25 
26 --More info--
27 
28  Check GUI.h
29 
30 */
31 
32 #ifndef INCLUDED_GUITEXT
33 #define INCLUDED_GUITEXT
34 
35 
36 //--------------------------------------------------------
37 // Includes / Compiler directives
38 //--------------------------------------------------------
39 #include <list>
40 
41 #include "CGUISprite.h"
42 
43 //--------------------------------------------------------
44 // Declarations
45 //--------------------------------------------------------
46 
47 /**
48  * An SGUIText object is a parsed string, divided into
49  * text-rendering components. Each component, being a
50  * call to the Renderer. For instance, if you by tags
51  * change the color, then the GUI will have to make
52  * individual calls saying it want that color on the
53  * text.
54  *
55  * For instance:
56  * "Hello [b]there[/b] bunny!"
57  *
58  * That without word-wrapping would mean 3 components.
59  * i.e. 3 calls to CRenderer. One drawing "Hello",
60  * one drawing "there" in bold, and one drawing "bunny!".
61  */
62 struct SGUIText
63 {
64  /**
65  * A sprite call to the CRenderer
66  */
67  struct SSpriteCall
68  {
70 
71  /**
72  * Size and position of sprite
73  */
75 
76  /**
77  * Sprite from global GUI sprite database.
78  */
80 
81  int m_CellID;
82 
83  /**
84  * Tooltip text
85  */
86  CStrW m_Tooltip;
87 
88  /**
89  * Tooltip style
90  */
92  };
93 
94  /**
95  * A text call to the CRenderer
96  */
97  struct STextCall
98  {
99  STextCall() :
100  m_UseCustomColor(false),
101  m_Bold(false), m_Italic(false), m_Underlined(false),
102  m_pSpriteCall(NULL) {}
103 
104  /**
105  * Position
106  */
108 
109  /**
110  * Size
111  */
113 
114  /**
115  * The string that is suppose to be rendered.
116  */
117  CStrW m_String;
118 
119  /**
120  * Use custom color? If true then m_Color is used,
121  * else the color inputted will be used.
122  */
124 
125  /**
126  * Color setup
127  */
129 
130  /**
131  * Font name
132  */
133  CStrW m_Font;
134 
135  /**
136  * Settings
137  */
139 
140  /**
141  * *IF* an icon, then this is not NULL.
142  */
143  std::list<SSpriteCall>::pointer m_pSpriteCall;
144  };
145 
146  /**
147  * List of TextCalls, for instance "Hello", "there!"
148  */
149  std::vector<STextCall> m_TextCalls;
150 
151  /**
152  * List of sprites, or "icons" that should be rendered
153  * along with the text.
154  */
155  std::list<SSpriteCall> m_SpriteCalls; // list for consistent mem addresses
156  // so that we can point to elements.
157 
158  /**
159  * Width and height of the whole output, used when setting up
160  * scrollbars and such.
161  */
163 };
164 
165 /**
166  * String class, substitute for CStr, but that parses
167  * the tags and builds up a list of all text that will
168  * be different when outputted.
169  *
170  * The difference between CGUIString and SGUIText is that
171  * CGUIString is a string-class that parses the tags
172  * when the value is set. The SGUIText is just a container
173  * which stores the positions and settings of all text-calls
174  * that will have to be made to the Renderer.
175  */
177 {
178 public:
179  /**
180  * A chunk of text that represents one call to the renderer.
181  * In other words, all text in one chunk, will be drawn
182  * exactly with the same settings.
183  */
184  struct TextChunk
185  {
186  /**
187  * A tag looks like this "Hello [B]there[/B] little"
188  */
189  struct Tag
190  {
191  /**
192  * Tag Type
193  */
194  enum TagType
195  {
204  };
205 
207  {
208  std::string attrib;
209  std::string value;
210  };
211 
212  /**
213  * Set tag from string
214  *
215  * @param tagtype TagType by string, like 'IMG' for [IMG]
216  * @return True if m_TagType was set.
217  */
218  bool SetTagType(const CStr& tagtype);
219 
220  /**
221  * In [B=Hello][/B]
222  * m_TagType is TAG_B
223  */
225 
226  /**
227  * In [B=Hello][/B]
228  * m_TagValue is 'Hello'
229  */
230  std::string m_TagValue;
231 
232  /**
233  * Some tags need an additional attributes
234  */
235  std::vector<TagAttribute> m_TagAttributes;
236  };
237 
238  /**
239  * m_From and m_To is the range of the string
240  */
241  int m_From, m_To;
242 
243  /**
244  * Tags that are present. [A][B]
245  */
246  std::vector<Tag> m_Tags;
247  };
248 
249  /**
250  * All data generated in GenerateTextCall()
251  */
252  struct SFeedback
253  {
254  // Constants
255  static const int Left=0;
256  static const int Right=1;
257 
258  /**
259  * Reset all member data.
260  */
261  void Reset();
262 
263  /**
264  * Image stacks, for left and right floating images.
265  */
266  std::vector<CStr> m_Images[2]; // left and right
267 
268  /**
269  * Text and Sprite Calls.
270  */
271  std::vector<SGUIText::STextCall> m_TextCalls;
272  std::list<SGUIText::SSpriteCall> m_SpriteCalls; // list for consistent mem addresses
273  // so that we can point to elements.
274 
275  /**
276  * Width and Height *feedback*
277  */
279 
280  /**
281  * If the word inputted was a new line.
282  */
283  bool m_NewLine;
284  };
285 
286  /**
287  * Set the value, the string will automatically
288  * be parsed when set.
289  */
290  void SetValue(const CStrW& str);
291 
292  /**
293  * Get String, without tags
294  */
295  const CStrW& GetRawString() const { return m_RawString; }
296 
297  /**
298  * Get String, with tags
299  */
300  const CStrW& GetOriginalString() const { return m_OriginalString; }
301 
302  /**
303  * Generate Text Call from specified range. The range
304  * must span only within ONE TextChunk though. Otherwise
305  * it can't be fit into a single Text Call
306  *
307  * Notice it won't make it complete, you will have to add
308  * X/Y values and such.
309  *
310  * @param Feedback contains all info that is generated.
311  * @param DefaultFont Default Font
312  * @param from From character n,
313  * @param to to character n.
314  * @param FirstLine Whether this is the first line of text, to calculate its height correctly
315  * @param pObject Only for Error outputting, optional! If NULL
316  * then no Errors will be reported! Useful when you need
317  * to make several GenerateTextCall in different phases,
318  * it avoids duplicates.
319  */
320  void GenerateTextCall(SFeedback &Feedback,
321  const CStrW& DefaultFont,
322  const int &from, const int &to,
323  const bool FirstLine,
324  const IGUIObject *pObject=NULL) const;
325 
326  /**
327  * Words
328  */
329  std::vector<int> m_Words;
330 
331  /**
332  * TextChunks
333  */
334  std::vector<TextChunk> m_TextChunks;
335 
336 private:
337  /**
338  * The full raw string. Stripped of tags.
339  */
340  CStrW m_RawString;
341 
342  /**
343  * The original string value passed to SetValue.
344  */
346 };
347 
348 #endif
A chunk of text that represents one call to the renderer.
Definition: GUItext.h:184
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
Definition: Overlay.h:205
static const int Right
Definition: GUItext.h:256
std::list< SSpriteCall >::pointer m_pSpriteCall
IF an icon, then this is not NULL.
Definition: GUItext.h:143
Definition: Overlay.h:34
All data generated in GenerateTextCall()
Definition: GUItext.h:252
std::vector< SGUIText::STextCall > m_TextCalls
Text and Sprite Calls.
Definition: GUItext.h:271
std::vector< Tag > m_Tags
Tags that are present.
Definition: GUItext.h:246
bool SetTagType(const CStr &tagtype)
Set tag from string.
Definition: GUItext.cpp:266
CSize m_Size
Width and Height feedback
Definition: GUItext.h:278
CStrW m_TooltipStyle
Tooltip style.
Definition: GUItext.h:91
void GenerateTextCall(SFeedback &Feedback, const CStrW &DefaultFont, const int &from, const int &to, const bool FirstLine, const IGUIObject *pObject=NULL) const
Generate Text Call from specified range.
Definition: GUItext.cpp:46
CRect m_Area
Size and position of sprite.
Definition: GUItext.h:74
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:140
A sprite call to the CRenderer.
Definition: GUItext.h:67
std::vector< TextChunk > m_TextChunks
TextChunks.
Definition: GUItext.h:334
const CStrW & GetRawString() const
Get String, without tags.
Definition: GUItext.h:295
int m_From
m_From and m_To is the range of the string
Definition: GUItext.h:241
std::vector< CStr > m_Images[2]
Image stacks, for left and right floating images.
Definition: GUItext.h:266
bool m_UseCustomColor
Use custom color? If true then m_Color is used, else the color inputted will be used.
Definition: GUItext.h:123
CSize m_Size
Width and height of the whole output, used when setting up scrollbars and such.
Definition: GUItext.h:162
CPos m_Pos
Position.
Definition: GUItext.h:107
std::vector< STextCall > m_TextCalls
List of TextCalls, for instance &quot;Hello&quot;, &quot;there!&quot;.
Definition: GUItext.h:149
static const int Left
Definition: GUItext.h:255
void SetValue(const CStrW &str)
Set the value, the string will automatically be parsed when set.
Definition: GUItext.cpp:303
bool m_Bold
Settings.
Definition: GUItext.h:138
CStrW m_String
The string that is suppose to be rendered.
Definition: GUItext.h:117
CColor m_Color
Color setup.
Definition: GUItext.h:128
Made to represent screen positions and delta values.
Definition: Overlay.h:167
CStrW m_Font
Font name.
Definition: GUItext.h:133
CStrW m_RawString
The full raw string.
Definition: GUItext.h:340
std::vector< int > m_Words
Words.
Definition: GUItext.h:329
CStrW m_OriginalString
The original string value passed to SetValue.
Definition: GUItext.h:345
std::list< SGUIText::SSpriteCall > m_SpriteCalls
Definition: GUItext.h:272
TagType m_TagType
In [B=Hello][/B] m_TagType is TAG_B.
Definition: GUItext.h:224
bool m_NewLine
If the word inputted was a new line.
Definition: GUItext.h:283
A tag looks like this &quot;Hello [B]there[/B] little&quot;.
Definition: GUItext.h:189
const wchar_t * DefaultFont
Definition: Font.cpp:29
void Reset()
Reset all member data.
Definition: GUItext.cpp:36
CSize m_Size
Size.
Definition: GUItext.h:112
std::list< SSpriteCall > m_SpriteCalls
List of sprites, or &quot;icons&quot; that should be rendered along with the text.
Definition: GUItext.h:155
A text call to the CRenderer.
Definition: GUItext.h:97
std::string m_TagValue
In [B=Hello][/B] m_TagValue is &#39;Hello&#39;.
Definition: GUItext.h:230
CGUISpriteInstance m_Sprite
Sprite from global GUI sprite database.
Definition: GUItext.h:79
const CStrW & GetOriginalString() const
Get String, with tags.
Definition: GUItext.h:300
CStrW m_Tooltip
Tooltip text.
Definition: GUItext.h:86
std::vector< TagAttribute > m_TagAttributes
Some tags need an additional attributes.
Definition: GUItext.h:235
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
Definition: GUItext.h:176
An SGUIText object is a parsed string, divided into text-rendering components.
Definition: GUItext.h:62
Rectangle class used for screen rectangles.
Definition: Overlay.h:71