コード例 #1
0
ファイル: dfMarkupBoxText.cs プロジェクト: sknchan/LegacyRust
    internal void SetText(string text)
    {
        this.Text = text;
        if (this.Style.Font == null)
        {
            return;
        }
        this.isWhitespace = dfMarkupBoxText.whitespacePattern.IsMatch(this.Text);
        string str = (this.Style.PreserveWhitespace || !this.isWhitespace ? this.Text : " ");

        CharacterInfo[] characterInfoArray = this.Style.Font.RequestCharacters(str, this.Style.FontSize, this.Style.FontStyle);
        int             fontSize           = this.Style.FontSize;
        Vector2         vector2            = new Vector2(0f, (float)this.Style.LineHeight);

        for (int i = 0; i < str.Length; i++)
        {
            CharacterInfo characterInfo = characterInfoArray[i];
            float         single        = characterInfo.vert.x + characterInfo.vert.width;
            if (str[i] == ' ')
            {
                single = Mathf.Max(single, (float)fontSize * 0.33f);
            }
            else if (str[i] == '\t')
            {
                single = single + (float)(fontSize * 3);
            }
            vector2.x = vector2.x + single;
        }
        this.Size = vector2;
        dfDynamicFont font      = this.Style.Font;
        float         fontSize1 = (float)fontSize / (float)font.FontSize;

        this.Baseline = Mathf.CeilToInt((float)font.Baseline * fontSize1);
    }
コード例 #2
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
        public float[] GetCharacterWidths(string text, int startIndex, int endIndex, out float totalWidth)
        {
            totalWidth = 0f;
            dfDynamicFont font = (dfDynamicFont)base.Font;
            int           num  = Mathf.CeilToInt((float)font.FontSize * base.TextScale);

            CharacterInfo[] characterInfoArray = font.RequestCharacters(text, num, FontStyle.Normal);
            float[]         pixelRatio         = new float[text.Length];
            float           single             = 0f;
            float           tabSize            = 0f;
            int             num1 = startIndex;

            while (num1 <= endIndex)
            {
                CharacterInfo characterInfo = characterInfoArray[num1];
                if (text[num1] != '\t')
                {
                    tabSize = (text[num1] != ' ' ? tabSize + (characterInfo.vert.x + characterInfo.vert.width) : tabSize + characterInfo.width);
                }
                else
                {
                    tabSize = tabSize + (float)base.TabSize;
                }
                pixelRatio[num1] = (tabSize - single) * base.PixelRatio;
                num1++;
                single = tabSize;
            }
            return(pixelRatio);
        }
コード例 #3
0
 internal void SetText(string text)
 {
     this.Text = text;
     if (this.Style.Font != null)
     {
         this.isWhitespace = whitespacePattern.IsMatch(this.Text);
         string          str       = (!this.Style.PreserveWhitespace && this.isWhitespace) ? " " : this.Text;
         CharacterInfo[] infoArray = this.Style.Font.RequestCharacters(str, this.Style.FontSize, this.Style.FontStyle);
         int             fontSize  = this.Style.FontSize;
         Vector2         vector    = new Vector2(0f, (float)this.Style.LineHeight);
         for (int i = 0; i < str.Length; i++)
         {
             CharacterInfo info = infoArray[i];
             float         a    = info.vert.x + info.vert.width;
             if (str[i] == ' ')
             {
                 a = Mathf.Max(a, fontSize * 0.33f);
             }
             else if (str[i] == '\t')
             {
                 a += fontSize * 3;
             }
             vector.x += a;
         }
         base.Size = vector;
         dfDynamicFont font = this.Style.Font;
         float         num4 = ((float)fontSize) / ((float)font.FontSize);
         base.Baseline = Mathf.CeilToInt(font.Baseline * num4);
     }
 }
コード例 #4
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
 public static dfFontRendererBase Obtain(dfDynamicFont font)
 {
     dfDynamicFont.DynamicFontRenderer dynamicFontRenderer = (dfDynamicFont.DynamicFontRenderer.objectPool.Count <= 0 ? new dfDynamicFont.DynamicFontRenderer() : dfDynamicFont.DynamicFontRenderer.objectPool.Dequeue());
     dynamicFontRenderer.Reset();
     dynamicFontRenderer.Font = font;
     return(dynamicFontRenderer);
 }
