/// <summary>
        /// Draws a multiline text using the Primitives spritebatch.
        /// </summary>
        /// <param name="text">Text to be drawn.</param>
        /// <param name="rectangle">The rectangle bounding the text.</param>
        /// <param name="color">Text color.</param>
        /// <param name="font">Text font (Verdana 14, if null).</param>
        /// <param name="alignment">Text alignment.</param>
        public static void DrawMultiLineText(
            string text,
            Rectangle rectangle,
            Color color,
            SpriteFont font         = null,
            TextAlignment alignment = TextAlignment.TopLeft)
        {
            if (font == null)
            {
                font = Library.FontVerdana;
            }
            Rectangle       empty;
            MultilineString ms = new MultilineString(text, rectangle, alignment, font, Vector2.Zero, true, null);

            foreach (MultilineString msCache in multilineStringCache)
            {
                if (ms.Equals(msCache))
                {
                    foreach (MultilineLine line in msCache.CachedLines)
                    {
                        spriteBatch.DrawString(font, line.Text, new Vector2(rectangle.X + line.PositionOffset.X, rectangle.Y + line.PositionOffset.Y), color);
                    }
                    return;
                }
            }
            List <MultilineLine> cachedLines;

            DrawMultiLineTextDetailedParameters(spriteBatch, font, text, rectangle, color, alignment, true, new Vector2(0, 0), out empty, out cachedLines);
            multilineStringCache.Add(new MultilineString(text, rectangle, alignment, font, Vector2.Zero, true, cachedLines));
        }
Esempio n. 2
0
        public static void DrawMultiLineText(string text, Rectangle rect, Color color, SpriteFont font = null, TextAlignment alignment = TextAlignment.TopLeft)
        {
            if (font == null)
            {
                font = Library.FontConsoleNormal;
            }
            Rectangle       empty = Rectangle.Empty;
            MultilineString ms    = new MultilineString(text, rect, alignment, font, Vector2.Zero, true, null);

            foreach (MultilineString msCache in MultilineStringCache)
            {
                if (ms.Equals(msCache))
                {
                    foreach (MultilineLine line in msCache.CachedLines)
                    {
                        SpriteBatch.DrawString(font, line.Text, line.Position, color);
                    }
                    return;
                }
            }
            List <MultilineLine> cachedLines = new List <MultilineLine>();

            DrawMultiLineTextDetailedParameters(SpriteBatch, font, text, rect, color, alignment, true, new Vector2(0, 0), out empty, out cachedLines);
            MultilineStringCache.Add(new MultilineString(text, rect, alignment, font, Vector2.Zero, true, cachedLines));
        }
        /// <summary>
        /// Draws a multiline text using the Primitives spritebatch.
        /// </summary>
        /// <param name="text">Text to be drawn.</param>
        /// <param name="rectangle">The rectangle bounding the text.</param>
        /// <param name="color">Text color.</param>
        /// <param name="font">Text font (Verdana 14, if null).</param>
        /// <param name="alignment">Text alignment.</param>
        public static void DrawMultiLineText(
            string text,
            Rectangle rectangle,
            Color color,
            FontFamily font         = FontFamily.Small,
            TextAlignment alignment = TextAlignment.TopLeft)
        {
            Rectangle       empty;
            MultilineString ms = new MultilineString(text, rectangle, alignment, font, Vector2.Zero, true, null, color);

            foreach (MultilineString msCache in multilineStringCache)
            {
                if (ms.Equals(msCache))
                {
                    foreach (MultilineFragment line in msCache.CachedLines)
                    {
                        if (line.Icon != null)
                        {
                            spriteBatch.Draw(line.Icon,
                                             new Rectangle(rectangle.X + (int)line.PositionOffset.X, rectangle.Y + (int)line.PositionOffset.Y,
                                                           line.IconWidth, line.IconWidth), Color.White);
                        }
                        else
                        {
                            if (line.Color != color)
                            {
                                /*
                                 * Color shadowColor = line.Color.Alpha(120);
                                 * spriteBatch.DrawString(line.Font, line.Text,
                                 *  new Vector2(rectangle.X + (int)line.PositionOffset.X - 1,
                                 *  rectangle.Y + (int)line.PositionOffset.Y - 1), shadowColor);
                                 * spriteBatch.DrawString(line.Font, line.Text,
                                 *  new Vector2(rectangle.X + (int)line.PositionOffset.X + 1,
                                 *  rectangle.Y + (int)line.PositionOffset.Y - 1), shadowColor);
                                 * spriteBatch.DrawString(line.Font, line.Text,
                                 *  new Vector2(rectangle.X + (int)line.PositionOffset.X - 1,
                                 *  rectangle.Y + (int)line.PositionOffset.Y + 1), shadowColor);
                                 * spriteBatch.DrawString(line.Font, line.Text,
                                 *  new Vector2(rectangle.X + (int)line.PositionOffset.X + 1,
                                 *  rectangle.Y + (int)line.PositionOffset.Y + 1), shadowColor);
                                 */
                            }
                            spriteBatch.DrawString(line.Font, line.Text,
                                                   new Vector2(rectangle.X + (int)line.PositionOffset.X,
                                                               rectangle.Y + (int)line.PositionOffset.Y), line.Color);
                        }
                    }
                    return;
                }
            }
            List <MultilineFragment> cachedLines;

            Primitives.SetupNewMultilineString(font, text, rectangle, color, alignment, out empty, out cachedLines);
            multilineStringCache.Add(new MultilineString(text, rectangle, alignment, font, Vector2.Zero, true, cachedLines, color));
            Primitives.DrawMultiLineText(text, rectangle, color, font, alignment);
        }