Ejemplo n.º 1
0
 public static dfFontRendererBase Obtain(dfFont font)
 {
     dfFont.BitmappedFontRenderer renderer = (objectPool.Count <= 0) ? new dfFont.BitmappedFontRenderer() : objectPool.Dequeue();
     renderer.Reset();
     renderer.Font = font;
     return(renderer);
 }
Ejemplo n.º 2
0
        public float[] GetCharacterWidths(string text, int startIndex, int endIndex, out float totalWidth)
        {
            totalWidth = 0f;
            dfFont font = (dfFont)base.Font;

            float[] singleArray      = new float[text.Length];
            float   textScale        = base.TextScale * base.PixelRatio;
            float   characterSpacing = (float)base.CharacterSpacing * textScale;

            for (int i = startIndex; i <= endIndex; i++)
            {
                dfFont.GlyphDefinition glyph = font.GetGlyph(text[i]);
                if (glyph != null)
                {
                    if (i > 0)
                    {
                        singleArray[i - 1] = singleArray[i - 1] + characterSpacing;
                        totalWidth         = totalWidth + characterSpacing;
                    }
                    float single = (float)glyph.xadvance * textScale;
                    singleArray[i] = single;
                    totalWidth     = totalWidth + single;
                }
            }
            return(singleArray);
        }
Ejemplo n.º 3
0
        public float[] GetCharacterWidths(string text, int startIndex, int endIndex, out float totalWidth)
        {
            totalWidth = 0f;
            dfFont font = (dfFont)base.Font;

            float[] numArray = new float[text.Length];
            float   num      = base.TextScale * base.PixelRatio;
            float   num2     = base.CharacterSpacing * num;

            for (int i = startIndex; i <= endIndex; i++)
            {
                dfFont.GlyphDefinition glyph = font.GetGlyph(text[i]);
                if (glyph != null)
                {
                    if (i > 0)
                    {
                        numArray[i - 1] += num2;
                        totalWidth      += num2;
                    }
                    float num4 = glyph.xadvance * num;
                    numArray[i] = num4;
                    totalWidth += num4;
                }
            }
            return(numArray);
        }
Ejemplo n.º 4
0
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         dfFont font         = (dfFont)base.Font;
         int    num          = 0;
         char   previousChar = '\0';
         char   id           = '\0';
         if ((token.TokenType == dfMarkupTokenType.Whitespace) || (token.TokenType == dfMarkupTokenType.Text))
         {
             int num2 = 0;
             while (num2 < token.Length)
             {
                 id = token[num2];
                 if (id == '\t')
                 {
                     num += base.TabSize;
                 }
                 else
                 {
                     dfFont.GlyphDefinition glyph = font.GetGlyph(id);
                     if (glyph != null)
                     {
                         if (num2 > 0)
                         {
                             num += font.GetKerning(previousChar, id);
                             num += base.CharacterSpacing;
                         }
                         num += glyph.xadvance;
                     }
                 }
                 num2++;
                 previousChar = id;
             }
         }
         else if ((token.TokenType == dfMarkupTokenType.StartTag) && token.Matches("sprite"))
         {
             if (token.AttributeCount < 1)
             {
                 throw new Exception("Missing sprite name in markup");
             }
             Texture          texture    = font.Texture;
             int              lineHeight = font.LineHeight;
             string           str        = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo info       = font.atlas[str];
             if (info != null)
             {
                 float num4 = (info.region.width * texture.width) / (info.region.height * texture.height);
                 num = Mathf.CeilToInt(lineHeight * num4);
             }
         }
         token.Height = base.Font.LineHeight;
         token.Width  = num;
     }
     finally
     {
     }
 }
