Exemple #1
0
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     style = base.applyTextStyleAttributes(style);
     style.PreserveWhitespace = true;
     style.Preformatted = true;
     if (style.Align == dfMarkupTextAlign.Justify)
     {
         style.Align = dfMarkupTextAlign.Left;
     }
     dfMarkupBox _dfMarkupBox = null;
     if (style.BackgroundColor.a <= 0.1f)
     {
         _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.block, style);
     }
     else
     {
         dfMarkupBoxSprite _dfMarkupBoxSprite = new dfMarkupBoxSprite(this, dfMarkupDisplayType.block, style);
         _dfMarkupBoxSprite.LoadImage(base.Owner.Atlas, base.Owner.BlankTextureSprite);
         _dfMarkupBoxSprite.Style.Color = style.BackgroundColor;
         _dfMarkupBox = _dfMarkupBoxSprite;
     }
     dfMarkupAttribute _dfMarkupAttribute = base.findAttribute(new string[] { "margin" });
     if (_dfMarkupAttribute != null)
     {
         _dfMarkupBox.Margins = dfMarkupBorders.Parse(_dfMarkupAttribute.Value);
     }
     dfMarkupAttribute _dfMarkupAttribute1 = base.findAttribute(new string[] { "padding" });
     if (_dfMarkupAttribute1 != null)
     {
         _dfMarkupBox.Padding = dfMarkupBorders.Parse(_dfMarkupAttribute1.Value);
     }
     container.AddChild(_dfMarkupBox);
     base._PerformLayoutImpl(_dfMarkupBox, style);
     _dfMarkupBox.FitToContents(false);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     dfMarkupAttribute _dfMarkupAttribute = base.findAttribute(new string[] { "name", "face" });
     if (_dfMarkupAttribute != null)
     {
         style.Font = dfDynamicFont.FindByName(_dfMarkupAttribute.Value) ?? style.Font;
     }
     dfMarkupAttribute _dfMarkupAttribute1 = base.findAttribute(new string[] { "size", "font-size" });
     if (_dfMarkupAttribute1 != null)
     {
         style.FontSize = dfMarkupStyle.ParseSize(_dfMarkupAttribute1.Value, style.FontSize);
     }
     dfMarkupAttribute _dfMarkupAttribute2 = base.findAttribute(new string[] { "color" });
     if (_dfMarkupAttribute2 != null)
     {
         style.Color = dfMarkupStyle.ParseColor(_dfMarkupAttribute2.Value, Color.red);
         style.Color.a = style.Opacity;
     }
     dfMarkupAttribute _dfMarkupAttribute3 = base.findAttribute(new string[] { "style" });
     if (_dfMarkupAttribute3 != null)
     {
         style.FontStyle = dfMarkupStyle.ParseFontStyle(_dfMarkupAttribute3.Value, style.FontStyle);
     }
     base._PerformLayoutImpl(container, style);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     style = base.applyTextStyleAttributes(style);
     if (style.FontStyle == FontStyle.Normal)
     {
         style.FontStyle = FontStyle.Bold;
     }
     else if (style.FontStyle == FontStyle.Italic)
     {
         style.FontStyle = FontStyle.BoldAndItalic;
     }
     base._PerformLayoutImpl(container, style);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     style = base.applyTextStyleAttributes(style);
     for (int i = 0; i < base.ChildNodes.Count; i++)
     {
         dfMarkupElement item = base.ChildNodes[i];
         if (!(item is dfMarkupString) || !((item as dfMarkupString).Text == "\n"))
         {
             item.PerformLayout(container, style);
         }
         else if (style.PreserveWhitespace)
         {
             container.AddLineBreak();
         }
     }
 }
