public void GetTextMesh(List <Mesh> result) { var drawableArea = GetDrawableInterior(); var stringMeshSize = new Rectangle(); var font = Root.GetTileSheet(Font); var text = (font is VariableWidthFont && WrapText) ? (font as VariableWidthFont).WordWrapString(Text, TextSize, drawableArea.Width) : Text; var stringMesh = Mesh.CreateStringMesh( text, font, new Vector2(TextSize, TextSize), out stringMeshSize) .Colorize(TextColor); var textDrawPos = Vector2.Zero; switch (TextHorizontalAlign) { case HorizontalAlign.Left: textDrawPos.X = drawableArea.X; break; case HorizontalAlign.Right: textDrawPos.X = drawableArea.X + drawableArea.Width - stringMeshSize.Width; break; case HorizontalAlign.Center: textDrawPos.X = drawableArea.X + ((drawableArea.Width - stringMeshSize.Width) / 2); break; } switch (TextVerticalAlign) { case VerticalAlign.Top: textDrawPos.Y = drawableArea.Y; break; case VerticalAlign.Bottom: textDrawPos.Y = drawableArea.Y + drawableArea.Height - stringMeshSize.Height; break; case VerticalAlign.Below: textDrawPos.Y = drawableArea.Y + drawableArea.Height; break; case VerticalAlign.Center: textDrawPos.Y = drawableArea.Y + ((drawableArea.Height - stringMeshSize.Height) / 2); break; } stringMesh.Translate(textDrawPos.X, textDrawPos.Y); result.Add(stringMesh); }
public void GetTextMesh(List <Mesh> result, String Text, Vector4 TextColor) { var drawableArea = GetDrawableInterior(); var stringMeshSize = new Rectangle(); var font = Root.GetTileSheet(Font); var text = (WrapText || WrapWithinWords) ? font.WordWrapString(Text, TextSize, drawableArea.Width, WrapWithinWords) : Text; var stringMesh = Mesh.CreateStringMesh( text, font, new Vector2(TextSize, TextSize), out stringMeshSize) .Colorize(TextColor); if (AutoResizeToTextHeight && stringMeshSize.Height < Rect.Height) { if (!String.IsNullOrEmpty(Border)) { var tileSheet = Root.GetTileSheet(Border); Rect = new Rectangle(Rect.X, Rect.Y, Rect.Width, stringMeshSize.Height + tileSheet.TileHeight * 2); } else { Rect = new Rectangle(Rect.X, Rect.Y, Rect.Width, stringMeshSize.Height); } MinimumSize.Y = stringMeshSize.Height; Parent.Layout(); } var textDrawPos = Vector2.Zero; switch (TextHorizontalAlign) { case HorizontalAlign.Left: textDrawPos.X = drawableArea.X; break; case HorizontalAlign.Right: textDrawPos.X = drawableArea.X + drawableArea.Width - stringMeshSize.Width; break; case HorizontalAlign.Center: textDrawPos.X = drawableArea.X + ((drawableArea.Width - stringMeshSize.Width) / 2); break; } switch (TextVerticalAlign) { case VerticalAlign.Top: textDrawPos.Y = drawableArea.Y; break; case VerticalAlign.Bottom: textDrawPos.Y = drawableArea.Y + drawableArea.Height - stringMeshSize.Height; break; case VerticalAlign.Below: textDrawPos.Y = drawableArea.Y + drawableArea.Height; break; case VerticalAlign.Center: textDrawPos.Y = drawableArea.Y + ((drawableArea.Height - stringMeshSize.Height) / 2); break; } stringMesh.Translate(textDrawPos.X, textDrawPos.Y); result.Add(stringMesh); }