Ejemplo n.º 5
0
 private void calculateTokenRenderSize(dfMarkupToken token)
 {
     try
     {
         dfFont font    = (dfFont)base.Font;
         int    kerning = 0;
         char   chr     = '\0';
         char   item    = '\0';
         if ((token.TokenType == dfMarkupTokenType.Whitespace ? true : token.TokenType == dfMarkupTokenType.Text))
         {
             int num = 0;
             while (num < token.Length)
             {
                 item = token[num];
                 if (item != '\t')
                 {
                     dfFont.GlyphDefinition glyph = font.GetGlyph(item);
                     if (glyph != null)
                     {
                         if (num > 0)
                         {
                             kerning = kerning + font.GetKerning(chr, item);
                             kerning = kerning + base.CharacterSpacing;
                         }
                         kerning = kerning + glyph.xadvance;
                     }
                 }
                 else
                 {
                     kerning = kerning + base.TabSize;
                 }
                 num++;
                 chr = item;
             }
         }
         else if (token.TokenType == dfMarkupTokenType.StartTag && token.Matches("sprite"))
         {
             if (token.AttributeCount < 1)
             {
                 throw new Exception("Missing sprite name in markup");
             }
             UnityEngine.Texture texture = font.Texture;
             int              lineHeight = font.LineHeight;
             string           value      = token.GetAttribute(0).Value.Value;
             dfAtlas.ItemInfo itemInfo   = font.atlas[value];
             if (itemInfo != null)
             {
                 float single = itemInfo.region.width * (float)texture.width / (itemInfo.region.height * (float)texture.height);
                 kerning = Mathf.CeilToInt((float)lineHeight * single);
             }
         }
         token.Height = base.Font.LineHeight;
         token.Width  = kerning;
     }
     finally
     {
     }
 }
Ejemplo n.º 6
0
        public static Font GetFontFromdfFont(dfFont font)
        {
            Font f = new Font();

            f.material                      = new Material(GUI.skin.font.material);
            f.material.mainTexture          = font.Texture;
            f.material.mainTexture.wrapMode = TextureWrapMode.Repeat;

            CharacterInfo[] chars = new CharacterInfo[font.Glyphs.Count];

            int maxHeight = 0;

            Debug.Log(font.Glyphs.Count);

            for (int i = 0; i < font.Glyphs.Count; i++)
            {
                CharacterInfo          inf             = new CharacterInfo();
                dfFont.GlyphDefinition glyphDefinition = font.Glyphs[i];

                dfAtlas.ItemInfo itemInfo = font.Atlas[font.Sprite];

                inf.glyphWidth  = glyphDefinition.width;
                inf.glyphHeight = glyphDefinition.height;

                inf.size = (int)size.x;

                if (inf.glyphHeight > maxHeight)
                {
                    maxHeight = inf.glyphHeight;
                }

                inf.index = glyphDefinition.id;

                float num9  = itemInfo.region.x + (float)glyphDefinition.x * f.material.mainTexture.texelSize.x;
                float num10 = itemInfo.region.yMax - (float)glyphDefinition.y * f.material.mainTexture.texelSize.y;
                float num11 = num9 + (float)glyphDefinition.width * f.material.mainTexture.texelSize.x;
                float num12 = num10 - (float)glyphDefinition.height * f.material.mainTexture.texelSize.y;

                inf.uvBottomLeft  = (new Vector2(num9, num12));
                inf.uvBottomRight = (new Vector2(num11, num12));
                inf.uvTopRight    = (new Vector2(num11, num10));
                inf.uvTopLeft     = (new Vector2(num9, num10));

                inf.advance = glyphDefinition.xadvance;

                inf.minY = 0;
                inf.maxY = inf.glyphHeight;
                inf.minX = 0;
                inf.maxX = inf.glyphWidth;

                chars[i] = inf;
            }

            f.characterInfo = chars;

            return(f);
        }
Ejemplo n.º 7
0
    private static void setValue(dfFont control, string propertyName, object value)
    {
        var property = control.GetType().GetProperty(propertyName);

        if (property == null)
        {
            throw new ArgumentException("Property '" + propertyName + "' does not exist on " + control.GetType().Name);
        }

        property.SetValue(control, value, null);
    }
Ejemplo n.º 8
0
    private static object getValue(dfFont control, string propertyName)
    {
        var property = control.GetType().GetProperty(propertyName);

        if (property == null)
        {
            throw new ArgumentException("Property '" + propertyName + "' does not exist on " + control.GetType().Name);
        }

        return(property.GetValue(control, null));
    }
