22 #include "precompiled.h"
48 const int &from,
const int &to,
58 std::vector<TextChunk>::const_iterator itTextChunk;
64 _from = std::max(from, itTextChunk->m_From);
65 _to = std::min(to, itTextChunk->m_To);
68 if (_to == _from && itTextChunk->m_From == itTextChunk->m_To)
71 ENSURE(itTextChunk->m_Tags.size()==1);
81 if (_to == to && to >= 1)
89 if (_from == from && from >= 1)
108 LOGERROR(L
"Trying to use an [imgleft]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str());
121 LOGERROR(L
"Trying to use an [imgright]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str());
153 std::vector<TextChunk::Tag::TagAttribute>::const_iterator att_it;
154 for(att_it = itTextChunk->m_Tags[0].m_TagAttributes.begin(); att_it != itTextChunk->m_Tags[0].m_TagAttributes.end(); ++att_it)
156 TextChunk::Tag::TagAttribute tagAttrib = (TextChunk::Tag::TagAttribute)(*att_it);
158 if (tagAttrib.attrib ==
"displace" && !tagAttrib.value.empty())
163 LOGERROR(L
"Error parsing 'displace' value for tag [ICON]");
165 SpriteCall.
m_Area += displacement;
168 else if(tagAttrib.attrib ==
"tooltip")
170 SpriteCall.
m_Tooltip = CStr(tagAttrib.value).FromUTF8();
172 else if(tagAttrib.attrib ==
"tooltip_style")
192 LOGERROR(L
"Trying to use an [icon]-tag with an undefined icon (\"%hs\").", itTextChunk->m_Tags[0].m_TagValue.c_str());
209 std::vector<CGUIString::TextChunk::Tag>::const_iterator it2;
210 for (it2 = itTextChunk->m_Tags.begin(); it2 != itTextChunk->m_Tags.end(); ++it2)
221 LOGERROR(L
"Error parsing the value of a [color]-tag in GUI text when reading object \"%hs\".", pObject->
GetPresentableName().c_str());
228 TextCall.
m_Font = CStr(it2->m_TagValue).FromUTF8();
268 CStr _tagtype = tagtype.UpperCase();
270 if (_tagtype == CStr(
"COLOR"))
272 m_TagType = TAG_COLOR;
276 if (_tagtype == CStr(
"FONT"))
278 m_TagType = TAG_FONT;
282 if (_tagtype == CStr(
"ICON"))
284 m_TagType = TAG_ICON;
288 if (_tagtype == CStr(
"IMGLEFT"))
290 m_TagType = TAG_IMGLEFT;
294 if (_tagtype == CStr(
"IMGRIGHT"))
296 m_TagType = TAG_IMGRIGHT;
318 Parser.
InputTaskType(
"start",
"$ident[_=_$value_[$ident_=_$value_]]");
329 for (;;position = curpos+1)
332 curpos = str.Find(position,
TagStart);
340 CurrentTextChunk.
m_From = from;
351 long pos_left = str.Find(curpos+1,
TagStart);
352 long pos_right = str.Find(curpos+1,
TagEnd);
356 m_RawString += str.substr(position, curpos-position+1);
360 if (pos_left != -1 && pos_left < pos_right)
362 m_RawString += str.substr(position, pos_left-position);
367 m_RawString += str.substr(position, curpos-position);
372 CStrW tagstr (str.substr(curpos+1, pos_right-curpos-1));
378 bool justtext =
false;
382 if (Line.m_TaskTypeName ==
"start")
386 std::string Str_TagType;
388 Line.GetArgString(0, Str_TagType);
397 if (Line.GetArgCount() >= 2)
402 for(argn = 2; argn < Line.GetArgCount(); argn += 2)
404 TextChunk::Tag::TagAttribute a;
406 Line.GetArgString(argn, a.attrib);
407 Line.GetArgString(argn+1, a.value);
413 if (curpos != from_nonraw)
415 CurrentTextChunk.
m_From = from;
416 CurrentTextChunk.
m_To = from + curpos - from_nonraw;
418 from = CurrentTextChunk.
m_To;
420 from_nonraw = pos_right+1;
433 FreshTextChunk.
m_From = from + pos_right+1 - from_nonraw;
434 FreshTextChunk.
m_To = from + pos_right+1 - from_nonraw;
436 FreshTextChunk.
m_Tags.push_back(tag);
444 std::vector<TextChunk::Tag>::iterator it;
445 for (it = CurrentTextChunk.
m_Tags.begin(); it != CurrentTextChunk.
m_Tags.end(); ++it)
449 CurrentTextChunk.
m_Tags.erase(it);
455 CurrentTextChunk.
m_Tags.push_back(tag);
460 if (Line.m_TaskTypeName ==
"end")
464 std::string Str_TagType;
466 Line.GetArgString(0, Str_TagType);
475 if (curpos != from_nonraw)
477 CurrentTextChunk.
m_From = from;
478 CurrentTextChunk.
m_To = from + curpos - from_nonraw;
480 from = CurrentTextChunk.
m_To;
482 from_nonraw = pos_right+1;
486 std::vector<TextChunk::Tag>::iterator it;
487 for (it = CurrentTextChunk.
m_Tags.begin(); it != CurrentTextChunk.
m_Tags.end(); ++it)
491 CurrentTextChunk.
m_Tags.erase(it);
498 else justtext =
true;
504 m_RawString += str.substr(curpos, pos_right-curpos+1);
522 for (position=0, curpos=0;;position = curpos+1)
535 for (position=0, curpos=0;;position = curpos+1)
548 for (position=0, curpos=0;;position = curpos+1)
568 std::vector<int>::iterator it;
572 if (last_word == *it)
585 for (
int i=0; i<(int)
m_Words.size(); ++i)
593 for (
int j=0; j<(int)
m_TextChunks[i].m_Tags.size(); ++j)
A chunk of text that represents one call to the renderer.
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
void CalculateStringSize(const wchar_t *string, int &w, int &h)
std::list< SSpriteCall >::pointer m_pSpriteCall
IF an icon, then this is not NULL.
All data generated in GenerateTextCall()
std::vector< SGUIText::STextCall > m_TextCalls
Text and Sprite Calls.
std::vector< Tag > m_Tags
Tags that are present.
bool SetTagType(const CStr &tagtype)
Set tag from string.
CSize m_Size
Width and Height feedback
CStrW m_TooltipStyle
Tooltip style.
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.
CRect m_Area
Size and position of sprite.
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
A sprite call to the CRenderer.
CStr GetPresentableName() const
std::vector< TextChunk > m_TextChunks
TextChunks.
bool IconExists(const CStr &str) const
See CGUI::IconExists; applies to the currently active page.
const CStrW & GetRawString() const
Get String, without tags.
static const wchar_t TagEnd
Includes static functions that needs one template argument.
SGUIIcon GetIcon(const CStr &str) const
See CGUI::GetIcon; applies to the currently active page.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
int m_From
m_From and m_To is the range of the string
std::vector< CStr > m_Images[2]
Image stacks, for left and right floating images.
bool m_UseCustomColor
Use custom color? If true then m_Color is used, else the color inputted will be used.
void SetValue(const CStrW &str)
Set the value, the string will automatically be parsed when set.
CStrW m_String
The string that is suppose to be rendered.
CColor m_Color
Color setup.
bool ParseString(const CParser &parser, const std::string &line)
CStrW m_RawString
The full raw string.
std::vector< int > m_Words
Words.
bool InputTaskType(const std::string &strName, const std::string &strSyntax)
CStrW m_OriginalString
The original string value passed to SetValue.
std::list< SGUIText::SSpriteCall > m_SpriteCalls
TagType m_TagType
In [B=Hello][/B] m_TagType is TAG_B.
bool m_NewLine
If the word inputted was a new line.
A tag looks like this "Hello [B]there[/B] little".
const wchar_t * DefaultFont
void Reset()
Reset all member data.
A text call to the CRenderer.
std::string m_TagValue
In [B=Hello][/B] m_TagValue is 'Hello'.
CGUISpriteInstance m_Sprite
Sprite from global GUI sprite database.
CStrW m_Tooltip
Tooltip text.
std::vector< TagAttribute > m_TagAttributes
Some tags need an additional attributes.
static const wchar_t TagStart