Beispiel #1
0
        void _drawButtonBackgroundsAndDividersStacked(Canvas canvas, Offset offset)
        {
            Offset dividerOffset      = new Offset(0.0f, this.dividerThickness);
            Path   backgroundFillPath = new Path();

            // fillType = PathFillType.evenOdd
            backgroundFillPath.addRect(Rect.fromLTWH(0.0f, 0.0f, this.size.width, this.size.height));

            Path      pressedBackgroundFillPath = new Path();
            Path      dividersPath       = new Path();
            Offset    accumulatingOffset = offset;
            RenderBox child     = this.firstChild;
            RenderBox prevChild = null;

            while (child != null)
            {
                D.assert(child.parentData is _ActionButtonParentData);
                _ActionButtonParentData currentButtonParentData = child.parentData as _ActionButtonParentData;
                bool isButtonPressed     = currentButtonParentData.isPressed;
                bool isPrevButtonPressed = false;
                if (prevChild != null)
                {
                    D.assert(prevChild.parentData is _ActionButtonParentData);
                    _ActionButtonParentData previousButtonParentData = prevChild.parentData as _ActionButtonParentData;
                    isPrevButtonPressed = previousButtonParentData.isPressed;
                }

                bool isDividerPresent = child != this.firstChild;
                bool isDividerPainted = isDividerPresent && !(isButtonPressed || isPrevButtonPressed);
                Rect dividerRect      = Rect.fromLTWH(
                    accumulatingOffset.dx,
                    accumulatingOffset.dy, this.size.width, this._dividerThickness
                    );
                Rect buttonBackgroundRect = Rect.fromLTWH(
                    accumulatingOffset.dx,
                    accumulatingOffset.dy + (isDividerPresent ? this.dividerThickness : 0.0f), this.size.width,
                    child.size.height
                    );
                if (isButtonPressed)
                {
                    backgroundFillPath.addRect(buttonBackgroundRect);
                    pressedBackgroundFillPath.addRect(buttonBackgroundRect);
                }

                if (isDividerPainted)
                {
                    backgroundFillPath.addRect(dividerRect);
                    dividersPath.addRect(dividerRect);
                }

                accumulatingOffset += (isDividerPresent ? dividerOffset : Offset.zero)
                                      + new Offset(0.0f, child.size.height);
                prevChild = child;
                child     = this.childAfter(child);
            }

            canvas.drawPath(backgroundFillPath, this._buttonBackgroundPaint);
            canvas.drawPath(pressedBackgroundFillPath, this._pressedButtonBackgroundPaint);
            canvas.drawPath(dividersPath, this._dividerPaint);
        }
