Print() public method

Print the specified text into the buffers. Note: 'lineWidth' parameter should be in pixels.
public Print ( string text, Color32 color, BetterList verts, BetterList uvs, BetterList cols, bool encoding, SymbolStyle symbolStyle, Alignment, alignment, int lineWidth, bool premultiply ) : void
text string
color UnityEngine.Color32
verts BetterList
uvs BetterList
cols BetterList
encoding bool
symbolStyle SymbolStyle
alignment Alignment,
lineWidth int
premultiply bool
return void
示例#1
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
#endif
    {
        if (mFont == null)
        {
            return;
        }
        MakePositionPerfect();
        Pivot p      = pivot;
        int   offset = verts.size;

        // Print the text into the buffers
        if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft)
        {
            mFont.Print(processedText, color, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0);
        }
        else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight)
        {
            mFont.Print(processedText, color, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right,
                        Mathf.RoundToInt(relativeSize.x * mFont.size));
        }
        else
        {
            mFont.Print(processedText, color, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center,
                        Mathf.RoundToInt(relativeSize.x * mFont.size));
        }

        // Apply an effect if one was requested
        if (effectStyle != Effect.None)
        {
            Vector3 scale = cachedTransform.localScale;
            if (scale.x == 0f || scale.y == 0f)
            {
                return;
            }

            int   end   = verts.size;
            float pixel = 1f / mFont.size;

            ApplyShadow(verts, uvs, cols, offset, end, pixel, -pixel);

            if (effectStyle == Effect.Outline)
            {
                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -pixel, pixel);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, pixel, pixel);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -pixel, -pixel);
            }
        }
    }
示例#2
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFont != null)
        {
            var pivot = this.pivot;
            var size  = verts.size;
            var c     = color;
            c.a *= mPanel.alpha;
            if (font.premultipliedAlpha)
            {
                c = NGUITools.ApplyPMA(c);
            }

            switch (pivot)
            {
            case Pivot.Left:
            case Pivot.TopLeft:
            case Pivot.BottomLeft:
                mFont.Print(processedText, c, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0, mPremultiply);
                break;

            case Pivot.Right:
            case Pivot.TopRight:
            case Pivot.BottomRight:
                mFont.Print(processedText, c, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply);
                break;

            default:
                mFont.Print(processedText, c, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply);
                break;
            }

            if (effectStyle != Effect.None)
            {
                var end  = verts.size;
                var num3 = 1f / mFont.size;
                var x    = num3 * mEffectDistance.x;
                var y    = num3 * mEffectDistance.y;
                ApplyShadow(verts, uvs, cols, size, end, x, -y);
                if (effectStyle == Effect.Outline)
                {
                    size = end;
                    end  = verts.size;
                    ApplyShadow(verts, uvs, cols, size, end, -x, y);
                    size = end;
                    end  = verts.size;
                    ApplyShadow(verts, uvs, cols, size, end, x, y);
                    size = end;
                    end  = verts.size;
                    ApplyShadow(verts, uvs, cols, size, end, -x, -y);
                }
            }
        }
    }
示例#3
0
    public override void OnFill(MeshBuffer m)
    {
        if (this.mFont == null)
        {
            return;
        }
        Color color = (!this.mInvisibleHack ? base.color : Color.clear);

        this.MakePositionPerfect();
        UIWidget.Pivot pivot = base.pivot;
        int            num   = m.vSize;

        if (pivot != UIWidget.Pivot.Left && pivot != UIWidget.Pivot.TopLeft && pivot != UIWidget.Pivot.BottomLeft)
        {
            if (pivot == UIWidget.Pivot.Right || pivot == UIWidget.Pivot.TopRight || pivot == UIWidget.Pivot.BottomRight)
            {
                UIFont             uIFont      = this.mFont;
                string             str         = this.processedText;
                bool               flag        = this.mEncoding;
                UIFont.SymbolStyle symbolStyle = this.mSymbols;
                Vector2            vector2     = this.relativeSize;
                uIFont.Print(str, color, m, flag, symbolStyle, UIFont.Alignment.Right, Mathf.RoundToInt(vector2.x * (float)this.mFont.size), ref this.mSelection, this.mCarratChar, this.mHighlightTextColor, this.mHighlightColor, this.mHighlightChar, this.mHighlightCharSplit);
            }
            else
            {
                UIFont             uIFont1      = this.mFont;
                string             str1         = this.processedText;
                bool               flag1        = this.mEncoding;
                UIFont.SymbolStyle symbolStyle1 = this.mSymbols;
                Vector2            vector21     = this.relativeSize;
                uIFont1.Print(str1, color, m, flag1, symbolStyle1, UIFont.Alignment.Center, Mathf.RoundToInt(vector21.x * (float)this.mFont.size), ref this.mSelection, this.mCarratChar, this.mHighlightTextColor, this.mHighlightColor, this.mHighlightChar, this.mHighlightCharSplit);
            }
        }
        else if (!this.mOverflowRight)
        {
            this.mFont.Print(this.processedText, color, m, this.mEncoding, this.mSymbols, UIFont.Alignment.Left, 0, ref this.mSelection, this.mCarratChar, this.mHighlightTextColor, this.mHighlightColor, this.mHighlightChar, this.mHighlightCharSplit);
        }
        else
        {
            UIFont             uIFont2      = this.mFont;
            string             str2         = this.processedText;
            bool               flag2        = this.mEncoding;
            UIFont.SymbolStyle symbolStyle2 = this.mSymbols;
            Vector2            vector22     = this.relativeSize;
            uIFont2.Print(str2, color, m, flag2, symbolStyle2, UIFont.Alignment.LeftOverflowRight, Mathf.RoundToInt(vector22.x * (float)this.mFont.size), ref this.mSelection, this.mCarratChar, this.mHighlightTextColor, this.mHighlightColor, this.mHighlightChar, this.mHighlightCharSplit);
        }
        m.ApplyEffect(base.cachedTransform, num, this.effectStyle, this.effectColor, (float)this.mFont.size);
    }
示例#4
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, Color32 color, Color32 gradualcolor, bool gradual, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
                      bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, gradualcolor, gradual, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else if (text != null)
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (mDynamicFont != null)
            {
                mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize);
            }
