Exemplo n.º 1
0
    private void rebuildUV(dfRenderData renderData)
    {
        dfList <Vector2> uV = renderData.UV;

        uV.Add(new Vector2(0f, 1f));
        uV.Add(new Vector2(1f, 1f));
        uV.Add(new Vector2(1f, 0f));
        uV.Add(new Vector2(0f, 0f));
        Vector2 zero = Vector2.zero;

        if (this.flip.IsSet(dfSpriteFlip.FlipHorizontal))
        {
            zero  = uV[1];
            uV[1] = uV[0];
            uV[0] = zero;
            zero  = uV[3];
            uV[3] = uV[2];
            uV[2] = zero;
        }
        if (this.flip.IsSet(dfSpriteFlip.FlipVertical))
        {
            zero  = uV[0];
            uV[0] = uV[3];
            uV[3] = zero;
            zero  = uV[1];
            uV[1] = uV[2];
            uV[2] = zero;
        }
    }
Exemplo n.º 2
0
    private static void rebuildUV(dfRenderData renderData, RenderOptions options)
    {
        Rect             region = options.spriteInfo.region;
        dfList <Vector2> uV     = renderData.UV;

        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));
        Vector2 zero = Vector2.zero;

        if (options.flip.IsSet(dfSpriteFlip.FlipHorizontal))
        {
            zero  = uV[1];
            uV[1] = uV[0];
            uV[0] = zero;
            zero  = uV[3];
            uV[3] = uV[2];
            uV[2] = zero;
        }
        if (options.flip.IsSet(dfSpriteFlip.FlipVertical))
        {
            zero  = uV[0];
            uV[0] = uV[3];
            uV[3] = zero;
            zero  = uV[1];
            uV[1] = uV[2];
            uV[2] = zero;
        }
    }
Exemplo n.º 3
0
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            num2      = ((float)fontSize) / ((float)font.FontSize);
        float            num3      = font.Descent * num2;
        float            num4      = 0f;

        CharacterInfo[] infoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo info = infoArray[i];
            addTriangleIndices(vertices, triangles);
            float   num6    = ((font.FontSize + info.vert.y) - fontSize) + num3;
            float   x       = num4 + info.vert.x;
            float   y       = num6;
            float   num9    = x + info.vert.width;
            float   num10   = y + info.vert.height;
            Vector3 item    = new Vector3(x, y);
            Vector3 vector2 = new Vector3(num9, y);
            Vector3 vector3 = new Vector3(num9, num10);
            Vector3 vector4 = new Vector3(x, num10);
            vertices.Add(item);
            vertices.Add(vector2);
            vertices.Add(vector3);
            vertices.Add(vector4);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  uv    = info.uv;
            float num11 = uv.x;
            float num12 = uv.y + uv.height;
            float num13 = num11 + uv.width;
            float num14 = uv.y;
            if (info.flipped)
            {
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num11, num14));
            }
            else
            {
                uV.Add(new Vector2(num11, num12));
                uV.Add(new Vector2(num13, num12));
                uV.Add(new Vector2(num13, num14));
                uV.Add(new Vector2(num11, num14));
            }
            num4 += Mathf.CeilToInt(info.vert.x + info.vert.width);
        }
    }
Exemplo n.º 4
0
    private void renderText(string text)
    {
        dfDynamicFont    font      = this.Style.Font;
        int              fontSize  = this.Style.FontSize;
        FontStyle        fontStyle = this.Style.FontStyle;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        float            single    = (float)fontSize / (float)font.FontSize;
        float            descent   = (float)font.Descent * single;
        float            num       = 0f;

        CharacterInfo[] characterInfoArray = font.RequestCharacters(text, fontSize, fontStyle);
        this.renderData.Material = font.Material;
        for (int i = 0; i < text.Length; i++)
        {
            CharacterInfo characterInfo = characterInfoArray[i];
            dfMarkupBoxText.addTriangleIndices(vertices, triangles);
            float   fontSize1 = (float)font.FontSize + characterInfo.vert.y - (float)fontSize + descent;
            float   single1   = num + characterInfo.vert.x;
            float   single2   = fontSize1;
            float   single3   = single1 + characterInfo.vert.width;
            float   single4   = single2 + characterInfo.vert.height;
            Vector3 vector3   = new Vector3(single1, single2);
            Vector3 vector31  = new Vector3(single3, single2);
            Vector3 vector32  = new Vector3(single3, single4);
            Vector3 vector33  = new Vector3(single1, single4);
            vertices.Add(vector3);
            vertices.Add(vector31);
            vertices.Add(vector32);
            vertices.Add(vector33);
            Color color = this.Style.Color;
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            colors.Add(color);
            Rect  rect    = characterInfo.uv;
            float single5 = rect.x;
            float single6 = rect.y + rect.height;
            float single7 = single5 + rect.width;
            float single8 = rect.y;
            if (!characterInfo.flipped)
            {
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single5, single8));
            }
            else
            {
                uV.Add(new Vector2(single7, single8));
                uV.Add(new Vector2(single7, single6));
                uV.Add(new Vector2(single5, single6));
                uV.Add(new Vector2(single5, single8));
            }
            num = num + (float)Mathf.CeilToInt(characterInfo.vert.x + characterInfo.vert.width);
        }
    }