Beispiel #2
0
        public void visualize(Canvas canvas, Rect rect)
        {
            Paint paint = new Paint {
                color = Colors.blue
            };
            Paint paint2 = new Paint {
                color = Colors.red
            };
            Paint paint3 = new Paint {
                color = Colors.green
            };
            Paint paint4 = new Paint {
                color = Colors.white70
            };

            float[] costFrames = this._laps;
            int     curFrame   = (this._currentSample - 1) % InstrumentationUtils.kMaxSamples;

            float barWidth  = Mathf.Max(1, rect.width / costFrames.Length);
            float perHeight = rect.height / 32.0f;

            canvas.drawRect(rect, paint4);
            canvas.drawRect(Rect.fromLTWH(rect.left, rect.top + perHeight * 16.0f, rect.width, 1), paint3);

            float cur_x   = rect.left;
            Path  barPath = new Path();

            for (var i = 0; i < costFrames.Length; i++)
            {
                if (costFrames[i] != 0)
                {
                    float curHeight = Mathf.Min(perHeight * costFrames[i] * 1000, rect.height);
                    Rect  barRect   = Rect.fromLTWH(cur_x, rect.top + rect.height - curHeight, barWidth, curHeight);
                    barPath.addRect(barRect);
                }

                cur_x += barWidth;
            }

            canvas.drawPath(barPath, paint);
            if (curFrame >= 0 && curFrame < costFrames.Length)
            {
                if (costFrames[curFrame] != 0)
                {
                    float curHeight = Mathf.Min(perHeight * costFrames[curFrame] * 1000, rect.height);
                    Rect  barRect   = Rect.fromLTWH(rect.left + barWidth * curFrame, rect.top + rect.height - curHeight,
                                                    barWidth, curHeight);
                    canvas.drawRect(barRect, paint2);
                }

                var pb = new ParagraphBuilder(new ParagraphStyle {
                });
                pb.addText("Current Frame Cost: " + costFrames[curFrame] * 1000 + "ms" +
                           " ; Max(in last 120 frames): " + this.maxDelta() * 1000 + "ms");
                var paragraph = pb.build();
                paragraph.layout(new ParagraphConstraints(width: 800));

                canvas.drawParagraph(paragraph, new Offset(rect.left, rect.top + rect.height - 12));
            }
        }
        void _drawCheck(Canvas canvas, Offset origin, float t, Paint paint)
        {
            D.assert(t >= 0.0f && t <= 1.0f);
            Path   path  = new Path();
            Offset start = new Offset(CheckboxUtils._kEdgeSize * 0.15f, CheckboxUtils._kEdgeSize * 0.45f);
            Offset mid   = new Offset(CheckboxUtils._kEdgeSize * 0.4f, CheckboxUtils._kEdgeSize * 0.7f);
            Offset end   = new Offset(CheckboxUtils._kEdgeSize * 0.85f, CheckboxUtils._kEdgeSize * 0.25f);

            if (t < 0.5f)
            {
                float  strokeT = t * 2.0f;
                Offset drawMid = Offset.lerp(start, mid, strokeT);
                path.moveTo(origin.dx + start.dx, origin.dy + start.dy);
                path.lineTo(origin.dx + drawMid.dx, origin.dy + drawMid.dy);
            }
            else
            {
                float  strokeT = (t - 0.5f) * 2.0f;
                Offset drawEnd = Offset.lerp(mid, end, strokeT);
                path.moveTo(origin.dx + start.dx, origin.dy + start.dy);
                path.lineTo(origin.dx + mid.dx, origin.dy + mid.dy);
                path.lineTo(origin.dx + drawEnd.dx, origin.dy + drawEnd.dy);
            }

            canvas.drawPath(path, paint);
        }
        void paintArrowhead(Canvas canvas, Size size)
        {
            float arcEnd = this.arcStart + this.arcSweep ?? 0.0f;
            float ux     = Mathf.Cos(arcEnd);
            float uy     = Mathf.Sin(arcEnd);

            D.assert(size.width == size.height);
            float radius          = size.width / 2.0f;
            float?arrowheadPointX = radius + ux * radius + -uy * this.strokeWidth * 2.0f * this.arrowheadScale;
            float?arrowheadPointY = radius + uy * radius + ux * this.strokeWidth * 2.0f * this.arrowheadScale;
            float?arrowheadRadius = this.strokeWidth * 1.5f * this.arrowheadScale;
            float?innerRadius     = radius - arrowheadRadius;
            float?outerRadius     = radius + arrowheadRadius;

            Path path = new Path();

            path.moveTo(radius + ux * innerRadius ?? 0.0f, radius + uy * innerRadius ?? 0.0f);
            path.lineTo(radius + ux * outerRadius ?? 0.0f, radius + uy * outerRadius ?? 0.0f);
            path.lineTo(arrowheadPointX ?? 0.0f, arrowheadPointY ?? 0.0f);
            path.close();
            Paint paint = new Paint();

            paint.color       = this.valueColor;
            paint.strokeWidth = this.strokeWidth ?? 0.0f;
            paint.style       = PaintingStyle.fill;
            canvas.drawPath(path, paint);
        }
