Extending StaticText with Simple HTML

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

ender81x
Just popping in
Just popping in
Posts: 5
Joined: Tue Mar 07, 2006 22:50

Extending StaticText with Simple HTML

Postby ender81x » Wed Mar 08, 2006 12:44

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!

User avatar
jacmoe
Just can't stay away
Just can't stay away
Posts: 136
Joined: Sun Apr 03, 2005 14:18
Location: Holbaek, Denmark
Contact:

Postby jacmoe » Wed Mar 08, 2006 20:27

That would be an awesome addition! :)

/* Thinking about the dialogs in Morrowind .. */

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Wed Mar 08, 2006 21:01

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

ender81x
Just popping in
Just popping in
Posts: 5
Joined: Tue Mar 07, 2006 22:50

Postby ender81x » Wed Mar 08, 2006 21:46

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Wed Mar 08, 2006 21:53

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...

ender81x
Just popping in
Just popping in
Posts: 5
Joined: Tue Mar 07, 2006 22:50

first screenshot

Postby ender81x » Mon Mar 20, 2006 01:47

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.

User avatar
Dalfy
CEGUI Team (Retired)
Posts: 130
Joined: Tue Oct 11, 2005 16:13
Location: Paris, FRANCE
Contact:

Postby Dalfy » Mon Mar 20, 2006 06:45

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.

ender81x
Just popping in
Just popping in
Posts: 5
Joined: Tue Mar 07, 2006 22:50

Update

Postby ender81x » Sat Mar 25, 2006 11:55

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.

User avatar
granx
Quite a regular
Quite a regular
Posts: 80
Joined: Fri Apr 29, 2005 21:58

Postby granx » Sun Apr 02, 2006 19:19

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.

ender81x
Just popping in
Just popping in
Posts: 5
Joined: Tue Mar 07, 2006 22:50

Postby ender81x » Sun Apr 02, 2006 20:39

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.


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests