コード例 #1
0
        public override void paint(Canvas canvas, Rect rect, TextDirection?textDirection = null)
        {
            switch (side.style)
            {
            case BorderStyle.none:
                break;

            case BorderStyle.solid:
                float width = side.width;
                if (width == 0.0)
                {
                    canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), side.toPaint());
                }
                else
                {
                    RRect outer = borderRadius.resolve(textDirection).toRRect(rect);
                    RRect inner = outer.deflate(width);
                    Paint paint = new Paint {
                        color = side.color,
                    };
                    canvas.drawDRRect(outer, inner, paint);
                }

                break;
            }
        }
コード例 #2
0
        void _drawBorder(Canvas canvas, RRect outer, float t, Paint paint)
        {
            D.assert(t >= 0.0f && t <= 0.5f);
            float size  = outer.width;
            RRect inner = outer.deflate(Mathf.Min(size / 2.0f, CheckboxUtils._kStrokeWidth + size * t));

            canvas.drawDRRect(outer, inner, paint);
        }
コード例 #3
0
ファイル: switch.cs プロジェクト: JC-ut0/CubeGame
        public override void paint(PaintingContext context, Offset offset)
        {
            Canvas canvas = context.canvas;

            float currentValue         = this._position.value;
            float currentReactionValue = this._reaction.value;

            float visualPosition = 0f;

            switch (this.textDirection)
            {
            case TextDirection.rtl:
                visualPosition = 1.0f - currentValue;
                break;

            case TextDirection.ltr:
                visualPosition = currentValue;
                break;
            }

            Color trackColor      = this._value ? this.activeColor : CupertinoSwitchUtils._kTrackColor;
            float borderThickness =
                1.5f + (CupertinoSwitchUtils._kTrackRadius - 1.5f) * Mathf.Max(currentReactionValue, currentValue);

            Paint paint = new Paint();

            paint.color = trackColor;

            Rect trackRect = Rect.fromLTWH(
                offset.dx + (this.size.width - CupertinoSwitchUtils._kTrackWidth) / 2.0f,
                offset.dy + (this.size.height - CupertinoSwitchUtils._kTrackHeight) / 2.0f,
                CupertinoSwitchUtils._kTrackWidth,
                CupertinoSwitchUtils._kTrackHeight
                );
            RRect outerRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(CupertinoSwitchUtils
                                                                                  ._kTrackRadius));
            RRect innerRRect = RRect.fromRectAndRadius(trackRect.deflate(borderThickness), Radius.circular
                                                           (CupertinoSwitchUtils._kTrackRadius));

            canvas.drawDRRect(outerRRect, innerRRect, paint);

            float currentThumbExtension = CupertinoThumbPainter.extension * currentReactionValue;
            float thumbLeft             = MathUtils.lerpFloat(
                trackRect.left + CupertinoSwitchUtils._kTrackInnerStart - CupertinoThumbPainter.radius,
                trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd - CupertinoThumbPainter.radius -
                currentThumbExtension,
                visualPosition
                );
            float thumbRight = MathUtils.lerpFloat(
                trackRect.left + CupertinoSwitchUtils._kTrackInnerStart + CupertinoThumbPainter.radius +
                currentThumbExtension,
                trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd + CupertinoThumbPainter.radius,
                visualPosition
                );
            float thumbCenterY = offset.dy + this.size.height / 2.0f;

            this._thumbPainter.paint(canvas, Rect.fromLTRB(
                                         thumbLeft,
                                         thumbCenterY - CupertinoThumbPainter.radius,
                                         thumbRight,
                                         thumbCenterY + CupertinoThumbPainter.radius
                                         ));
        }