I love it!
This is free to use, right?
Something though, why not add the default font to this constructor like sf::Text does?
explicit RichText(const String& source, const Font& font, unsigned int characterSize = 30);
This way the following is possible.
sf::RichText text("_nice and clean_");
Also, not sure how practical this is but, how about something like:
#rgb(255,0,0) red_text
This is my take on it.
Color
RichText::getColorByRGBA(String source) const
{
//replace all non numeric characters with white-spaces
for (size_t i = 0; i < source.getSize(); ++i)
{
if ( !isdigit(source[i]) )
source[i] = ' ';
}
//split string
std::string part;
std::vector<std::string> rgbValues;
std::stringstream ss(source);
while (ss >> part)
{
rgbValues.push_back(part);
}
unsigned char r = atoi( rgbValues[0].c_str() );
unsigned char g = atoi( rgbValues[1].c_str() );
unsigned char b = atoi( rgbValues[2].c_str() );
unsigned char a = rgbValues.size() < 4 ? 255 : atoi( rgbValues[3].c_str() );
return sf::Color(r, g, b, a);
}
Called here:
Color
RichText::getColor(const String& source) const
{
std::map<String, Color>::const_iterator result = colors.find(source);
if (result == colors.end())
{
//HERE
if (source.find("rgb") != std::string::npos)
{
return getColorByRGBA(source);
}
unsigned hex = 0x0;
if (!(std::stringstream(source) >> std::hex >> hex))
{
// Error parsing; return default
return Color::White;
};
return getColor(hex);
}
return result->second;
}