Jump to content
  • Advertisement
Sign in to follow this  
Shadowflare

Font Width Problem

This topic is 4287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My problem is real simple: I'm making a simple textbox control using D3DXFont. The problem is with clipping. When you write in a single line textbox, the text is clipped if it is larger than the textbox, so that you can see what you've most recently typed. I hope that makes sense :P I can get my textbox to do this, but the problem is that the characters are not all the same width. My textbox does not need to change size so at the moment I just have a maximum number of characters that are visible (i.e. if the text is larger than the text area, it will display the last 40 characters.) Since all the characters are different widths, if you enter many large characters, the text does not get properly clipped and the characters go out of sight. If you enter many small characters it does not clip it far enough and so there is a big empty space at the end of the textbox. I'm certain there has to be a better way to do this but I haven't found anything that would indicate the opposite :( Any help would be appreciated!

Share this post


Link to post
Share on other sites
Advertisement
You can check the final size of text to be drawn by calling ID3DXFont::DrawText with DT_CALCRECT format flag set.

Quote:
From MSDN

DT_CALCRECT
Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.


You can call DrawText twice - for calculation only, and for the actual drawing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!