Exemplo n.º 5
0
    private static void rebuildColors(dfRenderData renderData, RenderOptions options)
    {
        dfList <Color32> colors = renderData.Colors;

        colors.Add(options.color);
        colors.Add(options.color);
        colors.Add(options.color);
        colors.Add(options.color);
    }
    public dfList <dfRenderData> RenderMultiple()
    {
        if (renderData == null)
        {
            renderData           = dfRenderData.Obtain();
            textRenderData       = dfRenderData.Obtain();
            isControlInvalidated = true;
        }

        var matrix = transform.localToWorldMatrix;

        if (!isControlInvalidated)
        {
            for (int i = 0; i < buffers.Count; i++)
            {
                buffers[i].Transform = matrix;
            }

            return(buffers);
        }

        isControlInvalidated = false;

        buffers.Clear();
        renderData.Clear();

        if (Atlas != null)
        {
            renderData.Material  = Atlas.Material;
            renderData.Transform = matrix;

            renderBackground();
            buffers.Add(renderData);
        }

        var textBuffer = renderText();

        if (textBuffer != null && textBuffer != renderData)
        {
            textBuffer.Transform = matrix;
            buffers.Add(textBuffer);
        }

        // Make sure that the collider size always matches the control
        updateCollider();

        return(buffers);
    }
Exemplo n.º 7
0
        public void Release()
        {
            startOffset = endOffset = 0;
            lineWidth   = lineHeight = 0;

            pool.Add(this);
        }
Exemplo n.º 8
0
 private void addQuadTriangles(dfList <int> triangles, int baseIndex)
 {
     for (int i = 0; i < quadTriangles.Length; i++)
     {
         triangles.Add(quadTriangles[i] + baseIndex);
     }
 }
Exemplo n.º 9
0
    public void Merge(dfRenderData buffer, bool transformVertices = true)
    {
        int count = this.Vertices.Count;

        this.Vertices.EnsureCapacity(this.Vertices.Count + buffer.Vertices.Count);
        if (!transformVertices)
        {
            this.Vertices.AddRange(buffer.Vertices);
        }
        else
        {
            for (int i = 0; i < buffer.Vertices.Count; i++)
            {
                dfList <Vector3> vertices  = this.Vertices;
                Matrix4x4        transform = buffer.Transform;
                vertices.Add(transform.MultiplyPoint(buffer.Vertices[i]));
            }
        }
        this.UV.AddRange(buffer.UV);
        this.Colors.AddRange(buffer.Colors);
        this.Normals.AddRange(buffer.Normals);
        this.Tangents.AddRange(buffer.Tangents);
        this.Triangles.EnsureCapacity(this.Triangles.Count + buffer.Triangles.Count);
        for (int j = 0; j < buffer.Triangles.Count; j++)
        {
            this.Triangles.Add(buffer.Triangles[j] + count);
        }
    }