Ejemplo n.º 9
0
    internal static void DrawFontPreview(dfFont 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 x = 0;
        var y = 0;

        var atlas   = font.Atlas;
        var texture = getTexture(atlas, font.Sprite);

        if (texture == null)
        {
            return;
        }

        var width  = 1f / (float)texture.width;
        var height = 1f / (float)texture.height;

        for (int i = 0; i < previewString.Length && y < rect.height; i++)
        {
            var glyph = font.GetGlyph(previewString[i]);
            if (glyph == null)
            {
                continue;
            }

            if (x + glyph.xadvance > rect.width)
            {
                x  = 0;
                y += font.LineHeight;
                if (y + font.LineHeight >= rect.height)
                {
                    break;
                }
            }

            var xofs      = x + (x > 0 ? glyph.xoffset : 0);
            var yofs      = y + glyph.yoffset;
            var glyphRect = new Rect(rect.x + xofs, rect.y + yofs, glyph.width, glyph.height);

            var uv = new Rect(
                (float)glyph.x * width,
                1f - (float)glyph.y * height - (float)glyph.height * height,
                (float)glyph.width * width,
                (float)glyph.height * height
                );

            GUI.DrawTextureWithTexCoords(glyphRect, texture, uv, true);

            x += glyph.xadvance;
        }
    }
Ejemplo n.º 10
0
    protected internal static void EditSprite(string label, dfFont font, string propertyName, int labelWidth)
    {
        var atlas = font.Atlas;

        if (atlas == null)
        {
            return;
        }

        dfSpriteSelectionDialog.SelectionCallback callback = delegate(string spriteName)
        {
            dfEditorUtil.MarkUndo(font, "Change Sprite");
            font.Sprite = spriteName;
        };

        var value = font.Sprite;

        EditorGUILayout.BeginHorizontal();
        {
            GUILayout.Label(label, GUILayout.Width(labelWidth));

            var displayText = string.IsNullOrEmpty(value) ? "[none]" : value;
            GUILayout.Label(displayText, "TextField", GUILayout.ExpandWidth(true));

            var evt = Event.current;
            if (evt != null && evt.type == EventType.MouseDown && evt.clickCount == 2)
            {
                Rect rect = GUILayoutUtility.GetLastRect();
                if (rect.Contains(evt.mousePosition))
                {
                    if (GUI.enabled && value != null)
                    {
                        dfTextureAtlasInspector.SelectedSprite = value;
                        Selection.activeObject = atlas;
                        EditorGUIUtility.PingObject(atlas);
                    }
                }
            }

            if (GUILayout.Button(new GUIContent(" ", "Edit " + label), "IN ObjectField", GUILayout.Width(12)))
            {
                dfEditorUtil.DelayedInvoke((System.Action)(() =>
                {
                    dfSpriteSelectionDialog.Show("Select Sprite: " + label, atlas, value, callback);
                }));
            }
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(2);
    }
Ejemplo n.º 11
0
 private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3> vertices  = destination.Vertices;
         dfList <int>     triangles = destination.Triangles;
         dfList <Color32> colors    = destination.Colors;
         dfList <Vector2> uV        = destination.UV;
         dfFont           font      = (dfFont)base.Font;
         string           str       = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo info      = font.Atlas[str];
         if (info != null)
         {
             float num   = (token.Height * base.TextScale) * base.PixelRatio;
             float num2  = (token.Width * base.TextScale) * base.PixelRatio;
             float x     = position.x;
             float y     = position.y;
             int   count = vertices.Count;
             vertices.Add(new Vector3(x, y));
             vertices.Add(new Vector3(x + num2, y));
             vertices.Add(new Vector3(x + num2, y - num));
             vertices.Add(new Vector3(x, y - num));
             triangles.Add(count);
             triangles.Add(count + 1);
             triangles.Add(count + 3);
             triangles.Add(count + 3);
             triangles.Add(count + 1);
             triangles.Add(count + 2);
             Color32 item = !base.ColorizeSymbols ? this.applyOpacity(base.DefaultColor) : this.applyOpacity(color);
             colors.Add(item);
             colors.Add(item);
             colors.Add(item);
             colors.Add(item);
             Rect region = info.region;
             uV.Add(new Vector2(region.x, region.yMax));
             uV.Add(new Vector2(region.xMax, region.yMax));
             uV.Add(new Vector2(region.xMax, region.y));
             uV.Add(new Vector2(region.x, region.y));
         }
     }
     finally
     {
     }
 }
