TextElement doesn't take char spacing into account

Dec 8, 2009 at 11:48 PM
Edited Dec 8, 2009 at 11:59 PM

TextElement doesn't take char spacing into account.

When you create a SpriteFont, there is a field in the XML called "Spacing", but Xen does not use it, so if someone want this feature, change Xen.Ex\Graphics2D\TextElement.cs

Int the ElementFont class:

  • add a field :
    public readonly float charSpacing;
  • in the ctr, add :
    Get( font, "spacing", out charSpacing );
  • at the end of TextElement.Build(), change
    position.X += ((kerning.Y + kerning.Z));
    position.X += ((kerning.Y + kerning.Z)) + font.charSpacing;

I have not tested it, but doing the same thing to TextElementRect.Build() should work too.


Free Image Hosting at www.ImageShack.us

Dec 9, 2009 at 9:03 AM

Thank you for pointing this out.

I'm putting together a small maintenance release so I'll make sure to include this.

Dec 9, 2009 at 9:32 AM

Hi Iarus,

I see that you are using Xen and 2D Elements to build a GUI tool and I would like to ask you how you did solve the internal Xen 2D elements origin issue which is placed on the bottom left side of the screen while Mouse movements use an origin on the top left?

When I tried to implement my own GUI with it, I met this issue while trying to create the picking system to define mouse events on top of SpriteElements or TextElements.



Dec 9, 2009 at 8:30 PM

IDrawPosition selectedObject;

private void xenFormHost_MouseMove( object sender, System.Windows.Forms.MouseEventArgs e )
if( isMouseDown )
Vector2 newPos = new Vector2( e.X, -e.Y );
Vector2 delta = newPos - lastMousePosition;

if(selectedObject != null)
selectedObject.Position += delta;

lastMousePosition = newPos;

And every GUI element inherits from ElementRect so I get relative positionning and alignment for free. See my previous post inheritence and ElementRect

For example in my screenshot above, the selectedObject is a MenuTextItemDesign which is a special version of MenuTextItem for the GUI editor that make setting the font and color easier. The MenuTextItem class is like in my previous post and own a TextElement as a child.

also, I made the Element class for Xen implement the IDrawPosition interface (it's IDraw with a Position property), so I'm sure that everything has a position.