#endif
            // Make sure the characters are present in the dynamic font before printing them
            bool dynamic = isDynamic;

            mColors.Clear();
            mColors.Add(color);

            int     fs      = size;
            Vector2 invSize = fs > 0 ? new Vector2(1f / fs, 1f / fs) : Vector2.one;

            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            float   invX       = uvRect.width / mFont.texWidth;
            float   invY       = mUVRect.height / mFont.texHeight;
            int     textLength = text.Length;
            bool    useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != Alignment.Left)
                    {
                        Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && c == '[')
                {
                    int retVal = NGUITools.ParseSymbol(text, i, mColors, premultiply);

                    if (retVal > 0)
                    {
                        color = mColors[mColors.Count - 1];
                        i    += retVal - 1;
                        continue;
                    }
                }

                if (!dynamic)
                {
                    // See if there is a symbol matching this text
                    BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                    if (symbol == null)
                    {
                        BMGlyph glyph = mFont.GetGlyph(c);
                        if (glyph == null)
                        {
                            continue;
                        }

                        if (prev != 0)
                        {
                            x += glyph.GetKerning(prev);
                        }

                        if (c == ' ')
                        {
                            x   += mSpacingX + glyph.advance;
                            prev = c;
                            continue;
                        }

                        v0.x = invSize.x * (x + glyph.offsetX);
                        v0.y = -invSize.y * (y + glyph.offsetY);

                        v1.x = v0.x + invSize.x * glyph.width;
                        v1.y = v0.y - invSize.y * glyph.height;

                        u0.x = mUVRect.xMin + invX * glyph.x;
                        u0.y = mUVRect.yMax - invY * glyph.y;

                        u1.x = u0.x + invX * glyph.width;
                        u1.y = u0.y - invY * glyph.height;

                        x   += mSpacingX + glyph.advance;
                        prev = c;

                        if (glyph.channel == 0 || glyph.channel == 15)
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            // Packed fonts come as alpha masks in each of the RGBA channels.
                            // In order to use it we need to use a special shader.
                            //
                            // Limitations:
                            // - Effects (drop shadow, outline) will not work.
                            // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                            // - Lower color precision

                            Color col = color;

                            col *= 0.49f;

                            switch (glyph.channel)
                            {
                            case 1: col.b += 0.51f; break;

                            case 2: col.g += 0.51f; break;

                            case 4: col.r += 0.51f; break;

                            case 8: col.a += 0.51f; break;
                            }

                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(col);
                            }
                        }
                    }
                    else
                    {
                        v0.x = invSize.x * (x + symbol.offsetX);
                        v0.y = -invSize.y * (y + symbol.offsetY);

                        v1.x = v0.x + invSize.x * symbol.width;
                        v1.y = v0.y - invSize.y * symbol.height;

                        Rect uv = symbol.uvRect;

                        u0.x = uv.xMin;
                        u0.y = uv.yMax;
                        u1.x = uv.xMax;
                        u1.y = uv.yMin;

                        x   += mSpacingX + symbol.advance;
                        i   += symbol.length - 1;
                        prev = 0;

                        if (symbolStyle == SymbolStyle.Colored)
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            Color32 col = Color.white;
                            col.a = color.a;
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(col);
                            }
                        }
                    }

                    verts.Add(new Vector3(v1.x, v0.y));
                    verts.Add(new Vector3(v1.x, v1.y));
                    verts.Add(new Vector3(v0.x, v1.y));
                    verts.Add(new Vector3(v0.x, v0.y));

                    uvs.Add(new Vector2(u1.x, u0.y));
                    uvs.Add(new Vector2(u1.x, u1.y));
                    uvs.Add(new Vector2(u0.x, u1.y));
                    uvs.Add(new Vector2(u0.x, u0.y));
                }
#if DYNAMIC_FONT
                else
                {
                    if (!mDynamicFont.GetCharacterInfo(c, out mChar, mDynamicFontSize, mDynamicFontStyle))
                    {
                        continue;
                    }

                    v0.x = invSize.x * (x + mChar.vert.xMin);
                    v0.y = -invSize.y * (y - mChar.vert.yMax + mDynamicFontOffset);

                    v1.x = v0.x + invSize.x * mChar.vert.width;
                    v1.y = v0.y - invSize.y * mChar.vert.height;

                    u0.x = mChar.uv.xMin;
                    u0.y = mChar.uv.yMin;
                    u1.x = mChar.uv.xMax;
                    u1.y = mChar.uv.yMax;

                    x += mSpacingX + (int)mChar.width;

                    if (gradual)
                    {
                        Color32 topCol    = Color32.Lerp(gradualcolor, color, -v1.y);
                        Color32 bottomCol = Color32.Lerp(gradualcolor, color, -v0.y);
                        cols.Add(bottomCol);
                        cols.Add(bottomCol);
                        cols.Add(topCol);
                        cols.Add(topCol);
                    }
                    else
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }

                    if (mChar.flipped)
                    {
                        uvs.Add(new Vector2(u0.x, u1.y));
                        uvs.Add(new Vector2(u0.x, u0.y));
                        uvs.Add(new Vector2(u1.x, u0.y));
                        uvs.Add(new Vector2(u1.x, u1.y));
                    }
                    else
                    {
                        uvs.Add(new Vector2(u1.x, u0.y));
                        uvs.Add(new Vector2(u0.x, u0.y));
                        uvs.Add(new Vector2(u0.x, u1.y));
                        uvs.Add(new Vector2(u1.x, u1.y));
                    }

                    verts.Add(new Vector3(v1.x, v0.y));
                    verts.Add(new Vector3(v0.x, v0.y));
                    verts.Add(new Vector3(v0.x, v1.y));
                    verts.Add(new Vector3(v1.x, v1.y));
                }
#endif
            }

            if (alignment != Alignment.Left && indexOffset < verts.size)
            {
                Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
示例#5
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, int size, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
                      bool encoding, SymbolStyle symbolStyle, TextAlignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, size, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else if (text != null)
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                NGUIText.Print(text, dynamicFont, size, mDynamicFontStyle, color, encoding,
                               alignment, lineWidth, premultiply, verts, uvs, cols);
                return;
            }
#endif
            mColors.Clear();
            mColors.Add(color);

            int     fs = size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && NGUIText.ParseSymbol(text, ref i, mColors, premultiply))
                {
                    color = mColors[mColors.size - 1];
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += mSpacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += mSpacingX + glyph.advance;
                    prev = c;

                    if (glyph.channel == 0 || glyph.channel == 15)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        // Packed fonts come as alpha masks in each of the RGBA channels.
                        // In order to use it we need to use a special shader.
                        //
                        // Limitations:
                        // - Effects (drop shadow, outline) will not work.
                        // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                        // - Lower color precision

                        Color col = color;

                        col *= 0.49f;

                        switch (glyph.channel)
                        {
                        case 1: col.b += 0.51f; break;

                        case 2: col.g += 0.51f; break;

                        case 4: col.r += 0.51f; break;

                        case 8: col.a += 0.51f; break;
                        }

                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += mSpacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (symbolStyle == SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = color.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
示例#6
0
    /// <summary>
    /// Draw the label.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (!isValid)
        {
            return;
        }

        int offset = verts.size;

        Color col = color;

        col.a *= mPanel.finalAlpha;
        if (mFont != null && mFont.premultipliedAlpha)
        {
            col = NGUITools.ApplyPMA(col);
        }

        string text      = processedText;
        float  pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
        float  scale     = mScale * pixelSize;
        bool   usePS     = usePrintedSize;
        int    start     = verts.size;

        UpdateNGUIText();
        NGUIText.current.size      = usePS ? mPrintedSize : fontSize;
        NGUIText.current.lineWidth = usePS ? mWidth : Mathf.RoundToInt(mWidth / scale);
        NGUIText.current.tint      = col;

        if (mFont != null)
        {
            mFont.Print(text, verts, uvs, cols);
        }
#if DYNAMIC_FONT
        else
        {
            NGUIText.Print(mTrueTypeFont, text, verts, uvs, cols);
        }
#endif
        Vector2 po = pivotOffset;
        float   fx = Mathf.Lerp(0f, -mWidth, po.x);
        float   fy = Mathf.Lerp(mHeight, 0f, po.y);

        // Align vertically
        fy = Mathf.RoundToInt(fy + Mathf.Lerp(mCalculatedSize.y * scale - mHeight, 0f, po.y));

        if (usePS || scale == 1f)
        {
#if UNITY_FLASH
            for (int i = start; i < verts.size; ++i)
            {
                Vector3 buff = verts.buffer[i];
                buff.x         += fx;
                buff.y         += fy;
                verts.buffer[i] = buff;
            }
#else
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x += fx;
                verts.buffer[i].y += fy;
            }
#endif
        }
        else
        {
#if UNITY_FLASH
            for (int i = start; i < verts.size; ++i)
            {
                Vector3 buff = verts.buffer[i];
                buff.x          = fx + verts.buffer[i].x * scale;
                buff.y          = fy + verts.buffer[i].y * scale;
                verts.buffer[i] = buff;
            }
#else
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x = fx + verts.buffer[i].x * scale;
                verts.buffer[i].y = fy + verts.buffer[i].y * scale;
            }
#endif
        }

        // Apply an effect if one was requested
        if (effectStyle != Effect.None)
        {
            int   end   = verts.size;
            float pixel = pixelSize;
            fx = pixel * mEffectDistance.x;
            fy = pixel * mEffectDistance.y;

            ApplyShadow(verts, uvs, cols, offset, end, fx, -fy);

            if (effectStyle == Effect.Outline)
            {
                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy);
            }
        }
    }
