示例#1
0
        public static void RenderText(
            String text, float X, float Y, float wrapAt, float scale, Render.RenderContext context, BitmapFont font, float depth = 0)
        {
            //wrapAt /= scale;
            context.Texture = font.fontData;

            var x = X;
            var y = Y;

            var kx = (font.glyphWidth - font.kerningWidth) / 2;
            int col = (int)font.fontData.Width / (int)font.glyphWidth;

            for (var i = 0; i < text.Length; ++i)
            {
                if (x >= wrapAt)
                {
                    y += font.glyphHeight * scale;
                    x = X;
                }

                var code = text[i];
                if (code == '\n')
                {
                    x = X;
                    y += font.glyphHeight * scale;
                }
                else if (code == ' ')
                {
                    x += font.kerningWidth * scale;
                }
                else if (code < 0x80)
                {
                    var fx = (code % col) * font.fgWidth;
                    var fy = (code / col) * font.fgHeight;

                    context.ImmediateMode.Glyph(x, y, font.glyphWidth * scale, font.glyphHeight * scale,
                        fx,
                        fy,
             						font.fgWidth,
                        font.fgHeight,
                        depth);

                    x += font.kerningWidth * scale;
                }
            }
        }
示例#2
0
文件: BitmapFont.cs 项目: hvp/Gemgine
        public static void RenderText(
            String text, float X, float Y, float wrapAt, Renderer.RenderContext2D context, BitmapFont font, float depth = 0)
        {
            context.Texture = font.fontData;

            var x = X;
            var y = Y;

            var kx = (font.glypthWidth - font.kerningWidth) / 2;
            int col = (int)font.fontData.Width / (int)font.glypthWidth;

            for (var i = 0; i < text.Length; ++i)
            {
                if (x >= wrapAt)
                {
                    y += font.glypthHeight;
                    x = X;
                }

                var code = text[i];
                if (code == '\n')
                {
                    x = X;
                    y += font.glypthHeight;
                }
                else if (code == ' ')
                {
                    x += font.kerningWidth;
                }
                else if (code < 0x80)
                {
                    //code -= (char)0x20;
                    float fx = (code % col) * font.glypthWidth;
                    float fy = (code / col) * font.glypthHeight;

                    context.Glyph(x, y, font.glypthWidth, font.glypthHeight, fx / font.fontData.Width,
                        fy / font.fontData.Height, font.glypthWidth / font.fontData.Width,
                        font.glypthHeight / font.fontData.Height, depth);
                    //context.Quad(X, Y, font.glypthWidth, font.glypthHeight, fx, fy, font.glypthWidth, font.glyphHeight

                    x += font.kerningWidth;
                }
            }
        }
示例#3
0
        public static void RenderText(
            String text, float X, float Y, float wrapAt, Render.ImmediateMode2d context, BitmapFont font, float depth = 0)
        {
            context.Texture = font.fontData;

            var x = X;
            var y = Y;

            var kx  = (font.glyphWidth - font.kerningWidth) / 2;
            int col = (int)font.fontData.Width / (int)font.glyphWidth;

            for (var i = 0; i < text.Length; ++i)
            {
                if (x >= wrapAt)
                {
                    y += font.glyphHeight;
                    x  = X;
                }

                var code = text[i];
                if (code == '\n')
                {
                    x  = X;
                    y += font.glyphHeight;
                }
                else if (code == ' ')
                {
                    x += font.kerningWidth;
                }
                else if (code < 0x80)
                {
                    float fx = (code % col) * font.glyphWidth;
                    float fy = (code / col) * font.glyphHeight;

                    context.Glyph(x, y, font.glyphWidth, font.glyphHeight, fx / font.fontData.Width,
                                  fy / font.fontData.Height, (float)font.glyphWidth / (float)font.fontData.Width,
                                  (float)font.glyphHeight / (float)font.fontData.Height, depth);

                    x += font.kerningWidth;
                }
            }
        }