示例#1
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));
        }
示例#2
0
        static void Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count)
        {
            D.assert(m._hasPerspective());

            if (count > 0)
            {
                for (int i = 0; i < count; ++i)
                {
                    var sy = src[i].dy;
                    var sx = src[i].dx;
                    var x  = uiScalarUtils.sdot(sx, m.kMScaleX, sy, m.kMSkewX) +
                             m.kMTransX;
                    var y = uiScalarUtils.sdot(sx, m.kMSkewY, sy, m.kMScaleY) +
                            m.kMTransY;
                    var z = uiScalarUtils.sdot(sx, m.kMPersp0, sy, m.kMPersp1) +
                            m.kMPersp2;
                    if (z != 0)
                    {
                        z = 1 / z;
                    }

                    dst[i] = new uiOffset(x * z, y * z);
                }
            }
        }
示例#3
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);
 }
示例#4
0
        void _drawImage(Image image, uiOffset offset, uiPaint paint)
        {
            D.assert(image != null);

            this._drawImageRect(image,
                                null,
                                uiRectHelper.fromLTWH(
                                    offset.dx, offset.dy,
                                    image.width / this._devicePixelRatio,
                                    image.height / this._devicePixelRatio),
                                paint);
        }
示例#5
0
 static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count)
 {
     D.assert(m._getType() <= TypeMask.kTranslate_Mask);
     if (count > 0)
     {
         var tx = m.getTranslateX();
         var ty = m.getTranslateY();
         for (int i = 0; i < count; ++i)
         {
             dst[i] = new uiOffset(src[i].dx + tx, src[i].dy + ty);
         }
     }
 }
示例#6
0
        static void Scale_pts(uiMatrix3 m, ref uiOffset[] dst, ref uiOffset[] src, int count)
        {
            D.assert(m._getType() <= (TypeMask.kScale_Mask | TypeMask.kTranslate_Mask));
            if (count > 0)
            {
                var tx = m.getTranslateX();
                var ty = m.getTranslateY();
                var sx = m.getScaleX();
                var sy = m.getScaleY();

                for (int i = 0; i < count; ++i)
                {
                    dst[i] = new uiOffset(src[i].dx * sx + tx, src[i].dy * sy + ty);
                }
            }
        }
示例#7
0
        void _drawImage(Image image, uiOffset offset, uiPaint paint)
        {
            D.assert(image != null && image.valid);

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

            this._drawImageRect(image,
                                null,
                                uiRectHelper.fromLTWH(
                                    offset.dx, offset.dy,
                                    image.width / this._devicePixelRatio,
                                    image.height / this._devicePixelRatio),
                                paint);
        }
示例#8
0
        static void Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count)
        {
            D.assert(m._getType() != TypeMask.kPerspective_Mask);
            if (count > 0)
            {
                var tx = m.getTranslateX();
                var ty = m.getTranslateY();
                var sx = m.getScaleX();
                var sy = m.getScaleY();
                var kx = m.getSkewX();
                var ky = m.getSkewY();

                for (int i = 0; i < count; ++i)
                {
                    dst[i] = new uiOffset(
                        src[i].dx * sx + src[i].dy * kx + tx,
                        src[i].dx * ky + src[i].dy * sy + ty);
                }
            }
        }
示例#9
0
        void _drawTextBlob(TextBlob?textBlob, uiOffset offset, uiPaint paint)
        {
            D.assert(textBlob != null);

            var state = this._currentLayer.currentState;
            var scale = state.scale * this._devicePixelRatio;

            var matrix = new uiMatrix3(state.matrix.Value);

            matrix.preTranslate(offset.dx, offset.dy);

            var mesh           = TextBlobMesh.create(textBlob.Value, scale, matrix);
            var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.Value.boundsInText));

            // request font texture so text mesh could be generated correctly
            var     style          = textBlob.Value.style;
            var     font           = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
            var     fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
            var     subText        = textBlob.Value.text.Substring(textBlob.Value.textOffset, textBlob.Value.textSize);
            Texture tex            = null;
            bool    notEmoji       = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]);

            if (notEmoji)
            {
                font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle);
                tex = font.material.mainTexture;
            }

            if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0)
            {
                this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, null, false, 0, 0, tex,
                                         textBlobBounds, mesh, notEmoji, this.___drawTextDrawMeshCallback);
                return;
            }

            this._drawTextDrawMeshCallback(paint, null, null, false, 0, 0, tex, textBlobBounds, mesh, notEmoji);
        }
