Duality.Resources.Font.PickTextGlyph C# (CSharp) Method

PickTextGlyph() public method

Returns the index of the glyph that is located at a certain location within a text.
public PickTextGlyph ( string text, float x, float y ) : int
text string The text from which to pick a glyph.
x float X-Coordinate of the position where to look for a glyph.
y float Y-Coordinate of the position where to look for a glyph.
return int
        public int PickTextGlyph(string text, float x, float y)
        {
            float curOffset = 0.0f;
            GlyphData glyphData;
            Rect uvRect;
            Rect glyphRect;
            float glyphXOff;
            float glyphXAdv;
            for (int i = 0; i < text.Length; i++)
            {
                this.ProcessTextAdv(text, i, out glyphData, out uvRect, out glyphXAdv, out glyphXOff);

                glyphRect = new Rect(curOffset + glyphXOff, 0, glyphData.width, glyphData.height);
                if (glyphRect.Contains(x, y)) return i;

                curOffset += glyphXAdv;
            }

            return -1;
        }