コード例 #5
0
    internal static void DrawFontPreview(dfDynamicFont font, Rect rect)
    {
        var previewString = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz!@#$%^&*()[]{}\\/| Grumpy wizards make toxic brew for the evil Queen and Jack. The quick brown fox jumps over the lazy dog.";
        //var previewString = "Grumpy wizards make toxic brew for the evil Queen and Jack. The quick brown fox jumps over the lazy dog. 0123456789 Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz !@#$%^&*()[]{}\\/|";

        var style = new GUIStyle()
        {
            font      = font.BaseFont,
            fontSize  = font.FontSize,
            fontStyle = FontStyle.Normal,
            wordWrap  = true,
            normal    = new GUIStyleState()
            {
                textColor = Color.white
            },
        };

        GUI.BeginScrollView(rect, Vector2.zero, rect);

        rect.x      += 5;
        rect.y      += 5;
        rect.width  -= 10;
        rect.height -= 10;

        EditorGUI.DropShadowLabel(rect, previewString, style);

        GUI.EndScrollView();
    }
コード例 #6
0
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            num2      = ((float)fontSize) / ((float)font.FontSize);
        float            num3      = font.Descent * num2;
        float            num4      = 0f;

        CharacterInfo[] infoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo info = infoArray[i];
            addTriangleIndices(vertices, triangles);
            float   num6    = ((font.FontSize + info.vert.y) - fontSize) + num3;
            float   x       = num4 + info.vert.x;
            float   y       = num6;
            float   num9    = x + info.vert.width;
            float   num10   = y + info.vert.height;
            Vector3 item    = new Vector3(x, y);
            Vector3 vector2 = new Vector3(num9, y);
            Vector3 vector3 = new Vector3(num9, num10);
            Vector3 vector4 = new Vector3(x, num10);
            vertices.Add(item);
            vertices.Add(vector2);
            vertices.Add(vector3);
            vertices.Add(vector4);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  uv    = info.uv;
            float num11 = uv.x;
            float num12 = uv.y + uv.height;
            float num13 = num11 + uv.width;
            float num14 = uv.y;
            if (info.flipped)
            {
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num11, num14));
            }
            else
            {
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num11, num14));
            }
            num4 += Mathf.CeilToInt(info.vert.x + info.vert.width);
        }
    }
コード例 #7
0
ファイル: dfMarkupBoxText.cs プロジェクト: sknchan/LegacyRust
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            single    = (float)fontSize / (float)font.FontSize;
        float            descent   = (float)font.Descent * single;
        float            num       = 0f;

        CharacterInfo[] characterInfoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo characterInfo = characterInfoArray[i];
            dfMarkupBoxText.addTriangleIndices(vertices, triangles);
            float   fontSize1 = (float)font.FontSize + characterInfo.vert.y - (float)fontSize + descent;
            float   single1   = num + characterInfo.vert.x;
            float   single2   = fontSize1;
            float   single3   = single1 + characterInfo.vert.width;
            float   single4   = single2 + characterInfo.vert.height;
            Vector3 vector3   = new Vector3(single1, single2);
            Vector3 vector31  = new Vector3(single3, single2);
            Vector3 vector32  = new Vector3(single3, single4);
            Vector3 vector33  = new Vector3(single1, single4);
            vertices.Add(vector3);
            vertices.Add(vector31);
            vertices.Add(vector32);
            vertices.Add(vector33);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  rect    = characterInfo.uv;
            float single5 = rect.x;
            float single6 = rect.y + rect.height;
            float single7 = single5 + rect.width;
            float single8 = rect.y;
            if (!characterInfo.flipped)
            {
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single5, single8));
            }
            else
            {
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single5, single8));
            }
            num = num + (float)Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width);
        }
    }
コード例 #8
0
ファイル: dfDynamicFont.cs プロジェクト: Elringus/HajiJam
        public static dfFontRendererBase Obtain(dfDynamicFont font)
        {
            var renderer = objectPool.Count > 0 ? objectPool.Dequeue() : new DynamicFontRenderer();

            renderer.Reset();
            renderer.Font = font;

            return(renderer);
        }
