static DebugOverflowIndicatorMixin()
 {
     _indicatorPaint.shader = Gradient.linear(
         new Offset(0.0f, 0.0f),
         new Offset(10.0f, 10.0f),
         new List <Color> {
         _black, _yellow, _yellow, _black
     },
         new List <float> {
         0.25f, 0.25f, 0.75f, 0.75f
     },
         TileMode.repeated
         );
     _labelBackgroundPaint.color = new Color(0xFFFFFFFF);
     for (int i = 0; i < 4; i++)
     {
         _indicatorLabel.Add(new TextPainter(new TextSpan(""), textDirection: TextDirection.ltr));
     }
 }
Beispiel #2
0
        void drawRectShadow()
        {
            var canvas = new CommandBufferCanvas(this._renderTexture, Window.instance.devicePixelRatio,
                                                 this._meshPool);

            var paint = new Paint {
                color      = new Color(0xFF00FF00),
                maskFilter = MaskFilter.blur(BlurStyle.normal, 3),
            };

            canvas.clipRect(Unity.UIWidgets.ui.Rect.fromLTWH(25, 25, 300, 300));

            canvas.rotate(-Mathf.PI / 8.0f);

            canvas.drawRect(
                Unity.UIWidgets.ui.Rect.fromLTWH(10, 10, 100, 100),
                paint);

            paint = new Paint {
                color       = new Color(0xFFFFFF00),
                maskFilter  = MaskFilter.blur(BlurStyle.normal, 5),
                style       = PaintingStyle.stroke,
                strokeWidth = 55,
                shader      = Gradient.linear(new Offset(10, 10), new Offset(180, 180), new List <Color>()
                {
                    Colors.red, Colors.green, Colors.yellow
                }, null, TileMode.clamp)
            };

            canvas.drawRect(
                Unity.UIWidgets.ui.Rect.fromLTWH(10, 150, 200, 200),
                paint);

            canvas.drawImage(new Image(texture6, true),
                             new Offset(50, 150),
                             paint);

            canvas.flush();
        }
Beispiel #3
0
        void drawImageRect()
        {
            if (this._stream == null || this._stream.completer == null || this._stream.completer.currentImage == null)
            {
                return;
            }

            var canvas = new CommandBufferCanvas(this._renderTexture, (float)Window.instance.devicePixelRatio, this._meshPool);

            var paint = new Paint {
                // color = new Color(0x7FFF0000),
                shader = Gradient.linear(new Offset(100, 100), new Offset(280, 280), new List <Color>()
                {
                    Colors.red, Colors.black, Colors.green
                }, null, TileMode.clamp)
            };

            canvas.drawImageRect(this._stream.completer.currentImage.image,
                                 Unity.UIWidgets.ui.Rect.fromLTWH(100, 50, 250, 250),
                                 paint
                                 );
            canvas.flush();
        }
