コード例 #1
0
    float GetStringWidth(string str)
    {
        TGlyph prevGlyph = null;
        float  width     = 0f;

        foreach (char c in str)
        {
            int    charCode = (int)c;
            TGlyph glyph    = Font.Glyphs.Get(charCode);

            if (glyph == null)
            {
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
            {
                kerning = prevGlyph.GetKerning(charCode);
            }

            width    += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        return(width);
    }
コード例 #2
0
    float BlitString(string str, float cursorX, float cursorY, List <int> vertexPointers = null)
    {
        TGlyph prevGlyph = null;

        foreach (char c in str)
        {
            int    charCode = (int)c;
            TGlyph glyph    = Font.Glyphs.Get(charCode);

            if (glyph == null)
            {
                continue;
            }

            if (charCode == 32)
            {
                cursorX += glyph.xAdvance * Size + Tracking;
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
            {
                kerning = prevGlyph.GetKerning(charCode);
            }

            if (vertexPointers != null)
            {
                vertexPointers.Add(m_Vertices.Count);
            }

            BlitQuad(
                new Rect(
                    cursorX + glyph.xOffset * Size + kerning,
                    cursorY + glyph.yOffset * Size,
                    glyph.rect.width * Size,
                    glyph.rect.height * Size
                    ),
                glyph
                );

            cursorX  += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        if (cursorX > Width)
        {
            Width = cursorX;
        }

        return(cursorX);
    }
コード例 #3
0
    float GetStringWidth(string str)
    {
        TGlyph prevGlyph     = null;
        bool   inControlCode = false;
        float  width         = 0f;

        foreach (char c in str)
        {
            int charCode = (int)c;

            if (inControlCode)
            {
                inControlCode = false;

                if (charCode >= 48 && charCode <= 57)                 // 0-9
                {
                    continue;
                }
            }
            else
            {
                if (charCode == 92)                 // Backslash
                {
                    inControlCode = true;
                    continue;
                }
            }

            TGlyph glyph = Font.Glyphs.Get(charCode);

            if (glyph == null)
            {
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
            {
                kerning = prevGlyph.GetKerning(charCode) * Size;
            }

            width    += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        return(width);
    }
コード例 #4
0
    float BlitString(string str, float cursorX, float cursorY, List <int> vertexPointers = null)
    {
        TGlyph prevGlyph = null;
        Rect   r;
        bool   inControlCode     = false;
        int    requestedMaterial = 0;

        foreach (char c in str)
        {
            int charCode = (int)c;

            if (inControlCode)
            {
                inControlCode = false;

                if (charCode >= 48 && charCode <= 57)                 // 0-9
                {
                    requestedMaterial = charCode - 48;

                    if (requestedMaterial < _materialCount)
                    {
                        _currentMaterial = requestedMaterial;
                    }
                    else
                    {
                        Debug.LogWarning(string.Format(
                                             "Requested material {0} out of range.", requestedMaterial
                                             ));
                    }

                    AddPlaceholderGlyphBounds();
                    continue;
                }
            }
            else
            {
                if (charCode == 92)                 // Backslash
                {
                    inControlCode = true;
                    AddPlaceholderGlyphBounds();
                    continue;
                }
            }

            TGlyph glyph = Font.Glyphs.Get(charCode);

            if (glyph == null)
            {
                continue;
            }

            if (charCode == 32)
            {
                // Assuming here that spaces should not be clickable.
                AddPlaceholderGlyphBounds();
                cursorX += glyph.xAdvance * Size + Tracking;
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
            {
                kerning = prevGlyph.GetKerning(charCode) * Size;
            }

            if (vertexPointers != null)
            {
                vertexPointers.Add(m_Vertices.Count);
            }

            r = new Rect(
                cursorX + glyph.xOffset * Size + kerning,
                cursorY + glyph.yOffset * Size,
                glyph.rect.width * Size,
                glyph.rect.height * Size
                );

            BlitQuad(r, glyph);

            // Click bounds for glyphs are based on allocated space, not rendered space.
            // Otherwise we'll end up with unclickable dead zones between glyphs.
            r.width = glyph.xAdvance * Size;
            // And Y coordinates are just not handled the same at all.
            r.y = -cursorY - r.height - glyph.yOffset * Size;

            StoreGlyphBounds(r);

            cursorX  += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        if (cursorX > Width)
        {
            Width = cursorX;
        }

        return(cursorX);
    }
コード例 #5
0
    float BlitString(string str, float cursorX, float cursorY, List <int> vertexPointers = null)
    {
        TGlyph prevGlyph = null;
        Rect   r;
        bool   inControlCode     = false;
        int    requestedMaterial = 0;

        foreach (char c in str)
        {
            int charCode = (int)c;

            if (inControlCode)
            {
                inControlCode = false;

                if (charCode >= 48 && charCode <= 57)                 // 0-9
                {
                    requestedMaterial = charCode - 48;

                    if (requestedMaterial < _materialCount)
                    {
                        _currentMaterial = requestedMaterial;
                    }
                    else
                    {
                        Debug.LogWarning(string.Format(
                                             "Requested material {0} out of range.", requestedMaterial
                                             ));
                    }

                    if (EnableClickSupport)
                    {
                        AddPlaceholderGlyphBounds();
                    }

                    continue;
                }
            }
            else
            {
                if (charCode == 92)                 // Backslash
                {
                    inControlCode = true;
                    if (EnableClickSupport)
                    {
                        AddPlaceholderGlyphBounds();
                    }
                    continue;
                }
            }

            TGlyph glyph = Font.Glyphs.Get(charCode);

            if (glyph == null)
            {
                continue;
            }

            if (charCode == 32)
            {
                // Assuming here that spaces should not be clickable.
                if (EnableClickSupport)
                {
                    AddPlaceholderGlyphBounds();
                }
                cursorX += glyph.xAdvance * Size + Tracking;
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
            {
                kerning = prevGlyph.GetKerning(charCode) * Size;
            }

            if (vertexPointers != null)
            {
                vertexPointers.Add(m_Vertices.Count);
            }

            r = new Rect(
                cursorX + glyph.xOffset * Size + kerning,
                cursorY + glyph.yOffset * Size,
                glyph.rect.width * Size,
                glyph.rect.height * Size
                );

            BlitQuad(r, glyph);


            // Only need to store glyph bounds if click support is enabled.
            if (EnableClickSupport)
            {
                // Click bounds for glyphs are based on allocated space, not rendered space.
                // Otherwise we'll end up with unclickable dead zones between glyphs.
                r.width = glyph.xAdvance * Size;
                // And Y coordinates are just not handled the same at all.
                r.y = -cursorY - r.height - glyph.yOffset * Size;


                // Calculate relative world-space bounds for this glyph and store them.
                Bounds b = new Bounds(
                    new Vector3(r.x + r.width / 2f, r.y + r.height / 2f, 0f),
                    new Vector3(r.width, r.height, r.height)
                    );

                if (Stationary)
                {
                    // Bake the rotation and position into the bounds so we
                    // don't have to recalculate them on the fly later.
                    b = TranslateBounds(b);
                }
                StoreGlyphBounds(b);
            }


            cursorX  += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        if (cursorX > Width)
        {
            Width = cursorX;
        }

        return(cursorX);
    }