Ejemplo n.º 1
0
        void _drawImageNine(Image image, uiRect?src, uiRect center, uiRect dst, uiPaint paint)
        {
            D.assert(image != null);

            var scaleX = 1f / image.width;
            var scaleY = 1f / image.height;

            if (src == null)
            {
                src = uiRectHelper.one;
            }
            else
            {
                src = uiRectHelper.scale(src.Value, scaleX, scaleY);
            }

            center = uiRectHelper.scale(center, scaleX, scaleY);

            var layer = this._currentLayer;
            var state = layer.currentState;

            var mesh = ImageMeshGenerator.imageNineMesh(state.matrix, src.Value, center, image.width, image.height,
                                                        dst);

            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image));
        }
Ejemplo n.º 2
0
        void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter,
                                 uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex,
                                 uiRect texBound, TextBlobMesh textMesh, bool notEmoji,
                                 _drawPathDrawMeshCallbackDelegate drawCallback)
        {
            var layer      = this._currentLayer;
            var clipBounds = layer.layerBounds;

            uiRect?stackBounds;
            bool   iior;

            layer.clipStack.getBounds(out stackBounds, out iior);

            if (stackBounds != null)
            {
                clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value);
            }

            if (clipBounds.isEmpty)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            var   state = layer.currentState;
            float sigma = state.scale * maskFilter.sigma;

            if (sigma <= 0)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            float sigma3     = 3 * sigma;
            var   maskBounds = uiRectHelper.inflate(meshBounds, sigma3);

            maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds, sigma3));
            if (maskBounds.isEmpty)
            {
                this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh);
                return;
            }

            var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, strokeMult,
                                                  tex, texBound,
                                                  textMesh, fillMesh, strokeMesh, notEmoji);

            var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer);

            var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds);

            if (!this._applyClip(blurMesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(blurMesh);

                return;
            }

            layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
        }
Ejemplo n.º 3
0
        void _setLastClipGenId(uint clipGenId, uiRect clipBounds)
        {
            var layer = this._currentLayer;

            layer.lastClipGenId  = clipGenId;
            layer.lastClipBounds = clipBounds;
        }
Ejemplo n.º 4
0
        public void updateBoundAndGenID(ClipElement prior)
        {
            this._genId = ClipStack.getNextGenID();
            this._isIntersectionOfRects = false;

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

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

            if (this._bound.isEmpty)
            {
                this.setEmpty();
            }
        }
Ejemplo n.º 5
0
        void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha,
                                       float strokeMult, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(fillMesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(fillMesh);

                ObjectPool <uiMeshMesh> .release(strokeMesh);

                return;
            }

            var layer = this._currentLayer;

            if (convex)
            {
                layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh));
            }
            else
            {
                layer.draws.Add(CanvasShader.fill0(layer, fillMesh));
                layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh));
            }

            if (strokeMesh != null)
            {
                layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh));
                layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate()));
            }
        }
Ejemplo n.º 6
0
        public static ReducedClip create(ClipStack stack, uiRect layerBounds, uiRect queryBounds)
        {
            ReducedClip clip = ObjectPool <ReducedClip> .alloc();

            uiRect?stackBounds;
            bool   iior;

            stack.getBounds(out stackBounds, out iior);

            if (stackBounds == null)
            {
                clip.scissor = layerBounds;
                return(clip);
            }

            stackBounds = uiRectHelper.intersect(layerBounds, stackBounds.Value);
            if (iior)
            {
                clip.scissor = stackBounds;
                return(clip);
            }

            queryBounds = uiRectHelper.intersect(stackBounds.Value, queryBounds);
            if (queryBounds.isEmpty)
            {
                clip.scissor = uiRectHelper.zero;
                return(clip);
            }

            clip.scissor = queryBounds;
            clip._walkStack(stack, clip.scissor.Value);
            return(clip);
        }
Ejemplo n.º 7
0
        void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha,
                                       float strokeMult, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(textBlobBounds))
            {
                ObjectPool <TextBlobMesh> .release(textMesh);

                return;
            }

            var layer = this._currentLayer;

            if (notEmoji)
            {
                layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex));
            }
            else
            {
                uiPaint paintWithWhite = new uiPaint(p);
                paintWithWhite.color = uiColor.white;
                if (EmojiUtils.image == null)
                {
                    ObjectPool <TextBlobMesh> .release(textMesh);

                    return;
                }

                var raw_mesh = textMesh.resolveMesh();
                var meshmesh = raw_mesh.duplicate();
                ObjectPool <TextBlobMesh> .release(textMesh);

                layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image));
            }
        }
