Jump to content
  • Advertisement
Sign in to follow this  
marshdabeachy

Text manipulation

This topic is 4149 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

I've just written my own input component in DirectX which replicates a lot of the functionality of the respective Windows component using ID3DXFont. The only thing it's missing is text selection... is there an effective way to handle text selection? Also, for the blinking position cursor I've just been using the character "|" and hiding/showing it, which looks fine on the end of the text, but in the middle of the text it offsets everything after it to the right. Is there a way to get the blinking position cursor, or will I have to resort to some kind of workaround? Thanks, Marshall

Share this post


Link to post
Share on other sites
Advertisement
Don't insert the "|" character into the text itself, but rather render it on top the text (between the spaces). It's easiest to do this with a monospaced font.

Share this post


Link to post
Share on other sites
Even without a monospaced font, it's doable. Assuming you know the width of each character, and assuming the height of the tallest character is 1.0 (these depend on the way that you render your text), you can simply add up all the character's widths up until your cursor position and store that into some variable, x. Then, draw a line from (x, 0.0f) to (x, 1.0f). Ta-da!: a cursor, smack dab in the middle of any two characters, be the font fixed-width or not.

As far as text selection, as far as I've been able to surmise, you'll need the following things:
1) A pair of indices, (firstCharSelected, lastCharSelected), or something of the sort to store what, exactly, is selected.
2) Some way to handle mouse clicks, which will, depending on the projection used, involve either a straight mapping or a(n un)projection.
3) Working the selection into the keydown handling, so that typed characters replace whatever is selected, and delete works, and backspace works, and...

Best of luck!
-jouley

Share this post


Link to post
Share on other sites
I'm not using a monospaced font, so that makes things a bit more difficult. Is there a way to get individual character widths based on the font face and size I'm using?

As far as text selection goes, I understand what I have to do in principle, but is there a way to actually *select* the text short of drawing a box behind the text and inverting the text color myself?

Share this post


Link to post
Share on other sites
RE: Your first question: someone more versed in DX will have to fill you in on that one.
Quote:
Original post by marshdabeachy
As far as text selection goes, I understand what I have to do in principle, but is there a way to actually *select* the text short of drawing a box behind the text and inverting the text color myself?

You can choose to represent selected text however you want, be it simply changing the text color, background color, font, size, or even the style (underline, italics, etc.). The best way to do this depends on both your personal preference, and the answer to your first question I couldn't answer. [wink] Your proposed method is certainly valid, and shouldn't cause too much strain on your rendering.

Give it a go, and see how it behaves!
-jouley

Share this post


Link to post
Share on other sites
Alright, I was hoping there was a magic function to handle text selection, but I guess I'll get my hands dirty again. Thanks.

Anyone know about grabbing individual character widths?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!