Beispiel #5
0
        void _drawFrameCost(Canvas canvas, float x, float y, float width, float height)
        {
            Rect visualizationRect = Rect.fromLTWH(x, y, width, height);

            Paint paint = new Paint {
                color = Colors.blue
            };
            Paint paint2 = new Paint {
                color = Colors.red
            };
            Paint paint3 = new Paint {
                color = Colors.green
            };
            Paint paint4 = new Paint {
                color = Colors.white70
            };

            float[] costFrames = PerformanceUtils.instance.getFrames();
            int     curFrame   = PerformanceUtils.instance.getCurFrame();

            float barWidth  = Mathf.Max(1, width / costFrames.Length);
            float perHeight = height / 32.0f;

            canvas.drawRect(visualizationRect, paint4);
            canvas.drawRect(Rect.fromLTWH(x, y + perHeight * 16.0f, width, 1), paint3);

            float cur_x   = x;
            Path  barPath = new Path();

            for (var i = 0; i < costFrames.Length; i++)
            {
                if (costFrames[i] != 0)
                {
                    float curHeight = Mathf.Min(perHeight * costFrames[i], height);
                    Rect  barRect   = Rect.fromLTWH(cur_x, y + height - curHeight, barWidth, curHeight);
                    barPath.addRect(barRect);
                }

                cur_x += barWidth;
            }

            canvas.drawPath(barPath, paint);
            if (curFrame >= 0 && curFrame < costFrames.Length && costFrames[curFrame] != 0)
            {
                float curHeight = Mathf.Min(perHeight * costFrames[curFrame], height);
                Rect  barRect   = Rect.fromLTWH(x + barWidth * curFrame, y + height - curHeight, barWidth, curHeight);
                canvas.drawRect(barRect, paint2);

                var pb = new ParagraphBuilder(new ParagraphStyle {
                });
                pb.addText("Frame Cost: " + costFrames[curFrame] + "ms");
                var paragraph = pb.build();
                paragraph.layout(new ParagraphConstraints(width: 300));

                canvas.drawParagraph(paragraph, new Offset(x, y + height - 12));
            }
        }
        public override void paint(
            PaintingContext context,
            Offset center,
            Animation <float> activationAnimation = null,
            Animation <float> enableAnimation     = null,
            bool isDiscrete             = false,
            bool isEnabled              = false,
            bool?isOnTop                = null,
            TextDirection?textDirection = null,
            SliderThemeData sliderTheme = null,
            Thumb?thumb = null
            )
        {
            Canvas     canvas     = context.canvas;
            ColorTween colorTween = new ColorTween(
                begin: sliderTheme.disabledThumbColor,
                end: sliderTheme.thumbColor
                );

            float size      = _thumbSize * sizeTween.evaluate(enableAnimation);
            Path  thumbPath = null;

            switch (textDirection)
            {
            case TextDirection.rtl:
                switch (thumb)
                {
                case Thumb.start:
                    thumbPath = SliderDemoUtils._rightTriangle(size, center);
                    break;

                case Thumb.end:
                    thumbPath = SliderDemoUtils._leftTriangle(size, center);
                    break;
                }

                break;

            case TextDirection.ltr:
                switch (thumb)
                {
                case Thumb.start:
                    thumbPath = SliderDemoUtils._leftTriangle(size, center);
                    break;

                case Thumb.end:
                    thumbPath = SliderDemoUtils._rightTriangle(size, center);
                    break;
                }

                break;
            }

            canvas.drawPath(thumbPath, new Paint {
                color = colorTween.evaluate(enableAnimation)
            });
        }
Beispiel #7
0
    public void paint(Canvas canvas, Size size)
    {
        Path  path  = new Path();
        Paint paint = new Paint();

        path.moveTo(0, 0);
        path.lineTo(0, size.height * 0.75f);
        path.quadTo(size.width * 0.1f, size.height * 0.7f, size.width * 0.17f, size.height * 0.9f);
        path.quadTo(size.width * 0.2f, size.height, size.width * 0.25f, size.height * 0.9f);
        path.quadTo(size.width * 0.4f, size.height * 0.4f, size.width * 0.5f, size.height * 0.7f);
        path.quadTo(size.width * 0.6f, size.height * 0.85f, size.width * 0.85f, size.height * 0.65f);
        path.quadTo(size.width * 0.7f, size.height * 0.9f, size.width, 0);
        path.close();

        paint.color = new Color(0xfaff0000);
        canvas.drawPath(path, paint);

        path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0, size.height * 0.5f);
        path.quadTo(size.width * 0.1f, size.height * 0.8f, size.width * 0.15f, size.height * 0.6f);
        path.quadTo(size.width * 0.2f, size.height * 0.45f, size.width * 0.27f, size.height * 0.6f);
        path.quadTo(size.width * 0.45f, size.height, size.width * 0.5f, size.height * 0.8f);
        path.quadTo(size.width * 0.55f, size.height * 0.45f, size.width * 0.75f, size.height * 0.75f);
        path.quadTo(size.width * 0.85f, size.height * 0.93f, size.width, size.height * 0.6f);
        path.lineTo(size.width, 0);
        path.close();
        paint.color = new Color(0xfcff0000);
        canvas.drawPath(path, paint);

        path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0, size.height * 0.75f);
        path.quadTo(size.width * 0.1f, size.height * 0.55f, size.width * 0.22f, size.height * 0.7f);
        path.quadTo(size.width * 0.3f, size.height * 0.9f, size.width * 0.4f, size.height * 0.75f);
        path.quadTo(size.width * 0.52f, size.height * 0.5f, size.width * 0.65f, size.height * 0.7f);
        path.quadTo(size.width * 0.75f, size.height * 0.85f, size.width, size.height * 0.6f);
        path.lineTo(size.width, 0);
        path.close();
        paint.color = new Color(0xffff0000);
        canvas.drawPath(path, paint);
    }
