DrawColorText

Monkey Forums/Monkey Programming/DrawColorText

hub(Posted 2016) [#1]
i'm searching a way to display some coloured words inside a drawtext command so...

example DrawColorText "this is [[ff0000]] an example [[ffffff]] for you"

i"ve this. No work as expected. some others words are also ff0000 red.





dawlane(Posted 2016) [#2]
Here's a working example for you. Study this code and compare it to your code. Dig around the Monkey Code section. You will see a few other method of converting an hexadecimal string into an integer. Note that there may be a bug or two as I haven't fully tested it.
Edit: I've updated it to include alpha.
Edit: And fixed a small bug.

Edit: If a string doesn't change, then I would pre-process the string and store the parts of a string with the associated colour as an object onto a stack. It saves re-parsing a string over and over again.

If you need a brush up on strings then see my post here (post #36).


hub(Posted 2016) [#3]
Many thanks for your help dawlane ! Nice idea to add alpha.


dawlane(Posted 2016) [#4]
Your welcome. I've cleaned up the code above, add some comments and a few teaks.
I should point out that doing anything more, such as flashing text would require a display engine.

Edit: I think there is one the one bug in it to do with new line characters. Haven't the time to see what's up with it.