Beispiel #1
0
        void primativeText(float size, Vector2 pos, Color4 col, String text)
        {
            float x = (float)(int)pos.X;
            float y = (float)(int)pos.Y;

            //the built in font is 32 pixels high
            float scale      = size / 32.0f;
            float lineHeight = 32.0f * scale;

            foreach (Char c in text)
            {
                if (c < 32)
                {
                    if (c == '\n')
                    {
                        x  = pos.X;
                        y -= lineHeight;
                        continue;
                    }

                    if (c == '\r')
                    {
                        continue;
                    }
                }

                float charWidth = 0.0f;
                Glyph g         = theGlyphs[c];
                if (g != null)
                {
                    charWidth = g.size.X * scale;

                    if ((c != ' ') && (c != '\t'))
                    {
                        float x1 = x + g.offset.X * scale;
                        float y1 = y + g.offset.Y * scale;
                        float x2 = x + g.size.Y * scale;
                        float y2 = y + g.size.Y * scale;

                        //these seem backwards but only because we're doing some crazy inversion thing with UI screen space to window space
                        Vector2 uv1 = new Vector2(g.minTexCoord.X, g.maxTexCoord.Y);
                        Vector2 uv2 = new Vector2(g.maxTexCoord.X, g.minTexCoord.Y);

                        primativeRectUv(new Vector2(x1, y1), new Vector2(x2, y2), uv1, uv2, col);

                        //keep the letters a little closer together than needed
                        x += g.advance.X * scale;
                    }
                    else
                    {
                        if (c == ' ')
                        {
                            x += g.advance.X * scale;
                        }
                        if (c == '\t')
                        {
                            x += g.advance.X * scale * 3;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void addIcon(Icons icon, Vector2 a, Vector2 b)
        {
            Glyph g = theGlyphs[(int)icon];

            addImage(theDefaultTexture, a, b, g.minTexCoord, g.maxTexCoord, Color4.White);
        }