示例#7
0
    /// <summary>
    /// Draw the label.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFont == null)
        {
            return;
        }
        Pivot p      = pivot;
        int   offset = verts.size;

        Color col = color;

        col.a *= mPanel.alpha;
        if (font.premultipliedAlpha)
        {
            col = NGUITools.ApplyPMA(col);
        }

        string text  = processedText;
        float  scale = mScale * mFont.pixelSize;
        int    w     = Mathf.RoundToInt(width / scale);
        int    start = verts.size;

        // Print the text into the buffers
        if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft)
        {
            mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, w, mPremultiply);
        }
        else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight)
        {
            mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right, w, mPremultiply);
        }
        else
        {
            mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center, w, mPremultiply);
        }

        Vector2 po = pivotOffset;
        float   fx = Mathf.Lerp(0f, -mWidth, po.x);
        float   fy = Mathf.Lerp(mHeight, 0f, po.y);

        // Center vertically
        fy += Mathf.Lerp(mSize.y * scale - mHeight, 0f, po.y);

        if (scale == 1f)
        {
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x += fx;
                verts.buffer[i].y += fy;
            }
        }
        else
        {
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x = fx + verts.buffer[i].x * scale;
                verts.buffer[i].y = fy + verts.buffer[i].y * scale;
            }
        }

        // Apply an effect if one was requested
        if (effectStyle != Effect.None)
        {
            int   end   = verts.size;
            float pixel = mFont.pixelSize;
            fx = pixel * mEffectDistance.x;
            fy = pixel * mEffectDistance.y;

            ApplyShadow(verts, uvs, cols, offset, end, fx, -fy);

            if (effectStyle == Effect.Outline)
            {
                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy);
            }
        }
    }
示例#8
0
    public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
                      bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth)