コード例 #9
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
        private void calculateLineSize(dfDynamicFont.LineRenderInfo line)
        {
            dfDynamicFont font = (dfDynamicFont)base.Font;

            line.lineHeight = (float)font.Baseline * base.TextScale;
            int width = 0;

            for (int i = line.startOffset; i <= line.endOffset; i++)
            {
                width = width + this.tokens[i].Width;
            }
            line.lineWidth = (float)width;
        }
コード例 #10
0
    private void addInline(dfMarkupBox box)
    {
        bool            flag;
        dfMarkupBorders margins = box.Margins;

        if (this.Style.Preformatted)
        {
            flag = false;
        }
        else
        {
            flag = (this.currentLine == null ? false : (float)this.currentLinePos + box.Size.x > this.currentLine.Size.x);
        }
        if (this.currentLine == null || flag)
        {
            this.endCurrentLine(false);
            int         verticalPosition = this.getVerticalPosition(margins.top);
            dfMarkupBox containingBlock  = this.GetContainingBlock();
            if (containingBlock == null)
            {
                Debug.LogError("Containing block not found");
                return;
            }
            dfDynamicFont font         = this.Style.Font ?? this.Style.Host.Font;
            float         fontSize     = (float)font.FontSize / (float)font.FontSize;
            float         baseline     = (float)font.Baseline * fontSize;
            dfMarkupBox   _dfMarkupBox = new dfMarkupBox(this.Element, dfMarkupDisplayType.block, this.Style)
            {
                Size     = new Vector2(containingBlock.Size.x, (float)this.Style.LineHeight),
                Position = new Vector2(0f, (float)verticalPosition),
                Parent   = this,
                Baseline = (int)baseline
            };
            this.currentLine = _dfMarkupBox;
            this.children.Add(this.currentLine);
        }
        if (this.currentLinePos == 0 && !box.Style.PreserveWhitespace && box is dfMarkupBoxText && (box as dfMarkupBoxText).IsWhitespace)
        {
            return;
        }
        Vector2 vector2 = new Vector2((float)(this.currentLinePos + margins.left), (float)margins.top);

        box.Position = vector2;
        box.Parent   = this.currentLine;
        this.currentLine.children.Add(box);
        this.currentLinePos = (int)(vector2.x + box.Size.x + (float)box.Margins.right);
        float single  = Mathf.Max(this.currentLine.Size.x, vector2.x + box.Size.x);
        float single1 = Mathf.Max(this.currentLine.Size.y, vector2.y + box.Size.y);

        this.currentLine.Size = new Vector2(single, single1);
    }
コード例 #11
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         int           num  = 0;
         char          item = '\0';
         bool          flag = (token.TokenType == dfMarkupTokenType.Whitespace ? true : token.TokenType == dfMarkupTokenType.Text);
         dfDynamicFont font = (dfDynamicFont)base.Font;
         if (flag)
         {
             int             num1 = Mathf.CeilToInt((float)font.FontSize * base.TextScale);
             CharacterInfo[] characterInfoArray = font.RequestCharacters(token.Value, num1, FontStyle.Normal);
             for (int i = 0; i < token.Length; i++)
             {
                 item = token[i];
                 if (item != '\t')
                 {
                     CharacterInfo characterInfo = characterInfoArray[i];
                     num = num + (item == ' ' ? Mathf.CeilToInt(characterInfo.width) : Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width));
                     if (i > 0)
                     {
                         num = num + Mathf.CeilToInt((float)base.CharacterSpacing * base.TextScale);
                     }
                 }
                 else
                 {
                     num = num + base.TabSize;
                 }
             }
             token.Height = base.Font.LineHeight;
             token.Width  = num;
         }
         else if (token.TokenType == dfMarkupTokenType.StartTag && token.Matches("sprite") && this.SpriteAtlas != null && token.AttributeCount == 1)
         {
             Texture2D        texture  = this.SpriteAtlas.Texture;
             float            baseline = (float)font.Baseline * base.TextScale;
             string           value    = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo itemInfo = this.SpriteAtlas[value];
             if (itemInfo != null)
             {
                 float single = itemInfo.region.width * (float)texture.width / (itemInfo.region.height * (float)texture.height);
                 num = Mathf.CeilToInt(baseline * single);
             }
             token.Height = Mathf.CeilToInt(baseline);
             token.Width  = num;
         }
     }
     finally
     {
     }
 }