Exemple #5
0
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     if (base.Owner == null)
     {
         Debug.LogError(string.Concat("Tag has no parent: ", this));
         return;
     }
     style = this.applyStyleAttributes(style);
     dfMarkupAttribute _dfMarkupAttribute = base.findAttribute(new string[] { "src" });
     if (_dfMarkupAttribute == null)
     {
         return;
     }
     string value = _dfMarkupAttribute.Value;
     dfMarkupBox _dfMarkupBox = this.createImageBox(base.Owner.Atlas, value, style);
     if (_dfMarkupBox == null)
     {
         return;
     }
     Vector2 size = Vector2.zero;
     dfMarkupAttribute _dfMarkupAttribute1 = base.findAttribute(new string[] { "height" });
     if (_dfMarkupAttribute1 != null)
     {
         size.y = (float)dfMarkupStyle.ParseSize(_dfMarkupAttribute1.Value, (int)_dfMarkupBox.Size.y);
     }
     dfMarkupAttribute _dfMarkupAttribute2 = base.findAttribute(new string[] { "width" });
     if (_dfMarkupAttribute2 != null)
     {
         size.x = (float)dfMarkupStyle.ParseSize(_dfMarkupAttribute2.Value, (int)_dfMarkupBox.Size.x);
     }
     if (size.sqrMagnitude <= 1.401298E-45f)
     {
         size = _dfMarkupBox.Size;
     }
     else if (size.x <= 1.401298E-45f)
     {
         size.x = size.y * (_dfMarkupBox.Size.x / _dfMarkupBox.Size.y);
     }
     else if (size.y <= 1.401298E-45f)
     {
         size.y = size.x * (_dfMarkupBox.Size.y / _dfMarkupBox.Size.x);
     }
     _dfMarkupBox.Size = size;
     _dfMarkupBox.Baseline = (int)size.y;
     container.AddChild(_dfMarkupBox);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     if (base.ChildNodes.Count == 0)
     {
         return;
     }
     float size = container.Size.x;
     dfMarkupBox _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.listItem, style);
     _dfMarkupBox.Margins.top = 10;
     container.AddChild(_dfMarkupBox);
     dfMarkupTagList parent = base.Parent as dfMarkupTagList;
     if (parent == null)
     {
         base._PerformLayoutImpl(container, style);
         return;
     }
     style.VerticalAlign = dfMarkupVerticalAlign.Baseline;
     string str = "•";
     if (parent.TagName == "ol")
     {
         str = string.Concat(container.Children.Count, ".");
     }
     dfMarkupStyle _dfMarkupStyle = style;
     _dfMarkupStyle.VerticalAlign = dfMarkupVerticalAlign.Baseline;
     _dfMarkupStyle.Align = dfMarkupTextAlign.Right;
     dfMarkupBoxText bulletWidth = dfMarkupBoxText.Obtain(this, dfMarkupDisplayType.inlineBlock, _dfMarkupStyle);
     bulletWidth.SetText(str);
     bulletWidth.Width = parent.BulletWidth;
     bulletWidth.Margins.left = style.FontSize * 2;
     _dfMarkupBox.AddChild(bulletWidth);
     dfMarkupBox vector2 = new dfMarkupBox(this, dfMarkupDisplayType.inlineBlock, style);
     int fontSize = style.FontSize;
     float single = size - bulletWidth.Size.x - (float)bulletWidth.Margins.left - (float)fontSize;
     vector2.Size = new Vector2(single, (float)fontSize);
     vector2.Margins.left = (int)((float)style.FontSize * 0.5f);
     _dfMarkupBox.AddChild(vector2);
     for (int i = 0; i < base.ChildNodes.Count; i++)
     {
         base.ChildNodes[i].PerformLayout(vector2, style);
     }
     vector2.FitToContents(false);
     vector2.Parent.FitToContents(false);
     _dfMarkupBox.FitToContents(false);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     if (base.ChildNodes.Count == 0)
     {
         return;
     }
     style = base.applyTextStyleAttributes(style);
     int num = (container.Children.Count != 0 ? style.LineHeight : 0);
     dfMarkupBox _dfMarkupBox = null;
     if (style.BackgroundColor.a <= 0.005f)
     {
         _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.block, style);
     }
     else
     {
         dfMarkupBoxSprite _dfMarkupBoxSprite = new dfMarkupBoxSprite(this, dfMarkupDisplayType.block, style)
         {
             Atlas = base.Owner.Atlas,
             Source = base.Owner.BlankTextureSprite
         };
         _dfMarkupBoxSprite.Style.Color = style.BackgroundColor;
         _dfMarkupBox = _dfMarkupBoxSprite;
     }
     _dfMarkupBox.Margins = new dfMarkupBorders(0, 0, num, style.LineHeight);
     dfMarkupAttribute _dfMarkupAttribute = base.findAttribute(new string[] { "margin" });
     if (_dfMarkupAttribute != null)
     {
         _dfMarkupBox.Margins = dfMarkupBorders.Parse(_dfMarkupAttribute.Value);
     }
     dfMarkupAttribute _dfMarkupAttribute1 = base.findAttribute(new string[] { "padding" });
     if (_dfMarkupAttribute1 != null)
     {
         _dfMarkupBox.Padding = dfMarkupBorders.Parse(_dfMarkupAttribute1.Value);
     }
     container.AddChild(_dfMarkupBox);
     base._PerformLayoutImpl(_dfMarkupBox, style);
     if (_dfMarkupBox.Children.Count > 0)
     {
         _dfMarkupBox.Children[_dfMarkupBox.Children.Count - 1].IsNewline = true;
     }
     _dfMarkupBox.FitToContents(true);
 }
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     if (base.ChildNodes.Count == 0)
     {
         return;
     }
     style.Align = dfMarkupTextAlign.Left;
     dfMarkupBox _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.block, style);
     container.AddChild(_dfMarkupBox);
     this.calculateBulletWidth(style);
     for (int i = 0; i < base.ChildNodes.Count; i++)
     {
         dfMarkupTag item = base.ChildNodes[i] as dfMarkupTag;
         if (item != null && !(item.TagName != "li"))
         {
             item.PerformLayout(_dfMarkupBox, style);
         }
     }
     _dfMarkupBox.FitToContents(false);
 }
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        if (base.ChildNodes.Count == 0)
        {
            return;
        }
        style.Align = dfMarkupTextAlign.Left;
        dfMarkupBox _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.block, style);

        container.AddChild(_dfMarkupBox);
        this.calculateBulletWidth(style);
        for (int i = 0; i < base.ChildNodes.Count; i++)
        {
            dfMarkupTag item = base.ChildNodes[i] as dfMarkupTag;
            if (item != null && !(item.TagName != "li"))
            {
                item.PerformLayout(_dfMarkupBox, style);
            }
        }
        _dfMarkupBox.FitToContents(false);
    }
Exemple #10
0
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     style = base.applyTextStyleAttributes(style);
     for (int i = 0; i < base.ChildNodes.Count; i++)
     {
         dfMarkupElement element = base.ChildNodes[i];
         if (element is dfMarkupString)
         {
             dfMarkupString str = element as dfMarkupString;
             if (str.Text == "\n")
             {
                 if (style.PreserveWhitespace)
                 {
                     container.AddLineBreak();
                 }
                 continue;
             }
         }
         element.PerformLayout(container, style);
     }
 }
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        dfMarkupBorders dfMarkupBorder = new dfMarkupBorders();
        dfMarkupStyle   _dfMarkupStyle = this.applyDefaultStyles(style, ref dfMarkupBorder);

        _dfMarkupStyle = base.applyTextStyleAttributes(_dfMarkupStyle);
        dfMarkupAttribute _dfMarkupAttribute = base.findAttribute(new string[] { "margin" });

        if (_dfMarkupAttribute != null)
        {
            dfMarkupBorder = dfMarkupBorders.Parse(_dfMarkupAttribute.Value);
        }
        dfMarkupBox _dfMarkupBox = new dfMarkupBox(this, dfMarkupDisplayType.block, _dfMarkupStyle)
        {
            Margins = dfMarkupBorder
        };

        container.AddChild(_dfMarkupBox);
        base._PerformLayoutImpl(_dfMarkupBox, _dfMarkupStyle);
        _dfMarkupBox.FitToContents(false);
    }
Exemple #12
0
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        style = base.applyTextStyleAttributes(style);
        style.PreserveWhitespace = true;
        style.Preformatted       = true;
        if (style.Align == dfMarkupTextAlign.Justify)
        {
            style.Align = dfMarkupTextAlign.Left;
        }
        dfMarkupBox box = null;

        if (style.BackgroundColor.a > 0.1f)
        {
            dfMarkupBoxSprite sprite = new dfMarkupBoxSprite(this, dfMarkupDisplayType.block, style);
            sprite.LoadImage(base.Owner.Atlas, base.Owner.BlankTextureSprite);
            sprite.Style.Color = style.BackgroundColor;
            box = sprite;
        }
        else
        {
            box = new dfMarkupBox(this, dfMarkupDisplayType.block, style);
        }
        string[]          names     = new string[] { "margin" };
        dfMarkupAttribute attribute = base.findAttribute(names);

        if (attribute != null)
        {
            box.Margins = dfMarkupBorders.Parse(attribute.Value);
        }
        string[]          textArray2 = new string[] { "padding" };
        dfMarkupAttribute attribute2 = base.findAttribute(textArray2);

        if (attribute2 != null)
        {
            box.Padding = dfMarkupBorders.Parse(attribute2.Value);
        }
        container.AddChild(box);
        base._PerformLayoutImpl(box, style);
        box.FitToContents(false);
    }