Beispiel #4
0
        void drawLine()
        {
            var canvas = new CommandBufferCanvas(this._renderTexture, Window.instance.devicePixelRatio,
                                                 this._meshPool);

            var paint = new Paint {
                color       = new Color(0xFFFF0000),
                style       = PaintingStyle.stroke,
                strokeWidth = 10,
                shader      = Gradient.linear(new Offset(10, 10), new Offset(180, 180), new List <Color>()
                {
                    Colors.red, Colors.green, Colors.yellow
                }, null, TileMode.clamp)
            };

            canvas.drawLine(
                new Offset(10, 20),
                new Offset(50, 20),
                paint);

            canvas.drawLine(
                new Offset(10, 10),
                new Offset(100, 100),
                paint);

            canvas.drawLine(
                new Offset(10, 10),
                new Offset(10, 50),
                paint);

            canvas.drawLine(
                new Offset(40, 10),
                new Offset(90, 10),
                paint);


            canvas.drawArc(Unity.UIWidgets.ui.Rect.fromLTWH(200, 200, 100, 100), Mathf.PI / 4,
                           -Mathf.PI / 2 + Mathf.PI * 4 - 1, true, paint);

            paint.maskFilter  = MaskFilter.blur(BlurStyle.normal, 1);
            paint.strokeWidth = 4;

            canvas.drawLine(
                new Offset(40, 20),
                new Offset(120, 190),
                paint);

            canvas.scale(3);
            TextBlobBuilder builder = new TextBlobBuilder();
            string          text    = "This is a text blob";

            builder.allocRunPos(new TextStyle(), text, 0, text.Length);
            builder.setBounds(Unity.UIWidgets.ui.Rect.fromLTWH(-10, -20, 200, 50));
            builder.positions = new Vector2d[] {
                new Vector2d(10, 0),
                new Vector2d(20, 0),
                new Vector2d(30, 0),
                new Vector2d(40, 0),
                new Vector2d(50, 0),
                new Vector2d(60, 0),
                new Vector2d(70, 0),
                new Vector2d(80, 0),
                new Vector2d(90, 0),
                new Vector2d(100, 0),
                new Vector2d(110, 0),
                new Vector2d(120, 0),
                new Vector2d(130, 0),
                new Vector2d(140, 0),
                new Vector2d(150, 0),
                new Vector2d(160, 0),
                new Vector2d(170, 0),
                new Vector2d(180, 0),
                new Vector2d(190, 0),
            };

            var textBlob = builder.make();

            canvas.drawTextBlob(textBlob, new Offset(100, 100), new Paint {
                color      = Colors.black,
                maskFilter = MaskFilter.blur(BlurStyle.normal, 5),
            });
            canvas.drawTextBlob(textBlob, new Offset(100, 100), paint);

            canvas.drawLine(
                new Offset(10, 30),
                new Offset(10, 60),
                new Paint()
            {
                style = PaintingStyle.stroke, strokeWidth = 0.1f
            });

            canvas.drawLine(
                new Offset(20, 30),
                new Offset(20, 60),
                new Paint()
            {
                style = PaintingStyle.stroke, strokeWidth = 0.333f
            });

            canvas.flush();
        }
Beispiel #5
0
        void drawPloygon4()
        {
            var canvas = new CommandBufferCanvas(this._renderTexture, Window.instance.devicePixelRatio,
                                                 this._meshPool);

            var paint = new Paint {
                color  = new Color(0xFFFF0000),
                shader = Gradient.linear(new Offset(80, 80), new Offset(180, 180), new List <Color>()
                {
                    Colors.red, Colors.black, Colors.green
                }, null, TileMode.clamp)
            };

            var path = new Path();

            path.moveTo(10, 150);
            path.lineTo(10, 160);
            path.lineTo(140, 120);
            path.lineTo(110, 180);
            path.winding(PathWinding.clockwise);
            path.close();
            path.addRect(Unity.UIWidgets.ui.Rect.fromLTWH(0, 100, 100, 100));
            path.addRect(Unity.UIWidgets.ui.Rect.fromLTWH(200, 0, 100, 100));
            path.addRRect(RRect.fromRectAndRadius(Unity.UIWidgets.ui.Rect.fromLTWH(150, 100, 30, 30), 10));
            path.addOval(Unity.UIWidgets.ui.Rect.fromLTWH(150, 50, 100, 100));
            path.winding(PathWinding.clockwise);

            if (Event.current.type == EventType.MouseDown)
            {
                var pos = new Offset(
                    Event.current.mousePosition.x,
                    Event.current.mousePosition.y
                    );

                Debug.Log(pos + ": " + path.contains(pos));
            }

            canvas.drawPath(path, paint);

            canvas.rotate(Mathf.PI * 15 / 180);

            canvas.translate(100, 100);

            paint.shader = Gradient.radial(new Offset(80, 80), 100, new List <Color>()
            {
                Colors.red, Colors.black, Colors.green
            }, null, TileMode.clamp);
            canvas.drawPath(path, paint);


            canvas.translate(100, 100);
            paint.shader = Gradient.sweep(new Offset(120, 100), new List <Color>()
            {
                Colors.red, Colors.black, Colors.green, Colors.red,
            }, null, TileMode.clamp, 10 * Mathf.PI / 180, 135 * Mathf.PI / 180);
            canvas.drawPath(path, paint);


            canvas.translate(100, 100);
            //paint.maskFilter = MaskFilter.blur(BlurStyle.normal, 5);
            paint.shader = new ImageShader(new Image(texture6, true), TileMode.mirror);
            canvas.drawPath(path, paint);

            canvas.flush();
        }