Ejemplo n.º 12
0
 private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3> vertices  = destination.Vertices;
         dfList <int>     triangles = destination.Triangles;
         dfList <Color32> colors    = destination.Colors;
         dfList <Vector2> uV        = destination.UV;
         dfFont           font      = (dfFont)base.Font;
         string           value     = token.GetAttribute(0).Value.Value;
         dfAtlas.ItemInfo item      = font.Atlas[value];
         if (item != null)
         {
             float height  = (float)token.Height * base.TextScale * base.PixelRatio;
             float width   = (float)token.Width * base.TextScale * base.PixelRatio;
             float single  = position.x;
             float single1 = position.y;
             int   count   = vertices.Count;
             vertices.Add(new Vector3(single, single1));
             vertices.Add(new Vector3(single + width, single1));
             vertices.Add(new Vector3(single + width, single1 - height));
             vertices.Add(new Vector3(single, single1 - height));
             triangles.Add(count);
             triangles.Add(count + 1);
             triangles.Add(count + 3);
             triangles.Add(count + 3);
             triangles.Add(count + 1);
             triangles.Add(count + 2);
             Color32 color32 = (!base.ColorizeSymbols ? this.applyOpacity(base.DefaultColor) : this.applyOpacity(color));
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color32);
             colors.Add(color32);
             Rect rect = item.region;
             uV.Add(new Vector2(rect.x, rect.yMax));
             uV.Add(new Vector2(rect.xMax, rect.yMax));
             uV.Add(new Vector2(rect.xMax, rect.y));
             uV.Add(new Vector2(rect.x, rect.y));
         }
     }
     finally
     {
     }
 }
Ejemplo n.º 13
0
        public static Font DFFontToUnityFont(dfFont font, int scale = 1)
        {
            Font f = new Font(font.name);

            f.material                      = new Material(UnityEngine.GUI.skin.font.material);
            f.material.mainTexture          = font.Texture;
            f.material.mainTexture.wrapMode = TextureWrapMode.Repeat;

            CharacterInfo[] chars = new CharacterInfo[font.Glyphs.Count];

            for (int i = 0; i < chars.Length; i++)
            {
                CharacterInfo          inf             = new CharacterInfo();
                dfFont.GlyphDefinition glyphDefinition = font.Glyphs[i];
                dfAtlas.ItemInfo       itemInfo        = font.Atlas[font.Sprite];

                inf.glyphWidth  = glyphDefinition.width * scale;
                inf.glyphHeight = glyphDefinition.height * scale;
                inf.size        = 0; // Must be 0

                inf.index = glyphDefinition.id;

                float left   = itemInfo.region.x + glyphDefinition.x * f.material.mainTexture.texelSize.x;
                float right  = left + glyphDefinition.width * f.material.mainTexture.texelSize.x;
                float top    = itemInfo.region.yMax - glyphDefinition.y * f.material.mainTexture.texelSize.y;
                float bottom = top - glyphDefinition.height * f.material.mainTexture.texelSize.y;

                inf.uvTopLeft     = new Vector2(left, top);
                inf.uvTopRight    = new Vector2(right, top);
                inf.uvBottomLeft  = new Vector2(left, bottom);
                inf.uvBottomRight = new Vector2(right, bottom);

                inf.advance = glyphDefinition.xadvance * scale;

                inf.minY = scale * -glyphDefinition.height / 2;
                inf.maxY = scale * glyphDefinition.height / 2;

                chars[i] = inf;
            }

            f.characterInfo = chars;

            return(f);
        }
    private static void setValue( dfFont control, string propertyName, object value )
    {
        var property = control.GetType().GetProperty( propertyName );
        if( property == null )
            throw new ArgumentException( "Property '" + propertyName + "' does not exist on " + control.GetType().Name );

        property.SetValue( control, value, null );
    }
