Exemplo n.º 1
0
        private void DrawBatchString(float tx, float ty, string text, LColor c,
                                     int startIndex, int endIndex)
        {
            if (isClose)
            {
                return;
            }

            float x = tx, y = ty;

            displayList.GLBegin();

            CharDef lastCharDef = null;

            char[] data = text.ToCharArray();
            for (int i = 0; i < data.Length; i++)
            {
                int id = data[i];
                if (id == '\n')
                {
                    x  = 0;
                    y += GetLineHeight();
                    continue;
                }
                if (id >= chars.Length)
                {
                    continue;
                }
                CharDef charDef = chars[id];
                if (charDef == null)
                {
                    continue;
                }

                if (lastCharDef != null)
                {
                    x += lastCharDef.GetKerning(id);
                }
                lastCharDef = charDef;

                if ((i >= startIndex) && (i <= endIndex))
                {
                    charDef.Draw(x, y, 0, c);
                }

                x += charDef.advance;
            }

            displayList.GLEnd();
        }
Exemplo n.º 2
0
        public int GetWidth(string text)
        {
            if (text == null)
            {
                return(0);
            }
            int     width       = 0;
            CharDef lastCharDef = null;

            for (int i = 0, n = text.Length; i < n; i++)
            {
                int id = text[i];
                if (id == '\n')
                {
                    width = 0;
                    continue;
                }
                if (id >= chars.Length)
                {
                    continue;
                }
                CharDef charDef = chars[id];
                if (charDef == null)
                {
                    continue;
                }
                if (lastCharDef != null)
                {
                    width += lastCharDef.GetKerning(id);
                }
                lastCharDef = charDef;
                if (i < n - 1)
                {
                    width += charDef.advance;
                }
                else
                {
                    width += charDef.width;
                }
                width = MathUtils.Max(charDef.width, width);
            }

            return(width);
        }
Exemplo n.º 3
0
        private void DrawBatchString(float tx, float ty, string text, LColor c,
                                     int startIndex, int endIndex)
        {
            if (isClose)
            {
                return;
            }

            if (displays.Size() > DEFAULT_MAX_CHAR)
            {
                displays.Clear();
            }

            lazyHashCode = 1;

            if (c != null)
            {
                lazyHashCode = LSystem.Unite(lazyHashCode, c.r);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.g);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.b);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.a);
            }

            string key = text + lazyHashCode;

            Display display = (Display)displays.Get(key);

            if (display == null)
            {
                int x = 0, y = 0;

                displayList.GLBegin();
                displayList.SetBatchPos(tx, ty);

                if (c != null)
                {
                    displayList.SetImageColor(c);
                }

                CharDef lastCharDef = null;
                char[]  data        = text.ToCharArray();
                for (int i = 0; i < data.Length; i++)
                {
                    int id = data[i];
                    if (id == '\n')
                    {
                        x  = 0;
                        y += GetLineHeight();
                        continue;
                    }
                    if (id >= chars.Length)
                    {
                        continue;
                    }
                    CharDef charDef = chars[id];
                    if (charDef == null)
                    {
                        continue;
                    }

                    if (lastCharDef != null)
                    {
                        x += lastCharDef.GetKerning(id);
                    }
                    lastCharDef = charDef;

                    if ((i >= startIndex) && (i <= endIndex))
                    {
                        charDef.Draw(x, y);
                    }

                    x += charDef.advance;
                }

                if (c != null)
                {
                    displayList.SetImageColor(LColor.white);
                }

                displayList.GLEnd();

                display = new Display();

                display.cache  = displayList.NewBatchCache();
                display.text   = text;
                display.width  = 0;
                display.height = 0;

                displays.Put(key, display);
            }
            else if (display.cache != null)
            {
                display.cache.x = tx;
                display.cache.y = ty;
                LTextureBatch.Commit(displayList, display.cache);
            }
        }