In case it matters, I am using XNA 3.1, although if 4.0 would help greatly I may consider moving.
I am trying to draw a textbox in my game. I'd like to be able to have the text displayed only inside the textbox (so that if the string is longer, at the edge of the textbox only perhaps a partial character is shown).
The problem I have is that either the text isn't clipped, in which case it just carries on outside the bounds of the textbox, or using the suggestion described here -- http://social.msdn.microsoft.com/forums/en-US/xnagamestudioexpress/thread/9c395c84-2257-4103-b75c-d9378425cc09 -- I found that if I use the code:
spriteBatch.GraphicsDevice.RenderState.ScissorTestEnable = true;
spriteBatch.GraphicsDevice.ScissorRectangle = myTextBox.GetRectangle();
I can get it clipping inside the text box exactly as I would like but unfortunately, it doesn't show anything else within the game at all! The post that suggests using the ScissorRectangle says it needs to be done on each SpriteBatch. This led me to think I need a new SpriteBatch just for this bit. I tried creating a new spriteBatch using the existing one's graphics device (new SpriteBatch(spriteBath.GraphicsDevice)), and then modifying that, but since it's a reference it had the same problem, so I felt I need to either clone the SpriteBatch or GraphicsDevice objects somehow, or create a new GraphicsDevice (I wasn't sure what to put in the latter's parameters). Clone methods aren't available, and something tells me I'm complicating this somewhat, so that's why I've put all this background in.
If I want to display a textbox with clipped text, is a new SpriteBatch with this ScissorRectangle the best way forward (it does seem to work well), and if so, how do I go about getting a new SpriteBatch so that I can just display my textbox clipped like this, but the rest of the game draws fine? I tried creating a new spritebatch at the same time as I create the main game's one, but because the GraphicsDevice had to be the same, I couldn't make it so one changed and and the other didn't.
Thanks very much. If I've missed any useful details please let me know -- at this point I've no idea what might be relevant.