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, 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, 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, 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 Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffectsEx effects, Matrix transformMatrix)
        {
            if (activeVertices == maxVertices || (currentTexture != null && !currentTexture.Equals(texture)))
                DrawBuffer();

            currentTexture = texture;

            Rectangle textureRect = new Rectangle(0, 0, texture.Width, texture.Height);
            Rectangle rectangle;

            if (sourceRectangle.HasValue)
                rectangle = sourceRectangle.Value;
            else
                rectangle = textureRect;

            int width = rectangle.Width;
            int height = rectangle.Height;

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

            Vector2 uvTL, uvTR, uvBL, uvBR;
            Vector2 temp;

            if ((effects & SpriteEffectsEx.RotatePackedUVs) != SpriteEffectsEx.None)
            {
                uvTL = new Vector2((float)(rectangle.X + rectangle.Height) / textureWidth, (float)rectangle.Y / textureHeight);
                uvTR = new Vector2((float)(rectangle.X + rectangle.Height) / textureWidth, (float)(rectangle.Y + rectangle.Width) / textureHeight);
                uvBL = new Vector2((float)rectangle.X / textureWidth, (float)rectangle.Y / textureHeight);
                uvBR = new Vector2((float)rectangle.X / textureWidth, (float)(rectangle.Y + rectangle.Width) / textureHeight);
            }
            else
            {
                uvTL = new Vector2(rectangle.X / (float)textureWidth, rectangle.Y / (float)textureHeight);
                uvTR = new Vector2((rectangle.X + rectangle.Width) / (float)textureWidth, rectangle.Y / (float)textureHeight);
                uvBL = new Vector2(rectangle.X / (float)textureWidth, (rectangle.Y + rectangle.Height) / (float)textureHeight);
                uvBR = new Vector2((rectangle.X + rectangle.Width) / (float)textureWidth, (rectangle.Y + rectangle.Height) / (float)textureHeight);
            }

            if ((effects & SpriteEffectsEx.FlipVertically) != SpriteEffectsEx.None)
            {
                temp = uvTL;
                uvTL = uvBL;
                uvBL = temp;
                temp = uvTR;
                uvTR = uvBR;
                uvBR = temp;
            }
            if ((effects & SpriteEffectsEx.FlipHorizontally) != SpriteEffectsEx.None)
            {
                temp = uvTL;
                uvTL = uvTR;
                uvTR = temp;
                temp = uvBL;
                uvBL = uvBR;
                uvBR = temp;
            }

            Vector3 v;
            Matrix transform = Matrix.CreateScale(scale.X, scale.Y, 1.0f) *
                Matrix.CreateRotationZ(rotation) *
                Matrix.CreateTranslation(position.X, position.Y, 0) *
                transformMatrix;

            v.X = -width * origin.X;
            v.Y = -height * origin.Y;
            v.Z = 0;
            v = Vector3.Transform(v, transform);

            vertices[activeVertices].Position = new Microsoft.Xna.Framework.Vector3(v.X, v.Y, 0);
            vertices[activeVertices].Color = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A);
            vertices[activeVertices++].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(uvTL.X, uvTL.Y);

            v.X = width * (1 - origin.X);
            v.Y = -height * origin.Y;
            v.Z = 0;
            v = Vector3.Transform(v, transform);

            vertices[activeVertices].Position = new Microsoft.Xna.Framework.Vector3(v.X, v.Y, 0);
            vertices[activeVertices].Color = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A);
            vertices[activeVertices++].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(uvTR.X, uvTR.Y);

            v.X = -width * origin.X;
            v.Y = height * (1 - origin.Y);
            v.Z = 0;
            v = Vector3.Transform(v, transform);

            vertices[activeVertices].Position = new Microsoft.Xna.Framework.Vector3(v.X, v.Y, 0);
            vertices[activeVertices].Color = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A);
            vertices[activeVertices++].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(uvBL.X, uvBL.Y);

            v.X = width * (1 - origin.X);
            v.Y = height * (1 - origin.Y);
            v.Z = 0;
            v = Vector3.Transform(v, transform);

            vertices[activeVertices].Position = new Microsoft.Xna.Framework.Vector3(v.X, v.Y, 0);
            vertices[activeVertices].Color = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A);
            vertices[activeVertices++].TextureCoordinate = new Microsoft.Xna.Framework.Vector2(uvBR.X, uvBR.Y);
        }
        public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffectsEx effects, float layerDepth)
        {
            float width = (sourceRectangle.HasValue) ? sourceRectangle.Value.Width : texture.Width;
            float height = (sourceRectangle.HasValue) ? sourceRectangle.Value.Height : texture.Height;

            Draw(texture, new Vector2(destinationRectangle.X, destinationRectangle.Y), sourceRectangle, color, rotation, origin, new Vector2(destinationRectangle.Width / width, destinationRectangle.Height / height), effects, Matrix.Identity);
        }
 public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffectsEx effects, float layerDepth)
 {
     Draw(texture, position, sourceRectangle, color, rotation, origin, scale, effects, Matrix.Identity);
 }
 public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffectsEx effects, float layerDepth)
 {
     Draw(texture, position, sourceRectangle, color, rotation, origin, new Vector2(scale), effects, layerDepth);
 }