Exemplo n.º 10
0
    private void gatherRenderBuffers(dfMarkupBox box, dfList <dfRenderData> buffers)
    {
        dfIntersectionType type = this.getViewportIntersection(box);

        if (type != dfIntersectionType.None)
        {
            dfRenderData renderData = box.Render();
            if (renderData != null)
            {
                if ((renderData.Material == null) && (this.atlas != null))
                {
                    renderData.Material = this.atlas.Material;
                }
                float            num                = base.PixelsToUnits();
                Vector2          vector             = -this.scrollPosition.Scale(1f, -1f).RoundToInt();
                Vector3          vector2            = ((Vector3)(vector + box.GetOffset().Scale(1f, -1f))) + base.pivot.TransformToUpperLeft(base.Size);
                dfList <Vector3> vertices           = renderData.Vertices;
                Matrix4x4        localToWorldMatrix = base.transform.localToWorldMatrix;
                for (int j = 0; j < renderData.Vertices.Count; j++)
                {
                    vertices[j] = localToWorldMatrix.MultiplyPoint((Vector3)((vector2 + vertices[j]) * num));
                }
                if (type == dfIntersectionType.Intersecting)
                {
                    this.clipToViewport(renderData);
                }
                buffers.Add(renderData);
            }
            for (int i = 0; i < box.Children.Count; i++)
            {
                this.gatherRenderBuffers(box.Children[i], buffers);
            }
        }
    }
Exemplo n.º 11
0
        public void Release()
        {
            Characters = null;
            FontSize   = 0;
            FontStyle  = UnityEngine.FontStyle.Normal;

            pool.Add(this);
        }
Exemplo n.º 12
0
    private void renderCursor(int startIndex, int cursorIndex, float[] charWidths, float leftOffset)
    {
        if (string.IsNullOrEmpty(this.SelectionSprite) || base.Atlas == null)
        {
            return;
        }
        float single = 0f;

        for (int i = startIndex; i < cursorIndex; i++)
        {
            single = single + charWidths[i];
        }
        float            units     = base.PixelsToUnits();
        float            single1   = (single + leftOffset + (float)this.padding.left * units).Quantize(units);
        float            single2   = (float)(-this.padding.top) * units;
        float            single3   = units * (float)this.cursorWidth;
        float            single4   = (this.size.y - (float)this.padding.vertical) * units;
        Vector3          vector3   = new Vector3(single1, single2);
        Vector3          vector31  = new Vector3(single1 + single3, single2);
        Vector3          vector32  = new Vector3(single1 + single3, single2 - single4);
        Vector3          vector33  = new Vector3(single1, single2 - single4);
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <int>     triangles = this.renderData.Triangles;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        Vector3          upperLeft = this.pivot.TransformToUpperLeft(this.size) * units;

        this.addQuadIndices(vertices, triangles);
        vertices.Add(vector3 + upperLeft);
        vertices.Add(vector31 + upperLeft);
        vertices.Add(vector32 + upperLeft);
        vertices.Add(vector33 + upperLeft);
        Color32 color32 = base.ApplyOpacity(this.TextColor);

        colors.Add(color32);
        colors.Add(color32);
        colors.Add(color32);
        colors.Add(color32);
        Rect item = base.Atlas[this.SelectionSprite].region;

        uV.Add(new Vector2(item.x, item.yMax));
        uV.Add(new Vector2(item.xMax, item.yMax));
        uV.Add(new Vector2(item.xMax, item.y));
        uV.Add(new Vector2(item.x, item.y));
    }
Exemplo n.º 13
0
    public void Add(dfRenderData buffer)
    {
        if (Material == null && buffer.Material != null)
        {
            Material = buffer.Material;
        }

        buffers.Add(buffer);
    }
Exemplo n.º 14
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
     {
     }
 }
Exemplo n.º 15
0
    protected override void OnRebuildRenderData()
    {
        if (base.Atlas == null)
        {
            return;
        }
        dfAtlas.ItemInfo spriteInfo = base.SpriteInfo;
        if (spriteInfo == null)
        {
            return;
        }
        this.renderData.Material = base.Atlas.Material;
        dfList <Vector3> vertices  = this.renderData.Vertices;
        dfList <Vector2> uV        = this.renderData.UV;
        dfList <Color32> colors    = this.renderData.Colors;
        dfList <int>     triangles = this.renderData.Triangles;

        Vector2[] vector2Array = this.buildQuadUV();
        Vector2   vector2      = Vector2.Scale(spriteInfo.sizeInPixels, this.tileScale);
        Vector2   vector21     = new Vector2(this.tileScroll.x % 1f, this.tileScroll.y % 1f);

        for (float i = -Mathf.Abs(vector21.y * vector2.y); i < this.size.y; i = i + vector2.y)
        {
            for (float j = -Mathf.Abs(vector21.x * vector2.x); j < this.size.x; j = j + vector2.x)
            {
                int count = vertices.Count;
                vertices.Add(new Vector3(j, -i));
                vertices.Add(new Vector3(j + vector2.x, -i));
                vertices.Add(new Vector3(j + vector2.x, -i + -vector2.y));
                vertices.Add(new Vector3(j, -i + -vector2.y));
                this.addQuadTriangles(triangles, count);
                this.addQuadUV(uV, vector2Array);
                this.addQuadColors(colors);
            }
        }
        this.clipQuads(vertices, uV);
        float   units     = base.PixelsToUnits();
        Vector3 upperLeft = this.pivot.TransformToUpperLeft(this.size);

        for (int k = 0; k < vertices.Count; k++)
        {
            vertices[k] = (vertices[k] + upperLeft) * units;
        }
    }