#endif
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth);
        }
        else if (mFont != null && text != null)
        {
            if (!mFont.isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

            mColors.Clear();
            mColors.Add(color);

            Vector2 scale = mFont.charSize > 0 ? new Vector2(1f / mFont.charSize, 1f / mFont.charSize) : Vector2.one;

            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (mFont.charSize + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            float   invX       = uvRect.width / mFont.texWidth;
            float   invY       = mUVRect.height / mFont.texHeight;
            int     textLength = text.Length;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != Alignment.Left)
                    {
                        Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && c == '[')
                {
                    int retVal = NGUITools.ParseSymbol(text, i, mColors);

                    if (retVal > 0)
                    {
                        color = mColors[mColors.Count - 1];
                        i    += retVal - 1;
                        continue;
                    }
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = (encoding && symbolStyle != SymbolStyle.None) ? mFont.MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += mSpacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = scale.x * (x + glyph.offsetX);
                    v0.y = -scale.y * (y + glyph.offsetY);

                    v1.x = v0.x + scale.x * glyph.width;
                    v1.y = v0.y - scale.y * glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += mSpacingX + glyph.advance;
                    prev = c;

                    if (glyph.channel == 0 || glyph.channel == 15)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        // Packed fonts come as alpha masks in each of the RGBA channels.
                        // In order to use it we need to use a special shader.
                        //
                        // Limitations:
                        // - Effects (drop shadow, outline) will not work.
                        // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                        // - Lower color precision

                        Color col = color;

                        col *= 0.49f;

                        switch (glyph.channel)
                        {
                        case 1: col.b += 0.51f; break;

                        case 2: col.g += 0.51f; break;

                        case 4: col.r += 0.51f; break;

                        case 8: col.a += 0.51f; break;
                        }

                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }
                else
                {
                    v0.x = scale.x * x;
                    v0.y = -scale.y * y;

                    v1.x = v0.x + scale.x * symbol.width;
                    v1.y = v0.y - scale.y * symbol.height;

                    u0.x = mUVRect.xMin + invX * symbol.x;
                    u0.y = mUVRect.yMax - invY * symbol.y;

                    u1.x = u0.x + invX * symbol.width;
                    u1.y = u0.y - invY * symbol.height;

                    x   += mSpacingX + symbol.width;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (symbolStyle == SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(color);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = color.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (alignment != Alignment.Left && indexOffset < verts.size)
            {
                Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
示例#9
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, verts, uvs, cols);
        }
        else if (!string.IsNullOrEmpty(text))
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                // NOTE: This shouldn't be used anymore. All dynamic font printing goes directly through NGUIText instead.
                NGUIText.current.size  = mDynamicFontSize;
                NGUIText.current.style = mDynamicFontStyle;
                NGUIText.Print(dynamicFont, text, verts, uvs, cols);
                return;
            }
#endif
            mColors.Add(Color.white);

            int     fs = NGUIText.current.size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + NGUIText.current.spacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            Color   gb = NGUIText.current.tint * NGUIText.current.gradientBottom;
            Color   gt = NGUIText.current.tint * NGUIText.current.gradientTop;
            Color32 uc = NGUIText.current.tint;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = NGUIText.current.encoding && NGUIText.current.symbolStyle != NGUIText.SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (NGUIText.current.alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                bool isMineColor = false;

                if (NGUIText.current.encoding && NGUIText.ParseSymbol(text, ref i, mColors, NGUIText.current.premultiply, ref isMineColor))
                {
                    Color fc = mColors[mColors.size - 1];

                    if (isMineColor)
                    {
                        fc *= NGUIText.current.tint;
                    }

                    // *******************
                    // add sj.
                    // *******************
                    fc.a = uc.a / 255.0f;
                    // *******************
                    uc = fc;

                    if (NGUIText.current.gradient)
                    {
                        gb = NGUIText.current.gradientBottom * fc;
                        gt = NGUIText.current.gradientTop * fc;
                    }
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += NGUIText.current.spacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += NGUIText.current.spacingX + glyph.advance;
                    prev = c;

                    if (NGUIText.current.gradient)
                    {
                        float min = NGUIText.current.size - glyph.offsetY;
                        float max = min - glyph.height;

                        min /= NGUIText.current.size;
                        max /= NGUIText.current.size;

                        s_c0 = Color.Lerp(gb, gt, min);
                        s_c1 = Color.Lerp(gb, gt, max);

                        cols.Add(s_c0);
                        cols.Add(s_c1);
                        cols.Add(s_c1);
                        cols.Add(s_c0);
                    }
                    else
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += NGUIText.current.spacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (NGUIText.current.symbolStyle == NGUIText.SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = uc.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (NGUIText.current.alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                indexOffset = verts.size;
            }
            mColors.Clear();
        }
    }
示例#10
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols,
                      bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else if (mFont != null && text != null)
        {
            if (!mFont.isValid && !UseDynamicFont)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

            //JUDIVA, include symbols in font
            RegisterFont(this);
            if (UseDynamicFont)
            {
                dynamicFont.RequestCharactersInTexture(text, dynamicFontSize, dynamicFontStyle);
            }

            mColors.Clear();
            mColors.Add(color);

            Vector2 scale = charSize > 0 ? new Vector2(1f / charSize, 1f / charSize) : Vector2.one;

            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (charSize + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            float   invX       = uvRect.width / mFont.texWidth;
            float   invY       = mUVRect.height / mFont.texHeight;
            int     textLength = text.Length;
            bool    useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != Alignment.Left)
                    {
                        Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && c == '[')
                {
                    int retVal = NGUITools.ParseSymbol(text, i, mColors, premultiply);

                    if (retVal > 0)
                    {
                        color = mColors[mColors.Count - 1];
                        i    += retVal - 1;
                        continue;
                    }
                }

                if (!UseDynamicFont)
                {
                    // See if there is a symbol matching this text
                    BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                    if (symbol == null)
                    {
                        BMGlyph glyph = mFont.GetGlyph(c);
                        if (glyph == null)
                        {
                            continue;
                        }

                        if (prev != 0)
                        {
                            x += glyph.GetKerning(prev);
                        }

                        if (c == ' ')
                        {
                            x   += mSpacingX + glyph.advance;
                            prev = c;
                            continue;
                        }

                        v0.x = scale.x * (x + glyph.offsetX);
                        v0.y = -scale.y * (y + glyph.offsetY);

                        v1.x = v0.x + scale.x * glyph.width;
                        v1.y = v0.y - scale.y * glyph.height;

                        u0.x = mUVRect.xMin + invX * glyph.x;
                        u0.y = mUVRect.yMax - invY * glyph.y;

                        u1.x = u0.x + invX * glyph.width;
                        u1.y = u0.y - invY * glyph.height;

                        x   += mSpacingX + glyph.advance;
                        prev = c;

                        if (glyph.channel == 0 || glyph.channel == 15)
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            // Packed fonts come as alpha masks in each of the RGBA channels.
                            // In order to use it we need to use a special shader.
                            //
                            // Limitations:
                            // - Effects (drop shadow, outline) will not work.
                            // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                            // - Lower color precision

                            Color col = color;

                            col *= 0.49f;

                            switch (glyph.channel)
                            {
                            case 1: col.b += 0.51f; break;

                            case 2: col.g += 0.51f; break;

                            case 4: col.r += 0.51f; break;

                            case 8: col.a += 0.51f; break;
                            }

                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(col);
                            }
                        }
                    }
                    else
                    {
                        v0.x = scale.x * (x + symbol.offsetX);
                        v0.y = -scale.y * (y + symbol.offsetY);

                        v1.x = v0.x + scale.x * symbol.width;
                        v1.y = v0.y - scale.y * symbol.height;

                        Rect uv = symbol.uvRect;

                        u0.x = uv.xMin;
                        u0.y = uv.yMax;
                        u1.x = uv.xMax;
                        u1.y = uv.yMin;

                        x   += mSpacingX + symbol.advance;
                        i   += symbol.length - 1;
                        prev = 0;

                        if (symbolStyle == SymbolStyle.Colored)
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            Color32 col = Color.white;
                            col.a = color.a;
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(col);
                            }
                        }
                    }

                    verts.Add(new Vector3(v1.x, v0.y));
                    verts.Add(new Vector3(v1.x, v1.y));
                    verts.Add(new Vector3(v0.x, v1.y));
                    verts.Add(new Vector3(v0.x, v0.y));

                    uvs.Add(new Vector2(u1.x, u0.y));
                    uvs.Add(new Vector2(u1.x, u1.y));
                    uvs.Add(new Vector2(u0.x, u1.y));
                    uvs.Add(new Vector2(u0.x, u0.y));
                }

                else
                {
                    //v0 v1 are the two corners
                    CharacterInfo charInfo;
                    if (!dynamicFont.GetCharacterInfo(c, out charInfo, dynamicFontSize, dynamicFontStyle))
                    {
                        Debug.LogError("character not found in font");
                        continue;
                    }

                    float yOffset = CalculateYOffset();

                    v0.x = scale.x * (x + charInfo.vert.xMin);
                    v0.y = scale.x * (-y + charInfo.vert.yMax + yOffset) + fontConstYOffset;
                    v1.x = scale.y * (x + charInfo.vert.xMax);
                    v1.y = scale.y * (-y + charInfo.vert.yMin + yOffset) + fontConstYOffset;

                    u0.x = charInfo.uv.xMin;
                    u0.y = charInfo.uv.yMin;
                    u1.x = charInfo.uv.xMax;
                    u1.y = charInfo.uv.yMax;

                    x += mSpacingX + (int)charInfo.width;

                    for (int b = 0; b < 4; ++b)
                    {
                        cols.Add(color);
                    }

                    if (charInfo.flipped)
                    {
                        //swap entries
                        uvs.Add(new Vector2(u0.x, u1.y));
                        uvs.Add(new Vector2(u0.x, u0.y));
                        uvs.Add(new Vector2(u1.x, u0.y));
                        uvs.Add(new Vector2(u1.x, u1.y));
                    }
                    else
                    {
                        uvs.Add(new Vector2(u1.x, u0.y));
                        uvs.Add(new Vector2(u0.x, u0.y));
                        uvs.Add(new Vector2(u0.x, u1.y));
                        uvs.Add(new Vector2(u1.x, u1.y));
                    }

                    verts.Add(new Vector3(v1.x, v0.y));
                    verts.Add(new Vector3(v0.x, v0.y));
                    verts.Add(new Vector3(v0.x, v1.y));
                    verts.Add(new Vector3(v1.x, v1.y));
                }
            }

            if (alignment != Alignment.Left && indexOffset < verts.size)
            {
                Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
示例#11
0
    /// <summary>
    /// Draw the label.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (!isValid)
        {
            return;
        }

        Pivot p      = pivot;
        int   offset = verts.size;

        Color col = color;

        col.a *= mPanel.alpha;
        if (mFont != null && mFont.premultipliedAlpha)
        {
            col = NGUITools.ApplyPMA(col);
        }

        string text      = processedText;
        float  pixelSize = (mFont != null) ? mFont.pixelSize : 1f;
        float  scale     = mScale * pixelSize;
        bool   usePS     = usePrintedSize;
        int    size      = usePS ? mPrintedSize : fontSize;
        int    w         = usePS ? width : Mathf.RoundToInt(width / scale);
        int    start     = verts.size;

        TextAlignment alignment = TextAlignment.Center;

        // Print the text into the buffers
        if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft)
        {
            alignment = TextAlignment.Left;
        }
        else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight)
        {
            alignment = TextAlignment.Right;
        }

        if (mFont != null)
        {
            mFont.Print(text, size, col, verts, uvs, cols, mEncoding, mSymbols, alignment, w, mPremultiply);
        }
#if DYNAMIC_FONT
        else
        {
            NGUIText.mSpacingY = mSpacingY;             // change by xuzheng
            NGUIText.Print(text, mTrueTypeFont, size, fontStyle, col, mEncoding, alignment, w, mPremultiply, verts, uvs, cols);
            NGUIText.mSpacingY = 0;
        }
#endif
        Vector2 po = pivotOffset;
        float   fx = Mathf.Lerp(0f, -mWidth, po.x);
        float   fy = Mathf.Lerp(mHeight, 0f, po.y);

        // Center vertically
        fy = Mathf.RoundToInt(fy + Mathf.Lerp(mCalculatedSize.y * scale - mHeight, 0f, po.y));

        if (usePS || scale == 1f)
        {
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x += fx;
                verts.buffer[i].y += fy;
            }
        }
        else
        {
            for (int i = start; i < verts.size; ++i)
            {
                verts.buffer[i].x = fx + verts.buffer[i].x * scale;
                verts.buffer[i].y = fy + verts.buffer[i].y * scale;
            }
        }

        // Apply an effect if one was requested
        if (effectStyle != Effect.None)
        {
            int   end   = verts.size;
            float pixel = pixelSize;
            fx = pixel * mEffectDistance.x;
            fy = pixel * mEffectDistance.y;

            ApplyShadow(verts, uvs, cols, offset, end, fx, -fy);

            if (effectStyle == Effect.Outline)
            {
                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy);
            }
        }
    }
