Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CGUIString.h
Go to the documentation of this file.
1/* Copyright (C) 2022 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_CGUISTRING
19#define INCLUDED_CGUISTRING
20
21#include "gui/CGUIText.h"
22#include "ps/CStrIntern.h"
23
24#include <array>
25#include <list>
26#include <vector>
27
28class CGUI;
29
30/**
31 * String class, substitute for CStr, but that parses
32 * the tags and builds up a list of all text that will
33 * be different when outputted.
34 *
35 * The difference between CGUIString and CGUIText is that
36 * CGUIString is a string-class that parses the tags
37 * when the value is set. The CGUIText is just a container
38 * which stores the positions and settings of all text-calls
39 * that will have to be made to the Renderer.
40 */
42{
43public:
44 /**
45 * A chunk of text that represents one call to the renderer.
46 * In other words, all text in one chunk, will be drawn
47 * exactly with the same settings.
48 */
49 struct TextChunk
50 {
51 /**
52 * A tag looks like this "Hello [b]there[/b] little"
53 */
54 struct Tag
55 {
56 /**
57 * Tag Type
58 */
60 {
71 };
72
74 {
75 std::wstring attrib;
76 std::wstring value;
77 };
78
79 /**
80 * Set tag from string
81 *
82 * @param tagtype TagType by string, like 'img' for [img]
83 * @return True if m_TagType was set.
84 */
85 bool SetTagType(const CStrW& tagtype);
86 TagType GetTagType(const CStrW& tagtype) const;
87
88
89 /**
90 * In [b="Hello"][/b]
91 * m_TagType is TAG_B
92 */
94
95 /**
96 * In [b="Hello"][/b]
97 * m_TagValue is 'Hello'
98 */
99 std::wstring m_TagValue;
100
101 /**
102 * Some tags need an additional attributes
103 */
104 std::vector<TagAttribute> m_TagAttributes;
105 };
106
107 /**
108 * m_From and m_To is the range of the string
109 */
111
112 /**
113 * Tags that are present. [a][b]
114 */
115 std::vector<Tag> m_Tags;
116 };
117
118 /**
119 * All data generated in GenerateTextCall()
120 */
122 {
123 // Avoid copying the vector and list containers.
126 SFeedback() = default;
127
128 // Constants
129 static const int Left = 0;
130 static const int Right = 1;
131
132 /**
133 * Reset all member data.
134 */
135 void Reset();
136
137 /**
138 * Image stacks, for left and right floating images.
139 */
140 std::array<std::vector<CStr>, 2> m_Images; // left and right
141
142 /**
143 * Text and Sprite Calls.
144 */
145 std::vector<CGUIText::STextCall> m_TextCalls;
146
147 // list for consistent mem addresses so that we can point to elements.
148 std::list<CGUIText::SSpriteCall> m_SpriteCalls;
149
150 /**
151 * Width and Height *feedback*
152 */
154
155 /**
156 * If the word inputted was a new line.
157 */
159
160 /**
161 * If the word inputted ends with a space that can be collapsed when aligning.
162 */
164 };
165
166 /**
167 * Set the value, the string will automatically
168 * be parsed when set.
169 */
170 void SetValue(const CStrW& str);
171
172 /**
173 * Get String, with tags
174 */
175 const CStrW& GetOriginalString() const { return m_OriginalString; }
176
177 /**
178 * Get String, stripped of tags
179 */
180 const CStrW& GetRawString() const { return m_RawString; }
181
182 /**
183 * Generate Text Call from specified range. The range
184 * must span only within ONE TextChunk though. Otherwise
185 * it can't be fit into a single Text Call
186 *
187 * Notice it won't make it complete, you will have to add
188 * X/Y values and such.
189 *
190 * @param pGUI Pointer to CGUI object making this call, for e.g. icon retrieval.
191 * @param Feedback contains all info that is generated.
192 * @param DefaultFont Default Font
193 * @param from From character n,
194 * @param to to character n.
195 * @param FirstLine Whether this is the first line of text, to calculate its height correctly
196 * @param pObject Only for Error outputting, optional! If nullptr
197 * then no Errors will be reported! Useful when you need
198 * to make several GenerateTextCall in different phases,
199 * it avoids duplicates.
200 */
201 void GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject = nullptr) const;
202
203 /**
204 * Words
205 */
206 std::vector<int> m_Words;
207
208private:
209 /**
210 * TextChunks
211 */
212 std::vector<TextChunk> m_TextChunks;
213
214 /**
215 * The full raw string. Stripped of tags.
216 */
218
219 /**
220 * The original string value passed to SetValue.
221 */
223};
224
225#endif // INCLUDED_CGUISTRING
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
Definition: CGUIString.h:42
void GenerateTextCall(const CGUI &pGUI, SFeedback &Feedback, CStrIntern DefaultFont, const int &from, const int &to, const bool FirstLine, const IGUIObject *pObject=nullptr) const
Generate Text Call from specified range.
Definition: CGUIString.cpp:54
CStrW m_OriginalString
The original string value passed to SetValue.
Definition: CGUIString.h:222
const CStrW & GetRawString() const
Get String, stripped of tags.
Definition: CGUIString.h:180
std::vector< int > m_Words
Words.
Definition: CGUIString.h:206
const CStrW & GetOriginalString() const
Get String, with tags.
Definition: CGUIString.h:175
std::vector< TextChunk > m_TextChunks
TextChunks.
Definition: CGUIString.h:212
void SetValue(const CStrW &str)
Set the value, the string will automatically be parsed when set.
Definition: CGUIString.cpp:279
CStrW m_RawString
The full raw string.
Definition: CGUIString.h:217
The main object that represents a whole GUI page.
Definition: CGUI.h:61
Definition: Size2D.h:25
Interned 8-bit strings.
Definition: CStrIntern.h:38
GUI object such as a button or an input-box.
Definition: IGUIObject.h:60
All data generated in GenerateTextCall()
Definition: CGUIString.h:122
std::list< CGUIText::SSpriteCall > m_SpriteCalls
Definition: CGUIString.h:148
bool m_EndsWithSpace
If the word inputted ends with a space that can be collapsed when aligning.
Definition: CGUIString.h:163
void Reset()
Reset all member data.
Definition: CGUIString.cpp:43
bool m_NewLine
If the word inputted was a new line.
Definition: CGUIString.h:158
CSize2D m_Size
Width and Height feedback
Definition: CGUIString.h:153
static const int Right
Definition: CGUIString.h:130
static const int Left
Definition: CGUIString.h:129
std::vector< CGUIText::STextCall > m_TextCalls
Text and Sprite Calls.
Definition: CGUIString.h:145
std::array< std::vector< CStr >, 2 > m_Images
Image stacks, for left and right floating images.
Definition: CGUIString.h:140
Definition: CGUIString.h:74
std::wstring value
Definition: CGUIString.h:76
std::wstring attrib
Definition: CGUIString.h:75
A tag looks like this "Hello [b]there[/b] little".
Definition: CGUIString.h:55
bool SetTagType(const CStrW &tagtype)
Set tag from string.
Definition: CGUIString.cpp:251
TagType m_TagType
In [b="Hello"][/b] m_TagType is TAG_B.
Definition: CGUIString.h:93
std::wstring m_TagValue
In [b="Hello"][/b] m_TagValue is 'Hello'.
Definition: CGUIString.h:99
TagType GetTagType(const CStrW &tagtype) const
Definition: CGUIString.cpp:261
std::vector< TagAttribute > m_TagAttributes
Some tags need an additional attributes.
Definition: CGUIString.h:104
TagType
Tag Type.
Definition: CGUIString.h:60
@ TAG_I
Definition: CGUIString.h:62
@ TAG_SIZE
Definition: CGUIString.h:64
@ TAG_IMGLEFT
Definition: CGUIString.h:66
@ TAG_COLOR
Definition: CGUIString.h:65
@ TAG_INVALID
Definition: CGUIString.h:70
@ TAG_FONT
Definition: CGUIString.h:63
@ TAG_B
Definition: CGUIString.h:61
@ TAG_ICON
Definition: CGUIString.h:68
@ TAG_IMGRIGHT
Definition: CGUIString.h:67
@ TAG_TOOLTIP
Definition: CGUIString.h:69
A chunk of text that represents one call to the renderer.
Definition: CGUIString.h:50
std::vector< Tag > m_Tags
Tags that are present.
Definition: CGUIString.h:115
int m_From
m_From and m_To is the range of the string
Definition: CGUIString.h:110
int m_To
Definition: CGUIString.h:110