2

So I have 25 lines of text with 40 characters per line held in an array of strings, and within that there are control codes which denote a colour which the following chars should be, for example one line may be:

[RED] Hello [BLUE] World

Where Hello must be in red, and World must be in blue. Currently I've gotten to the point where I can read the first code, i.e [RED] (actual control codes are hexadecimal) and using the following line I can highlight it:

TTF_RenderUTF8_Shaded(d->font, array_pointers[i], colors.foreground, colors.background);

Where d->font is the font, array_pointers[i] is that line of text, and the colors are the back/foreground to be set (default black background for all so not a worry. This line will render the entire string red and ignore the second control code.

My question is: is there something I can use/a way which can render specific parts of a string different colors? As far as i know RenderUTF8_Shaded only takes a whole string as an argument.

Finlandia_C
  • 385
  • 6
  • 19
  • 2
    I don't know what might also be in the library, but if `TTF_RenderUTF8_Shaded` is all you have to work with, I'd guess that you need to have a routine that parses each line in turn, looking for the control-codes. For each fragment that is one colour (e.g. `Hello` and `World`) you would copy that fragment to a temporary string and make one call to `TTF_RenderUTF8_Shaded`. Repeat for each fragment and each line. – TripeHound Jan 06 '16 at 12:21
  • Good idea, I'll try implement that now. – Finlandia_C Jan 06 '16 at 14:13

0 Answers0