示例#12
0
    public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else if (text != null)
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
            }
            else
            {
                var isDynamic = this.isDynamic;
                if (isDynamic)
                {
                    mDynamicFont.textureRebuildCallback = OnFontChanged;
                    mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
                    mDynamicFont.textureRebuildCallback = null;
                }

                mColors.Clear();
                mColors.Add(color);
                var size         = this.size;
                var vector       = size <= 0 ? Vector2.one : new Vector2(1f / size, 1f / size);
                var indexOffset  = verts.size;
                var num3         = 0;
                var x            = 0;
                var num5         = 0;
                var previousChar = 0;
                var num7         = size + mSpacingY;
                var zero         = Vector3.zero;
                var vector3      = Vector3.zero;
                var vector4      = Vector2.zero;
                var vector5      = Vector2.zero;
                var num8         = this.uvRect.width / mFont.texWidth;
                var num9         = mUVRect.height / mFont.texHeight;
                var length       = text.Length;
                var flag2        = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null;
                for (var i = 0; i < length; i++)
                {
                    var index = text[i];
                    if (index == '\n')
                    {
                        if (x > num3)
                        {
                            num3 = x;
                        }

                        if (alignment != Alignment.Left)
                        {
                            Align(verts, indexOffset, alignment, x, lineWidth);
                            indexOffset = verts.size;
                        }

                        x            = 0;
                        num5        += num7;
                        previousChar = 0;
                        continue;
                    }

                    if (index < ' ')
                    {
                        previousChar = 0;
                        continue;
                    }

                    if (encoding && index == '[')
                    {
                        var num12 = NGUITools.ParseSymbol(text, i, mColors, premultiply);
                        if (num12 > 0)
                        {
                            color = mColors[mColors.Count - 1];
                            i    += num12 - 1;
                            continue;
                        }
                    }

                    if (!isDynamic)
                    {
                        var symbol = !flag2 ? null : MatchSymbol(text, i, length);
                        if (symbol == null)
                        {
                            var glyph = mFont.GetGlyph(index);
                            if (glyph == null)
                            {
                                continue;
                            }

                            if (previousChar != 0)
                            {
                                x += glyph.GetKerning(previousChar);
                            }

                            if (index == ' ')
                            {
                                x           += mSpacingX + glyph.advance;
                                previousChar = index;
                                continue;
                            }

                            zero.x       = vector.x * (x + glyph.offsetX);
                            zero.y       = -vector.y * (num5 + glyph.offsetY);
                            vector3.x    = zero.x + vector.x * glyph.width;
                            vector3.y    = zero.y - vector.y * glyph.height;
                            vector4.x    = mUVRect.xMin + num8 * glyph.x;
                            vector4.y    = mUVRect.yMax - num9 * glyph.y;
                            vector5.x    = vector4.x + num8 * glyph.width;
                            vector5.y    = vector4.y - num9 * glyph.height;
                            x           += mSpacingX + glyph.advance;
                            previousChar = index;
                            if (glyph.channel == 0 || glyph.channel == 15)
                            {
                                for (var j = 0; j < 4; j++)
                                {
                                    cols.Add(color);
                                }
                            }
                            else
                            {
                                Color item = color;
                                item = item * 0.49f;
                                switch (glyph.channel)
                                {
                                case 1:
                                    item.b += 0.51f;
                                    break;

                                case 2:
                                    item.g += 0.51f;
                                    break;

                                case 4:
                                    item.r += 0.51f;
                                    break;

                                case 8:
                                    item.a += 0.51f;
                                    break;
                                }

                                for (var k = 0; k < 4; k++)
                                {
                                    cols.Add(item);
                                }
                            }
                        }
                        else
                        {
                            zero.x    = vector.x * (x + symbol.offsetX);
                            zero.y    = -vector.y * (num5 + symbol.offsetY);
                            vector3.x = zero.x + vector.x * symbol.width;
                            vector3.y = zero.y - vector.y * symbol.height;
                            var uvRect = symbol.uvRect;
                            vector4.x    = uvRect.xMin;
                            vector4.y    = uvRect.yMax;
                            vector5.x    = uvRect.xMax;
                            vector5.y    = uvRect.yMin;
                            x           += mSpacingX + symbol.advance;
                            i           += symbol.length - 1;
                            previousChar = 0;
                            if (symbolStyle == SymbolStyle.Colored)
                            {
                                for (var m = 0; m < 4; m++)
                                {
                                    cols.Add(color);
                                }
                            }
                            else
                            {
                                Color32 white = Color.white;
                                white.a = color.a;
                                for (var n = 0; n < 4; n++)
                                {
                                    cols.Add(white);
                                }
                            }
                        }

                        verts.Add(new Vector3(vector3.x, zero.y));
                        verts.Add(new Vector3(vector3.x, vector3.y));
                        verts.Add(new Vector3(zero.x, vector3.y));
                        verts.Add(new Vector3(zero.x, zero.y));
                        uvs.Add(new Vector2(vector5.x, vector4.y));
                        uvs.Add(new Vector2(vector5.x, vector5.y));
                        uvs.Add(new Vector2(vector4.x, vector5.y));
                        uvs.Add(new Vector2(vector4.x, vector4.y));
                        continue;
                    }

                    if (mDynamicFont.GetCharacterInfo(index, out mChar, mDynamicFontSize, mDynamicFontStyle))
                    {
                        zero.x    = vector.x * (x + mChar.vert.xMin);
                        zero.y    = -vector.y * (num5 - mChar.vert.yMax + mDynamicFontOffset);
                        vector3.x = zero.x + vector.x * mChar.vert.width;
                        vector3.y = zero.y - vector.y * mChar.vert.height;
                        vector4.x = mChar.uv.xMin;
                        vector4.y = mChar.uv.yMin;
                        vector5.x = mChar.uv.xMax;
                        vector5.y = mChar.uv.yMax;
                        x        += mSpacingX + (int)mChar.width;
                        for (var num18 = 0; num18 < 4; num18++)
                        {
                            cols.Add(color);
                        }

                        if (mChar.flipped)
                        {
                            uvs.Add(new Vector2(vector4.x, vector5.y));
                            uvs.Add(new Vector2(vector4.x, vector4.y));
                            uvs.Add(new Vector2(vector5.x, vector4.y));
                            uvs.Add(new Vector2(vector5.x, vector5.y));
                        }
                        else
                        {
                            uvs.Add(new Vector2(vector5.x, vector4.y));
                            uvs.Add(new Vector2(vector4.x, vector4.y));
                            uvs.Add(new Vector2(vector4.x, vector5.y));
                            uvs.Add(new Vector2(vector5.x, vector5.y));
                        }

                        verts.Add(new Vector3(vector3.x, zero.y));
                        verts.Add(new Vector3(zero.x, zero.y));
                        verts.Add(new Vector3(zero.x, vector3.y));
                        verts.Add(new Vector3(vector3.x, vector3.y));
                    }
                }

                if (alignment != Alignment.Left && indexOffset < verts.size)
                {
                    Align(verts, indexOffset, alignment, x, lineWidth);
                    indexOffset = verts.size;
                }
            }
        }
    }
