Sign in to follow this  
vs322

LPD3DXFONT and scrollable text.

Recommended Posts

So I am working on a set of Gui classes and is is going pretty well. However I have come across a small stumbling block in regards to scrollable text. I can see implementing scrolling / scrollable text by rendering my the full text to an off screen renter target. Then only displaying enough of the texture as there is room for, Then scroll over that texture. Although I could see myself using this method I would rather not. Is there some way to cut up a std::string into chunks that would fit into a certain line length...I can't just go by number of characters as they actually have different widths with d3dxfont. I have also played around with DT_CALCRECT to determine if the text will fit in the RECT it is to be displayed in or if it needs scrolling...but I can't see how it will help me to actually implement the scrolling. Thanks -vs

Share this post


Link to post
Share on other sites
Fixed-rectangle text scrolling is not for the weak.

Just a suggestion:

Keep a pointer (an index pointing to a position in the string) which points to the first char in the string. Do a calcrect for a single char to get the height of the rectangle for a single line. You may have to pick a capital letter or a letter with a descender to get the correct height.

Starting with that pointer, increase the length of the substr() starting at the pointer, doing calcrect, until you get the width you want. If you're not at the end of a word, back up the length of the string to the previous white-space. That's the first line of text.

Store the indices of the first and last character in the first line in an array.

Start with the first character in the second line (the character after the last character of the first line) and calculate the length of the second line. Store the position of the characters in the second line.

Continue for the entire string.

You end up with a line number indexed array of character positions.

Now calculate the number of lines you can display in the size rectangle you want by calculating the rectangle as you draw 1 line, then 2 lines, etc., to get a maxLines number.

To scroll down, increase the "first-line" index and display the substr from the first character in the "first-line" through the last character in line number: firstLine+maxLines-1. If firstLine+maxLines-1 is greater than the number of lines in the array, display the substr() from the first character in the "first-line" through the end of the string.

To scroll up, decrease the "first-line" index and ... see above.

Share this post


Link to post
Share on other sites
I was thinking something along those lines, but I really wanted to stay away from finding line breaks myself. I think I am gonna use the render serface method I mentioned above even though it seems inelegant. Either way seems like it will require rethinking some of my gui encapsulation, but Oh well.

Thanks for such an in depth discussion Buckeye. You made it very clear how to go about self-parsing the string. It seems like having a line offset as a standard part of the DX Font class would have happened by now. I may go ahead and implement both methods and compare which is faster / prettier.

Share this post


Link to post
Share on other sites
Quote:
I think I am gonna use the render serface method

If you use a texture rather than a font, you'll have to implement smooth scrolling rather than line-by-line scrolling, which, esthetically, would be visually appealing.

However, if you still want line-by-line scrolling, you'll still have to determine the height of a line in pixels.

In either case, (I just though of this) checking to see how faithful d3dxfont is to the font metrics (height, not pitch - which as you say is variable) may give you a way to determine the height of a line other than doing CALCRECT's.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this