Ejemplo n.º 15
0
 protected internal static void EditSprite(string label, dfFont font, string propertyName)
 {
     EditSprite(label, font, propertyName, 90);
 }
    protected internal static void EditSprite( string label, dfFont font, string propertyName, int labelWidth = 90 )
    {
        var atlas = font.Atlas;
        if( atlas == null )
            return;

        dfSpriteSelectionDialog.SelectionCallback callback = delegate( string spriteName )
        {
            dfEditorUtil.MarkUndo( font, "Change Sprite" );
            font.Sprite = spriteName;
        };

        var value = font.Sprite;

        EditorGUILayout.BeginHorizontal();
        {

            GUILayout.Label( label, GUILayout.Width( labelWidth ) );

            var displayText = string.IsNullOrEmpty( value ) ? "[none]" : value;
            GUILayout.Label( displayText, "TextField", GUILayout.ExpandWidth( true ) );

            var evt = Event.current;
            if( evt != null && evt.type == EventType.mouseDown && evt.clickCount == 2 )
            {
                Rect rect = GUILayoutUtility.GetLastRect();
                if( rect.Contains( evt.mousePosition ) )
                {
                    if( GUI.enabled && value != null )
                    {
                        dfTextureAtlasInspector.SelectedSprite = value;
                        Selection.activeObject = atlas;
                        EditorGUIUtility.PingObject( atlas );
                    }
                }
            }

            if( GUILayout.Button( new GUIContent( " ", "Edit " + label ), "IN ObjectField", GUILayout.Width( 12 ) ) )
            {
                dfEditorUtil.DelayedInvoke( (System.Action)( () =>
                {
                    dfSpriteSelectionDialog.Show( "Select Sprite: " + label, atlas, value, callback );
                } ) );
            }

        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space( 2 );
    }
    protected internal static void SelectTextureAtlas( string label, dfFont view, string propertyName, bool readOnly, bool colorizeIfMissing, int labelWidth = 95 )
    {
        var savedColor = GUI.color;
        var showDialog = false;

        try
        {

            var atlas = getValue( view, propertyName ) as dfAtlas;

            GUI.enabled = !readOnly;

            if( atlas == null && colorizeIfMissing )
                GUI.color = Color.red;

            dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate( GameObject item )
            {
                var newAtlas = ( item == null ) ? null : item.GetComponent<dfAtlas>();
                dfEditorUtil.MarkUndo( view, "Change Atlas" );
                setValue( view, propertyName, newAtlas );
            };

            var value = (dfAtlas)getValue( view, propertyName );

            EditorGUILayout.BeginHorizontal();
            {

                EditorGUILayout.LabelField( label, "", GUILayout.Width( labelWidth ) );

                var displayText = value == null ? "[none]" : value.name;
                GUILayout.Label( displayText, "TextField" );

                var evt = Event.current;
                if( evt != null )
                {
                    Rect textRect = GUILayoutUtility.GetLastRect();
                    if( evt.type == EventType.mouseDown && evt.clickCount == 2 )
                    {
                        if( textRect.Contains( evt.mousePosition ) )
                        {
                            if( GUI.enabled && value != null )
                            {
                                Selection.activeObject = value;
                                EditorGUIUtility.PingObject( value );
                            }
                        }
                    }
                    else if( evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform )
                    {
                        if( textRect.Contains( evt.mousePosition ) )
                        {
                            var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                            var draggedFont = draggedObject != null ? draggedObject.GetComponent<dfAtlas>() : null;
                            DragAndDrop.visualMode = ( draggedFont != null ) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                            if( evt.type == EventType.DragPerform )
                            {
                                selectionCallback( draggedObject );
                            }
                            evt.Use();
                        }
                    }
                }

                if( GUI.enabled && GUILayout.Button( new GUIContent( " ", "Edit Atlas" ), "IN ObjectField", GUILayout.Width( 14 ) ) )
                {
                    showDialog = true;
                }

            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space( 2 );

            if( showDialog )
            {
                var dialog = dfPrefabSelectionDialog.Show( "Select Texture Atlas", typeof( dfAtlas ), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null );
                dialog.previewSize = 200;
            }

        }
        finally
        {
            GUI.enabled = true;
            GUI.color = savedColor;
        }
    }
Ejemplo n.º 18
0
    protected internal static void SelectTextureAtlas(string label, dfFont view, string propertyName, bool readOnly, bool colorizeIfMissing, int labelWidth)
    {
        var savedColor = GUI.color;
        var showDialog = false;

        try
        {
            var atlas = getValue(view, propertyName) as dfAtlas;

            GUI.enabled = !readOnly;

            if (atlas == null && colorizeIfMissing)
            {
                GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red;
            }

            dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
            {
                var newAtlas = (item == null) ? null : item.GetComponent <dfAtlas>();
                dfEditorUtil.MarkUndo(view, "Change Atlas");
                setValue(view, propertyName, newAtlas);
            };

            var value = (dfAtlas)getValue(view, propertyName);

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(label, "", GUILayout.Width(labelWidth));

                var displayText = value == null ? "[none]" : value.name;
                GUILayout.Label(displayText, "TextField");

                var evt = Event.current;
                if (evt != null)
                {
                    Rect textRect = GUILayoutUtility.GetLastRect();
                    if (evt.type == EventType.MouseDown && evt.clickCount == 2)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            if (GUI.enabled && value != null)
                            {
                                Selection.activeObject = value;
                                EditorGUIUtility.PingObject(value);
                            }
                        }
                    }
                    else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                            var draggedFont   = draggedObject != null?draggedObject.GetComponent <dfAtlas>() : null;

                            DragAndDrop.visualMode = (draggedFont != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                            if (evt.type == EventType.DragPerform)
                            {
                                selectionCallback(draggedObject);
                            }
                            evt.Use();
                        }
                    }
                }

                if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Edit Atlas"), "IN ObjectField", GUILayout.Width(14)))
                {
                    showDialog = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(2);

            if (showDialog)
            {
                var dialog = dfPrefabSelectionDialog.Show("Select Texture Atlas", typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null);
                dialog.previewSize = 200;
            }
        }
        finally
        {
            GUI.enabled = true;
            GUI.color   = savedColor;
        }
    }
    internal static void DrawFontPreview( dfFont 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 x = 0;
        var y = 0;

        var atlas = font.Atlas;
        var texture = getTexture( atlas, font.Sprite );
        if( texture == null )
            return;

        var width = 1f / (float)texture.width;
        var height = 1f / (float)texture.height;

        for( int i = 0; i < previewString.Length && y < rect.height; i++ )
        {

            var glyph = font.GetGlyph( previewString[ i ] );
            if( glyph == null )
                continue;

            if( x + glyph.xadvance > rect.width )
            {
                x = 0;
                y += font.LineHeight;
                if( y + font.LineHeight >= rect.height )
                    break;
            }

            var xofs = x + ( x > 0 ? glyph.xoffset : 0 );
            var yofs = y + glyph.yoffset;
            var glyphRect = new Rect( rect.x + xofs, rect.y + yofs, glyph.width, glyph.height );

            var uv = new Rect(
                (float)glyph.x * width,
                1f - (float)glyph.y * height - (float)glyph.height * height,
                (float)glyph.width * width,
                (float)glyph.height * height
            );

            GUI.DrawTextureWithTexCoords( glyphRect, texture, uv, true );

            x += glyph.xadvance;

        }
    }