Ejemplo n.º 8
0
        bool _convexContains(uiRect rect)
        {
            if (this.mesh.vertices.Count <= 2)
            {
                return(false);
            }

            for (var i = 0; i < this.mesh.vertices.Count; i++)
            {
                var p1 = this.mesh.vertices[i];
                var p0 = this.mesh.vertices[i == this.mesh.vertices.Count - 1 ? 0 : i + 1];

                var v = p1 - p0;
                if (v.x == 0.0 && v.y == 0.0)
                {
                    continue;
                }

                float yL = v.y * (rect.left - p0.x);
                float xT = v.x * (rect.top - p0.y);
                float yR = v.y * (rect.right - p0.x);
                float xB = v.x * (rect.bottom - p0.y);

                if ((xT < yL) || (xT < yR) || (xB < yL) || (xB < yR))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        void _drawImageRect(Image image, uiRect?src, uiRect dst, uiPaint paint)
        {
            D.assert(image != null && image.valid);

            if (image == null || !image.valid)
            {
                return;
            }

            if (src == null)
            {
                src = uiRectHelper.one;
            }
            else
            {
                src = uiRectHelper.scale(src.Value, 1f / image.width, 1f / image.height);
            }

            var layer = this._currentLayer;
            var state = layer.currentState;
            var mesh  = ImageMeshGenerator.imageMesh(state.matrix, src.Value, dst);

            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image));
        }
Ejemplo n.º 10
0
        public static uiMeshMesh imageMesh(uiMatrix3?matrix, uiRect src, uiRect dst)
        {
            var vertices = ObjectPool <uiList <Vector3> > .alloc();

            vertices.SetCapacity(4);

            var uv = ObjectPool <uiList <Vector2> > .alloc();

            uv.SetCapacity(4);

            float uvx0 = src.left;
            float uvx1 = src.right;
            float uvy0 = 1.0f - src.top;
            float uvy1 = 1.0f - src.bottom;

            vertices.Add(new Vector2(dst.left, dst.top));
            uv.Add(new Vector2(uvx0, uvy0));
            vertices.Add(new Vector2(dst.left, dst.bottom));
            uv.Add(new Vector2(uvx0, uvy1));
            vertices.Add(new Vector2(dst.right, dst.bottom));
            uv.Add(new Vector2(uvx1, uvy1));
            vertices.Add(new Vector2(dst.right, dst.top));
            uv.Add(new Vector2(uvx1, uvy0));

            var _triangles = ObjectPool <uiList <int> > .alloc();

            _triangles.AddRange(_imageTriangles);

            return(uiMeshMesh.create(matrix, vertices, _triangles, uv));
        }
Ejemplo n.º 11
0
        public static uiMeshMesh imageMesh(uiMatrix3?matrix,
                                           uiOffset srcTL, uiOffset srcBL, uiOffset srcBR, uiOffset srcTR,
                                           uiRect dst)
        {
            var vertices = ObjectPool <uiList <Vector3> > .alloc();

            vertices.SetCapacity(4);

            var uv = ObjectPool <uiList <Vector2> > .alloc();

            uv.SetCapacity(4);

            vertices.Add(new Vector2(dst.left, dst.top));
            uv.Add(new Vector2(srcTL.dx, 1.0f - srcTL.dy));
            vertices.Add(new Vector2(dst.left, dst.bottom));
            uv.Add(new Vector2(srcBL.dx, 1.0f - srcBL.dy));
            vertices.Add(new Vector2(dst.right, dst.bottom));
            uv.Add(new Vector2(srcBR.dx, 1.0f - srcBR.dy));
            vertices.Add(new Vector2(dst.right, dst.top));
            uv.Add(new Vector2(srcTR.dx, 1.0f - srcTR.dy));

            var _triangles = ObjectPool <uiList <int> > .alloc();

            _triangles.AddRange(_imageTriangles);

            return(uiMeshMesh.create(matrix, vertices, _triangles, uv));
        }