コード例 #12
0
ファイル: dfMarkupStyle.cs プロジェクト: sknchan/LegacyRust
 public dfMarkupStyle(dfDynamicFont Font, int FontSize, UnityEngine.FontStyle FontStyle)
 {
     this.Host               = null;
     this.Atlas              = null;
     this.Font               = Font;
     this.FontSize           = FontSize;
     this.FontStyle          = FontStyle;
     this.Align              = dfMarkupTextAlign.Left;
     this.VerticalAlign      = dfMarkupVerticalAlign.Baseline;
     this.Color              = UnityEngine.Color.white;
     this.BackgroundColor    = UnityEngine.Color.clear;
     this.TextDecoration     = dfMarkupTextDecoration.None;
     this.PreserveWhitespace = false;
     this.Preformatted       = false;
     this.WordSpacing        = 0;
     this.CharacterSpacing   = 0;
     this.lineHeight         = 0;
     this.Opacity            = 1f;
 }
コード例 #13
0
ファイル: dfButton.cs プロジェクト: sknchan/LegacyRust
    private dfRenderData renderText()
    {
        if (this.Font == null || !this.Font.IsValid || string.IsNullOrEmpty(this.Text))
        {
            return(null);
        }
        dfRenderData material = this.renderData;

        if (this.font is dfDynamicFont)
        {
            dfDynamicFont _dfDynamicFont = (dfDynamicFont)this.font;
            material = this.textRenderData;
            material.Clear();
            material.Material = _dfDynamicFont.Material;
        }
        using (dfFontRendererBase _dfFontRendererBase = this.obtainTextRenderer())
        {
            _dfFontRendererBase.Render(this.text, material);
        }
        return(material);
    }
コード例 #14
0
ファイル: dfButton.cs プロジェクト: Virobeast2/RCLIENT
    private dfRenderData renderText()
    {
        if (((this.Font == null) || !this.Font.IsValid) || string.IsNullOrEmpty(this.Text))
        {
            return(null);
        }
        dfRenderData renderData = base.renderData;

        if (this.font is dfDynamicFont)
        {
            dfDynamicFont font = (dfDynamicFont)this.font;
            renderData = this.textRenderData;
            renderData.Clear();
            renderData.Material = font.Material;
        }
        using (dfFontRendererBase base2 = this.obtainTextRenderer())
        {
            base2.Render(this.text, renderData);
        }
        return(renderData);
    }
コード例 #15
0
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        string[]          names     = new string[] { "name", "face" };
        dfMarkupAttribute attribute = base.findAttribute(names);

        if (attribute != null)
        {
            dfDynamicFont font1 = dfDynamicFont.FindByName(attribute.Value);
            if (font1 == null)
            {
            }
            style.Font = style.Font;
        }
        string[]          textArray2 = new string[] { "size", "font-size" };
        dfMarkupAttribute attribute2 = base.findAttribute(textArray2);

        if (attribute2 != null)
        {
            style.FontSize = dfMarkupStyle.ParseSize(attribute2.Value, style.FontSize);
        }
        string[]          textArray3 = new string[] { "color" };
        dfMarkupAttribute attribute3 = base.findAttribute(textArray3);

        if (attribute3 != null)
        {
            style.Color   = dfMarkupStyle.ParseColor(attribute3.Value, Color.red);
            style.Color.a = style.Opacity;
        }
        string[]          textArray4 = new string[] { "style" };
        dfMarkupAttribute attribute4 = base.findAttribute(textArray4);

        if (attribute4 != null)
        {
            style.FontStyle = dfMarkupStyle.ParseFontStyle(attribute4.Value, style.FontStyle);
        }
        base._PerformLayoutImpl(container, style);
    }
