Ejemplo n.º 1
0
        private static string WrapText(ISpriteFont font, string text, double maxLineWidth)
        {
            const string Space         = " ";
            var          stringBuilder = new StringBuilder();

            string[] words = WhiteSpaceRegEx.Split(text);

            double lineWidth  = 0;
            double spaceWidth = font.MeasureString(Space).Width;

            foreach (string word in words)
            {
                Size size = font.MeasureString(word);

                if (lineWidth + size.Width < maxLineWidth)
                {
                    stringBuilder.AppendFormat("{0}{1}", lineWidth == 0 ? string.Empty : Space, word);
                    lineWidth += size.Width + spaceWidth;
                }
                else
                {
                    stringBuilder.AppendFormat("\n{0}", word);
                    lineWidth = size.Width + spaceWidth;
                }
            }

            return(stringBuilder.ToString());
        }
Ejemplo n.º 2
0
        private static string WrapText(ISpriteFont font, string text, double maxLineWidth)
        {
            const string Space = " ";
            var stringBuilder = new StringBuilder();
            string[] words = WhiteSpaceRegEx.Split(text);

            double lineWidth = 0;
            double spaceWidth = font.MeasureString(Space).Width;

            foreach (string word in words)
            {
                Size size = font.MeasureString(word);

                if (lineWidth + size.Width < maxLineWidth)
                {
                    stringBuilder.AppendFormat("{0}{1}", lineWidth == 0 ? string.Empty : Space, word);
                    lineWidth += size.Width + spaceWidth;
                }
                else
                {
                    stringBuilder.AppendFormat("\n{0}", word);
                    lineWidth = size.Width + spaceWidth;
                }
            }

            return stringBuilder.ToString();
        }
Ejemplo n.º 3
0
 private void SetData(Vector2 position, ISpriteFont font, string text, Vector2 scale, Color color)
 {
     DrawnStrings.AddLast(text);
     SetData(position, font.MeasureString(text), scale, color);
 }