Exemple #13
0
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        style = applyTextStyleAttributes(style);

        dfMarkupBox spanBox = container;

        var marginAttribute = findAttribute("margin");

        if (marginAttribute != null)
        {
            spanBox         = new dfMarkupBox(this, dfMarkupDisplayType.inlineBlock, style);
            spanBox.Margins = dfMarkupBorders.Parse(marginAttribute.Value);

            // Span does not utilize top and bottom margins
            spanBox.Margins.top    = 0;
            spanBox.Margins.bottom = 0;

            container.AddChild(spanBox);
        }

        for (int i = 0; i < ChildNodes.Count; i++)
        {
            var child = ChildNodes[i];

            if (child is dfMarkupString)
            {
                var text = child as dfMarkupString;
                if (text.Text == "\n")
                {
                    if (style.PreserveWhitespace)
                    {
                        spanBox.AddLineBreak();
                    }
                    continue;
                }
            }

            child.PerformLayout(spanBox, style);
        }
    }
Exemple #14
0
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        dfMarkupBorders margins = new dfMarkupBorders();
        dfMarkupStyle   style2  = this.applyDefaultStyles(style, ref margins);

        style2 = base.applyTextStyleAttributes(style2);
        string[]          names     = new string[] { "margin" };
        dfMarkupAttribute attribute = base.findAttribute(names);

        if (attribute != null)
        {
            margins = dfMarkupBorders.Parse(attribute.Value);
        }
        dfMarkupBox box = new dfMarkupBox(this, dfMarkupDisplayType.block, style2)
        {
            Margins = margins
        };

        container.AddChild(box);
        base._PerformLayoutImpl(box, style2);
        box.FitToContents(false);
    }
Exemple #15
0
    internal void AddLineBreak()
    {
        if (currentLine != null)
        {
            currentLine.IsNewline = true;
        }

        var lineOffsetTop = getVerticalPosition(0);

        endCurrentLine();

        var block = GetContainingBlock();

        currentLine = new dfMarkupBox(this.Element, dfMarkupDisplayType.block, this.Style)
        {
            Size     = new Vector2(block.Size.x, Style.FontSize),
            Position = new Vector2(0, lineOffsetTop),
            Parent   = this
        };

        children.Add(currentLine);
    }
Exemple #16
0
    private void processMarkup()
    {
        releaseMarkupReferences();

        this.elements = dfMarkupParser.Parse(this, this.text);

        var scaleMultiplier = getTextScaleMultiplier();

        var scaledFontSize   = Mathf.CeilToInt(this.FontSize * scaleMultiplier);
        var scaledLineHeight = Mathf.CeilToInt(this.LineHeight * scaleMultiplier);

        var style = new dfMarkupStyle()
        {
            Host               = this,
            Atlas              = this.Atlas,
            Font               = this.Font,
            FontSize           = scaledFontSize,
            FontStyle          = this.FontStyle,
            LineHeight         = scaledLineHeight,
            Color              = ApplyOpacity(this.Color),
            Opacity            = this.CalculateOpacity(),
            Align              = this.TextAlignment,
            PreserveWhitespace = this.preserveWhitespace
        };

        viewportBox = new dfMarkupBox(null, dfMarkupDisplayType.block, style)
        {
            Size = this.Size
        };

        for (int i = 0; i < elements.Count; i++)
        {
            var child = elements[i];
            if (child != null)
            {
                child.PerformLayout(viewportBox, style);
            }
        }
    }
Exemple #17
0
    private void endCurrentLine(bool removeEmpty)
    {
        if (currentLine == null)
        {
            return;
        }

        if (currentLinePos == 0)
        {
            if (removeEmpty)
            {
                children.Remove(currentLine);
            }
        }
        else
        {
            currentLine.doHorizontalAlignment();
            currentLine.doVerticalAlignment();
        }

        currentLine    = null;
        currentLinePos = 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);
    }
Exemple #19
0
    private dfIntersectionType getViewportIntersection(dfMarkupBox box)
    {
        if (box.Display == dfMarkupDisplayType.none)
        {
            return(dfIntersectionType.None);
        }
        Vector2 size    = base.Size;
        Vector2 vector2 = box.GetOffset() - this.scrollPosition;
        Vector2 vector3 = vector2 + box.Size;

        if ((vector3.x <= 0f) || (vector3.y <= 0f))
        {
            return(dfIntersectionType.None);
        }
        if ((vector2.x >= size.x) || (vector2.y >= size.y))
        {
            return(dfIntersectionType.None);
        }
        if (((vector2.x >= 0f) && (vector2.y >= 0f)) && ((vector3.x <= size.x) && (vector3.y <= size.y)))
        {
            return(dfIntersectionType.Inside);
        }
        return(dfIntersectionType.Intersecting);
    }
Exemple #20
0
    private int getVerticalPosition(int topMargin)
    {
        if (this.children.Count == 0)
        {
            return(topMargin);
        }
        int num  = 0;
        int num1 = 0;

        for (int i = 0; i < this.children.Count; i++)
        {
            dfMarkupBox item     = this.children[i];
            float       position = item.Position.y + item.Size.y + (float)item.Margins.bottom;
            if (position > (float)num)
            {
                num  = (int)position;
                num1 = i;
            }
        }
        dfMarkupBox _dfMarkupBox = this.children[num1];
        int         num2         = Mathf.Max(_dfMarkupBox.Margins.bottom, topMargin);

        return((int)(_dfMarkupBox.Position.y + _dfMarkupBox.Size.y + (float)num2));
    }
Exemple #21
0
    private int getVerticalPosition(int topMargin)
    {
        if (this.children.Count == 0)
        {
            return(topMargin);
        }
        int num  = 0;
        int num2 = 0;

        for (int i = 0; i < this.children.Count; i++)
        {
            dfMarkupBox box  = this.children[i];
            float       num4 = (box.Position.y + box.Size.y) + box.Margins.bottom;
            if (num4 > num)
            {
                num  = (int)num4;
                num2 = i;
            }
        }
        dfMarkupBox box2 = this.children[num2];
        int         num5 = Mathf.Max(box2.Margins.bottom, topMargin);

        return(((int)(box2.Position.y + box2.Size.y)) + num5);
    }
Exemple #22
0
    private void processMarkup()
    {
        this.releaseMarkupReferences();
        this.elements = dfMarkupParser.Parse(this, this.text);
        float         textScaleMultiplier = this.getTextScaleMultiplier();
        int           num            = Mathf.CeilToInt((float)this.FontSize * textScaleMultiplier);
        int           num1           = Mathf.CeilToInt((float)this.LineHeight * textScaleMultiplier);
        dfMarkupStyle _dfMarkupStyle = new dfMarkupStyle();
        dfMarkupStyle atlas          = _dfMarkupStyle;

        atlas.Host               = this;
        atlas.Atlas              = this.Atlas;
        atlas.Font               = this.Font;
        atlas.FontSize           = num;
        atlas.FontStyle          = this.FontStyle;
        atlas.LineHeight         = num1;
        atlas.Color              = base.ApplyOpacity(base.Color);
        atlas.Opacity            = base.CalculateOpacity();
        atlas.Align              = this.TextAlignment;
        atlas.PreserveWhitespace = this.preserveWhitespace;
        _dfMarkupStyle           = atlas;
        dfMarkupBox _dfMarkupBox = new dfMarkupBox(null, dfMarkupDisplayType.block, _dfMarkupStyle)
        {
            Size = base.Size
        };

        this.viewportBox = _dfMarkupBox;
        for (int i = 0; i < this.elements.Count; i++)
        {
            dfMarkupElement item = this.elements[i];
            if (item != null)
            {
                item.PerformLayout(this.viewportBox, _dfMarkupStyle);
            }
        }
    }