コード例 #16
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
    public static dfDynamicFont FindByName(string name)
    {
        for (int i = 0; i < dfDynamicFont.loadedFonts.Count; i++)
        {
            if (string.Equals(dfDynamicFont.loadedFonts[i].name, name, StringComparison.InvariantCultureIgnoreCase))
            {
                return(dfDynamicFont.loadedFonts[i]);
            }
        }
        GameObject gameObject = Resources.Load(name) as GameObject;

        if (gameObject == null)
        {
            return(null);
        }
        dfDynamicFont component = gameObject.GetComponent <dfDynamicFont>();

        if (component == null)
        {
            return(null);
        }
        dfDynamicFont.loadedFonts.Add(component);
        return(component);
    }
コード例 #17
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData renderData)
 {
     try
     {
         dfDynamicFont    font               = (dfDynamicFont)base.Font;
         int              num                = Mathf.CeilToInt((float)font.FontSize * base.TextScale);
         FontStyle        fontStyle          = FontStyle.Normal;
         int              descent            = font.Descent;
         dfList <Vector3> vertices           = renderData.Vertices;
         dfList <int>     triangles          = renderData.Triangles;
         dfList <Vector2> uV                 = renderData.UV;
         dfList <Color32> colors             = renderData.Colors;
         string           value              = token.Value;
         float            characterSpacing   = position.x;
         float            single             = position.y;
         CharacterInfo[]  characterInfoArray = font.RequestCharacters(value, num, fontStyle);
         renderData.Material = font.Material;
         Color32 color32  = this.applyOpacity(this.multiplyColors(color, base.DefaultColor));
         Color32 color321 = color32;
         if (base.BottomColor.HasValue)
         {
             Color   color1      = color;
             Color32?bottomColor = base.BottomColor;
             color321 = this.applyOpacity(this.multiplyColors(color1, bottomColor.Value));
         }
         for (int i = 0; i < value.Length; i++)
         {
             if (i > 0)
             {
                 characterSpacing = characterSpacing + (float)base.CharacterSpacing * base.TextScale;
             }
             CharacterInfo characterInfo = characterInfoArray[i];
             float         fontSize      = (float)font.FontSize + characterInfo.vert.y - (float)num + (float)descent;
             float         single1       = characterSpacing + characterInfo.vert.x;
             float         single2       = single + fontSize;
             float         single3       = single1 + characterInfo.vert.width;
             float         single4       = single2 + characterInfo.vert.height;
             Vector3       vector3       = new Vector3(single1, single2) * base.PixelRatio;
             Vector3       vector31      = new Vector3(single3, single2) * base.PixelRatio;
             Vector3       vector32      = new Vector3(single3, single4) * base.PixelRatio;
             Vector3       vector33      = new Vector3(single1, single4) * base.PixelRatio;
             if (base.Shadow)
             {
                 dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
                 Vector3 shadowOffset = base.ShadowOffset * base.PixelRatio;
                 vertices.Add(vector3 + shadowOffset);
                 vertices.Add(vector31 + shadowOffset);
                 vertices.Add(vector32 + shadowOffset);
                 vertices.Add(vector33 + shadowOffset);
                 Color32 color322 = this.applyOpacity(base.ShadowColor);
                 colors.Add(color322);
                 colors.Add(color322);
                 colors.Add(color322);
                 colors.Add(color322);
                 dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
             }
             if (base.Outline)
             {
                 for (int j = 0; j < (int)dfDynamicFont.DynamicFontRenderer.OUTLINE_OFFSETS.Length; j++)
                 {
                     dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
                     Vector3 oUTLINEOFFSETS = (dfDynamicFont.DynamicFontRenderer.OUTLINE_OFFSETS[j] * (float)base.OutlineSize) * base.PixelRatio;
                     vertices.Add(vector3 + oUTLINEOFFSETS);
                     vertices.Add(vector31 + oUTLINEOFFSETS);
                     vertices.Add(vector32 + oUTLINEOFFSETS);
                     vertices.Add(vector33 + oUTLINEOFFSETS);
                     Color32 color323 = this.applyOpacity(base.OutlineColor);
                     colors.Add(color323);
                     colors.Add(color323);
                     colors.Add(color323);
                     colors.Add(color323);
                     dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
                 }
             }
             dfDynamicFont.DynamicFontRenderer.addTriangleIndices(vertices, triangles);
             vertices.Add(vector3);
             vertices.Add(vector31);
             vertices.Add(vector32);
             vertices.Add(vector33);
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color321);
             colors.Add(color321);
             dfDynamicFont.DynamicFontRenderer.addUVCoords(uV, characterInfo);
             characterSpacing = characterSpacing + (float)Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width);
         }
     }
     finally
     {
     }
 }
