Page 1 of 1
Extending StaticText with Simple HTML
Posted: Wed Mar 08, 2006 12:44
by ender81x
I am going to need a widget similar to StaticText, but that will be able to have some limited functionality similar to HTML. I am planning on developing this, but I figured I would throw it out there in case someone else has already implemented something similar or would like to provide some insight/feedback.
Here are the basic requirements I'm trying to fulfill:
1. Be able to set colors and limited font formatting inline (italics, bold, underline, etc)
2. Be able to set certain parts of the text as "links" that would be clickable and have their own callback event handler
3. Text would be marked up in a fashion very similar to HTML using <tag></tag> syntax.
I don't need anything more than that at the moment for my project, and I can probably even do without the the font formatting if that proves to be too much of an issue. I would image that it would require the font used to have the underline/bold/italic versions of each character, and I think that links in the text being an alternate color would be enough without needing them to be underlined like standard HTML.
I saw another thread about implementing something similar to this, and it was suggested that they were planning on modify the actual Font code so that the ability to set colors inline would be universal for all controls. I do like this idea, but I think that since I'm going to be needing the callbacks for link handling I'll just make it specific to this extended StaticText control for now.
I have been using CEGUI for a while, but this will be my first attempt at customizing or adding on to it (I haven't had the need since it is already so full-featured). Any comments/advice/suggestions are welcome!
Posted: Wed Mar 08, 2006 20:27
by jacmoe
That would be an awesome addition!
/* Thinking about the dialogs in Morrowind .. */
Posted: Wed Mar 08, 2006 21:01
by lindquist
This would be an awesome addition to CEGUI, and as you've seen it's be discussed a few times.
The biggest proplem will definitely be the font formatting. The current font system is'nt in anyway geared for it, and yes it would require a new font for each different formatting.
Colours are "easy" though, but you'll be doing some customized splitting of the text into section with the different colours.
One thing I would suggest was that you worked against CVS head.
It's much more friendly to customization...
[edit] And porting it from 0.4 to 0.5 will likely be VERY troublesome...[/edit]
HTH, and _please_ ask if there's anything. I'd love to see this in action
-Tomas
Posted: Wed Mar 08, 2006 21:46
by ender81x
Thanks for the encouragement and advice... unfortunately, all the work I've done so far has been against the 0.4.1 source, but I'm learning a lot about how the internal text rendering stuff works so I assume that will be useful with the current source as well. For my first pass, I'm simply adding in the color feature which is similar to the method you mentioned above (with splitting the text into multiple parts). The way i'm currently doing it is by parsing the string to be rendered and looking for embedded tags like {color:.5,0,0}dark red text{/col} and then storing a list of character position offsets and color values that will then be used at the time of rendering to change the color appropriately during rendering. I'm almost finished with this part, and once it's done I'll take another pass at it using the CVS HEAD source and try to implement it more efficiently and with more features using what I've learned so far.
By the way, is this the right forum or should I start a thread in a more technical developer forum once I start getting to the nitty gritty details and need to dicuss it?
Posted: Wed Mar 08, 2006 21:53
by lindquist
As you're doing the implementation yourself this is'nt really a suggestion or feature request, so I'll move the thread into the Library development forum
It's nice not having to look for the old thread with how things started...
first screenshot
Posted: Mon Mar 20, 2006 01:47
by ender81x
http://www.indpoint.com/screenshots/scr ... acked2.png
Here is a link to the first screenshot using the control I'm building...
It is extending the Window class, and you add elements to it using either an addText(String str,Font *font) method, or addWindow(Window *wnd). It then arranges all of the added elements "inline" and wraps using the Width of the container window, or wraps at any \n line breaks in the text. It still needs a bit of work, but its starting to come together.
One thing I'm still trying to decide on... if you want a certain section of text to be clickable, like a link, then I am thinking I may just overlay a transparent Window on top of the text to handle all of the event processing... but I'm open to any suggestions if anyone has any.
Posted: Mon Mar 20, 2006 06:45
by Dalfy
Another approach would be to use a list of area computed while parsing the text that can be used on the handler of your new window. Each time an area is clicked/hoovered you can traverse the various zone previously extracted and trigger the corresponding actions. Hope I made it understandable.
Update
Posted: Sat Mar 25, 2006 11:55
by ender81x
I have the links working (I used a method based on what Dalfy mentioned above). The links fire an EventLinkClicked event, and I created an implementation of the EventArgs class to pass along a user-defined link value based on which link was clicked. There are still plenty of optimizations to be done, and I'm not even entirely sure I implemented it in the best way possible... but in any case it's working and I'm in the process of testing it a bit more thoroughly... I'll post a link to the source if it looks like it's working okay for me.
Posted: Sun Apr 02, 2006 19:19
by granx
This sounds great. I am interested to see the code, and to know what features are supported by this new addition. I am interested because I have a game that shows a large amount of text in a ScrollablePane widget. I desparately need some formatting options.
Posted: Sun Apr 02, 2006 20:39
by ender81x
Well, I haven't had a chance to put the finishing touches on the project yet... I am currently in the progress of porting all my code to C#, so that has been taking up most of my free time. I have been reluctant to post the source that I have currently, since I think it might be better to wait until it is completely working so that nobody is trying to use hacked together code that I introduce into the community... I will hopefully be able to get back to it this week if all goes well. I'll keep you posted though, and will try to have some source up this week.