Page 1 of 1

auto-adjust the Size of Textwindows, colored text

Posted: Wed Jan 14, 2009 15:21
by Lastmerlin
Hi to all,

I want to make some speech bubbles. The size of these windows should be adjusted to the amount of text they display. Furthermore I'd like to make some words colored to show that some name refers to an important person or item.

What I found so far is:
- Tooltip window allows sizeSelf
- StaticText has TextColours property.

The problem is to put things together.
My questions are:
1. Is it a good idea to use a Tooltip windows for this? I dont think this is the intended use of the Tooltip class ;)
2. Is it possible to color single words ? As far as I have read here, I guess not. If I try to split the text into subwindows, will sizeSelf still work.

Thanks a lot for any advice :)

Posted: Wed Jan 14, 2009 19:09
by Jamarr
You would have to write the functionality for both of these yourself afaik.

For the text bubbles, you should probably create a whole new class. For example, either by deriving from Tooltip, copying the desired Tooltip code into a completely separate object, or just creating a completely new object all together; call it TextBubble or something.

As far as color coding words/phrases, you will have to split these up yourself. What I'm thinking is that you could set it up similar to how the editbox works, except instead of characters use window (StaticText) objects. Eg, determine the maximum width you want for the box, then iteratively add each window in sequence to the current row until that width is consumed. When you've reached the max width just move to the next row, and continue to add windows like this until you've run out. Then when in the drawing operation iterate all of the rows drawing the child-windows in sequence and storing the max height per-row, when you change rows use the row height to set the top offset for the next row.

This way you could use it for more than just StaticText windows - you could use it for displaying sets of images, etc. as is; and you could easily extended it to make lists like [#][checkbox][icon][text], etc.

Anyway, that's just a basic idea...it's a shame CEGUI doesn't have widget like this built-in eh :(

Posted: Wed Jan 14, 2009 21:26
by CrazyEddie
Coloured text via markup (though actually it should be a more generalised text formatting system that can use customised parsing of tags in strings) is on the list of things to be done for 0.7.0.

Writing a Window type that sizes itself to a string is trivial. If you're only going to use single-line strings, you could even do that via XML LookNFeel alone (though maybe not if you need to add extensions to support coloured text).

CE.

Posted: Thu Jan 15, 2009 20:45
by Pompei2
CrazyEddie wrote:Writing a Window type that sizes itself to a string is trivial. If you're only going to use single-line strings, you could even do that via XML LookNFeel alone (though maybe not if you need to add extensions to support coloured text).

pointers plz? This would interest me.

As for the coloured text, there has been a long post in the forums that talk about how you can add this feature yourself into CEGUI (modify the sourcecode). They work pretty good for simple scenarios but they have some problems too (if more then one word is within the colour tag and they get wrapped, if used in editboxes). They are a big hack :)

Posted: Fri Jan 16, 2009 09:18
by CrazyEddie
Pompei2 wrote:pointers plz? This would interest me.

I thought about this just now, and what I said might have been a brain fart :oops: What I considered before, when I made the original statement, would affect just the imagery as opposed to the actual Window size itself.

Apologies for the confusion, and for making these wild claims :) In my defence, I have my mind totally consumed by other things at the moment :D

CE.

Posted: Sat Jan 17, 2009 01:10
by Pompei2
Hehehe now you know what you can do after that rendertarget stuff :P

Posted: Tue Jan 20, 2009 10:31
by Lastmerlin
Thanks alot.
As I dont have enough time to dig deep into CEGUI atm I will wait for 0.7 for coloured text. For the window size, I am using a simple approximations based on the number of letters and newlines.