Exemple #23
0
    private dfIntersectionType getViewportIntersection(dfMarkupBox box)
    {
        if (box.Display == dfMarkupDisplayType.none)
        {
            return(dfIntersectionType.None);
        }
        Vector2 size    = base.Size;
        Vector2 offset  = box.GetOffset() - this.scrollPosition;
        Vector2 vector2 = offset + box.Size;

        if (vector2.x <= 0f || vector2.y <= 0f)
        {
            return(dfIntersectionType.None);
        }
        if (offset.x >= size.x || offset.y >= size.y)
        {
            return(dfIntersectionType.None);
        }
        if (offset.x >= 0f && offset.y >= 0f && vector2.x <= size.x && vector2.y <= size.y)
        {
            return(dfIntersectionType.Inside);
        }
        return(dfIntersectionType.Intersecting);
    }
Exemple #24
0
    private void gatherRenderBuffers(dfMarkupBox box, dfList <dfRenderData> buffers)
    {
        dfIntersectionType viewportIntersection = this.getViewportIntersection(box);

        if (viewportIntersection == dfIntersectionType.None)
        {
            return;
        }
        dfRenderData material = box.Render();

        if (material != null)
        {
            if (material.Material == null && this.atlas != null)
            {
                material.Material = this.atlas.Material;
            }
            float            units     = base.PixelsToUnits();
            Vector2          num       = -this.scrollPosition.Scale(1f, -1f).RoundToInt();
            Vector3          vector3   = (num + box.GetOffset().Scale(1f, -1f)) + this.pivot.TransformToUpperLeft(base.Size);
            dfList <Vector3> vertices  = material.Vertices;
            Matrix4x4        matrix4x4 = base.transform.localToWorldMatrix;
            for (int i = 0; i < material.Vertices.Count; i++)
            {
                vertices[i] = matrix4x4.MultiplyPoint((vector3 + vertices[i]) * units);
            }
            if (viewportIntersection == dfIntersectionType.Intersecting)
            {
                this.clipToViewport(material);
            }
            buffers.Add(material);
        }
        for (int j = 0; j < box.Children.Count; j++)
        {
            this.gatherRenderBuffers(box.Children[j], buffers);
        }
    }
    private void gatherRenderBuffers( dfMarkupBox box, dfList<dfRenderData> buffers )
    {
        var intersectionType = getViewportIntersection( box );
        if( intersectionType == dfIntersectionType.None )
        {
            return;
        }

        var buffer = box.Render();
        if( buffer != null )
        {

            if( buffer.Material == null )
            {
                if( this.atlas != null )
                {
                    buffer.Material = atlas.Material;
                }
            }

            var p2u = PixelsToUnits();
            var scroll = -scrollPosition.Scale( 1, -1 ).RoundToInt();
            var offset = (Vector3)( scroll + box.GetOffset().Scale( 1, -1 ) ) + pivot.TransformToUpperLeft( Size );

            var vertices = buffer.Vertices;
            for( int i = 0; i < buffer.Vertices.Count; i++ )
            {
                vertices[ i ] = ( offset + vertices[ i ] ) * p2u;
            }

            if( intersectionType == dfIntersectionType.Intersecting )
            {
                clipToViewport( buffer );
            }

            buffer.Transform = transform.localToWorldMatrix;
            buffers.Add( buffer );

        }

        for( int i = 0; i < box.Children.Count; i++ )
        {
            gatherRenderBuffers( box.Children[ i ], buffers );
        }
    }
Exemple #26
0
    private void addInline( dfMarkupBox box )
    {
        var margin = box.Margins;

        bool needsWordwrap =
            !Style.Preformatted &&
            ( currentLine != null && currentLinePos + box.Size.x > currentLine.Size.x );

        if( currentLine == null || needsWordwrap )
        {

            endCurrentLine();

            var lineOffsetTop = getVerticalPosition( margin.top );

            var block = GetContainingBlock();
            if( block == null )
            {
                Debug.LogError( "Containing block not found" );
                return;
            }

            var font = Style.Font ?? Style.Host.Font;
            var multiplier = (float)font.FontSize / (float)font.FontSize;
            var lineBaseline = font.Baseline * multiplier;

            currentLine = new dfMarkupBox( this.Element, dfMarkupDisplayType.block, this.Style )
            {
                Size = new Vector2( block.Size.x, Style.LineHeight ),
                Position = new Vector2( 0, lineOffsetTop ),
                Parent = this,
                Baseline = (int)lineBaseline
            };

            children.Add( currentLine );

        }

        // Eliminate whitespace at beginning of the line, if whitespace is not preserved
        if( currentLinePos == 0 && !box.Style.PreserveWhitespace && box is dfMarkupBoxText )
        {
            var text = box as dfMarkupBoxText;
            if( text.IsWhitespace )
            {
                return;
            }
        }

        var boxPosition = new Vector2( currentLinePos + margin.left, margin.top );
        box.Position = boxPosition;

        box.Parent = currentLine;
        currentLine.children.Add( box );

        currentLinePos = (int)( boxPosition.x + box.Size.x + box.Margins.right );

        var lineWidth = Mathf.Max( currentLine.Size.x, boxPosition.x + box.Size.x );
        var lineHeight = Mathf.Max( currentLine.Size.y, boxPosition.y + box.Size.y );

        currentLine.Size = new Vector2( lineWidth, lineHeight );
    }
Exemple #27
0
    private void addBlock( dfMarkupBox box )
    {
        if( currentLine != null )
        {
            currentLine.IsNewline = true;
            endCurrentLine( true );
        }

        var container = GetContainingBlock();

        // If a block box does not have a size specified, then by default it
        // is the width of the containing block
        if( box.Size.sqrMagnitude <= float.Epsilon )
        {
            box.Size = new Vector2( container.Size.x - box.Margins.horizontal, Style.FontSize );
        }

        var boxTop = getVerticalPosition( box.Margins.top );
        box.Position = new Vector2( box.Margins.left, boxTop );

        this.Size = new Vector2( this.Size.x, Mathf.Max( this.Size.y, box.Position.y + box.Size.y ) );

        box.Parent = this;
        children.Add( box );
    }
