示例#1
0
 public AdvancedDrawBatch(GraphicsDevice device)
 {
     GraphicsDevice  = device;
     _primitiveBatch = new PrimitiveBatch(device);
     _spriteBatch    = new SpriteBatch(device);
     _basicEffect    = new BasicEffect(device);
 }
示例#2
0
        internal void Draw(PrimitiveBatch primitiveBatch, string text, Vector2 position, Color color, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            _colors[0] = color;
            DrawInternal(primitiveBatch, provider, position, _colors, 1, spacing, lineHeight, scale, rotation);
        }
示例#3
0
        void DrawGlyph(PrimitiveBatch primitiveBatch, Glyph glyph, ref Vector2 position, ref Color color, float scale, ref Vector2 right, ref Vector2 down)
        {
            float topLeftX = (glyph.X - 1) / (float)FontSheet.Width;
            float topLeftY = (glyph.Y - 1) / (float)FontSheet.Height;

            float bottomRightX = (float)(glyph.X + glyph.Width + 1) / (float)FontSheet.Width;
            float bottomRightY = (float)(glyph.Y + glyph.Height + 1) / (float)FontSheet.Height;

            Vector2 topLeft  = position - (right + down) * scale;
            Vector2 topRight = position + (right - down) * scale + right * glyph.Width * scale;

            Vector2 bottomLeft  = position - (right - down) * scale + down * glyph.Height * scale;
            Vector2 bottomRight = position + (right + down) * scale + right * glyph.Width * scale + down * glyph.Height * scale;

            primitiveBatch.AddVertex(topLeft.X, topLeft.Y, ref color, topLeftX, topLeftY);
            primitiveBatch.AddVertex(bottomLeft.X, bottomLeft.Y, ref color, topLeftX, bottomRightY);
            primitiveBatch.AddVertex(topRight.X, topRight.Y, ref color, bottomRightX, topLeftY);

            primitiveBatch.AddVertex(bottomLeft.X, bottomLeft.Y, ref color, topLeftX, bottomRightY);
            primitiveBatch.AddVertex(topRight.X, topRight.Y, ref color, bottomRightX, topLeftY);
            primitiveBatch.AddVertex(bottomRight.X, bottomRight.Y, ref color, bottomRightX, bottomRightY);
        }
示例#4
0
        void DrawInternal(PrimitiveBatch primitiveBatch, StringProvider text, Vector2 targetPosition, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation)
        {
            if (primitiveBatch.PrimitiveType != PrimitiveType.TriangleList)
            {
                throw new Exception("PrimitiveBatch has to be started with TriangleList primitive type.");
            }

            Vector2 right = new Vector2(1, 0);
            Vector2 down  = new Vector2(0, 1);

            switch (rotation)
            {
            case TextRotation.Rotate180:
                right = new Vector2(-1, 0);
                down  = new Vector2(0, -1);
                break;

            case TextRotation.Rotate270:
                right = new Vector2(0, 1);
                down  = new Vector2(-1, 0);
                break;

            case TextRotation.Rotate90:
                right = new Vector2(0, -1);
                down  = new Vector2(1, 0);
                break;
            }

            int  count        = text.Length;
            char previousChar = '\0';

            spacing = (float)Height * spacing * scale;

            Vector2 position = targetPosition;

            Color color;

            for (int idx = 0; idx < count; ++idx)
            {
                char  character = text[idx];
                Glyph glyph     = Find(character);

                if (glyph != null)
                {
                    if (previousChar != '\0')
                    {
                        float kerning = (float)glyph.Kerning(previousChar) / 10f;
                        position += right * (kerning * scale + spacing);
                    }

                    previousChar = character;

                    Vector2 pos = position + down * (scale * (glyph.Top - CapLine));

                    color = colors[idx % colors.Length] * opacity;

                    DrawGlyph(primitiveBatch, glyph, ref pos, ref color, scale, ref right, ref down);

                    position += right * (glyph.Width * scale);
                }
                else if (text[idx] == '\n')
                {
                    if (rotation == TextRotation.Rotate270 || rotation == TextRotation.Rotate90)
                    {
                        position.Y = targetPosition.Y;
                    }
                    else
                    {
                        position.X = targetPosition.X;
                    }

                    position    += down * (lineHeight * Height * scale);
                    previousChar = '\0';
                }
            }
        }
示例#5
0
        internal void Draw(PrimitiveBatch primitiveBatch, StringBuilder text, Vector2 position, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            DrawInternal(primitiveBatch, provider, position, colors, opacity, spacing, lineHeight, scale, rotation);
        }