Exemple #1
0
        public static void DrawString(this SpriteBatch spriteBatch, SpriteBitmapFont font, string text, Vector2 position, Color color, Color outlineColor)
        {
            var previousCharacter = ' ';
            var normalizedText = text.Replace("\r\n", "\n").Replace("\r", "\n");

            var x = 0;
            var y = 0;

            foreach (var character in normalizedText)
            {
                if (character == '\n')
                {
                    x = 0;
                    y += font.LineHeight;
                    continue;
                }

                var data = font[character];
                var kerning = font.GetKerning(previousCharacter, character);

                DrawSymbol(spriteBatch, font, data, (int)position.X + (x + data.Offset.X + kerning), (int)position.Y + (y + data.Offset.Y), color, outlineColor);
                x += data.XAdvance + kerning;

                previousCharacter = character;
            }
        }
Exemple #2
0
        private static void DrawSymbol(SpriteBatch spriteBatch, SpriteBitmapFont font, ISymbol symbol, int x, int y, Color color, Color outlineColor)
        {
            if (symbol.SymbolType == SymbolType.Icon)
            {
                var iconSymbol = (IconSymbol)symbol;

                spriteBatch.Draw(iconSymbol.Texture, new Vector2(x, y), null, Color.White);
                return;
            }

            spriteBatch.Draw(font.Textures[symbol.TexturePage], new Vector2(x, y), symbol.Bounds, color);
        }
Exemple #3
0
        public static SpriteBitmapFont LoadFile(Stream stream, ContentManager contentManager)
        {
            var font = new SpriteBitmapFont();
            font.Load(stream);

            font.Textures = new Texture2D[font.Pages.Length];
            for (int i = 0; i < font.Pages.Length; i++)
            {
                font.Textures[i] = contentManager.Load<Texture2D>(font.Pages[i].FileName);
            }

            return font;
        }
Exemple #4
0
        public static SpriteBitmapFont LoadFile(Stream stream, ContentManager contentManager)
        {
            var font = new SpriteBitmapFont();

            font.Load(stream);

            font.Textures = new Texture2D[font.Pages.Length];
            for (int i = 0; i < font.Pages.Length; i++)
            {
                font.Textures[i] = contentManager.Load <Texture2D>(font.Pages[i].FileName);
            }

            return(font);
        }
Exemple #5
0
        public static SpriteBitmapFont LoadFile(Stream stream, GraphicsDevice graphicsDevice)
        {
            var font = new SpriteBitmapFont();
            font.Load(stream);

            font.Textures = new Texture2D[font.Pages.Length];
            for (int i = 0; i < font.Pages.Length; i++)
            {
                using (var fs = new FileStream(font.Pages[i].FileName, FileMode.Open, FileAccess.Read))
                {
                    font.Textures[i] = Texture2D.FromStream(graphicsDevice, fs);
                }
            }

            return font;
        }
Exemple #6
0
        public static SpriteBitmapFont LoadFile(Stream stream, GraphicsDevice graphicsDevice)
        {
            var font = new SpriteBitmapFont();

            font.Load(stream);

            font.Textures = new Texture2D[font.Pages.Length];
            for (int i = 0; i < font.Pages.Length; i++)
            {
                using (var fs = new FileStream(font.Pages[i].FileName, FileMode.Open, FileAccess.Read))
                {
                    font.Textures[i] = Texture2D.FromStream(graphicsDevice, fs);
                }
            }

            return(font);
        }
Exemple #7
0
 public static void DrawString(this SpriteBatch spriteBatch, SpriteBitmapFont font, string text, Vector2 position, Color color)
 {
     spriteBatch.DrawString(font, text, position, color, color);
 }
Exemple #8
0
        protected override void LoadContent()
        {
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            Assets.Initialize(GraphicsDevice, Content.RootDirectory);

            Assets.RegisterTextureCollection("animals", new[]
            {
                "monkey.png",
                "parrot.png",
                "penguin.png",
                "pig.png",
                "snake.png",
                "rabbit.png",
                "giraffe.png"
            },
            true);

            Assets.RegisterTexture("starburst_1024_blue.png", "background");
            Assets.RegisterFont("Content/Fonts/dsfont.fnt", "dsfont");

            _font = Assets.GetFont("dsfont");
            base.LoadContent();
        }