

Moderators: CEGUI MVP, CEGUI Team
Ludi wrote:What about adding a starting trigger, which indicates to use font coloring or not for the current string? This trigger could be set like the color trigger.
_This is a ^00ff00ff colored text.
This is a not a colored text.
Ludi wrote:This was more a sort of "opimization". Currently, as I understand your changes, you parse every string, when you enable coloring, even if it doesn't contain color information.
Could you post your changes here or the font.cpp/.h directly here, instead of the diff. I don't have cegui in a repository and I'm to lazy to apply all the changes by hand
Code: Select all
...
bool foundColourTrigger = false;
if (d_colourFormatEnabled)
// find first occurance of colour trigger string.
if (text.find_first_of(d_colourFormatTrigger) != String::npos)
foundColourTrigger = true;
for (size_t c = 0; c < textlen; ++c)
{
// parse color information if enabled and we found a colour trigger.
if (foundColourTrigger)
{
// only try to parse colour information when enough chars exist.
if (c + triglen + 8 <= textlen)
{
// look for colour trigger at position c.
if (strncmp(&str[c], trigstr, triglen) == 0)
{
// found colour trigger, skip past trigger string
c += triglen;
// copy colour string into buffer
memcpy(buf, &str[c], 8);
// convert colour string into hex format (AARRGGBB)
sscanf(buf, "%x", &argb);
curColour.setColours(argb);
// skip past colour string.
c += 8;
}
}
}
...
Code: Select all
// this is the font i use for drawing the text in those little windows
Font* font = FontManager::getSingleton().getFont("dc146-9");
font->setColourTrigger("|c");
font->setColourTriggerEnabled(true);
Code: Select all
// the heading line of the player window
char buf[128];
sprintf(buf, "|cFFFFFFFFHeading: |cFF00FF00%.2f %.2f %.2f", mHeading.x, mHeading.y, mHeading.z);
mPlayerStateWindow->mPlayerHeading->setText(buf);
Code: Select all
bool coloring = false;
ColourRect color = colours;
size_t charPos = 0;
char colorBuffer[8];
argb_t argb;
if (length > 1)
{
if (text[0] == '_')
{
// The String begins with _Text, so we color the string
// If it begins with __Text, we skip one underscore
++charPos;
if (text[1] != '_')
{
coloring = true;
}
}
}
for (; charPos < length; ++charPos)
{
if (coloring && text[charPos] == '^' && (charPos + 8) < length)
{
++charPos;
if (text[charPos] != '^')
{
memcpy(colorBuffer, text.c_str() + charPos, 8);
sscanf(colorBuffer, "%x", &argb);
color.setColours(argb);
charPos += 8;
}
}
...
Ludi wrote:Hi ldb (is it an akronym?),
Basically, it's the same as yours, except that I'm using a fixed color trigger (the ^ like Quake3) and I'm using the _ to indicate, wheather the string should be colored.
About the alpha problem: Why not using the original alpha (this should contain the correct alpha value, right?). This way, you will just be able to set the color in the string.
And one more thing is to use instead a doule hex value per color only one (so, instead FF only F for red). So, we will only need three characters for a complete color value (and without alpha). The reason for this is that, in my case, I'm using a big string table for localization. And with the current method, everything is full with hex codes and therefore you'll lose the overview fast.
"^F00This is a red text" instead of "^FFFF0000This is a read text." With only three characters for the color, there's still the possibility to have 4096 different colors (16^3), which should be enough.
Why does it only work with english text? German is working too
Pompei2 wrote:But in a per-font basis he can set it globally too, so it's better. You chose the right one
Pompei2 wrote:One question tough: why does it only work with static text ??If your two patch files are still the actual ones, then I see no reference to static text in them ?
ldb wrote:and thank you for the kind words. its nice to know someone likes what youre doing! your idea of a colour trigger, etc was brilliant!
zarroba wrote:ldb, thanks for your work. I was about to start doing some kind of a RichText Multiline Editbox when I saw this thread and your solution for rendering different colours in a line of text. I think its a very good way to start. I was thinking of implementing some triggers for the font style (bold, italic, etc), so I'll read carefully Rackle's posts. I have just tried your code and it really works funny in an editbox or multiline editbox. For my project I would rather prefer if the colour code wouldn't be shown. Have you research further into this behaviour so I can correct it if you haven't already?
thanks
Return to “Bug Reports, Suggestions, Feature Requests”
Users browsing this forum: No registered users and 11 guests