Exemple #28
0
    private void doHorizontalAlignment()
    {
        if (this.Style.Align == dfMarkupTextAlign.Left || this.children.Count == 0)
        {
            return;
        }
        int count = this.children.Count - 1;

        while (count > 0)
        {
            dfMarkupBoxText item = this.children[count] as dfMarkupBoxText;
            if (item == null || !item.IsWhitespace)
            {
                break;
            }
            else
            {
                count--;
            }
        }
        if (this.Style.Align == dfMarkupTextAlign.Center)
        {
            float size = 0f;
            for (int i = 0; i <= count; i++)
            {
                size = size + this.children[i].Size.x;
            }
            float single = (this.Size.x - (float)this.Padding.horizontal - size) * 0.5f;
            for (int j = 0; j <= count; j++)
            {
                Vector2 position = this.children[j].Position;
                position.x = position.x + single;
                this.children[j].Position = position;
            }
        }
        else if (this.Style.Align != dfMarkupTextAlign.Right)
        {
            if (this.Style.Align != dfMarkupTextAlign.Justify)
            {
                throw new NotImplementedException(string.Concat("text-align: ", this.Style.Align, " is not implemented"));
            }
            if (this.children.Count <= 1)
            {
                return;
            }
            if (this.IsNewline || this.children[this.children.Count - 1].IsNewline)
            {
                return;
            }
            float single1 = 0f;
            for (int k = 0; k <= count; k++)
            {
                dfMarkupBox _dfMarkupBox = this.children[k];
                single1 = Mathf.Max(single1, _dfMarkupBox.Position.x + _dfMarkupBox.Size.x);
            }
            float size1 = (this.Size.x - (float)this.Padding.horizontal - single1) / (float)this.children.Count;
            for (int l = 1; l <= count; l++)
            {
                dfMarkupBox item1 = this.children[l];
                item1.Position = item1.Position + new Vector2((float)l * size1, 0f);
            }
            dfMarkupBox _dfMarkupBox1 = this.children[count];
            Vector2     vector2       = _dfMarkupBox1.Position;
            vector2.x = this.Size.x - (float)this.Padding.horizontal - _dfMarkupBox1.Size.x;
            _dfMarkupBox1.Position = vector2;
        }
        else
        {
            float size2 = this.Size.x - (float)this.Padding.horizontal;
            for (int m = count; m >= 0; m--)
            {
                Vector2 position1 = this.children[m].Position;
                position1.x = size2 - this.children[m].Size.x;
                this.children[m].Position = position1;
                size2 = size2 - this.children[m].Size.x;
            }
        }
    }
Exemple #29
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        if( this.ChildNodes.Count == 0 )
            return;

        style.Align = dfMarkupTextAlign.Left;

        var listContainer = new dfMarkupBox( this, dfMarkupDisplayType.block, style );
        container.AddChild( listContainer );

        calculateBulletWidth( style );

        for( int i = 0; i < ChildNodes.Count; i++ )
        {

            var child = ChildNodes[ i ] as dfMarkupTag;
            if( child == null || child.TagName != "li" )
            {
                continue;
            }

            child.PerformLayout( listContainer, style );

        }

        listContainer.FitToContents();
    }
Exemple #30
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        var headingMargins = new dfMarkupBorders();

        var headingStyle = applyDefaultStyles( style, ref headingMargins );
        headingStyle = applyTextStyleAttributes( headingStyle );

        // Allow overriding of margins
        var marginAttribute = findAttribute( "margin" );
        if( marginAttribute != null )
        {
            headingMargins = dfMarkupBorders.Parse( marginAttribute.Value );
        }

        var headingBox = new dfMarkupBox( this, dfMarkupDisplayType.block, headingStyle );
        headingBox.Margins = headingMargins;

        container.AddChild( headingBox );

        base._PerformLayoutImpl( headingBox, headingStyle );
        headingBox.FitToContents();
    }
Exemple #31
0
 protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
 {
     container.AddLineBreak();
 }
Exemple #32
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        // Only happens while user is in the process of typing an unfinished tag
        if( this.IsEndTag )
        {
            return;
        }

        var marginAttribute = findAttribute( "margin" );
        if( marginAttribute != null )
        {
        }

        for( int i = 0; i < ChildNodes.Count; i++ )
        {
            ChildNodes[ i ].PerformLayout( container, style );
        }
    }
 protected abstract void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style);
 protected abstract void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style );
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        if( style.Font == null )
            return;

        var effectiveText = style.PreserveWhitespace || !isWhitespace ? this.Text : " ";

        var box = dfMarkupBoxText.Obtain( this, dfMarkupDisplayType.inline, style );
        box.SetText( effectiveText );

        container.AddChild( box );
    }
    private dfIntersectionType getViewportIntersection( dfMarkupBox box )
    {
        if( box.Display == dfMarkupDisplayType.none )
            return dfIntersectionType.None;

        var viewSize = this.Size;
        var min = box.GetOffset() - scrollPosition;
        var max = min + box.Size;

        if( max.x <= 0 || max.y <= 0 )
            return dfIntersectionType.None;

        if( min.x >= viewSize.x || min.y >= viewSize.y )
            return dfIntersectionType.None;

        if( min.x < 0 || min.y < 0 || max.x > viewSize.x || max.y > viewSize.y )
            return dfIntersectionType.Intersecting;

        return dfIntersectionType.Inside;
    }