Exemplo n.º 16
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
     {
     }
 }
Exemplo n.º 17
0
    public dfList <TResult> Convert <TResult>()
    {
        dfList <TResult> list = dfList <TResult> .Obtain(this.count);

        for (int i = 0; i < this.count; i++)
        {
            list.Add((TResult)System.Convert.ChangeType(this.items[i], typeof(TResult)));
        }
        return(list);
    }
Exemplo n.º 18
0
    private void addQuadIndices(dfList <Vector3> verts, dfList <int> triangles)
    {
        int count = verts.Count;

        int[] numArray = new int[] { 0, 1, 3, 3, 1, 2 };
        for (int i = 0; i < numArray.Length; i++)
        {
            triangles.Add(count + numArray[i]);
        }
    }
Exemplo n.º 19
0
        private static void addTriangleIndices(dfList <Vector3> verts, dfList <int> triangles)
        {
            int count = verts.Count;

            int[] tRIANGLEINDICES = dfFont.BitmappedFontRenderer.TRIANGLE_INDICES;
            for (int i = 0; i < (int)tRIANGLEINDICES.Length; i++)
            {
                triangles.Add(count + tRIANGLEINDICES[i]);
            }
        }
Exemplo n.º 20
0
    private static void addTriangleIndices(dfList <Vector3> verts, dfList <int> triangles)
    {
        int count = verts.Count;

        int[] tRIANGLEINDICES = dfMarkupBoxSprite.TRIANGLE_INDICES;
        for (int i = 0; i < (int)tRIANGLEINDICES.Length; i++)
        {
            triangles.Add(count + tRIANGLEINDICES[i]);
        }
    }
Exemplo n.º 21
0
        private static void addTriangleIndices(dfList <Vector3> verts, dfList <int> triangles)
        {
            var vcount  = verts.Count;
            var indices = TRIANGLE_INDICES;

            for (int ii = 0; ii < indices.Length; ii++)
            {
                triangles.Add(vcount + indices[ii]);
            }
        }
Exemplo n.º 22
0
    public dfList <TResult> Convert <TResult>()
    {
        dfList <TResult> tResults = dfList <TResult> .Obtain(this.count);

        for (int i = 0; i < this.count; i++)
        {
            tResults.Add((TResult)Convert.ChangeType(this.items[i], typeof(TResult)));
        }
        return(tResults);
    }
Exemplo n.º 23
0
    private void addQuadColors(dfList <Color32> colors)
    {
        colors.EnsureCapacity(colors.Count + 4);
        Color32 item = base.ApplyOpacity(!base.IsEnabled ? base.disabledColor : base.color);

        for (int i = 0; i < 4; i++)
        {
            colors.Add(item);
        }
    }
Exemplo n.º 24
0
    private void addQuadColors(dfList <Color32> colors)
    {
        colors.EnsureCapacity(colors.Count + 4);
        Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? this.disabledColor : this.color));

        for (int i = 0; i < 4; i++)
        {
            colors.Add(color32);
        }
    }
Exemplo n.º 25
0
    private static void addTriangleIndices(dfList <Vector3> verts, dfList <int> triangles)
    {
        int count = verts.Count;

        int[] numArray = TRIANGLE_INDICES;
        for (int i = 0; i < numArray.Length; i++)
        {
            triangles.Add(count + numArray[i]);
        }
    }