Beispiel #6
0
        void drawLine()
        {
            var canvas = new CommandBufferCanvas(this._renderTexture, (float)Window.instance.devicePixelRatio, this._meshPool);

            var paint = new Paint {
                color       = new Color(0xFFFF0000),
                style       = PaintingStyle.stroke,
                strokeWidth = 10,
                shader      = Gradient.linear(new Offset(10, 10), new Offset(180, 180), new List <Color>()
                {
                    Colors.red, Colors.green, Colors.yellow
                }, null, TileMode.clamp)
            };

            canvas.drawLine(
                new Offset(10, 20),
                new Offset(50, 20),
                paint);

            canvas.drawLine(
                new Offset(10, 10),
                new Offset(100, 100),
                paint);

            canvas.drawLine(
                new Offset(10, 10),
                new Offset(10, 50),
                paint);

            canvas.drawLine(
                new Offset(40, 10),
                new Offset(90, 10),
                paint);

            paint.maskFilter  = MaskFilter.blur(BlurStyle.normal, 1);
            paint.strokeWidth = 4;

            canvas.drawLine(
                new Offset(40, 20),
                new Offset(120, 190),
                paint);

            canvas.scale(3);
            TextBlob textBlob = new TextBlob("This is a text blob", 0, 19, new Vector2d[] {
                new Vector2d(10, 0),
                new Vector2d(20, 0),
                new Vector2d(30, 0),
                new Vector2d(40, 0),
                new Vector2d(50, 0),
                new Vector2d(60, 0),
                new Vector2d(70, 0),
                new Vector2d(80, 0),
                new Vector2d(90, 0),
                new Vector2d(100, 0),
                new Vector2d(110, 0),
                new Vector2d(120, 0),
                new Vector2d(130, 0),
                new Vector2d(140, 0),
                new Vector2d(150, 0),
                new Vector2d(160, 0),
                new Vector2d(170, 0),
                new Vector2d(180, 0),
                new Vector2d(190, 0),
            }, Unity.UIWidgets.ui.Rect.fromLTWH(0, 0, 200, 50), new TextStyle());

            canvas.drawTextBlob(textBlob, new Offset(100, 100), paint);

            canvas.drawLine(
                new Offset(10, 30),
                new Offset(10, 60),
                new Paint()
            {
                style = PaintingStyle.stroke, strokeWidth = 0.1
            });

            canvas.drawLine(
                new Offset(20, 30),
                new Offset(20, 60),
                new Paint()
            {
                style = PaintingStyle.stroke, strokeWidth = 0.333
            });

            canvas.flush();
        }