示例#13
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, verts, uvs, cols);
        }
        else if (!string.IsNullOrEmpty(text))
        {
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

#if DYNAMIC_FONT
            if (isDynamic)
            {
                // NOTE: This shouldn't be used anymore. All dynamic font printing goes directly through NGUIText instead.
                NGUIText.current.size  = mDynamicFontSize;
                NGUIText.current.style = mDynamicFontStyle;
                NGUIText.Print(dynamicFont, text, verts, uvs, cols);
                return;
            }
#endif
            mColors.Add(Color.white);

            int     fs = NGUIText.current.size;
            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (fs + NGUIText.current.spacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            Color   gb = NGUIText.current.tint * NGUIText.current.gradientBottom;
            Color   gt = NGUIText.current.tint * NGUIText.current.gradientTop;
            Color32 uc = NGUIText.current.tint;

            float invX = uvRect.width / mFont.texWidth;
            float invY = mUVRect.height / mFont.texHeight;

            int  textLength = text.Length;
            bool useSymbols = NGUIText.current.encoding && NGUIText.current.symbolStyle != NGUIText.SymbolStyle.None && hasSymbols && sprite != null;

            for (int i = 0; i < textLength; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (NGUIText.current.alignment != TextAlignment.Left)
                    {
                        NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (NGUIText.current.encoding && NGUIText.ParseSymbol(text, ref i, mColors, NGUIText.current.premultiply))
                {
                    Color fc = NGUIText.current.tint * mColors[mColors.size - 1];
                    uc = fc;

                    if (NGUIText.current.gradient)
                    {
                        gb = NGUIText.current.gradientBottom * fc;
                        gt = NGUIText.current.gradientTop * fc;
                    }
                    --i;
                    continue;
                }

                // See if there is a symbol matching this text
                BMSymbol symbol = useSymbols ? MatchSymbol(text, i, textLength) : null;

                if (symbol == null)
                {
                    BMGlyph glyph = mFont.GetGlyph(c);
                    if (glyph == null)
                    {
                        continue;
                    }

                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c == ' ')
                    {
                        x   += NGUIText.current.spacingX + glyph.advance;
                        prev = c;
                        continue;
                    }

                    v0.x = (x + glyph.offsetX);
                    v0.y = -(y + glyph.offsetY);

                    v1.x = v0.x + glyph.width;
                    v1.y = v0.y - glyph.height;

                    u0.x = mUVRect.xMin + invX * glyph.x;
                    u0.y = mUVRect.yMax - invY * glyph.y;

                    u1.x = u0.x + invX * glyph.width;
                    u1.y = u0.y - invY * glyph.height;

                    x   += NGUIText.current.spacingX + glyph.advance;
                    prev = c;

                    if (glyph.channel == 0 || glyph.channel == 15)
                    {
                        if (NGUIText.current.gradient)
                        {
                            float min = NGUIText.current.size - glyph.offsetY;
                            float max = min - glyph.height;

                            min /= NGUIText.current.size;
                            max /= NGUIText.current.size;

                            s_c0 = Color.Lerp(gb, gt, min);
                            s_c1 = Color.Lerp(gb, gt, max);

                            cols.Add(s_c0);
                            cols.Add(s_c1);
                            cols.Add(s_c1);
                            cols.Add(s_c0);
                        }
                        else
                        {
                            for (int b = 0; b < 4; ++b)
                            {
                                cols.Add(uc);
                            }
                        }
                    }
                    else
                    {
                        // Packed fonts come as alpha masks in each of the RGBA channels.
                        // In order to use it we need to use a special shader.
                        //
                        // Limitations:
                        // - Effects (drop shadow, outline) will not work.
                        // - Should not be a part of the atlas (eastern fonts rarely are anyway).
                        // - Lower color precision

                        Color col = uc;

                        col *= 0.49f;

                        switch (glyph.channel)
                        {
                        case 1: col.b += 0.51f; break;

                        case 2: col.g += 0.51f; break;

                        case 4: col.r += 0.51f; break;

                        case 8: col.a += 0.51f; break;
                        }

                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }
                else
                {
                    v0.x = (x + symbol.offsetX);
                    v0.y = -(y + symbol.offsetY);

                    v1.x = v0.x + symbol.width;
                    v1.y = v0.y - symbol.height;

                    Rect uv = symbol.uvRect;

                    u0.x = uv.xMin;
                    u0.y = uv.yMax;
                    u1.x = uv.xMax;
                    u1.y = uv.yMin;

                    x   += NGUIText.current.spacingX + symbol.advance;
                    i   += symbol.length - 1;
                    prev = 0;

                    if (NGUIText.current.symbolStyle == NGUIText.SymbolStyle.Colored)
                    {
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(uc);
                        }
                    }
                    else
                    {
                        Color32 col = Color.white;
                        col.a = uc.a;
                        for (int b = 0; b < 4; ++b)
                        {
                            cols.Add(col);
                        }
                    }
                }

                verts.Add(new Vector3(v1.x, v0.y));
                verts.Add(new Vector3(v1.x, v1.y));
                verts.Add(new Vector3(v0.x, v1.y));
                verts.Add(new Vector3(v0.x, v0.y));

                uvs.Add(new Vector2(u1.x, u0.y));
                uvs.Add(new Vector2(u1.x, u1.y));
                uvs.Add(new Vector2(u0.x, u1.y));
                uvs.Add(new Vector2(u0.x, u0.y));
            }

            if (NGUIText.current.alignment != TextAlignment.Left && indexOffset < verts.size)
            {
                NGUIText.Align(verts, indexOffset, x - NGUIText.current.spacingX);
                indexOffset = verts.size;
            }
            mColors.Clear();
        }
    }
