/// <summary>
        /// Places the specified text centered within the specified width. If the text is too long
        /// to fit on a single line, the text is optimally divided up and placed on consecutive lines.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="yPos">Y-position to draw the text at.</param>
        /// <param name="fontEx">Font info for the text.</param>
        /// <param name="width">Width of the area to draw the text in.</param>
        private void PlaceAssertText(string text, ref float yPos, ref SpriteFontEx fontEx, int width)
        {
            AssertText at;
            float      xPos;

            // Check if the text is too long to place on a single line.
            if ((xPos = (float)Text.CenterWidthwise(text, fontEx.width, width)) < 5f)
            {
                // Text can't fit on one line, so optimally divide it up so it can fit on multiple lines.
                string[] segments = Text.FitToWidthBalanced(text, fontEx.width, width - 10);

                // Place each segment on its own line and center it.
                foreach (string textSegment in segments)
                {
                    at.text       = textSegment;
                    at.position.X = (float)Text.CenterWidthwise(textSegment, fontEx.width, width);
                    at.position.Y = yPos;

                    assertText.Add(at);
                    yPos += fontEx.font.LineSpacing;
                }
            }
            else
            {
                // Text fits on one line.
                at.text       = text;
                at.position.X = xPos;
                at.position.Y = yPos;

                assertText.Add(at);
                yPos += fontEx.font.LineSpacing;
            }
        }
        /// <param name="args">Arguments passed from Debug.Assert.</param>
        public AssertScreen(DebugEventArgs args)
            : base()
        {
            assertText = new List <AssertText>();

            int          width  = VolumetricRenderer.Game.GraphicsDevice.PresentationParameters.BackBufferWidth;
            SpriteFontEx fontEx = VolumetricRenderer.Game.ScreenManager.DefaultFontEx;

            // Set up all the text to be drawn.
            float yPos = 0;

            PlaceAssertText("ASSERT:", ref yPos, ref fontEx, width);

            if (args.Messages.Length > 0)
            {
                for (int i = 0; i < args.Messages.Length; ++i)
                {
                    PlaceAssertText(args.Messages[i], ref yPos, ref fontEx, width);
                    yPos += fontEx.font.LineSpacing;
                }
            }
            else
            {
                PlaceAssertText("(no info)", ref yPos, ref fontEx, width);
                yPos += fontEx.font.LineSpacing;
            }

            PlaceAssertText("IN:", ref yPos, ref fontEx, width);
            PlaceAssertText(args.MethodName, ref yPos, ref fontEx, width);
            PlaceAssertText(args.FileName + ": line " + args.LineNumber, ref yPos, ref fontEx, width);

            yPos += fontEx.font.LineSpacing * 2;
            PlaceAssertText("Press Enter to quit...", ref yPos, ref fontEx, width);

            // Shift all the text down a bit so it's not right at the top of the screen.
            int height  = VolumetricRenderer.Game.GraphicsDevice.PresentationParameters.BackBufferHeight;
            int yOffset = (height - (fontEx.font.LineSpacing * (assertText.Count + 4))) / 3;

            if (yOffset < 5)
            {
                yOffset = 5;
            }

            for (int i = 0; i < assertText.Count; ++i)
            {
                AssertText at = assertText[i];
                at.position.Y += yOffset;
                assertText[i]  = at;
            }

            // Set up the flashing text parameters.
            flashColor = Color.White;
            flashRate  = TimeSpan.FromMilliseconds(700);
            flashDir   = -1;
        }
 public void DrawString(SpriteFontEx spriteFont, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffectsEx effects, Matrix transformMatrix)
 {
     DrawString(spriteFont, text.ToString(), position, color, rotation, origin, scale, effects, transformMatrix);
 }
        public void DrawString(SpriteFontEx spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffectsEx effects, Matrix transformMatrix)
        {
            if (activeVertices == maxVertices || (currentTexture != null && !currentTexture.Equals(spriteFont.Texture)))
                DrawBuffer();

            Vector2 stringSize = spriteFont.MeasureString(text);

            origin.X *= stringSize.X;
            origin.Y *= stringSize.Y;

            if ((effects & SpriteEffectsEx.FlipHorizontally) != SpriteEffectsEx.None)
            {
                scale.X *= -1;
                position.X += stringSize.X;
            }
            if ((effects & SpriteEffectsEx.FlipVertically) != SpriteEffectsEx.None)
            {
                scale.Y *= -1;
                position.Y += stringSize.Y;
            }

            currentTexture = spriteFont.Texture;

            float x = 0, y = 0;

            foreach (char c in text)
            {
                if (c == '\n')
                {
                    y += spriteFont.LineSpacing;
                    continue;
                }
                if (c == '\r')
                {
                    x = 0;
                    continue;
                }

                SpriteFontEx.CharacterData cd = spriteFont[c];

                if (cd.width == 0 || cd.height == 0)
                {
                    x += cd.advanceX;
                    continue;
                }

                if (activeVertices == maxVertices)
                    DrawBuffer();

                int width = cd.width;
                int height = cd.height;

                int textureWidth = currentTexture.Width;
                int textureHeight = currentTexture.Height;

                Vector3 v;
                Matrix transform = Matrix.CreateTranslation(x + cd.offsetX, y + cd.offsetY, 0) *
                    Matrix.CreateTranslation(-origin.X, -origin.Y, 0) *
                    Matrix.CreateScale(scale.X, scale.Y, 1.0f) *
                    Matrix.CreateRotationZ(rotation) *
                    Matrix.CreateTranslation(position.X, position.Y, 0) *
                    transformMatrix;

                v = new Vector3(0, 0, 0);
                v = Vector3.Transform(v, transform);

                vertices[activeVertices].Position = v;
                vertices[activeVertices].Color = color;
                vertices[activeVertices++].TextureCoordinate = new Vector2((float)cd.x / textureWidth, (float)cd.y / textureHeight);

                v = new Vector3(width, 0, 0);
                v = Vector3.Transform(v, transform);

                vertices[activeVertices].Position = v;
                vertices[activeVertices].Color = color;
                vertices[activeVertices++].TextureCoordinate = new Vector2((float)(cd.x + cd.width) / textureWidth, (float)cd.y / textureHeight);

                v = new Vector3(0, height, 0);
                v = Vector3.Transform(v, transform);

                vertices[activeVertices].Position = v;
                vertices[activeVertices].Color = color;
                vertices[activeVertices++].TextureCoordinate = new Vector2((float)cd.x / textureWidth, (float)(cd.y + cd.height) / textureHeight);

                v = new Vector3(width, height, 0);
                v = Vector3.Transform(v, transform);

                vertices[activeVertices].Position = v;
                vertices[activeVertices].Color = color;
                vertices[activeVertices++].TextureCoordinate = new Vector2((float)(cd.x + cd.width) / textureWidth, (float)(cd.y + cd.height) / textureHeight);

                x += cd.advanceX;
            }
        }
 public void DrawString(SpriteFontEx spriteFont, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffectsEx effects, float layerDepth)
 {
     DrawString(spriteFont, text.ToString(), position, color, rotation, origin, scale, effects, Matrix.Identity);
 }
 public void DrawString(SpriteFontEx spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffectsEx effects, float layerDepth)
 {
     DrawString(spriteFont, text, position, color, rotation, origin, new Vector2(scale), effects, Matrix.Identity);
 }
 public void DrawString(SpriteFontEx spriteFont, StringBuilder text, Vector2 position, Color color)
 {
     DrawString(spriteFont, text.ToString(), position, color, 0, Vector2.Zero, Vector2.One, SpriteEffectsEx.None, Matrix.Identity);
 }