Game Development Community

dev|Pro Game Development Curriculum

GuiMLTextCtrl::stripGameLink

by Orion Elenzil · 04/29/2009 (11:40 am) · 4 comments

GuiMLTextCtrl is a great control. We use it heavily for all sorts of UI stuff.
You can embed an anchor-like tag in GuiMLText, and when the user clicks it, your control will receive an OnURL() callback, and since the "url" can actually be arbitrary text, we often use this in the place of a button.
Normally the links are rendered with underlining, but you can omit the underlining by prepending "gamelink:".
However, the url passed to OnURL() then has "gamelink:" in front of it.
I finally got tired of parsing out the "gamelink:" in script, so changed GuiMLTextCtrl to have an option to dtrip it for you.

note, the right thing to do would be to have the link styling be a tag itself, like linkcolor, but life is short and there's always bigger fish in the morning.

This is for a TGE 1.3.5 codebase,
but is probably applicable to all torque technologies which implement GuiMLTextCtrl in C++.

GuiMLTextCtrl.h
add a protected member mStripGamelink:
bool mStripGamelink;

GuiMLTextCtrl.cc
initialize to false in the constructor. i think TRUE would actually be a much better default, but it needs to be false for strict backwards-compatability.
mStripGamelink             = false;

in initPersistFields(), expose it to script:
addField("stripGamelink",     TypeBool,            Offset(mStripGamelink,     GuiMLTextCtrl));

in onMouseUp(), just before the onURL callback, insert:
if (mStripGamelink && (dStrstr(url, "gamelink:") == url))
      {
         dStrcpy(url, url + sizeof("gamelink:") - 1);  // copying string onto itself.
      }

#1
04/30/2009 (9:27 am)
woops - null post
#2
04/30/2009 (4:48 pm)
Thanks for sharing, Orion.

Do you use GuiMLTextCtrl in the place of GuiTextCtrl? I noticed GuiTextCtrl font is not good looking comparing to GuiMLTextCtrl, which support markup language. But I've never tried GuiMLTextCtrl instead of it yet. How about GuiMLTextEditCtrl? Can it replace GuiTextEditCtrl?

#3
05/01/2009 (2:55 pm)
heya -

i used to only use GuiMLTextCtrl when i wanted clickable links in the text, but now i never use GuiTextCtrl at all. GuiMLTextCtrl is so much more flexible: you don't have to make a whole new profile to change the text font, size, color, etc. you can multiple text styles in a single control. it supports stuff like left-and-right justify and can arrange things in columns for you via the "< tab >" tag. you can embed images in your text. etc. my initial shyness was that i assumed MLText would render slower than regular text, but i've seen no evidence for that at all.

GuiMLTextEditCtrl is reasonable if you want to have the user editing multi-line text, but for short text entry like "PlayerName", i've found regular GuiTextEditCtrl to be fine. Note they both suffer from a lack of support for many standard text-editor keys & features, some of which i've addressed here (GuiTextEditCtrl) and here (GuiMLTextEditCtrl).

You might also be interested in this resource, which adds bold and strikethrough rendering to GuiMLText.
#4
05/01/2009 (6:45 pm)
Hey Orion,
Much appreciated for the information. It really helped me.

BTW, I had a chance to play your VSide long ago. It was so wonderful. Good luck to you.