示例#14
0
    public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth, bool premultiply)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply);
        }
        else
        {
            if (text == null)
            {
                return;
            }
            if (!isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }
            bool isDynamic = this.isDynamic;
            if (isDynamic)
            {
                Font.textureRebuilt += OnFontChanged;
                // mDynamicFont.textureRebuildCallback = OnFontChanged;
                mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle);
                // mDynamicFont.textureRebuildCallback = null;
                Font.textureRebuilt -= OnFontChanged;
            }
            mColors.Clear();
            mColors.Add(color);
            int     size   = this.size;
            Vector2 vector = (size <= 0) ? Vector2.one : new Vector2(1f / (float)size, 1f / (float)size);
            int     size2  = verts.size;
            int     num    = 0;
            int     num2   = 0;
            int     num3   = 0;
            int     num4   = 0;
            int     num5   = size + mSpacingY;
            Vector3 zero   = Vector3.zero;
            Vector3 zero2  = Vector3.zero;
            Vector2 zero3  = Vector2.zero;
            Vector2 zero4  = Vector2.zero;
            float   num6   = this.uvRect.width / (float)mFont.texWidth;
            float   num7   = mUVRect.height / (float)mFont.texHeight;
            int     length = text.Length;
            bool    flag   = encoding && symbolStyle != 0 && hasSymbols && sprite != null;
            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if (c == '\n')
                {
                    if (num2 > num)
                    {
                        num = num2;
                    }
                    if (alignment != 0)
                    {
                        Align(verts, size2, alignment, num2, lineWidth);
                        size2 = verts.size;
                    }
                    num2  = 0;
                    num3 += num5;
                    num4  = 0;
                    continue;
                }
                if (c < ' ')
                {
                    num4 = 0;
                    continue;
                }
                if (encoding && c == '[')
                {
                    int num8 = NGUITools.ParseSymbol(text, i, mColors, premultiply);
                    if (num8 > 0)
                    {
                        color = mColors[mColors.Count - 1];
                        i    += num8 - 1;
                        continue;
                    }
                }
                if (!isDynamic)
                {
                    BMSymbol bMSymbol = (!flag) ? null : MatchSymbol(text, i, length);
                    if (bMSymbol == null)
                    {
                        BMGlyph glyph = mFont.GetGlyph(c);
                        if (glyph == null)
                        {
                            continue;
                        }
                        if (num4 != 0)
                        {
                            num2 += glyph.GetKerning(num4);
                        }
                        if (c == ' ')
                        {
                            num2 += mSpacingX + glyph.advance;
                            num4  = c;
                            continue;
                        }
                        zero.x  = vector.x * (float)(num2 + glyph.offsetX);
                        zero.y  = (0f - vector.y) * (float)(num3 + glyph.offsetY);
                        zero2.x = zero.x + vector.x * (float)glyph.width;
                        zero2.y = zero.y - vector.y * (float)glyph.height;
                        zero3.x = mUVRect.xMin + num6 * (float)glyph.x;
                        zero3.y = mUVRect.yMax - num7 * (float)glyph.y;
                        zero4.x = zero3.x + num6 * (float)glyph.width;
                        zero4.y = zero3.y - num7 * (float)glyph.height;
                        num2   += mSpacingX + glyph.advance;
                        num4    = c;
                        if (glyph.channel == 0 || glyph.channel == 15)
                        {
                            for (int j = 0; j < 4; j++)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            Color c2 = color;
                            c2 *= 0.49f;
                            switch (glyph.channel)
                            {
                            case 1:
                                c2.b += 0.51f;
                                break;

                            case 2:
                                c2.g += 0.51f;
                                break;

                            case 4:
                                c2.r += 0.51f;
                                break;

                            case 8:
                                c2.a += 0.51f;
                                break;
                            }
                            for (int k = 0; k < 4; k++)
                            {
                                cols.Add(c2);
                            }
                        }
                    }
                    else
                    {
                        zero.x  = vector.x * (float)(num2 + bMSymbol.offsetX);
                        zero.y  = (0f - vector.y) * (float)(num3 + bMSymbol.offsetY);
                        zero2.x = zero.x + vector.x * (float)bMSymbol.width;
                        zero2.y = zero.y - vector.y * (float)bMSymbol.height;
                        Rect uvRect = bMSymbol.uvRect;
                        zero3.x = uvRect.xMin;
                        zero3.y = uvRect.yMax;
                        zero4.x = uvRect.xMax;
                        zero4.y = uvRect.yMin;
                        num2   += mSpacingX + bMSymbol.advance;
                        i      += bMSymbol.length - 1;
                        num4    = 0;
                        if (symbolStyle == SymbolStyle.Colored)
                        {
                            for (int l = 0; l < 4; l++)
                            {
                                cols.Add(color);
                            }
                        }
                        else
                        {
                            Color32 item = Color.white;
                            item.a = color.a;
                            for (int m = 0; m < 4; m++)
                            {
                                cols.Add(item);
                            }
                        }
                    }
                    verts.Add(new Vector3(zero2.x, zero.y));
                    verts.Add(new Vector3(zero2.x, zero2.y));
                    verts.Add(new Vector3(zero.x, zero2.y));
                    verts.Add(new Vector3(zero.x, zero.y));
                    uvs.Add(new Vector2(zero4.x, zero3.y));
                    uvs.Add(new Vector2(zero4.x, zero4.y));
                    uvs.Add(new Vector2(zero3.x, zero4.y));
                    uvs.Add(new Vector2(zero3.x, zero3.y));
                }
                else if (mDynamicFont.GetCharacterInfo(c, out mChar, mDynamicFontSize, mDynamicFontStyle))
                {
                    zero.x  = vector.x * ((float)num2 + mChar.vert.xMin);
                    zero.y  = (0f - vector.y) * ((float)num3 - mChar.vert.yMax + mDynamicFontOffset);
                    zero2.x = zero.x + vector.x * mChar.vert.width;
                    zero2.y = zero.y - vector.y * mChar.vert.height;
                    zero3.x = mChar.uv.xMin;
                    zero3.y = mChar.uv.yMin;
                    zero4.x = mChar.uv.xMax;
                    zero4.y = mChar.uv.yMax;
                    num2   += mSpacingX + (int)mChar.width;
                    for (int n = 0; n < 4; n++)
                    {
                        cols.Add(color);
                    }
                    if (mChar.flipped)
                    {
                        uvs.Add(new Vector2(zero3.x, zero4.y));
                        uvs.Add(new Vector2(zero3.x, zero3.y));
                        uvs.Add(new Vector2(zero4.x, zero3.y));
                        uvs.Add(new Vector2(zero4.x, zero4.y));
                    }
                    else
                    {
                        uvs.Add(new Vector2(zero4.x, zero3.y));
                        uvs.Add(new Vector2(zero3.x, zero3.y));
                        uvs.Add(new Vector2(zero3.x, zero4.y));
                        uvs.Add(new Vector2(zero4.x, zero4.y));
                    }
                    verts.Add(new Vector3(zero2.x, zero.y));
                    verts.Add(new Vector3(zero.x, zero.y));
                    verts.Add(new Vector3(zero.x, zero2.y));
                    verts.Add(new Vector3(zero2.x, zero2.y));
                }
            }
            if (alignment != 0 && size2 < verts.size)
            {
                Align(verts, size2, alignment, num2, lineWidth);
                size2 = verts.size;
            }
        }
    }
示例#15
0
    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFont == null)
        {
            return;
        }
        Pivot pivot = base.pivot;
        int   size  = verts.size;
        Color c     = base.color;

        c.a *= mPanel.alpha;
        if (font.premultipliedAlpha)
        {
            c = NGUITools.ApplyPMA(c);
        }
        switch (pivot)
        {
        case Pivot.TopLeft:
        case Pivot.Left:
        case Pivot.BottomLeft:
            mFont.Print(this.processedText, c, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0, mPremultiply);
            break;

        case Pivot.TopRight:
        case Pivot.Right:
        case Pivot.BottomRight:
        {
            UIFont             uIFont2        = mFont;
            string             processedText2 = this.processedText;
            Color32            color2         = c;
            bool               encoding2      = mEncoding;
            UIFont.SymbolStyle symbolStyle2   = mSymbols;
            Vector2            relativeSize2  = this.relativeSize;
            uIFont2.Print(processedText2, color2, verts, uvs, cols, encoding2, symbolStyle2, UIFont.Alignment.Right, Mathf.RoundToInt(relativeSize2.x * (float)mFont.size), mPremultiply);
            break;
        }

        default:
        {
            UIFont             uIFont        = mFont;
            string             processedText = this.processedText;
            Color32            color         = c;
            bool               encoding      = mEncoding;
            UIFont.SymbolStyle symbolStyle   = mSymbols;
            Vector2            relativeSize  = this.relativeSize;
            uIFont.Print(processedText, color, verts, uvs, cols, encoding, symbolStyle, UIFont.Alignment.Center, Mathf.RoundToInt(relativeSize.x * (float)mFont.size), mPremultiply);
            break;
        }
        }
        if (effectStyle != 0)
        {
            int   size2 = verts.size;
            float num   = 1f / (float)mFont.size;
            float num2  = num * mEffectDistance.x;
            float num3  = num * mEffectDistance.y;
            ApplyShadow(verts, uvs, cols, size, size2, num2, 0f - num3);
            if (effectStyle == Effect.Outline)
            {
                size  = size2;
                size2 = verts.size;
                ApplyShadow(verts, uvs, cols, size, size2, 0f - num2, num3);
                size  = size2;
                size2 = verts.size;
                ApplyShadow(verts, uvs, cols, size, size2, num2, num3);
                size  = size2;
                size2 = verts.size;
                ApplyShadow(verts, uvs, cols, size, size2, 0f - num2, 0f - num3);
            }
        }
    }