Ejemplo n.º 20
0
 protected internal static void SelectTextureAtlas(string label, dfFont view, string propertyName, bool readOnly, bool colorizeIfMissing)
 {
     SelectTextureAtlas(label, view, propertyName, readOnly, colorizeIfMissing, 95);
 }
Ejemplo n.º 21
0
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3>    vertices  = destination.Vertices;
         dfList <int>        triangles = destination.Triangles;
         dfList <Color32>    colors    = destination.Colors;
         dfList <Vector2>    uV        = destination.UV;
         dfFont              font      = (dfFont)base.Font;
         dfAtlas.ItemInfo    item      = font.Atlas[font.sprite];
         UnityEngine.Texture texture   = font.Texture;
         float   single    = 1f / (float)texture.width;
         float   single1   = 1f / (float)texture.height;
         float   single2   = single * 0.125f;
         float   single3   = single1 * 0.125f;
         float   textScale = base.TextScale * base.PixelRatio;
         char    chr       = '\0';
         char    item1     = '\0';
         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));
         }
         int num = 0;
         while (num < token.Length)
         {
             item1 = token[num];
             if (item1 != 0)
             {
                 dfFont.GlyphDefinition glyph = font.GetGlyph(item1);
                 if (glyph != null)
                 {
                     int     kerning  = font.GetKerning(chr, item1);
                     float   single4  = position.x + (float)(glyph.xoffset + kerning) * textScale;
                     float   single5  = position.y - (float)glyph.yoffset * textScale;
                     float   single6  = (float)glyph.width * textScale;
                     float   single7  = (float)glyph.height * textScale;
                     float   single8  = single4 + single6;
                     float   single9  = single5 - single7;
                     Vector3 vector3  = new Vector3(single4, single5);
                     Vector3 vector31 = new Vector3(single8, single5);
                     Vector3 vector32 = new Vector3(single8, single9);
                     Vector3 vector33 = new Vector3(single4, single9);
                     float   single10 = item.region.x + (float)glyph.x * single - single2;
                     float   single11 = item.region.yMax - (float)glyph.y * single1 - single3;
                     float   single12 = single10 + (float)glyph.width * single - single2;
                     float   single13 = single11 - (float)glyph.height * single1 + single3;
                     if (base.Shadow)
                     {
                         dfFont.BitmappedFontRenderer.addTriangleIndices(vertices, triangles);
                         Vector3 shadowOffset = base.ShadowOffset * textScale;
                         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);
                         uV.Add(new Vector2(single10, single11));
                         uV.Add(new Vector2(single12, single11));
                         uV.Add(new Vector2(single12, single13));
                         uV.Add(new Vector2(single10, single13));
                     }
                     if (base.Outline)
                     {
                         for (int i = 0; i < (int)dfFont.BitmappedFontRenderer.OUTLINE_OFFSETS.Length; i++)
                         {
                             dfFont.BitmappedFontRenderer.addTriangleIndices(vertices, triangles);
                             Vector3 oUTLINEOFFSETS = (dfFont.BitmappedFontRenderer.OUTLINE_OFFSETS[i] * (float)base.OutlineSize) * textScale;
                             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);
                             uV.Add(new Vector2(single10, single11));
                             uV.Add(new Vector2(single12, single11));
                             uV.Add(new Vector2(single12, single13));
                             uV.Add(new Vector2(single10, single13));
                         }
                     }
                     dfFont.BitmappedFontRenderer.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);
                     uV.Add(new Vector2(single10, single11));
                     uV.Add(new Vector2(single12, single11));
                     uV.Add(new Vector2(single12, single13));
                     uV.Add(new Vector2(single10, single13));
                     position.x = position.x + (float)(glyph.xadvance + kerning + base.CharacterSpacing) * textScale;
                 }
             }
             num++;
             chr = item1;
         }
     }
     finally
     {
     }
 }
 protected internal static void EditSprite( string label, dfFont font, string propertyName )
 {
     EditSprite( label, font, propertyName, 90 );
 }
 protected internal static void SelectTextureAtlas( string label, dfFont view, string propertyName, bool readOnly, bool colorizeIfMissing )
 {
     SelectTextureAtlas( label, view, propertyName, readOnly, colorizeIfMissing, 95 );
 }
