Graphics2D Elements and inherited classes and Position mix up

Aug 23, 2009 at 11:53 PM

StatusUnknown, (or anyone else who got it working correctly :p)

When you get a chance, I would really appreciate some help to understand how you compute all the 2D positions on Graphics2D Elements and its inherited classes as I'm getting totally lost with positioning them as well as sizing them correctly.

The BottomLeft 2D origin is really annoying especially when you are used to compare positions with Mouse TopLeft origin.

TextElementRect instances do not size correctly and always put three dots even when using SpriteFont.MeasureString(TextElementRect.Text) which should give the exact size... Is it a bug?

Thanks :-)


Sep 1, 2009 at 8:49 PM
Edited Sep 2, 2009 at 8:23 PM

Hi phil, sorry I didn't see your post.

TextElementRect can be set to automatically size itself downwards to fit the content, so then you just set the width, however, if you want to just display a text string then use TextElement (it won't cut off...)
SpriteFont measure string possibly will be different, as I handle a lot of things internally very differently (eg, tabs are valid, where they are ignored by SpriteFont).

The alignment of elements can be to top/bottom left/right corners or centre, and then the position is the offset from that aligned position. So for example, top left alignment is x = 0, y = max. So to bring the element down, you'd need to set the position to a negative value for y. The confusing bit (I admit) is that text element default to top left, all other elements default to bottom right. It made sense at the time sorry :-)

Sep 2, 2009 at 8:22 PM

Hi StatusUnknown,

That's fine if you didn't had the time to answer in a shorter time. I couldn't myself work on my project due to my current job tasks :)

Do you expect to change this confusing bit or should we consider the current behavior to stay as is? Would you see any issue if I made a change in the code and submit it to you as a patch?


Sep 21, 2009 at 9:36 AM


Could you please tell me if you plan to change the current origin coordinates behavior from bottom left to top left so that it matches the mouse coordinate system?

Or maybe could you tell me how I could manage to test if the mouse is over any 2D element?



Sep 21, 2009 at 8:31 PM

No, because bottom left matches the 3D coordinate system, and it would break existing code.

And you can always do mouse.y = windowHeight - mouse.y.