示例#10
0
 public uiRect shift(uiOffset offset)
 {
     return(uiRectHelper.fromLTRB(this.left + offset.dx, this.top + offset.dy, this.right + offset.dx,
                                  this.bottom + offset.dy));
 }
示例#11
0
 public static bool contains(uiRect a, uiOffset offset)
 {
     return(offset.dx >= a.left && offset.dx < a.right && offset.dy >= a.top && offset.dy < a.bottom);
 }
示例#12
0
        void _saveLayer(uiRect bounds, uiPaint paint)
        {
            D.assert(bounds.width > 0);
            D.assert(bounds.height > 0);

            var parentLayer  = this._currentLayer;
            var state        = parentLayer.currentState;
            var textureWidth = Mathf.CeilToInt(
                bounds.width * state.scale * this._devicePixelRatio);

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

            var textureHeight = Mathf.CeilToInt(
                bounds.height * state.scale * this._devicePixelRatio);

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

            var layer = RenderLayer.create(
                rtID: Shader.PropertyToID(this._getNewRenderTextureKey()),
                width: textureWidth,
                height: textureHeight,
                layerBounds: bounds,
                layerPaint: paint
                );

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

            if (paint.backdrop != null)
            {
                if (paint.backdrop is _uiBlurImageFilter)
                {
                    var filter = (_uiBlurImageFilter)paint.backdrop;
                    if (!(filter.sigmaX == 0 && filter.sigmaY == 0))
                    {
                        _cachedPoints[0] = bounds.topLeft;
                        _cachedPoints[1] = bounds.bottomLeft;
                        _cachedPoints[2] = bounds.bottomRight;
                        _cachedPoints[3] = bounds.topRight;

                        state.matrix.Value.mapPoints(ref _cachedPoints);

                        var parentBounds = parentLayer.layerBounds;
                        for (int i = 0; i < 4; i++)
                        {
                            _cachedPoints[i] = new uiOffset(
                                (_cachedPoints[i].dx - parentBounds.left) / parentBounds.width,
                                (_cachedPoints[i].dy - parentBounds.top) / parentBounds.height
                                );
                        }

                        var mesh = ImageMeshGenerator.imageMesh(
                            null,
                            _cachedPoints[0],
                            _cachedPoints[1],
                            _cachedPoints[2],
                            _cachedPoints[3],
                            bounds);
                        var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
                        layer.draws.Add(renderDraw);

                        var blurLayer = this._createBlurLayer(layer, filter.sigmaX, filter.sigmaY, layer);
                        var blurMesh  = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, bounds);
                        layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
                    }
                }
                else if (paint.backdrop is _uiMatrixImageFilter)
                {
                    var filter = (_uiMatrixImageFilter)paint.backdrop;
                    if (!filter.transform.isIdentity())
                    {
                        layer.filterMode = filter.filterMode;

                        _cachedPoints[0] = bounds.topLeft;
                        _cachedPoints[1] = bounds.bottomLeft;
                        _cachedPoints[2] = bounds.bottomRight;
                        _cachedPoints[3] = bounds.topRight;

                        state.matrix.Value.mapPoints(ref _cachedPoints);

                        var parentBounds = parentLayer.layerBounds;
                        for (int i = 0; i < 4; i++)
                        {
                            _cachedPoints[i] = new uiOffset(
                                (_cachedPoints[i].dx - parentBounds.left) / parentBounds.width,
                                (_cachedPoints[i].dy - parentBounds.top) / parentBounds.height
                                );
                        }

                        var matrix = uiMatrix3.makeTrans(-bounds.left, -bounds.top);
                        matrix.postConcat(filter.transform);
                        matrix.postTranslate(bounds.left, bounds.top);

                        var mesh = ImageMeshGenerator.imageMesh(
                            matrix,
                            _cachedPoints[0],
                            _cachedPoints[1],
                            _cachedPoints[2],
                            _cachedPoints[3],
                            bounds);
                        var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
                        layer.draws.Add(renderDraw);
                    }
                }
            }
        }