Exemple #37
0
    private void doVerticalAlignment()
    {
        if (this.children.Count == 0)
        {
            return;
        }
        float single  = Single.MinValue;
        float single1 = Single.MaxValue;
        float single2 = Single.MinValue;

        this.Baseline = (int)(this.Size.y * 0.95f);
        for (int i = 0; i < this.children.Count; i++)
        {
            dfMarkupBox item = this.children[i];
            single2 = Mathf.Max(single2, item.Position.y + (float)item.Baseline);
        }
        for (int j = 0; j < this.children.Count; j++)
        {
            dfMarkupBox           _dfMarkupBox  = this.children[j];
            dfMarkupVerticalAlign verticalAlign = _dfMarkupBox.Style.VerticalAlign;
            Vector2 position = _dfMarkupBox.Position;
            if (verticalAlign == dfMarkupVerticalAlign.Baseline)
            {
                position.y = single2 - (float)_dfMarkupBox.Baseline;
            }
            _dfMarkupBox.Position = position;
        }
        for (int k = 0; k < this.children.Count; k++)
        {
            dfMarkupBox item1   = this.children[k];
            Vector2     vector2 = item1.Position;
            Vector2     size    = item1.Size;
            single1 = Mathf.Min(single1, vector2.y);
            single  = Mathf.Max(single, vector2.y + size.y);
        }
        for (int l = 0; l < this.children.Count; l++)
        {
            dfMarkupBox           _dfMarkupBox1          = this.children[l];
            dfMarkupVerticalAlign _dfMarkupVerticalAlign = _dfMarkupBox1.Style.VerticalAlign;
            Vector2 position1 = _dfMarkupBox1.Position;
            Vector2 size1     = _dfMarkupBox1.Size;
            if (_dfMarkupVerticalAlign == dfMarkupVerticalAlign.Top)
            {
                position1.y = single1;
            }
            else if (_dfMarkupVerticalAlign == dfMarkupVerticalAlign.Bottom)
            {
                position1.y = single - size1.y;
            }
            else if (_dfMarkupVerticalAlign == dfMarkupVerticalAlign.Middle)
            {
                position1.y = (this.Size.y - size1.y) * 0.5f;
            }
            _dfMarkupBox1.Position = position1;
        }
        int num = 2147483647;

        for (int m = 0; m < this.children.Count; m++)
        {
            num = Mathf.Min(num, (int)this.children[m].Position.y);
        }
        for (int n = 0; n < this.children.Count; n++)
        {
            Vector2 vector21 = this.children[n].Position;
            vector21.y = vector21.y - (float)num;
            this.children[n].Position = vector21;
        }
    }
    private void processMarkup()
    {
        releaseMarkupReferences();

        this.elements = dfMarkupParser.Parse( this, this.text );

        var scaleMultiplier = getTextScaleMultiplier();

        var scaledFontSize = Mathf.CeilToInt( this.FontSize * scaleMultiplier );
        var scaledLineHeight = Mathf.CeilToInt( this.LineHeight * scaleMultiplier );

        var style = new dfMarkupStyle()
        {
            Host = this,
            Atlas = this.Atlas,
            Font = this.Font,
            FontSize = scaledFontSize,
            FontStyle = this.FontStyle,
            LineHeight = scaledLineHeight,
            Color = ApplyOpacity( this.Color ),
            Opacity = this.CalculateOpacity(),
            Align = this.TextAlignment,
            PreserveWhitespace = this.preserveWhitespace
        };

        viewportBox = new dfMarkupBox( null, dfMarkupDisplayType.block, style )
        {
            Size = this.Size
        };

        //@Profiler.BeginSample( "Perform layout on markup" );
        for( int i = 0; i < elements.Count; i++ )
        {
            var child = elements[ i ];
            if( child != null )
            {
                child.PerformLayout( viewportBox, style );
            }
        }
        Profiler.EndSample();
    }
Exemple #39
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        if( this.ChildNodes.Count == 0 )
            return;

        style = applyTextStyleAttributes( style );

        var topMargin = container.Children.Count == 0 ? 0 : style.LineHeight;

        dfMarkupBox paragraphBox = null;

        if( style.BackgroundColor.a > 0.005f )
        {

            var spriteBox = new dfMarkupBoxSprite( this, dfMarkupDisplayType.block, style );
            spriteBox.Atlas = this.Owner.Atlas;
            spriteBox.Source = this.Owner.BlankTextureSprite;
            spriteBox.Style.Color = style.BackgroundColor;

            paragraphBox = spriteBox;

        }
        else
        {
            paragraphBox = new dfMarkupBox( this, dfMarkupDisplayType.block, style );
        }

        paragraphBox.Margins = new dfMarkupBorders( 0, 0, topMargin, style.LineHeight );

        #region Allow overriding of margins and padding

        var marginAttribute = findAttribute( "margin" );
        if( marginAttribute != null )
        {
            paragraphBox.Margins = dfMarkupBorders.Parse( marginAttribute.Value );
        }

        var paddingAttribute = findAttribute( "padding" );
        if( paddingAttribute != null )
        {
            paragraphBox.Padding = dfMarkupBorders.Parse( paddingAttribute.Value );
        }

        #endregion

        container.AddChild( paragraphBox );

        base._PerformLayoutImpl( paragraphBox, style );

        if( paragraphBox.Children.Count > 0 )
        {
            paragraphBox.Children[ paragraphBox.Children.Count - 1 ].IsNewline = true;
        }

        paragraphBox.FitToContents( true );
    }
 public void PerformLayout( dfMarkupBox container, dfMarkupStyle style )
 {
     Profiler.BeginSample( "Perform markup layout: " + this.GetType().Name );
     _PerformLayoutImpl( container, style );
     Profiler.EndSample();
 }
Exemple #41
0
 protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
 {
     container.AddLineBreak();
 }
 public void PerformLayout(dfMarkupBox container, dfMarkupStyle style)
 {
     //@Profiler.BeginSample( "Perform markup layout: " + this.GetType().Name );
     _PerformLayoutImpl(container, style);
     //@Profiler.EndSample();
 }
Exemple #43
0
    private void doVerticalAlignment()
    {
        if (this.children.Count != 0)
        {
            float minValue = float.MinValue;
            float maxValue = float.MaxValue;
            float a        = float.MinValue;
            this.Baseline = (int)(this.Size.y * 0.95f);
            for (int i = 0; i < this.children.Count; i++)
            {
                dfMarkupBox box = this.children[i];
                a = Mathf.Max(a, box.Position.y + box.Baseline);
            }
            for (int j = 0; j < this.children.Count; j++)
            {
                dfMarkupBox           box2          = this.children[j];
                dfMarkupVerticalAlign verticalAlign = box2.Style.VerticalAlign;
                Vector2 position = box2.Position;
                if (verticalAlign == dfMarkupVerticalAlign.Baseline)
                {
                    position.y = a - box2.Baseline;
                }
                box2.Position = position;
            }
            for (int k = 0; k < this.children.Count; k++)
            {
                dfMarkupBox box3    = this.children[k];
                Vector2     vector2 = box3.Position;
                Vector2     size    = box3.Size;
                maxValue = Mathf.Min(maxValue, vector2.y);
                minValue = Mathf.Max(minValue, vector2.y + size.y);
            }
            for (int m = 0; m < this.children.Count; m++)
            {
                dfMarkupBox           box4   = this.children[m];
                dfMarkupVerticalAlign align2 = box4.Style.VerticalAlign;
                Vector2 vector4 = box4.Position;
                Vector2 vector5 = box4.Size;
                switch (align2)
                {
                case dfMarkupVerticalAlign.Top:
                    vector4.y = maxValue;
                    break;

                case dfMarkupVerticalAlign.Bottom:
                    vector4.y = minValue - vector5.y;
                    break;

                case dfMarkupVerticalAlign.Middle:
                    vector4.y = (this.Size.y - vector5.y) * 0.5f;
                    break;
                }
                box4.Position = vector4;
            }
            int num8 = 0x7fffffff;
            for (int n = 0; n < this.children.Count; n++)
            {
                num8 = Mathf.Min(num8, (int)this.children[n].Position.y);
            }
            for (int num10 = 0; num10 < this.children.Count; num10++)
            {
                Vector2 vector6 = this.children[num10].Position;
                vector6.y -= num8;
                this.children[num10].Position = vector6;
            }
        }
    }