Beispiel #8
0
        public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color)
        {
            var path = new Path();

            path.fillType = PathFillType.evenOdd;
            path.addRect(rect: outerRect);
            path.addRect(rect: innerRect);
            var paint = new Paint {
                color = color
            };

            canvas.drawPath(path: path, paint: paint);
        }
Beispiel #9
0
        public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color)
        {
            Path path = new Path();

            path.addRect(outerRect);
            path.addRect(innerRect);
            path.winding(PathWinding.clockwise);
            var paint = new Paint {
                color = color
            };

            canvas.drawPath(path, paint);
        }
        public override void paint(Canvas canvas, Size size)
        {
            Paint paint = new Paint();

            paint.color = color;
            float radius = size.width / 2.0f;
            Rect  circle = Rect.fromCircle(center: new Offset(radius, radius), radius: radius);
            Rect  point  = Rect.fromLTWH(0.0f, 0.0f, radius, radius);
            Path  path   = new Path();

            path.addOval(circle);
            path.addRect(point);
            canvas.drawPath(path, paint);
        }
        public override void paint(Canvas canvas, Size size)
        {
            Paint paint = new Paint();

            paint.color = CupertinoTextSelectionUtils._kToolbarBackgroundColor;
            paint.style = PaintingStyle.fill;

            Path triangle = new Path();

            triangle.lineTo(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2, 0.0f);
            triangle.lineTo(0.0f, CupertinoTextSelectionUtils._kToolbarTriangleSize.height);
            triangle.lineTo(-(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2), 0.0f);
            triangle.close();
            canvas.drawPath(triangle, paint);
        }
Beispiel #12
0
        void _debugDrawArrow(Canvas canvas, Paint paint, Offset p0, Offset p1, GrowthDirection direction)
        {
            D.assert(() => {
                if (p0 == p1)
                {
                    return(true);
                }

                D.assert(p0.dx == p1.dx || p0.dy == p1.dy);
                float d = (p1 - p0).distance * 0.2f;
                Offset temp;
                float dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
                switch (direction)
                {
                case GrowthDirection.forward:
                    dx1 = dx2 = dy1 = dy2 = d;
                    break;

                case GrowthDirection.reverse:
                    temp = p0;
                    p0   = p1;
                    p1   = temp;
                    dx1  = dx2 = dy1 = dy2 = -d;
                    break;
                }

                if (p0.dx == p1.dx)
                {
                    dx2 = -dx2;
                }
                else
                {
                    dy2 = -dy2;
                }
                var path = new Path();
                path.moveTo(p0.dx, p0.dy);
                path.lineTo(p1.dx, p1.dy);
                path.moveTo(p1.dx - dx1, p1.dy - dy1);
                path.lineTo(p1.dx, p1.dy);
                path.lineTo(p1.dx - dx2, p1.dy - dy2);
                canvas.drawPath(
                    path,
                    paint
                    );

                return(true);
            });
        }
Beispiel #13
0
        void _paintSelection(Canvas canvas, Offset effectiveOffset)
        {
            D.assert(this._selectionRects != null);
            D.assert(this.selectionColor != null);
            var paint = new Paint {
                color = this.selectionColor
            };

            Path barPath = new Path();

            foreach (var box in this._selectionRects)
            {
                barPath.addRect(box.toRect().shift(effectiveOffset));
            }
            canvas.drawPath(barPath, paint);
        }