Ejemplo n.º 12
0
 public static uiRect scale(uiRect a, float scaleX, float?scaleY = null)
 {
     scaleY = scaleY ?? scaleX;
     return(fromLTRB(
                a.left * scaleX, a.top * scaleY.Value,
                a.right * scaleX, a.bottom * scaleY.Value));
 }
Ejemplo n.º 13
0
        public static uiPicture create(List <uiDrawCmd> drawCmds, uiRect paintBounds)
        {
            var picture = ObjectPool <uiPicture> .alloc();

            picture.drawCmds    = drawCmds;
            picture.paintBounds = paintBounds;
            return(picture);
        }
Ejemplo n.º 14
0
        void _clipUIRect(uiRect rect)
        {
            var path = uiPath.create();

            path.addRect(rect);
            this._clipPath(path);
            uiPathCacheManager.putToCache(path);
        }
Ejemplo n.º 15
0
 public void addRect(uiRect rect)
 {
     this._appendMoveTo(rect.left, rect.top);
     this._appendLineTo(rect.left, rect.bottom);
     this._appendLineTo(rect.right, rect.bottom);
     this._appendLineTo(rect.right, rect.top);
     this._appendClose();
 }
Ejemplo n.º 16
0
 public static uiRect roundOut(uiRect a, float devicePixelRatio)
 {
     return(fromLTRB(
                Mathf.Floor(a.left * devicePixelRatio) / devicePixelRatio,
                Mathf.Floor(a.top * devicePixelRatio) / devicePixelRatio,
                Mathf.Ceil(a.right * devicePixelRatio) / devicePixelRatio,
                Mathf.Ceil(a.bottom * devicePixelRatio) / devicePixelRatio));
 }
Ejemplo n.º 17
0
 public void addRect(uiRect rect)
 {
     this._updateRRectFlag(true, uiPathShapeHint.Rect);
     this._appendMoveTo(rect.left, rect.top);
     this._appendLineTo(rect.left, rect.bottom);
     this._appendLineTo(rect.right, rect.bottom);
     this._appendLineTo(rect.right, rect.top);
     this._appendClose();
 }
Ejemplo n.º 18
0
 public uiRect intersect(uiRect other)
 {
     return(uiRectHelper.fromLTRB(
                Mathf.Max(this.left, other.left),
                Mathf.Max(this.top, other.top),
                Mathf.Min(this.right, other.right),
                Mathf.Min(this.bottom, other.bottom)
                ));
 }
Ejemplo n.º 19
0
 public static uiOffset[] toQuad(uiRect a)
 {
     uiOffset[] dst = new uiOffset[4];
     dst[0] = new uiOffset(a.left, a.top);
     dst[1] = new uiOffset(a.right, a.top);
     dst[2] = new uiOffset(a.right, a.bottom);
     dst[3] = new uiOffset(a.left, a.bottom);
     return(dst);
 }
Ejemplo n.º 20
0
 public static uiRect intersect(uiRect a, uiRect other)
 {
     return(fromLTRB(
                Mathf.Max(a.left, other.left),
                Mathf.Max(a.top, other.top),
                Mathf.Min(a.right, other.right),
                Mathf.Min(a.bottom, other.bottom)
                ));
 }
Ejemplo n.º 21
0
        public static uiPicture create(List <uiDrawCmd> drawCmds,
                                       uiRect paintBounds,
                                       BBoxHierarchy <IndexedRect> bbh = null,
                                       uiList <int> stateUpdateIndices = null)
        {
            var picture = ObjectPool <uiPicture> .alloc();

            picture.drawCmds            = drawCmds;
            picture.paintBounds         = paintBounds;
            picture.bbh                 = bbh;
            picture.stateUpdatesIndices = stateUpdateIndices;
            return(picture);
        }
Ejemplo n.º 22
0
        public static bool overlaps(uiRect a, uiRect other)
        {
            if (a.right <= other.left || other.right <= a.left)
            {
                return(false);
            }

            if (a.bottom <= other.top || other.bottom <= a.top)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 23
0
        public static uiRect normalize(uiRect a)
        {
            if (a.left <= a.right && a.top <= a.bottom)
            {
                return(a);
            }

            return(fromLTRB(
                       Mathf.Min(a.left, a.right),
                       Mathf.Min(a.top, a.bottom),
                       Mathf.Max(a.left, a.right),
                       Mathf.Max(a.top, a.bottom)
                       ));
        }
Ejemplo n.º 24
0
        void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
                                        uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            var layer = this._currentLayer;

            layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh));
            layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
        }
