Fontmachine - clickable words

Monkey Forums/Monkey Beginners/Fontmachine - clickable words

TVCruelty(Posted 2014) [#1]
Hi,

Another Fontmachine query from me! Here's my requirement:

I'd like to place some text on-screen using Fontmachine.
I'd like some of the words/phrases in the text to be clickable. In other words, I might make the word "north" clickable so that, when it's clicked, my hero moves north.
The clickable words/phrases could be underlined or in a different colour or have a box around them.

I can probably figure out a way of doing this myself using screen coordinates but wonder if there's either something in the Fontmachine API that would help or whether someone has a class already developed?

Thanks,
Ian


Gerry Quinn(Posted 2014) [#2]
Have a look for code that formats text to fit a rectangular area. There's probably some around (and you'll need it for your game anyway), and you can just modify it so it records the row and the beginning and ending x-position of each important word.


TVCruelty(Posted 2014) [#3]
OK, yes, that's probably the way. I'm using a little word wrap routine anyway so I could definitely modify that.

Still wondering if there's anything already half-written. This is (honestly!) not just laziness on my part but a genuine desire to find the simplest, most performant solution.


ziggy(Posted 2014) [#4]
Not implemented, the more sensible way to do it would be to add a pick-text function on the WrappedText class, so once text is wrapped, you can calculate which is the word under given coordinates, according to text size, scrolling, etc. But that would require tokening and a concise definition of what's a separator and what's not a separator. Not a trivial thing to do if you want to support 16 bit strings