Ejemplo n.º 24
0
 private void renderText(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination)
 {
     try
     {
         dfList <Vector3> vertices     = destination.Vertices;
         dfList <int>     triangles    = destination.Triangles;
         dfList <Color32> colors       = destination.Colors;
         dfList <Vector2> uV           = destination.UV;
         dfFont           font         = (dfFont)base.Font;
         dfAtlas.ItemInfo info         = font.Atlas[font.sprite];
         Texture          texture      = font.Texture;
         float            num          = 1f / ((float)texture.width);
         float            num2         = 1f / ((float)texture.height);
         float            num3         = num * 0.125f;
         float            num4         = num2 * 0.125f;
         float            num5         = base.TextScale * base.PixelRatio;
         char             previousChar = '\0';
         char             id           = '\0';
         Color32          item         = this.applyOpacity(this.multiplyColors((Color)color, (Color)base.DefaultColor));
         Color32          color3       = item;
         if (base.BottomColor.HasValue)
         {
             color3 = this.applyOpacity(this.multiplyColors((Color)color, base.BottomColor.Value));
         }
         int num6 = 0;
         while (num6 < token.Length)
         {
             id = token[num6];
             if (id != '\0')
             {
                 dfFont.GlyphDefinition glyph = font.GetGlyph(id);
                 if (glyph != null)
                 {
                     int     kerning = font.GetKerning(previousChar, id);
                     float   x       = position.x + ((glyph.xoffset + kerning) * num5);
                     float   y       = position.y - (glyph.yoffset * num5);
                     float   num10   = glyph.width * num5;
                     float   num11   = glyph.height * num5;
                     float   num12   = x + num10;
                     float   num13   = y - num11;
                     Vector3 vector  = new Vector3(x, y);
                     Vector3 vector2 = new Vector3(num12, y);
                     Vector3 vector3 = new Vector3(num12, num13);
                     Vector3 vector4 = new Vector3(x, num13);
                     float   num14   = (info.region.x + (glyph.x * num)) - num3;
                     float   num15   = (info.region.yMax - (glyph.y * num2)) - num4;
                     float   num16   = (num14 + (glyph.width * num)) - num3;
                     float   num17   = (num15 - (glyph.height * num2)) + num4;
                     if (base.Shadow)
                     {
                         addTriangleIndices(vertices, triangles);
                         Vector3 vector5 = (Vector3)(base.ShadowOffset * num5);
                         vertices.Add(vector + vector5);
                         vertices.Add(vector2 + vector5);
                         vertices.Add(vector3 + vector5);
                         vertices.Add(vector4 + vector5);
                         Color32 color4 = this.applyOpacity(base.ShadowColor);
                         colors.Add(color4);
                         colors.Add(color4);
                         colors.Add(color4);
                         colors.Add(color4);
                         uV.Add(new Vector2(num14, num15));
                         uV.Add(new Vector2(num16, num15));
                         uV.Add(new Vector2(num16, num17));
                         uV.Add(new Vector2(num14, num17));
                     }
                     if (base.Outline)
                     {
                         for (int i = 0; i < OUTLINE_OFFSETS.Length; i++)
                         {
                             addTriangleIndices(vertices, triangles);
                             Vector3 vector6 = (Vector3)((OUTLINE_OFFSETS[i] * base.OutlineSize) * num5);
                             vertices.Add(vector + vector6);
                             vertices.Add(vector2 + vector6);
                             vertices.Add(vector3 + vector6);
                             vertices.Add(vector4 + vector6);
                             Color32 color5 = this.applyOpacity(base.OutlineColor);
                             colors.Add(color5);
                             colors.Add(color5);
                             colors.Add(color5);
                             colors.Add(color5);
                             uV.Add(new Vector2(num14, num15));
                             uV.Add(new Vector2(num16, num15));
                             uV.Add(new Vector2(num16, num17));
                             uV.Add(new Vector2(num14, num17));
                         }
                     }
                     addTriangleIndices(vertices, triangles);
                     vertices.Add(vector);
                     vertices.Add(vector2);
                     vertices.Add(vector3);
                     vertices.Add(vector4);
                     colors.Add(item);
                     colors.Add(item);
                     colors.Add(color3);
                     colors.Add(color3);
                     uV.Add(new Vector2(num14, num15));
                     uV.Add(new Vector2(num16, num15));
                     uV.Add(new Vector2(num16, num17));
                     uV.Add(new Vector2(num14, num17));
                     position.x += ((glyph.xadvance + kerning) + base.CharacterSpacing) * num5;
                 }
             }
             num6++;
             previousChar = id;
         }
     }
     finally
     {
     }
 }