3
GUIText::GUIText(const std::string &text)
8
color.set(1.0,1.0,1.0);
9
scales.set(1.0f, 1.0f);
13
GUIText::GUIText(const GUIText & copy)
15
this->operator=(copy);
18
GUIText &GUIText::operator =(const GUIText & copy)
22
fontIndex = copy.fontIndex;
32
GUIText &GUIText::operator =(const std::string & str)
38
bool GUIText::loadXMLSettings(const TiXmlElement *element)
40
if(!element || !element->Value() || strcmp(element->Value(), "Text"))
41
return Logger::writeErrorLog("Need a Text node in the xml file");
43
for(const TiXmlElement *child = element->FirstChildElement();
45
child = child->NextSiblingElement() )
47
const char * value = child->Value();
51
if(!strcmp(value, "Color"))
52
XMLArbiter::fillComponents3f(child, color);
54
if(!strcmp(value, "Font"))
55
fontIndex = GUIFontManager::addFont(child);
59
setHeightScale(XMLArbiter::fillComponents1f(element, "hScale", 1.0f));
60
setWidthScale(XMLArbiter::fillComponents1f(element, "wScale", 1.0f));
61
setFontIndex(XMLArbiter::fillComponents1i(element, "fontIndex", fontIndex));
62
setString(element->Attribute("string"));
67
const std::string& GUIText::getString(){ return text; }
69
void GUIText::setString(const std::string &textArg)
71
if(textArg.size() && text != textArg)
78
void GUIText::setString(const char *textArg)
80
if(textArg && text != textArg)
94
int GUIText::getFontIndex()
99
void GUIText::setFontIndex(int index)
104
void GUIText::print(int x, int y, int startIndex, int endIndex)
109
endIndex = (endIndex < 0) ? int(text.size()) : endIndex;
110
startIndex = clamp(startIndex, 0, endIndex);
112
GUIFontManager::setCurrentFont(fontIndex);
113
GUIFont *currentFont = GUIFontManager::getCurrentFont();
116
if(!currentFont && !(currentFont = GUIFontManager::getDefaultFont()))
119
currentFont->getFontObject()->printSubString(float(x), float(y), scales.x, scales.y,
120
color.x, color.y, color.z,
121
startIndex, endIndex,
125
void GUIText::printCenteredX (int x, int y, int startIndex, int endIndex)
131
print(x - size.x/2, y, startIndex, endIndex);
134
void GUIText::printCenteredY (int x, int y, int startIndex, int endIndex)
140
print(x, y - size.y/2, startIndex, endIndex);
143
void GUIText::printCenteredXY(int x, int y, int startIndex, int endIndex)
149
print(x - size.x/2, y - size.y/2, startIndex, endIndex);
152
void GUIText::computeDimensions()
156
GUIFontManager::setCurrentFont(fontIndex);
157
GUIFont *currentFont = GUIFontManager::getCurrentFont();
159
if(!currentFont && !(currentFont = GUIFontManager::getDefaultFont()))
162
if(currentFont == GUIFontManager::getDefaultFont())
163
fontIndex = GUIFontManager::findFontIndex(currentFont);
167
size = currentFont->getFontObject()->getStringDimensions(text);
168
size.x = int(float(size.x)*scales.x);
170
size.y = int(float(currentFont->getFontObject()->getHeight())*scales.y);
175
void GUIText::setSize(const Tuple2i& sizeArg){ size = sizeArg; }
176
void GUIText::setSize(int x, int y){ size.set(x, y); }
178
int GUIText::getHeight(){ return abs(size.y); }
179
int GUIText::getWidth() { return abs(size.x); }
181
const Tuple2i& GUIText::getSize(){ return size; }
182
bool GUIText::needUpdating(){ return update; }
184
void GUIText::forceUpdate(bool updateArg){ update = updateArg; }
185
void GUIText::setColor(const Tuple3f &color){ setColor(color.x, color.y, color.z); }
187
void GUIText::setColor(float r, float g, float b)
189
color.set(clamp(r, 0.0f, 255.0f),
190
clamp(g, 0.0f, 255.0f),
191
clamp(b, 0.0f, 255.0f));
193
color.x /= (color.x > 1.0) ? 255.0f : 1.0f;
194
color.y /= (color.y > 1.0) ? 255.0f : 1.0f;
195
color.z /= (color.z > 1.0) ? 255.0f : 1.0f;
198
void GUIText::setHeightScale(float hs)
200
scales.y = clamp(hs, 0.1f, 20.0f);
202
void GUIText::setWidthScale(float ws)
204
scales.x = clamp(ws, 0.1f, 20.0f);
206
void GUIText::setScales(Tuple2f scales)
208
setHeightScale(scales.y);
209
setWidthScale(scales.x);
212
float GUIText::getHeightScale()
217
float GUIText::getWidthScale()
222
const Tuple2f &GUIText::getScales()
226
const Tuple3f &GUIText::getColor()