Beispiel #14
0
        public void paint(Canvas canvas, Color color, _UiPathFactory uiPathFactory, float progress)
        {
            float opacity = AnimatedIconUtils._interpolate(opacities, progress);
            Paint paint   = new Paint();

            paint.style = PaintingStyle.fill;
            paint.color = color.withOpacity(color.opacity * opacity);
            Path path = uiPathFactory();

            foreach (_PathCommand command in commands)
            {
                command.apply(path, progress);
            }

            canvas.drawPath(path, paint);
        }
Beispiel #15
0
        public override void paint(Canvas canvas, Size size)
        {
            Paint paint = new Paint {
                color = CustomTextSelectionControlsUtils._kToolbarBackgroundColor,
                style = PaintingStyle.fill
            };
            float triangleBottomY = this.arrowDirection == _ArrowDirection.down
                ? 0.0f
                : CustomTextSelectionControlsUtils._kToolbarTriangleSize.height;
            Path triangle = new Path();

            triangle.lineTo(CustomTextSelectionControlsUtils._kToolbarTriangleSize.width / 2, triangleBottomY);
            triangle.lineTo(0.0f, CustomTextSelectionControlsUtils._kToolbarTriangleSize.height);
            triangle.lineTo(-(CustomTextSelectionControlsUtils._kToolbarTriangleSize.width / 2), triangleBottomY);
            triangle.close();
            canvas.drawPath(triangle, paint);
        }
        public override void paint(
            PaintingContext context,
            Offset center,
            Animation <float> activationAnimation = null,
            Animation <float> enableAnimation     = null,
            bool isDiscrete             = false,
            TextPainter labelPainter    = null,
            RenderBox parentBox         = null,
            SliderThemeData sliderTheme = null,
            TextDirection?textDirection = null,
            float?value = null)
        {
            Canvas     canvas      = context.canvas;
            ColorTween enableColor = new ColorTween(
                begin: sliderTheme.disabledThumbColor,
                end: sliderTheme.valueIndicatorColor
                );

            Tween <float> slideUpTween = new FloatTween(
                begin: 0.0f,
                end: _slideUpHeight
                );
            float  size          = _indicatorSize * sizeTween.evaluate(enableAnimation);
            Offset slideUpOffset = new Offset(0.0f, -slideUpTween.evaluate(activationAnimation));
            Path   thumbPath     = SliderDemoUtils._upTriangle(size, center + slideUpOffset);
            Color  paintColor    = enableColor.evaluate(enableAnimation)
                                   .withAlpha((255.0f * activationAnimation.value).round());

            canvas.drawPath(
                thumbPath,
                new Paint {
                color = paintColor
            }
                );
            canvas.drawLine(
                center,
                center + slideUpOffset,
                new Paint
            {
                color       = paintColor,
                style       = PaintingStyle.stroke,
                strokeWidth = 2.0f
            });
            labelPainter.paint(canvas,
                               center + slideUpOffset + new Offset(-labelPainter.width / 2.0f, -labelPainter.height - 4.0f));
        }
        public override void paint(Canvas canvas, Rect rect)
        {
            if (rect.isEmpty)
            {
                return;
            }

            switch (this.side.style)
            {
            case BorderStyle.none:
                break;

            case BorderStyle.solid:
                Path  path  = this.getOuterPath(rect);
                Paint paint = this.side.toPaint();
                canvas.drawPath(path, paint);
                break;
            }
        }
        public override void paint(Canvas canvas, Rect rect)
        {
            if (rect.isEmpty)
            {
                return;
            }

            switch (this.side.style)
            {
            case BorderStyle.none:
                break;

            case BorderStyle.solid:
                Path path = this.getOuterPath(rect);
                path.addPath(this.getInnerPath(rect), Offset.zero);
                canvas.drawPath(path, this.side.toPaint());
                break;
            }
        }
