Tuesday, January 16, 2007

The mojito is a descendant of the Draquecito, named after Sir Francis Drake and said to be his favorite drink before pirate battles

My chest is opening and shutting, and I want to give the character *prizes!*. First in a crude, text box manner. You've found blah, blah in a text box.

To do that I need to know how big text is. Will the text fit in the box, how big should the box be, what are my options for decorating the box and so on.

This leads to a bit of problem (a problem I vaguely remember having before), that is that using DirectX3D.Font, there's no way to tell how big the fonts going to be. . .

. . . not in early versions of DirectX anyway. I'm sure I was quite current, but I downloaded the December 2006 SDK, and suddenly Font aquired a measure string property. It's a reasonably strange (stupid?) function.

font.MeasureString(null, text, Microsoft.DirectX.Direct3D.DrawTextFormat.None, Colour.White);

That's right, you have to give a colour! Because we all know how a colour can change the size of a given text string. Also the first argument is a sprite, which is also not needed.

This is my very crappy label. At the moment it's a little hard coded. My batcher doesn't do non-textured quads. So hmmmmmmm. I might make a colour quad. I think batching the GUI would be pretty awkard too, but we'll see.


Jani said...

I had some problems with the text width too but the measurestring thing was also my solution (at one point, anyway, the code is mostly scrapped now)

Have you considered using bitmap fonts? ie. have all letters you'll be using in a texture, then draw a single quad for every letter.

balaam said...

Yeah I considered it, I'm using bitmaps fonts in another project. But in this case is was whatever's easiest :D