示例#1
0
        public static ClipElement create(int saveCount, uiPath uiPath, uiMatrix3 matrix, float scale)
        {
            ClipElement newElement = ObjectPool <ClipElement> .alloc();

            newElement.saveCount = saveCount;

            var pathCache = uiPath.flatten(scale);
            var fillMesh  = pathCache.getFillMesh(out newElement.convex);

            newElement.mesh = fillMesh.transform(matrix);

            var vertices = newElement.mesh.vertices;

            if (newElement.convex && vertices.Count == 4 && matrix.rectStaysRect() &&
                (Mathf.Abs(vertices[0].x - vertices[1].x) < 1e-6 && Mathf.Abs(vertices[1].y - vertices[2].y) < 1e-6 &&
                 Mathf.Abs(vertices[2].x - vertices[3].x) < 1e-6 && Mathf.Abs(vertices[3].y - vertices[0].y) < 1e-6 ||
                 Mathf.Abs(vertices[0].y - vertices[1].y) < 1e-6 && Mathf.Abs(vertices[1].x - vertices[2].x) < 1e-6 &&
                 Mathf.Abs(vertices[2].y - vertices[3].y) < 1e-6 && Mathf.Abs(vertices[3].x - vertices[0].x) < 1e-6))
            {
                newElement.isRect = true;
                newElement.rect   = newElement.mesh.bounds;
            }
            else
            {
                newElement.isRect = false;
                newElement.rect   = null;
            }

            return(newElement);
        }
示例#2
0
        public void updateBoundAndGenID(ClipElement prior)
        {
            this._genId = ClipStack.getNextGenID();
            this._isIntersectionOfRects = false;

            if (this.isRect)
            {
                this._bound = this.rect;
                if (prior == null || prior.isIntersectionOfRects())
                {
                    this._isIntersectionOfRects = true;
                }
            }
            else
            {
                this._bound = this.mesh.bounds;
            }

            if (prior != null)
            {
                this._bound = this._bound.intersect(prior.getBound());
            }

            if (this._bound.isEmpty)
            {
                this.setEmpty();
            }
        }
示例#3
0
        public override void clear()
        {
            this._saveCount   = 0;
            this._lastElement = null;
            foreach (var clipelement in this.stack)
            {
                ObjectPool <ClipElement> .release(clipelement);
            }

            this.stack.Clear();
        }
示例#4
0
        void _restoreTo(int saveCount)
        {
            while (this._lastElement != null)
            {
                if (this._lastElement.saveCount <= saveCount)
                {
                    break;
                }

                this.stack.RemoveAt(this.stack.Count - 1);
                this._lastElement = this.stack.Count == 0 ? null : this.stack[this.stack.Count - 1];
            }
        }
示例#5
0
        void _pushElement(ClipElement element)
        {
            ClipElement prior = this._lastElement;

            if (prior != null)
            {
                if (prior.isEmpty())
                {
                    ObjectPool <ClipElement> .release(element);

                    return;
                }

                if (prior.saveCount == this._saveCount)
                {
                    // can not update prior if it's cross save count.
                    if (prior.isRect && element.isRect)
                    {
                        var isectRect = uiRectHelper.intersect(prior.rect.Value, element.rect.Value);
                        if (isectRect.isEmpty)
                        {
                            prior.setEmpty();
                            ObjectPool <ClipElement> .release(element);

                            return;
                        }

                        prior.setRect(isectRect);
                        var priorprior = this.stack.Count > 1 ? this.stack[this.stack.Count - 2] : null;
                        prior.updateBoundAndGenID(priorprior);
                        ObjectPool <ClipElement> .release(element);

                        return;
                    }

                    if (!uiRectHelper.overlaps(prior.getBound(), element.getBound()))
                    {
                        prior.setEmpty();
                        ObjectPool <ClipElement> .release(element);

                        return;
                    }
                }
            }

            this.stack.Add(element);
            this._lastElement = element;
            element.updateBoundAndGenID(prior);
        }
示例#6
0
        void _restoreTo(int saveCount)
        {
            while (this._lastElement != null)
            {
                if (this._lastElement.saveCount <= saveCount)
                {
                    break;
                }

                var lastelement = this.stack[this.stack.Count - 1];
                ObjectPool <ClipElement> .release(lastelement);

                this.stack.RemoveAt(this.stack.Count - 1);
                this._lastElement = this.stack.Count == 0 ? null : this.stack[this.stack.Count - 1];
            }
        }
示例#7
0
        void _walkStack(ClipStack stack, Rect queryBounds)
        {
            foreach (var element in stack.stack)
            {
                if (element.isRect)
                {
                    continue;
                }

                if (element.contains(queryBounds))
                {
                    continue;
                }

                this.maskElements.Add(element);
                this._lastElement = element;
            }
        }
示例#8
0
        void _pushElement(ClipElement element)
        {
            ClipElement prior = this.stack.LastOrDefault();

            if (prior != null)
            {
                if (prior.isEmpty())
                {
                    return;
                }

                if (prior.saveCount == this._saveCount)
                {
                    // can not update prior if it's cross save count.
                    if (prior.isRect && element.isRect)
                    {
                        var isectRect = prior.rect.intersect(element.rect);
                        if (isectRect.isEmpty)
                        {
                            prior.setEmpty();
                            return;
                        }

                        prior.setRect(isectRect);
                        var priorprior = this.stack.Count > 1 ? this.stack[this.stack.Count - 2] : null;
                        prior.updateBoundAndGenID(priorprior);
                        return;
                    }

                    if (!prior.getBound().overlaps(element.getBound()))
                    {
                        prior.setEmpty();
                        return;
                    }
                }
            }

            this.stack.Add(element);
            element.updateBoundAndGenID(prior);
        }
示例#9
0
        public void clipPath(Path path, Matrix3 matrix, float scale)
        {
            var element = new ClipElement(this._saveCount, path, matrix, scale);

            this._pushElement(element);
        }
示例#10
0
 public override void clear()
 {
     this.scissor = null;
     this.maskElements.Clear();
     this._lastElement = null;
 }
示例#11
0
        public void clipPath(uiPath uiPath, uiMatrix3 matrix, float scale)
        {
            var element = ClipElement.create(this._saveCount, uiPath, matrix, scale);

            this._pushElement(element);
        }