Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In XNA I am building my own textbox, and listbox.

For the textbox, I want it to render all text it can, and then cut off at the end of the textbox. But I don't want it to cut whole letters. I want it to cut exactly where the pixel limit is, so that if I write "SPAAAAAAAACE", and the size is 50 for instance, then it will only render "SPAAAA" and then a half A, or whatever is remaining in the pixels.

For my listbox, it's kind of the same thing. If I am scrolled half down, one element needs to be only half-visible.

How can I do this? Is it possible to add something to a buffer, and then before drawing it, clearing a specific rectangle from the buffer again?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You could use a scissor rectangle. It's a property on the GraphicsDevice class that you can set. Scissor testing must also be enabled.

The scissor rectangle only allows draws in a certain area (a rectangle). This would cut off the pixels, not the letters, of the text you are trying to draw. There are other ways to do this, but you might find this to be the easiest.

share|improve this answer

Set your GraphicsDevice.Viewport or GraphicsDevice.ScissorRectangle so that you are only drawing over the top of your text area. You must be outside of a sprite-batch when you do this (ie: between end and begin). Remember to set it back when you're done.

Remember that SpriteBatch's drawing area covers the viewport (so (0,0) is the top-left of the viewport).

share|improve this answer
    
Wow, literally didn't see this till after I posted... –  Michael Coleman May 29 '11 at 2:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.