Ejemplo n.º 25
0
        RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds,
                                     _drawPathDrawMeshCallbackDelegate drawCallback,
                                     uiPaint paint, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound,
                                     TextBlobMesh textMesh,
                                     uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool notEmoji)
        {
            var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio);

            if (textureWidth < 1)
            {
                textureWidth = 1;
            }

            var textureHeight = Mathf.CeilToInt(maskBounds.height * this._devicePixelRatio);

            if (textureHeight < 1)
            {
                textureHeight = 1;
            }

            var maskLayer = RenderLayer.create(
                rtID: Shader.PropertyToID(this._getNewRenderTextureKey()),
                width: textureWidth,
                height: textureHeight,
                layerBounds: maskBounds,
                filterMode: FilterMode.Bilinear,
                noMSAA: true
                );

            parentLayer.addLayer(maskLayer);
            this._layers.Add(maskLayer);
            this._currentLayer = maskLayer;

            var parentState = parentLayer.states[parentLayer.states.Count - 1];
            var maskState   = maskLayer.states[maskLayer.states.Count - 1];

            maskState.matrix = parentState.matrix;

            drawCallback.Invoke(uiPaint.shapeOnly(paint), fillMesh, strokeMesh, convex, alpha, strokeMult, tex,
                                texBound, textMesh, notEmoji);

            var removed = this._layers.removeLast();

            D.assert(removed == maskLayer);
            this._currentLayer = this._layers[this._layers.Count - 1];

            return(maskLayer);
        }
Ejemplo n.º 26
0
        void _walkStack(ClipStack stack, uiRect queryBounds)
        {
            foreach (var element in stack.stack)
            {
                if (element.isRect)
                {
                    continue;
                }

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

                this.maskElements.Add(element);
                this._lastElement = element;
            }
        }
Ejemplo n.º 27
0
        public static uiMeshMesh create(uiRect rect)
        {
            uiMeshMesh newMesh = ObjectPool <uiMeshMesh> .alloc();

            newMesh.vertices = ObjectPool <uiList <Vector3> > .alloc();

            newMesh.vertices.Add(new Vector3(rect.right, rect.bottom));
            newMesh.vertices.Add(new Vector3(rect.right, rect.top));
            newMesh.vertices.Add(new Vector3(rect.left, rect.bottom));
            newMesh.vertices.Add(new Vector3(rect.left, rect.top));

            newMesh.triangles = ObjectPool <uiList <int> > .alloc();

            newMesh.triangles.AddRange(_boundsTriangles);
            newMesh.rawBounds = rect;

            newMesh._bounds = newMesh.rawBounds;

            return(newMesh);
        }
Ejemplo n.º 28
0
        void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
                                       uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji)
        {
            if (!this._applyClip(mesh.bounds))
            {
                ObjectPool <uiMeshMesh> .release(mesh);

                return;
            }

            var layer = this._currentLayer;

            if (convex)
            {
                layer.draws.Add(CanvasShader.convexFill(layer, p, mesh));
            }
            else
            {
                layer.draws.Add(CanvasShader.fill0(layer, mesh));
                layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh));
            }
        }
Ejemplo n.º 29
0
        public bool contains(uiRect rect)
        {
            if (this.isRect)
            {
                return(uiRectHelper.contains(this.rect.Value, rect));
            }

            if (this.convex)
            {
                if (this.mesh.matrix != null && !this.mesh.matrix.Value.isIdentity())
                {
                    if (this._invMat == null)
                    {
                        this._invMat = this.mesh.matrix.Value.invert();
                    }

                    rect = this._invMat.Value.mapRect(rect);
                }

                return(this._convexContains(rect));
            }

            return(false);
        }
Ejemplo n.º 30
0
 public static UnityEngine.Rect toRect(uiRect rect)
 {
     return(new UnityEngine.Rect(rect.left, rect.top, rect.width, rect.height));
 }