Exemplo n.º 26
0
    private static void rebuildTriangles(dfRenderData renderData, dfSprite.RenderOptions options)
    {
        int          baseIndex = options.baseIndex;
        dfList <int> triangles = renderData.Triangles;

        for (int i = 0; i < triangleIndices.Length; i++)
        {
            triangles.Add(baseIndex + triangleIndices[i]);
        }
    }
    private void addQuadColors(dfList <Color32> colors)
    {
        colors.EnsureCapacity(colors.Count + 4);
        var color = ApplyOpacity(IsEnabled ? this.color : this.disabledColor);

        for (int i = 0; i < 4; i++)
        {
            colors.Add(color);
        }
    }
Exemplo n.º 28
0
    public dfList <TResult> Select <TResult>(Func <T, TResult> selector)
    {
        dfList <TResult> list = dfList <TResult> .Obtain(this.count);

        for (int i = 0; i < this.count; i++)
        {
            list.Add(selector(this.items[i]));
        }
        return(list);
    }
Exemplo n.º 29
0
    public void Release()
    {
        this.source = null;
        this.index  = 0;

        if (!pool.Contains(this))
        {
            pool.Add(this);
        }
    }
Exemplo n.º 30
0
    private static void rebuildVertices(dfRenderData renderData, RenderOptions options)
    {
        dfList <Vector3> vertices = renderData.Vertices;
        int   baseIndex           = options.baseIndex;
        float x    = 0f;
        float y    = 0f;
        float num4 = Mathf.Ceil(options.size.x);
        float num5 = Mathf.Ceil(-options.size.y);

        vertices.Add((Vector3)(new Vector3(x, y, 0f) * options.pixelsToUnits));
        vertices.Add((Vector3)(new Vector3(num4, y, 0f) * options.pixelsToUnits));
        vertices.Add((Vector3)(new Vector3(num4, num5, 0f) * options.pixelsToUnits));
        vertices.Add((Vector3)(new Vector3(x, num5, 0f) * options.pixelsToUnits));
        Vector3 vector = (Vector3)(options.offset.RoundToInt() * options.pixelsToUnits);

        for (int i = 0; i < 4; i++)
        {
            vertices[baseIndex + i] = (vertices[baseIndex + i] + vector).Quantize(options.pixelsToUnits);
        }
    }
Exemplo n.º 31
0
    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 );
        }
    }
Exemplo n.º 32
0
        private static void addTriangleIndices( dfList<Vector3> verts, dfList<int> triangles )
        {

        var vcount = verts.Count;
        var indices = TRIANGLE_INDICES;

        for( int ii = 0; ii < indices.Length; ii++ )
        {
            triangles.Add( vcount + indices[ ii ] );
        }

        }
Exemplo n.º 33
0
		/// <summary>
		/// Determine where each line of text starts. Assumes that the
		/// tokens array is already populated and that the render size
		/// of each token has already been determined.
		/// </summary>
		/// <returns></returns>
		private dfList<LineRenderInfo> calculateLinebreaks()
		{

			try
			{

				//@Profiler.BeginSample( "Calculate line breaks" );

				if( lines != null )
				{
					return lines;
				}

				lines = dfList<LineRenderInfo>.Obtain();

				var font = (dfDynamicFont)Font;
				var lastBreak = 0;
				var startIndex = 0;
				var index = 0;
				var lineWidth = 0;
				var lineHeight = font.Baseline * TextScale;

				while( index < tokens.Count && lines.Count * lineHeight <= MaxSize.y + lineHeight )
				{

					var token = tokens[ index ];
					var type = token.TokenType;

					if( type == dfMarkupTokenType.Newline )
					{

						lines.Add( LineRenderInfo.Obtain( startIndex, index ) );

						startIndex = lastBreak = ++index;
						lineWidth = 0;

						continue;

					}

					var tokenWidth = Mathf.CeilToInt( token.Width );

					var canWrap =
						WordWrap &&
						lastBreak > startIndex &&
						(
							type == dfMarkupTokenType.Text ||
							( type == dfMarkupTokenType.StartTag && token.Matches( "sprite" ) )
						);

					if( canWrap && lineWidth + tokenWidth >= MaxSize.x )
					{

						if( lastBreak > startIndex )
						{

							lines.Add( LineRenderInfo.Obtain( startIndex, lastBreak - 1 ) );

							startIndex = index = ++lastBreak;
							lineWidth = 0;

						}
						else
						{

							lines.Add( LineRenderInfo.Obtain( startIndex, lastBreak - 1 ) );

							startIndex = lastBreak = ++index;
							lineWidth = 0;

						}

						continue;

					}

					if( type == dfMarkupTokenType.Whitespace )
					{
						lastBreak = index;
					}

					lineWidth += tokenWidth;
					index += 1;

				}

				if( startIndex < tokens.Count )
				{
					lines.Add( LineRenderInfo.Obtain( startIndex, tokens.Count - 1 ) );
				}

				for( int i = 0; i < lines.Count; i++ )
				{
					calculateLineSize( lines[ i ] );
				}

				return lines;

			}
			finally
			{
				//@Profiler.EndSample();
			}

		}