コード例 #18
0
ファイル: dfDynamicFont.cs プロジェクト: HexHash/LegacyRust
 private int calculateLineAlignment(dfDynamicFont.LineRenderInfo line)
 {
     float single = line.lineWidth;
     if (base.TextAlign == TextAlignment.Left || single < 1f)
     {
         return 0;
     }
     float single1 = 0f;
     single1 = (base.TextAlign != TextAlignment.Right ? (base.MaxSize.x - single) * 0.5f : base.MaxSize.x - single);
     return Mathf.CeilToInt(Mathf.Max(0f, single1));
 }
コード例 #19
0
ファイル: dfMarkupStyle.cs プロジェクト: AhrenLi/2048
    public dfMarkupStyle( dfDynamicFont Font, int FontSize, FontStyle FontStyle )
    {
        Host = null;
        Atlas = null;

        this.Font = Font;
        this.FontSize = FontSize;
        this.FontStyle = FontStyle;

        Align = dfMarkupTextAlign.Left;
        VerticalAlign = dfMarkupVerticalAlign.Baseline;
        Color = UnityEngine.Color.white;
        BackgroundColor = UnityEngine.Color.clear;
        TextDecoration = dfMarkupTextDecoration.None;

        PreserveWhitespace = false;
        Preformatted = false;
        WordSpacing = 0;
        CharacterSpacing = 0;
        lineHeight = 0;
        Opacity = 1f;
    }
コード例 #20
0
		public static dfFontRendererBase Obtain( dfDynamicFont font )
		{

			var renderer = objectPool.Count > 0 ? objectPool.Dequeue() : new DynamicFontRenderer();
			renderer.Reset();
			renderer.Font = font;
			renderer.inUse = true;

			return renderer;

		}
コード例 #21
0
    internal static void DrawFontPreview( dfDynamicFont font, Rect rect )
    {
        var previewString = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz!@#$%^&*()[]{}\\/| Grumpy wizards make toxic brew for the evil Queen and Jack. The quick brown fox jumps over the lazy dog.";
        //var previewString = "Grumpy wizards make toxic brew for the evil Queen and Jack. The quick brown fox jumps over the lazy dog. 0123456789 Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz !@#$%^&*()[]{}\\/|";

        var style = new GUIStyle()
        {
            font = font.BaseFont,
            fontSize = font.FontSize,
            fontStyle = FontStyle.Normal,
            wordWrap = true,
            normal = new GUIStyleState() { textColor = Color.white },
        };

        GUI.BeginScrollView( rect, Vector2.zero, rect );

        rect.x += 5;
        rect.y += 5;
        rect.width -= 10;
        rect.height -= 10;

        EditorGUI.DropShadowLabel( rect, previewString, style );

        GUI.EndScrollView();
    }
コード例 #22
0
ファイル: dfDynamicFont.cs プロジェクト: HexHash/LegacyRust
 private void calculateLineSize(dfDynamicFont.LineRenderInfo line)
 {
     dfDynamicFont font = (dfDynamicFont)base.Font;
     line.lineHeight = (float)font.Baseline * base.TextScale;
     int width = 0;
     for (int i = line.startOffset; i <= line.endOffset; i++)
     {
         width = width + this.tokens[i].Width;
     }
     line.lineWidth = (float)width;
 }
コード例 #23
0
ファイル: dfDynamicFont.cs プロジェクト: HexHash/LegacyRust
 private void renderLine(dfDynamicFont.LineRenderInfo line, Stack<Color32> colors, Vector3 position, dfRenderData destination)
 {
     position.x = position.x + (float)this.calculateLineAlignment(line);
     for (int i = line.startOffset; i <= line.endOffset; i++)
     {
         dfMarkupToken item = this.tokens[i];
         dfMarkupTokenType tokenType = item.TokenType;
         if (tokenType == dfMarkupTokenType.Text)
         {
             this.renderText(item, colors.Peek(), position, destination);
         }
         else if (tokenType != dfMarkupTokenType.StartTag)
         {
             if (tokenType == dfMarkupTokenType.EndTag && item.Matches("color") && colors.Count > 1)
             {
                 colors.Pop();
             }
         }
         else if (item.Matches("sprite") && this.SpriteAtlas != null && this.SpriteBuffer != null)
         {
             this.renderSprite(item, colors.Peek(), position, this.SpriteBuffer);
         }
         else if (item.Matches("color"))
         {
             colors.Push(this.parseColor(item));
         }
         position.x = position.x + (float)item.Width;
     }
 }