Exemple #44
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        style = applyTextStyleAttributes( style );

        dfMarkupBox spanBox = container;

        var marginAttribute = findAttribute( "margin" );
        if( marginAttribute != null )
        {

            spanBox = new dfMarkupBox( this, dfMarkupDisplayType.inlineBlock, style );
            spanBox.Margins = dfMarkupBorders.Parse( marginAttribute.Value );

            // Span does not utilize top and bottom margins
            spanBox.Margins.top = 0;
            spanBox.Margins.bottom = 0;

            container.AddChild( spanBox );

        }

        for( int i = 0; i < ChildNodes.Count; i++ )
        {

            var child = ChildNodes[i];

            if( child is dfMarkupString )
            {

                var text = child as dfMarkupString;
                if( text.Text == "\n" )
                {
                    if( style.PreserveWhitespace )
                    {
                        spanBox.AddLineBreak();
                    }
                    continue;
                }

            }

            child.PerformLayout( spanBox, style );

        }
    }
Exemple #45
0
 public void PerformLayout(dfMarkupBox container, dfMarkupStyle style)
 {
     this._PerformLayoutImpl(container, style);
 }
Exemple #46
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        style.TextDecoration = dfMarkupTextDecoration.Underline;
        style = applyTextStyleAttributes( style );

        for( int i = 0; i < ChildNodes.Count; i++ )
        {

            var child = ChildNodes[ i ];

            if( child is dfMarkupString )
            {

                var text = child as dfMarkupString;
                if( text.Text == "\n" )
                {
                    if( style.PreserveWhitespace )
                    {
                        container.AddLineBreak();
                    }
                    continue;
                }

            }

            child.PerformLayout( container, style );

        }
    }
Exemple #47
0
    protected override void _PerformLayoutImpl(dfMarkupBox container, dfMarkupStyle style)
    {
        if (this.ChildNodes.Count == 0)
        {
            return;
        }

        var containerWidth = container.Size.x;

        var listItemContainer = new dfMarkupBox(this, dfMarkupDisplayType.listItem, style);

        listItemContainer.Margins.top = 10;
        container.AddChild(listItemContainer);

        var list = this.Parent as dfMarkupTagList;

        if (list == null)
        {
            // If the list item is not contained in a list, process its
            // child elements as normal html elements
            base._PerformLayoutImpl(container, style);
            return;
        }

        style.VerticalAlign = dfMarkupVerticalAlign.Baseline;

        var bulletText = "•";

        if (list.TagName == "ol")
        {
            bulletText = container.Children.Count + ".";
        }

        var bulletBoxStyle = style;

        bulletBoxStyle.VerticalAlign = dfMarkupVerticalAlign.Baseline;
        bulletBoxStyle.Align         = dfMarkupTextAlign.Right;

        // TODO: Pre-measure bullet item size (for ordered lists) at the <UL> tag level
        var listBulletElement = dfMarkupBoxText.Obtain(this, dfMarkupDisplayType.inlineBlock, bulletBoxStyle);

        listBulletElement.SetText(bulletText);
        listBulletElement.Width        = list.BulletWidth;
        listBulletElement.Margins.left = style.FontSize * 2;
        listItemContainer.AddChild(listBulletElement);

        var listItemBox        = new dfMarkupBox(this, dfMarkupDisplayType.inlineBlock, style);
        var listItemLeftMargin = style.FontSize;
        var listItemWidth      = containerWidth - listBulletElement.Size.x - listBulletElement.Margins.left - listItemLeftMargin;

        listItemBox.Size         = new Vector2(listItemWidth, listItemLeftMargin);
        listItemBox.Margins.left = (int)(style.FontSize * 0.5f);
        listItemContainer.AddChild(listItemBox);

        for (int i = 0; i < ChildNodes.Count; i++)
        {
            ChildNodes[i].PerformLayout(listItemBox, style);
        }

        listItemBox.FitToContents();

        // The listItemBox.Parent property will actually refer to an internal
        // linebox that hosts the listItemBox, which needs to be fit to the
        // contents of the list item box.
        if (listItemBox.Parent != null)
        {
            listItemBox.Parent.FitToContents();
        }

        listItemContainer.FitToContents();
    }
Exemple #48
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        var fontAttribute = findAttribute( "name", "face" );
        if( fontAttribute != null )
        {
            style.Font = dfDynamicFont.FindByName( fontAttribute.Value ) ?? style.Font;
        }

        var fontSizeAttribute = findAttribute( "size", "font-size" );
        if( fontSizeAttribute != null )
        {
            style.FontSize = dfMarkupStyle.ParseSize( fontSizeAttribute.Value, style.FontSize );
        }

        var fontColorAttribute = findAttribute( "color" );
        if( fontColorAttribute != null )
        {
            style.Color = dfMarkupStyle.ParseColor( fontColorAttribute.Value, Color.red );
            style.Color.a = style.Opacity;
        }

        var fontStyleAttribute = findAttribute( "style" );
        if( fontStyleAttribute != null )
        {
            style.FontStyle = dfMarkupStyle.ParseFontStyle( fontStyleAttribute.Value, style.FontStyle );
        }

        base._PerformLayoutImpl( container, style );
    }
Exemple #49
0
    public virtual void AddChild( dfMarkupBox box )
    {
        var display = box.Display;
        var needsBlockLayout =
            display == dfMarkupDisplayType.block ||
            display == dfMarkupDisplayType.table ||
            display == dfMarkupDisplayType.listItem ||
            display == dfMarkupDisplayType.tableRow;

        if( needsBlockLayout )
            addBlock( box );
        else
            addInline( box );
    }
Exemple #50
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        if( Owner == null )
        {
            Debug.LogError( "Tag has no parent: " + this );
            return;
        }

        style = applyStyleAttributes( style );

        var sourceAttribute = findAttribute( "src" );
        if( sourceAttribute == null )
            return;

        var source = sourceAttribute.Value;

        var imageBox = createImageBox( Owner.Atlas, source, style );
        if( imageBox == null )
            return;

        var size = Vector2.zero;

        var heightAttribute = findAttribute( "height" );
        if( heightAttribute != null )
        {
            size.y = dfMarkupStyle.ParseSize( heightAttribute.Value, (int)imageBox.Size.y );
        }

        var widthAttribute = findAttribute( "width" );
        if( widthAttribute != null )
        {
            size.x = dfMarkupStyle.ParseSize( widthAttribute.Value, (int)imageBox.Size.x );
        }

        if( size.sqrMagnitude <= float.Epsilon )
        {
            size = imageBox.Size;
        }
        else if( size.x <= float.Epsilon )
        {
            size.x = size.y * ( imageBox.Size.x / imageBox.Size.y );
        }
        else if( size.y <= float.Epsilon )
        {
            size.y = size.x * ( imageBox.Size.y / imageBox.Size.x );
        }

        imageBox.Size = size;
        imageBox.Baseline = (int)size.y;

        container.AddChild( imageBox );
    }