Exemplo n.º 34
0
		private static void addUVCoords( dfList<Vector2> uvs, UnityEngine.CharacterInfo glyph )
		{

			var region = glyph.uv;
			var uvLeft = region.x;
			var uvTop = region.y + region.height;
			var uvRight = uvLeft + region.width;
			var uvBottom = region.y;

			if( glyph.flipped )
			{
				uvs.Add( new Vector2( uvRight, uvBottom ) );
				uvs.Add( new Vector2( uvRight, uvTop ) );
				uvs.Add( new Vector2( uvLeft, uvTop ) );
				uvs.Add( new Vector2( uvLeft, uvBottom ) );
			}
			else
			{
				uvs.Add( new Vector2( uvLeft, uvTop ) );
				uvs.Add( new Vector2( uvRight, uvTop ) );
				uvs.Add( new Vector2( uvRight, uvBottom ) );
				uvs.Add( new Vector2( uvLeft, uvBottom ) );
			}

		}
Exemplo n.º 35
0
    private void addQuadIndices( dfList<Vector3> verts, dfList<int> triangles )
    {
        var vcount = verts.Count;
        var indices = new int[] { 0, 1, 3, 3, 1, 2 };

        for( int ii = 0; ii < indices.Length; ii++ )
        {
            triangles.Add( vcount + indices[ ii ] );
        }
    }
Exemplo n.º 36
0
 private void addQuadIndices(dfList<Vector3> verts, dfList<int> triangles)
 {
     int count = verts.Count;
     int[] numArray = new int[] { 0, 1, 3, 3, 1, 2 };
     for (int i = 0; i < (int)numArray.Length; i++)
     {
         triangles.Add(count + numArray[i]);
     }
 }
Exemplo n.º 37
0
 private void addQuadColors(dfList<Color32> colors)
 {
     colors.EnsureCapacity(colors.Count + 4);
     Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? this.disabledColor : this.color));
     for (int i = 0; i < 4; i++)
     {
         colors.Add(color32);
     }
 }
Exemplo n.º 38
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);
     }
 }
Exemplo n.º 39
0
 private void addQuadColors( dfList<Color32> colors )
 {
     colors.EnsureCapacity( colors.Count + 4 );
     var color = ApplyOpacity( IsEnabled ? this.color : this.disabledColor );
     for( int i = 0; i < 4; i++ )
     {
         colors.Add( color );
     }
 }
Exemplo n.º 40
0
 private static void addUVCoords(dfList<Vector2> uvs, CharacterInfo glyph)
 {
     Rect rect = glyph.uv;
     float single = rect.x;
     float single1 = rect.y + rect.height;
     float single2 = single + rect.width;
     float single3 = rect.y;
     if (!glyph.flipped)
     {
         uvs.Add(new Vector2(single, single1));
         uvs.Add(new Vector2(single2, single1));
         uvs.Add(new Vector2(single2, single3));
         uvs.Add(new Vector2(single, single3));
     }
     else
     {
         uvs.Add(new Vector2(single2, single3));
         uvs.Add(new Vector2(single2, single1));
         uvs.Add(new Vector2(single, single1));
         uvs.Add(new Vector2(single, single3));
     }
 }
Exemplo n.º 41
0
 private void addQuadTriangles( dfList<int> triangles, int baseIndex )
 {
     for( int i = 0; i < quadTriangles.Length; i++ )
     {
         triangles.Add( quadTriangles[ i ] + baseIndex );
     }
 }
Exemplo n.º 42
0
 private static void addTriangleIndices(dfList<Vector3> verts, dfList<int> triangles)
 {
     int count = verts.Count;
     int[] tRIANGLEINDICES = dfMarkupBoxText.TRIANGLE_INDICES;
     for (int i = 0; i < (int)tRIANGLEINDICES.Length; i++)
     {
         triangles.Add(count + tRIANGLEINDICES[i]);
     }
 }