Beispiel #19
0
        public override void paint(Canvas canvas, Rect rect, TextDirection?textDirection = null)
        {
            if (rect.isEmpty)
            {
                return;
            }

            switch (side.style)
            {
            case BorderStyle.none:
                break;

            case BorderStyle.solid:
                Path path = getOuterPath(rect, textDirection);
                path.addPath(getInnerPath(rect, textDirection), Offset.zero);
                canvas.drawPath(path, side.toPaint());
                break;
            }
        }
        public override void paint(Canvas canvas, Rect rect,
            float gapStart,
            float gapExtent = 0.0f,
            float gapPercentage = 0.0f
        ) {
            D.assert(gapPercentage >= 0.0f && gapPercentage <= 1.0f);
            D.assert(_cornersAreCircular(this.borderRadius));

            Paint paint = this.borderSide.toPaint();
            RRect outer = this.borderRadius.toRRect(rect);
            RRect center = outer.deflate(this.borderSide.width / 2.0f);
            if (gapExtent <= 0.0f || gapPercentage == 0.0f) {
                canvas.drawRRect(center, paint);
            }
            else {
                float extent = MathUtils.lerpFloat(0.0f, gapExtent + this.gapPadding * 2.0f, gapPercentage);
                Path path = this._gapBorderPath(canvas, center, Mathf.Max(0.0f,gapStart - this.gapPadding), extent);
                canvas.drawPath(path, paint);
            }
        }
        public override void paint(Canvas canvas, Size size)
        {
            if (NodeGraphData == null || NodeGraphData.allNodes.Count <= 0)
            {
                return;
            }

            Vector2 inPortPos  = NodeGraphData.allNodes[0].outDataPorts[0].portCenter;
            Vector2 outPortPos = NodeGraphData.allNodes[1].inDataPorts[0].portCenter;

            Paint bezierPaint = new Paint {
                style = PaintingStyle.stroke, color = Colors.yellow, strokeWidth = 4
            };

            float controlPointOffsetX = Mathf.Abs((inPortPos - outPortPos).x) / 2;

            Path bezierPath = new Path();

            bezierPath.moveTo(inPortPos.x, inPortPos.y);
            bezierPath.bezierTo(inPortPos.x + controlPointOffsetX, inPortPos.y, outPortPos.x - controlPointOffsetX, outPortPos.y, outPortPos.x, outPortPos.y);

            canvas.drawPath(bezierPath, bezierPaint);
        }
        public static void paintZigZag(Canvas canvas, Paint paint, Offset start, Offset end, int zigs, float width)
        {
            D.assert(MathUtils.isFinite(zigs));
            D.assert(zigs > 0);
            canvas.save();
            canvas.translate(start.dx, start.dy);
            end = end - start;
            canvas.rotate(Mathf.Atan2(end.dy, end.dx));
            float length  = end.distance;
            float spacing = length / (zigs * 2.0f);
            Path  path    = new Path();

            path.moveTo(0.0f, 0.0f);
            for (int index = 0; index < zigs; index += 1)
            {
                float x = (index * 2.0f + 1.0f) * spacing;
                float y = width * ((index % 2.0f) * 2.0f - 1.0f);
                path.lineTo(x, y);
            }

            path.lineTo(length, 0.0f);
            canvas.drawPath(path, paint);
            canvas.restore();
        }
Beispiel #23
0
        public override void paint(Canvas canvas, Size size)
        {
            float halfStrokeWidth = 1.0f;
            Paint paint           = new Paint();

            paint.color = color;
            Rect circle = Rect.fromCircle(
                center: new Offset(CupertinoTextSelectionUtils._kSelectionHandleRadius, CupertinoTextSelectionUtils._kSelectionHandleRadius),
                radius: CupertinoTextSelectionUtils._kSelectionHandleRadius
                );
            Rect line = Rect.fromPoints(
                new Offset(
                    CupertinoTextSelectionUtils._kSelectionHandleRadius - halfStrokeWidth,
                    2 * CupertinoTextSelectionUtils._kSelectionHandleRadius - CupertinoTextSelectionUtils._kSelectionHandleOverlap
                    ),
                new Offset(CupertinoTextSelectionUtils._kSelectionHandleRadius + halfStrokeWidth, size.height)
                );
            Path path = new Path();

            path.addOval(circle);
            // Draw line so it slightly overlaps the circle.
            path.addRect(line);
            canvas.drawPath(path, paint);
        }
        public override void paint(
            PaintingContext context,
            Offset center,
            Animation <float> activationAnimation = null,
            Animation <float> enableAnimation     = null,
            bool isDiscrete             = false,
            TextPainter labelPainter    = null,
            RenderBox parentBox         = null,
            SliderThemeData sliderTheme = null,
            TextDirection?textDirection = null,
            float?value = null)
        {
            Canvas     canvas     = context.canvas;
            ColorTween colorTween = new ColorTween(
                begin: sliderTheme.disabledThumbColor,
                end: sliderTheme.thumbColor
                );
            float size      = _thumbSize * sizeTween.evaluate(enableAnimation);
            Path  thumbPath = SliderDemoUtils._downTriangle(size, center);

            canvas.drawPath(thumbPath, new Paint {
                color = colorTween.evaluate(enableAnimation)
            });
        }
        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);
        }
