In class Font:
Code: Select all
void Font::drawTextLine(const String; text, const Vector3;
position, const Rect; clip_rect, const ColourRect; colours) const
{
Vector3 cur_pos(position);
uint char_count = text.length();
CodepointMap::const_iterator pos, end = d_cp_map.end();
/** FORMATING **/
size_t pos1 = String::npos, pos2 = String::npos;
ColourRect aCol = colours;
String r,g,b;
pos1 = text.find("###");
pos2 = text.find("#-#");
for (uint c = 0; c < char_count; ++c)
{
if (c > pos1 + 9) pos1 = text.find("###", c);
if (c > pos2 + 3) pos2 = text.find("#-#", c);
// >< pos1 >< pos2
// >< + 3 >< + 3
// >< + 9
// texttext###012345texttext#-#texttexttext
if ((char_count < pos1 + 10 || c < pos1 || c >=
pos1 + 9) ;;
(char_count < pos2 + 4 || c < pos2 || c
>= pos2 + 3))
{
pos = d_cp_map.find(text[c]);
if (pos != end)
{
pos->second.d_image->draw(cur_pos,
clip_rect, aCol);
cur_pos.d_x +=
pos->second.d_horz_advance;
}
}
else if (pos1 == c)
{
r = text.substr(pos1 + 3, 2);
g = text.substr(pos1 + 5, 2);
b = text.substr(pos1 + 7, 2);
aCol.setColours(colour(
(float)(TextUtils::hex2dec(r) / 255.0f),
(float)(TextUtils::hex2dec(g) / 255.0f),
(float)(TextUtils::hex2dec(b) / 255.0f)));
}
else if (pos2 == c)
{
aCol = colours;
}
}
}
Code: Select all
float Font::getTextExtent(const String; text) const
{
uint cur_extent = 0;
uint char_count = text.length();
CodepointMap::const_iterator pos, end = d_cp_map.end();
size_t pos1 = String::npos, pos2 = String::npos;
pos1 = text.find("###");
pos2 = text.find("#-#");
for (uint c = 0; c < char_count; ++c)
{
if (c > pos1 + 9) pos1 = text.find("###", c);
if (c > pos2 + 3) pos2 = text.find("#-#", c);
if ((char_count < pos1 + 10 || c < pos1 || c >=
pos1 + 9) ;;
(char_count < pos2 + 4 || c < pos2 || c
>= pos2 + 3))
{
pos = d_cp_map.find(text[c]);
if (pos != end)
{
cur_extent +=
pos->second.d_horz_advance;
}
}
}
return (float)cur_extent;
}
and in class TextUtils: I added the function hex2dec:
in CEGUITextUtils.cpp:
Code: Select all
unsigned char TextUtils::hex2dec(String twoLetters)
{
char values[256] = "\0";
values['0'] = 0;
values['1'] = 1;
values['2'] = 2;
values['3'] = 3;
values['4'] = 4;
values['5'] = 5;
values['6'] = 6;
values['7'] = 7;
values['8'] = 8;
values['9'] = 9;
values['A'] = 10;
values['B'] = 11;
values['C'] = 12;
values['D'] = 13;
values['E'] = 14;
values['F'] = 15;
values['a'] = 10;
values['b'] = 11;
values['c'] = 12;
values['d'] = 13;
values['e'] = 14;
values['f'] = 15;
return values[twoLetters.at(0)] * 16 + values[twoLetters.at(1)];
}
and, of course, in CEGUITextUtils.h:
Code: Select all
static unsigned char hex2dec(String twoLetters);
have phun,
Emmeran
PS:
by the way: you can format your text with this changes this way:
text text text ###ff0000red text red text###00ff00green text green text and so on#-#text in orginial colour ... ###0000ffand now comes blue text ...
you can use every colour specified by an 6-char hexcode
EDIT Improved readability by converting the HMTL tags into real characters: "e; into "