示例#16
0
    /// <summary>
    /// Print the specified text into the buffers.
    /// Note: 'lineWidth' parameter should be in pixels.
    /// </summary>

    public void Print(string text, Color color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols,
                      bool encoding, Alignment alignment, int lineWidth)
    {
        if (mReplacement != null)
        {
            mReplacement.Print(text, color, verts, uvs, cols, encoding, alignment, lineWidth);
        }
        else if (mFont != null && text != null)
        {
            if (!mFont.isValid)
            {
                Debug.LogError("Attempting to print using an invalid font!");
                return;
            }

            mColors.Clear();
            mColors.Add(color);

            Vector2 scale = mFont.charSize > 0 ? new Vector2(1f / mFont.charSize, 1f / mFont.charSize) : Vector2.one;

            int     indexOffset = verts.size;
            int     maxX = 0;
            int     x = 0;
            int     y = 0;
            int     prev = 0;
            int     lineHeight = (mFont.charSize + mSpacingY);
            Vector3 v0 = Vector3.zero, v1 = Vector3.zero;
            Vector2 u0 = Vector2.zero, u1 = Vector2.zero;
            float   invX = uvRect.width / mFont.texWidth;
            float   invY = mUVRect.height / mFont.texHeight;

            for (int i = 0, imax = text.Length; i < imax; ++i)
            {
                char c = text[i];

                if (c == '\n')
                {
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (alignment != Alignment.Left)
                    {
                        Align(verts, indexOffset, alignment, x, lineWidth);
                        indexOffset = verts.size;
                    }

                    x    = 0;
                    y   += lineHeight;
                    prev = 0;
                    continue;
                }

                if (c < ' ')
                {
                    prev = 0;
                    continue;
                }

                if (encoding && c == '[')
                {
                    int retVal = NGUITools.ParseSymbol(text, i, mColors);

                    if (retVal > 0)
                    {
                        color = mColors[mColors.Count - 1];
                        i    += retVal - 1;
                        continue;
                    }
                }

                BMGlyph glyph = mFont.GetGlyph(c);

                if (glyph != null)
                {
                    if (prev != 0)
                    {
                        x += glyph.GetKerning(prev);
                    }

                    if (c != ' ')
                    {
                        v0.x = scale.x * (x + glyph.offsetX);
                        v0.y = -scale.y * (y + glyph.offsetY);

                        v1.x = v0.x + scale.x * glyph.width;
                        v1.y = v0.y - scale.y * glyph.height;

                        u0.x = mUVRect.xMin + invX * glyph.x;
                        u0.y = mUVRect.yMax - invY * glyph.y;

                        u1.x = u0.x + invX * glyph.width;
                        u1.y = u0.y - invY * glyph.height;

                        verts.Add(new Vector3(v1.x, v0.y));
                        verts.Add(new Vector3(v1.x, v1.y));
                        verts.Add(new Vector3(v0.x, v1.y));
                        verts.Add(new Vector3(v0.x, v0.y));

                        uvs.Add(new Vector2(u1.x, u0.y));
                        uvs.Add(new Vector2(u1.x, u1.y));
                        uvs.Add(new Vector2(u0.x, u1.y));
                        uvs.Add(new Vector2(u0.x, u0.y));

                        cols.Add(color);
                        cols.Add(color);
                        cols.Add(color);
                        cols.Add(color);
                    }
                    x   += mSpacingX + glyph.advance;
                    prev = c;
                }
            }

            if (alignment != Alignment.Left && indexOffset < verts.size)
            {
                Align(verts, indexOffset, alignment, x, lineWidth);
                indexOffset = verts.size;
            }
        }
    }
示例#17
0
    /// <summary>
    /// Draw the label.
    /// </summary>

    public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        if (mFont == null)
        {
            return;
        }
        Pivot p      = pivot;
        int   offset = verts.size;

        Color col = color;

        col.a *= mPanel.alpha;
        if (font.premultipliedAlpha)
        {
            col = NGUITools.ApplyPMA(col);
        }

        // Print the text into the buffers
        if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft)
        {
            mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0, mPremultiply);
        }
        else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight)
        {
            mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right,
                        Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply);
        }
        else
        {
            mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center,
                        Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply);
        }

        // Apply an effect if one was requested
        if (effectStyle != Effect.None)
        {
            int   end   = verts.size;
            float pixel = 1f / mFont.size;

            float fx = pixel * mEffectDistance.x;
            float fy = pixel * mEffectDistance.y;

            ApplyShadow(verts, uvs, cols, offset, end, fx, -fy);

            if (effectStyle == Effect.Outline)
            {
                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, fx, fy);

                offset = end;
                end    = verts.size;

                ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy);
            }
        }
    }
示例#18
0
    public void RefreshText()
    {
        if (Font == null)
        {
            return;
        }

        mMesh.Clear();
        var text = Text.Replace("\\n", "\n");

        if (string.IsNullOrEmpty(text))
        {
            return;
        }

        s_verts.Clear();
        s_uvs.Clear();
        s_cols.Clear();
        Vector3 offsetVec = Font.CalculatePrintedSize(text, true, UIFont.SymbolStyle.Uncolored) * -0.5f;

        Font.Print(text, TextColor1, TextColor2, UIWidget.E_Direction.Vertical, s_verts, s_uvs, s_cols, false, UIFont.SymbolStyle.Uncolored, UIFont.Alignment.Center, LineWidth, false);

        int drawCnt = 1;

        if (EffectStyle == Effect.Outline)
        {
            drawCnt = 5;
        }
        else if (EffectStyle == Effect.Shadow)
        {
            drawCnt = 2;
        }

        var uvs  = new Vector2[s_uvs.size * drawCnt];
        var cols = new Color32[s_cols.size * drawCnt];

        Array.Copy(s_uvs.buffer, uvs, s_uvs.size);
        Array.Copy(s_cols.buffer, cols, s_cols.size);

        var verts = new Vector3[s_verts.size * drawCnt];

        for (int i = 0; i < s_verts.size; ++i)
        {
            verts[i] = s_verts[i] + offsetVec;
        }
        if (EffectStyle != Effect.None)
        {
            float pixel = 1f / Font.size;

            float fx = pixel * EffectDistance.x;
            float fy = pixel * EffectDistance.y;
            if (EffectStyle == Effect.Outline)
            {
                ApplyShadow(verts, uvs, cols, s_verts.size * 0, s_verts.size, new Vector3(fx, fy));
                ApplyShadow(verts, uvs, cols, s_verts.size * 1, s_verts.size, new Vector3(fx, -fy));
                ApplyShadow(verts, uvs, cols, s_verts.size * 2, s_verts.size, new Vector3(-fx, fy));
                ApplyShadow(verts, uvs, cols, s_verts.size * 3, s_verts.size, new Vector3(-fx, -fy));
            }
            else if (EffectStyle == Effect.Shadow)
            {
                ApplyShadow(verts, uvs, cols, 0, s_verts.size, new Vector3(fx, fy));
            }
        }

        int rcCount   = verts.Length / 4;
        var triangles = new int[rcCount * 6];

        for (int i = 0; i < rcCount; ++i)
        {
            triangles[i * 6 + 0] = i * 4 + 0;
            triangles[i * 6 + 1] = i * 4 + 1;
            triangles[i * 6 + 2] = i * 4 + 2;

            triangles[i * 6 + 3] = i * 4 + 2;
            triangles[i * 6 + 4] = i * 4 + 3;
            triangles[i * 6 + 5] = i * 4 + 0;
        }


        mMesh.vertices  = verts;
        mMesh.triangles = triangles;
        mMesh.uv        = uvs;
        mMesh.colors32  = cols;
    }