Beispiel #26
0
        public static void paintBorder(Canvas canvas, Rect rect,
                                       BorderSide top    = null,
                                       BorderSide right  = null,
                                       BorderSide bottom = null,
                                       BorderSide left   = null
                                       )
        {
            D.assert(canvas != null);
            D.assert(rect != null);
            top    = top ?? BorderSide.none;
            right  = right ?? BorderSide.none;
            bottom = bottom ?? BorderSide.none;
            left   = left ?? BorderSide.none;

            switch (top.style)
            {
            case BorderStyle.solid:
                Paint paint = new Paint {
                    strokeWidth = 0.0f,
                    color       = top.color,
                };

                Path path = new Path();
                path.moveTo(rect.left, rect.top);
                path.lineTo(rect.right, rect.top);
                if (top.width == 0.0f)
                {
                    paint.style = PaintingStyle.stroke;
                }
                else
                {
                    paint.style = PaintingStyle.fill;
                    path.lineTo(rect.right - right.width, rect.top + top.width);
                    path.lineTo(rect.left + left.width, rect.top + top.width);
                }

                canvas.drawPath(path, paint);
                break;

            case BorderStyle.none:
                break;
            }

            switch (right.style)
            {
            case BorderStyle.solid:
                Paint paint = new Paint {
                    strokeWidth = 0.0f,
                    color       = right.color,
                };

                Path path = new Path();
                path.moveTo(rect.right, rect.top);
                path.lineTo(rect.right, rect.bottom);
                if (right.width == 0.0)
                {
                    paint.style = PaintingStyle.stroke;
                }
                else
                {
                    paint.style = PaintingStyle.fill;
                    path.lineTo(rect.right - right.width, rect.bottom - bottom.width);
                    path.lineTo(rect.right - right.width, rect.top + top.width);
                }

                canvas.drawPath(path, paint);
                break;

            case BorderStyle.none:
                break;
            }

            switch (bottom.style)
            {
            case BorderStyle.solid:
                Paint paint = new Paint {
                    strokeWidth = 0.0f,
                    color       = bottom.color,
                };

                Path path = new Path();
                path.moveTo(rect.right, rect.bottom);
                path.lineTo(rect.left, rect.bottom);
                if (bottom.width == 0.0)
                {
                    paint.style = PaintingStyle.stroke;
                }
                else
                {
                    paint.style = PaintingStyle.fill;
                    path.lineTo(rect.left + left.width, rect.bottom - bottom.width);
                    path.lineTo(rect.right - right.width, rect.bottom - bottom.width);
                }

                canvas.drawPath(path, paint);
                break;

            case BorderStyle.none:
                break;
            }

            switch (left.style)
            {
            case BorderStyle.solid:
                Paint paint = new Paint {
                    strokeWidth = 0.0f,
                    color       = left.color,
                };

                Path path = new Path();
                path.moveTo(rect.left, rect.bottom);
                path.lineTo(rect.left, rect.top);
                if (left.width == 0.0f)
                {
                    paint.style = PaintingStyle.stroke;
                }
                else
                {
                    paint.style = PaintingStyle.fill;
                    path.lineTo(rect.left + left.width, rect.top + top.width);
                    path.lineTo(rect.left + left.width, rect.bottom - bottom.width);
                }

                canvas.drawPath(path, paint);
                break;

            case BorderStyle.none:
                break;
            }
        }
        void _drawValueIndicator(
            RenderBox parentBox,
            Canvas canvas,
            Offset center,
            Paint paint,
            float scale,
            TextPainter labelPainter
            )
        {
            canvas.save();
            canvas.translate(center.dx, center.dy);

            float textScaleFactor = labelPainter.height / _labelTextDesignSize;
            float overallScale    = scale * textScaleFactor;

            canvas.scale(overallScale, overallScale);
            float inverseTextScale = textScaleFactor != 0 ? 1.0f / textScaleFactor : 0.0f;
            float labelHalfWidth   = labelPainter.width / 2.0f;

            float halfWidthNeeded = Mathf.Max(
                0.0f,
                inverseTextScale * labelHalfWidth - (_topLobeRadius - _labelPadding)
                );

            float shift = this._getIdealOffset(parentBox, halfWidthNeeded, overallScale, center);
            float leftWidthNeeded;
            float rightWidthNeeded;

            if (shift < 0.0)
            {
                shift = Mathf.Max(shift, -halfWidthNeeded);
            }
            else
            {
                shift = Mathf.Min(shift, halfWidthNeeded);
            }

            rightWidthNeeded = halfWidthNeeded + shift;
            leftWidthNeeded  = halfWidthNeeded - shift;

            Path   path          = new Path();
            Offset bottomLobeEnd = this._addBottomLobe(path);

            float neckTriangleBase = _topNeckRadius - bottomLobeEnd.dx;

            float leftAmount  = Mathf.Max(0.0f, Mathf.Min(1.0f, leftWidthNeeded / neckTriangleBase));
            float rightAmount = Mathf.Max(0.0f, Mathf.Min(1.0f, rightWidthNeeded / neckTriangleBase));

            float  leftTheta      = (1.0f - leftAmount) * _thirtyDegrees;
            float  rightTheta     = (1.0f - rightAmount) * _thirtyDegrees;
            Offset neckLeftCenter = new Offset(
                -neckTriangleBase,
                _topLobeCenter.dy + Mathf.Cos(leftTheta) * _neckTriangleHypotenuse
                );
            Offset neckRightCenter = new Offset(
                neckTriangleBase,
                _topLobeCenter.dy + Mathf.Cos(rightTheta) * _neckTriangleHypotenuse
                );

            float leftNeckArcAngle  = _ninetyDegrees - leftTheta;
            float rightNeckArcAngle = Mathf.PI + _ninetyDegrees - rightTheta;

            float  neckStretchBaseline = bottomLobeEnd.dy - Mathf.Max(neckLeftCenter.dy, neckRightCenter.dy);
            float  t           = Mathf.Pow(inverseTextScale, 3.0f);
            float  stretch     = (neckStretchBaseline * t).clamp(0.0f, 10.0f * neckStretchBaseline);
            Offset neckStretch = new Offset(0.0f, neckStretchBaseline - stretch);

            D.assert(() => {
                if (!_debuggingLabelLocation)
                {
                    return(true);
                }

#pragma warning disable 0162
                Offset leftCenter  = _topLobeCenter - new Offset(leftWidthNeeded, 0.0f) + neckStretch;
                Offset rightCenter = _topLobeCenter + new Offset(rightWidthNeeded, 0.0f) + neckStretch;
                Rect valueRect     = Rect.fromLTRB(
                    leftCenter.dx - _topLobeRadius,
                    leftCenter.dy - _topLobeRadius,
                    rightCenter.dx + _topLobeRadius,
                    rightCenter.dy + _topLobeRadius
                    );
                Paint outlinePaint       = new Paint();
                outlinePaint.color       = new Color(0xffff0000);
                outlinePaint.style       = PaintingStyle.stroke;
                outlinePaint.strokeWidth = 1.0f;
                canvas.drawRect(valueRect, outlinePaint);
                return(true);

#pragma warning restore 0162
            });

            _addArc(
                path,
                neckLeftCenter + neckStretch,
                _topNeckRadius,
                0.0f,
                -leftNeckArcAngle
                );
            _addArc(
                path,
                _topLobeCenter - new Offset(leftWidthNeeded, 0.0f) + neckStretch,
                _topLobeRadius,
                _ninetyDegrees + leftTheta,
                _twoSeventyDegrees
                );
            _addArc(
                path,
                _topLobeCenter + new Offset(rightWidthNeeded, 0.0f) + neckStretch,
                _topLobeRadius,
                _twoSeventyDegrees,
                _twoSeventyDegrees + Mathf.PI - rightTheta
                );
            _addArc(
                path,
                neckRightCenter + neckStretch,
                _topNeckRadius,
                rightNeckArcAngle,
                Mathf.PI
                );
            canvas.drawPath(path, paint);

            canvas.save();
            canvas.translate(shift, -_distanceBetweenTopBottomCenters + neckStretch.dy);
            canvas.scale(inverseTextScale, inverseTextScale);
            labelPainter.paint(canvas, Offset.zero - new Offset(labelHalfWidth, labelPainter.height / 2.0f));
            canvas.restore();
            canvas.restore();
        }