コード例 #24
0
ファイル: dfDynamicFont.cs プロジェクト: HexHash/LegacyRust
 public static dfFontRendererBase Obtain(dfDynamicFont font)
 {
     dfDynamicFont.DynamicFontRenderer dynamicFontRenderer = (dfDynamicFont.DynamicFontRenderer.objectPool.Count <= 0 ? new dfDynamicFont.DynamicFontRenderer() : dfDynamicFont.DynamicFontRenderer.objectPool.Dequeue());
     dynamicFontRenderer.Reset();
     dynamicFontRenderer.Font = font;
     return dynamicFontRenderer;
 }
コード例 #25
0
ファイル: dfDynamicFont.cs プロジェクト: sknchan/LegacyRust
        private dfList <dfDynamicFont.LineRenderInfo> calculateLinebreaks()
        {
            dfList <dfDynamicFont.LineRenderInfo> lineRenderInfos;
            bool flag;

            try
            {
                if (this.lines == null)
                {
                    this.lines = dfList <dfDynamicFont.LineRenderInfo> .Obtain();

                    dfDynamicFont font     = (dfDynamicFont)base.Font;
                    int           num      = 0;
                    int           num1     = 0;
                    int           num2     = 0;
                    int           num3     = 0;
                    float         baseline = (float)font.Baseline * base.TextScale;
                    while (num2 < this.tokens.Count)
                    {
                        Vector2 maxSize = base.MaxSize;
                        if ((float)this.lines.Count * baseline > maxSize.y + baseline)
                        {
                            break;
                        }
                        dfMarkupToken     item      = this.tokens[num2];
                        dfMarkupTokenType tokenType = item.TokenType;
                        if (tokenType != dfMarkupTokenType.Newline)
                        {
                            int num4 = Mathf.CeilToInt((float)item.Width);
                            if (!base.WordWrap || num <= num1)
                            {
                                flag = false;
                            }
                            else if (tokenType == dfMarkupTokenType.Text)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = (tokenType != dfMarkupTokenType.StartTag ? false : item.Matches("sprite"));
                            }
                            if (!flag || (float)(num3 + num4) < base.MaxSize.x)
                            {
                                if (tokenType == dfMarkupTokenType.Whitespace)
                                {
                                    num = num2;
                                }
                                num3 = num3 + num4;
                                num2++;
                            }
                            else if (num <= num1)
                            {
                                this.lines.Add(dfDynamicFont.LineRenderInfo.Obtain(num1, num - 1));
                                int num5 = num2 + 1;
                                num2 = num5;
                                num  = num5;
                                num1 = num5;
                                num3 = 0;
                            }
                            else
                            {
                                this.lines.Add(dfDynamicFont.LineRenderInfo.Obtain(num1, num - 1));
                                int num6 = num + 1;
                                num  = num6;
                                num2 = num6;
                                num1 = num6;
                                num3 = 0;
                            }
                        }
                        else
                        {
                            this.lines.Add(dfDynamicFont.LineRenderInfo.Obtain(num1, num2));
                            int num7 = num2 + 1;
                            num2 = num7;
                            num  = num7;
                            num1 = num7;
                            num3 = 0;
                        }
                    }
                    if (num1 < this.tokens.Count)
                    {
                        this.lines.Add(dfDynamicFont.LineRenderInfo.Obtain(num1, this.tokens.Count - 1));
                    }
                    for (int i = 0; i < this.lines.Count; i++)
                    {
                        this.calculateLineSize(this.lines[i]);
                    }
                    lineRenderInfos = this.lines;
                }
                else
                {
                    lineRenderInfos = this.lines;
                }
            }
            finally
            {
            }
            return(lineRenderInfos);
        }