// Adds a token to text result. private static String AddToken(Direct3D.Font font, Sprite sprite, int width, String text, ref String currLine, String token, Color color) { Rectangle r = font.MeasureString(sprite, currLine + token, DrawTextFormat.None, color); if (r.Width <= width || currLine == "") { text += token; currLine += token; } else { if (token == " ") token = ""; text += ("\n" + token); currLine = token; } return text; }
/// <summary> /// Measures the rectangle dimensions of the specified text string when /// drawn with the specified <see cref="Microsoft.DirectX.Direct3D.Sprite"> /// Microsoft.DirectX.Direct3D.Sprite</see> object. /// </summary> /// <param name="font"> /// The Direct3D font for which to measure the specified text. /// </param> /// <param name="sprite"> /// A <see cref="Microsoft.DirectX.Direct3D.Sprite">Sprite</see> object that /// contains the string. /// </param> /// <param name="text">String to measure.</param> /// <param name="width">Maximum width of the string.</param> /// <param name="color">Color of the text.</param> /// <returns> /// A Rectangle structure that contains the rectangle, in logical coordinates, that /// encompasses the formatted text string. /// </returns> public static Rectangle MeasureString(Direct3D.Font font, Sprite sprite, String text, int width, Color color) { return font.MeasureString(sprite, WrapString(sprite, font, text, width, color), DrawTextFormat.None, color); }