Beispiel #7
0
        public static void paintOverflowIndicator(
            RenderObject renderObject,
            PaintingContext context,
            Offset offset,
            Rect containerRect,
            Rect childRect,
            List <DiagnosticsNode> overflowHints = null
            )
        {
            RelativeRect overflow = RelativeRect.fromRect(containerRect, childRect);

            if (overflow.left <= 0.0f &&
                overflow.right <= 0.0f &&
                overflow.top <= 0.0f &&
                overflow.bottom <= 0.0f)
            {
                return;
            }

            TextStyle _indicatorTextStyle = new TextStyle(
                color: new Color(0xFF900000),
                fontSize: _indicatorFontSizePixels,
                fontWeight: FontWeight.w800
                );

            Paint _indicatorPaint = new Paint {
                shader = Gradient.linear(
                    new Offset(0.0f, 0.0f),
                    new Offset(10.0f, 10.0f),
                    new List <Color> {
                    _black, _yellow, _yellow, _black
                },
                    new List <float> {
                    0.25f, 0.25f, 0.75f, 0.75f
                },
                    TileMode.repeated
                    )
            };

            Paint _labelBackgroundPaint = new Paint {
                color = new Color(0xFFFFFFFF)
            };

            List <_OverflowRegionData> overflowRegions = _calculateOverflowRegions(overflow, containerRect);

            foreach (_OverflowRegionData region in overflowRegions)
            {
                context.canvas.drawRect(region.rect.shift(offset), _indicatorPaint);

                var textPainter = new TextPainter(textDirection: TextDirection.ltr)
                {
                    text = new TextSpan(
                        text: region.label,
                        style: _indicatorTextStyle)
                };
                textPainter.layout();

                Offset labelOffset        = region.labelOffset + offset;
                Offset centerOffset       = new Offset(-textPainter.width / 2.0f, 0.0f);
                Rect   textBackgroundRect = centerOffset & textPainter.size;
                context.canvas.save();
                context.canvas.translate(labelOffset.dx, labelOffset.dy);
                context.canvas.rotate(region.rotation);
                context.canvas.drawRect(textBackgroundRect, _labelBackgroundPaint);
                textPainter.paint(context.canvas, centerOffset);
                context.canvas.restore();
            }

            bool containsKey = _overflowReportNeeded.TryGetValue(renderObject, out var overflowReportNeeded);

            overflowReportNeeded |= !containsKey;
            if (overflowReportNeeded)
            {
                _overflowReportNeeded[renderObject] = false;
                _reportOverflow(renderObject, overflow, overflowHints);
            }
        }
        public override void paint(Canvas canvas, Size size)
        {
            var paint = new Paint()
            {
                color = new Color(0xFFFF0000),
            };

            paint.color       = Colors.yellow;
            paint.style       = PaintingStyle.stroke;
            paint.strokeWidth = 3;

            var startPoint    = new Offset(0, size.height / 6);
            var controlPoint1 = new Offset(size.width / 4, 0);
            var controlPoint2 = new Offset(3 * size.width / 4, 0);
            var endPoint      = new Offset(size.width, size.height / 6);

            var path = new Path();

            path.moveTo(startPoint.dx, startPoint.dy);
            path.cubicTo(
                controlPoint1.dx, controlPoint1.dy,
                controlPoint2.dx, controlPoint2.dy,
                endPoint.dx, endPoint.dy
                );

            path.moveTo(10, 10);
            path.lineTo(90, 10);
            path.lineTo(10, 90);
            path.lineTo(90, 90);
            path.winding(PathWinding.clockwise);
            path.close();

            path.moveTo(110, 10);
            path.lineTo(190, 10);
            path.lineTo(110, 90);
            path.lineTo(190, 90);
            path.close();

            path.addRect(UIWidgetRect.fromLTWH(10, 25, 180, 50));

            path.addRect(UIWidgetRect.fromLTWH(200, 0, 100, 100));
            path.addRRect(RRect.fromRectAndRadius(UIWidgetRect.fromLTWH(225, 25, 50, 50), 10));
            path.winding(PathWinding.clockwise);
            path.addOval(UIWidgetRect.fromLTWH(200, 50, 100, 100));
            path.winding(PathWinding.clockwise);


            canvas.drawPath(path, paint);

            paint = new Paint {
                color  = new Color(0xFFFF0000),
                shader = Gradient.linear(
                    new Offset(0, 0),
                    new Offset(size.width, 200),
                    new List <Color>()
                {
                    Colors.red, Colors.black, Colors.green
                }, null, TileMode.clamp),
            };
            canvas.translate(0, 200);
            canvas.drawPath(path, paint);

            canvas.translate(0, 200);
            // paint.maskFilter = MaskFilter.blur(BlurStyle.normal, 5);
            paint.shader = new ImageShader(new Image(texture6, true), TileMode.mirror);
            canvas.drawPath(path, paint);

            canvas.translate(0, 200);
            paint = new Paint {
                color  = new Color(0xFF00FF00),
                shader = Gradient.sweep(
                    new Offset(size.width / 2, 100),
                    new List <Color>()
                {
                    Colors.red, Colors.black, Colors.green, Colors.red,
                }, null, TileMode.clamp, 0 * Mathf.PI / 180, 360 * Mathf.PI / 180),
            };
            canvas.drawPath(path, paint);


            paint.shader = Gradient.radial(
                new Offset(size.width / 2, 100), 200f,
                new List <Color>()
            {
                Colors.red, Colors.black, Colors.green
            }, null, TileMode.clamp);
            canvas.translate(0, 200);
            canvas.drawPath(path, paint);
        }