Exemple #51
0
    internal void AddLineBreak()
    {
        if( currentLine != null )
        {
            currentLine.IsNewline = true;
        }

        var lineOffsetTop = getVerticalPosition( 0 );
        endCurrentLine();

        var block = GetContainingBlock();

        currentLine = new dfMarkupBox( this.Element, dfMarkupDisplayType.block, this.Style )
        {
            Size = new Vector2( block.Size.x, Style.FontSize ),
            Position = new Vector2( 0, lineOffsetTop ),
            Parent = this
        };

        children.Add( currentLine );
    }
Exemple #52
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        if( this.ChildNodes.Count == 0 )
            return;

        var containerWidth = container.Size.x;

        var listItemContainer = new dfMarkupBox( this, dfMarkupDisplayType.listItem, style );
        listItemContainer.Margins.top = 10;
        container.AddChild( listItemContainer );

        var list = this.Parent as dfMarkupTagList;
        if( list == null )
        {
            // If the list item is not contained in a list, process its
            // child elements as normal html elements
            base._PerformLayoutImpl( container, style );
            return;
        }

        style.VerticalAlign = dfMarkupVerticalAlign.Baseline;

        var bulletText = "•";
        if( list.TagName == "ol" )
        {
            bulletText = container.Children.Count + ".";
        }

        var bulletBoxStyle = style;
        bulletBoxStyle.VerticalAlign = dfMarkupVerticalAlign.Baseline;
        bulletBoxStyle.Align = dfMarkupTextAlign.Right;

        // TODO: Pre-measure bullet item size (for ordered lists) at the <UL> tag level
        var listBulletElement = dfMarkupBoxText.Obtain( this, dfMarkupDisplayType.inlineBlock, bulletBoxStyle );
        listBulletElement.SetText( bulletText );
        listBulletElement.Width = list.BulletWidth;
        listBulletElement.Margins.left = style.FontSize * 2;
        listItemContainer.AddChild( listBulletElement );

        var listItemBox = new dfMarkupBox( this, dfMarkupDisplayType.inlineBlock, style );
        var listItemLeftMargin = style.FontSize;
        var listItemWidth = containerWidth - listBulletElement.Size.x - listBulletElement.Margins.left - listItemLeftMargin;
        listItemBox.Size = new Vector2( listItemWidth, listItemLeftMargin );
        listItemBox.Margins.left = (int)( style.FontSize * 0.5f );
        listItemContainer.AddChild( listItemBox );

        for( int i = 0; i < ChildNodes.Count; i++ )
        {
            ChildNodes[ i ].PerformLayout( listItemBox, style );
        }

        listItemBox.FitToContents();

        // The listItemBox.Parent property will actually refer to an internal
        // linebox that hosts the listItemBox, which needs to be fit to the
        // contents of the list item box.
        if( listItemBox.Parent != null )
        {
            listItemBox.Parent.FitToContents();
        }

        listItemContainer.FitToContents();
    }
Exemple #53
0
 public void PerformLayout(dfMarkupBox container, dfMarkupStyle style)
 {
     this._PerformLayoutImpl(container, style);
 }
Exemple #54
0
    protected override void _PerformLayoutImpl( dfMarkupBox container, dfMarkupStyle style )
    {
        style = applyTextStyleAttributes( style );

        style.PreserveWhitespace = true;
        style.Preformatted = true;

        if( style.Align == dfMarkupTextAlign.Justify )
        {
            style.Align = dfMarkupTextAlign.Left;
        }

        dfMarkupBox paragraphBox = null;

        if( style.BackgroundColor.a > 0.1f )
        {

            var spriteBox = new dfMarkupBoxSprite( this, dfMarkupDisplayType.block, style );
            spriteBox.LoadImage( this.Owner.Atlas, this.Owner.BlankTextureSprite );
            spriteBox.Style.Color = style.BackgroundColor;

            paragraphBox = spriteBox;

        }
        else
        {
            paragraphBox = new dfMarkupBox( this, dfMarkupDisplayType.block, style );
        }

        #region Allow overriding of margins and padding

        var marginAttribute = findAttribute( "margin" );
        if( marginAttribute != null )
        {
            paragraphBox.Margins = dfMarkupBorders.Parse( marginAttribute.Value );
        }

        var paddingAttribute = findAttribute( "padding" );
        if( paddingAttribute != null )
        {
            paragraphBox.Padding = dfMarkupBorders.Parse( paddingAttribute.Value );
        }

        #endregion

        container.AddChild( paragraphBox );

        base._PerformLayoutImpl( paragraphBox, style );

        paragraphBox.FitToContents();
    }
Exemple #55
0
 private void doHorizontalAlignment()
 {
     if ((this.Style.Align != dfMarkupTextAlign.Left) && (this.children.Count != 0))
     {
         int num = this.children.Count - 1;
         while (num > 0)
         {
             dfMarkupBoxText text = this.children[num] as dfMarkupBoxText;
             if ((text == null) || !text.IsWhitespace)
             {
                 break;
             }
             num--;
         }
         if (this.Style.Align == dfMarkupTextAlign.Center)
         {
             float num2 = 0f;
             for (int i = 0; i <= num; i++)
             {
                 num2 += this.children[i].Size.x;
             }
             float num4 = ((this.Size.x - this.Padding.horizontal) - num2) * 0.5f;
             for (int j = 0; j <= num; j++)
             {
                 Vector2 position = this.children[j].Position;
                 position.x += num4;
                 this.children[j].Position = position;
             }
         }
         else if (this.Style.Align == dfMarkupTextAlign.Right)
         {
             float num6 = this.Size.x - this.Padding.horizontal;
             for (int k = num; k >= 0; k--)
             {
                 Vector2 vector2 = this.children[k].Position;
                 vector2.x = num6 - this.children[k].Size.x;
                 this.children[k].Position = vector2;
                 num6 -= this.children[k].Size.x;
             }
         }
         else
         {
             if (this.Style.Align != dfMarkupTextAlign.Justify)
             {
                 throw new NotImplementedException("text-align: " + this.Style.Align + " is not implemented");
             }
             if ((this.children.Count > 1) && (!this.IsNewline && !this.children[this.children.Count - 1].IsNewline))
             {
                 float a = 0f;
                 for (int m = 0; m <= num; m++)
                 {
                     dfMarkupBox box = this.children[m];
                     a = Mathf.Max(a, box.Position.x + box.Size.x);
                 }
                 float num10 = ((this.Size.x - this.Padding.horizontal) - a) / ((float)this.children.Count);
                 for (int n = 1; n <= num; n++)
                 {
                     dfMarkupBox local1 = this.children[n];
                     local1.Position += new Vector2(n * num10, 0f);
                 }
                 dfMarkupBox box2    = this.children[num];
                 Vector2     vector3 = box2.Position;
                 vector3.x     = (this.Size.x - this.Padding.horizontal) - box2.Size.x;
                 box2.Position = vector3;
             }
         }
     }
 }