Exemplo n.º 1
0
        void _showCaretOnScreen()
        {
            if (this._showCaretOnScreenScheduled)
            {
                return;
            }

            this._showCaretOnScreenScheduled = true;
            SchedulerBinding.instance.addPostFrameCallback(_ => {
                this._showCaretOnScreenScheduled = false;
                if (this._currentCaretRect == null || !this._scrollController.hasClients)
                {
                    return;
                }

                float scrollOffsetForCaret = this._getScrollOffsetForCaret(this._currentCaretRect);
                this._scrollController.animateTo(scrollOffsetForCaret,
                                                 duration: _caretAnimationDuration,
                                                 curve: _caretAnimationCurve);

                Rect newCaretRect = this._getCaretRectAtScrollOffset(this._currentCaretRect, scrollOffsetForCaret);
                // Enlarge newCaretRect by scrollPadding to ensure that caret is not positioned directly at the edge after scrolling.
                Rect inflatedRect = Rect.fromLTRB(
                    newCaretRect.left - this.widget.scrollPadding.left,
                    newCaretRect.top - this.widget.scrollPadding.top,
                    newCaretRect.right + this.widget.scrollPadding.right,
                    newCaretRect.bottom + this.widget.scrollPadding.bottom
                    );
                this._editableKey.currentContext.findRenderObject().showOnScreen(
                    rect: inflatedRect,
                    duration: _caretAnimationDuration,
                    curve: _caretAnimationCurve
                    );
            });
        }
Exemplo n.º 2
0
 public Rect getRowBox(int row)
 {
     D.assert(row >= 0);
     D.assert(row < rows);
     D.assert(!debugNeedsLayout);
     return(Rect.fromLTRB(0.0f, _rowTops[row], size.width, _rowTops[row + 1]));
 }
Exemplo n.º 3
0
        Rect _adjustRect(Rect rect)
        {
            if (circleness == 0.0 || rect.width == rect.height)
            {
                return(rect);
            }

            if (rect.width < rect.height)
            {
                float delta = circleness * (rect.height - rect.width) / 2.0f;
                return(Rect.fromLTRB(
                           rect.left,
                           rect.top + delta,
                           rect.right,
                           rect.bottom - delta
                           ));
            }
            else
            {
                float delta = circleness * (rect.width - rect.height) / 2.0f;
                return(Rect.fromLTRB(
                           rect.left + delta,
                           rect.top,
                           rect.right - delta,
                           rect.bottom
                           ));
            }
        }
Exemplo n.º 4
0
        Rect getRowBox(int row)
        {
            D.assert(row >= 0);
            D.assert(row < this.rows);

            return(Rect.fromLTRB(0.0f, this._rowTops[row], this.size.width, this._rowTops[row + 1]));
        }
Exemplo n.º 5
0
        public override void paint(PaintingContext context, Offset offset)
        {
            Canvas canvas               = context.canvas;
            float  currentValue         = _state.position.value;
            float  currentReactionValue = _state._reaction.value;

            float visualPosition = 0.0f;

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

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

            Paint paint = new Paint()
            {
                color = Color.lerp(trackColor, activeColor, currentValue)
            };
            Rect trackRect = Rect.fromLTWH(
                offset.dx + (size.width - CupertinoSwitchUtils._kTrackWidth) / 2.0f,
                offset.dy + (size.height - CupertinoSwitchUtils._kTrackHeight) / 2.0f,
                CupertinoSwitchUtils._kTrackWidth,
                CupertinoSwitchUtils._kTrackHeight
                );
            RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(CupertinoSwitchUtils._kTrackRadius));

            canvas.drawRRect(trackRRect, paint);

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

            context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect,
                                  (PaintingContext innerContext, Offset offset1) => {
                CupertinoThumbPainter.switchThumb().paint(innerContext.canvas, thumbBounds);
            });
        }
Exemplo n.º 6
0
 public Rect toRect(Rect container)
 {
     return(Rect.fromLTRB(
                this.left + container.left,
                this.top + container.top,
                container.right - this.right,
                container.bottom - this.bottom));
 }
Exemplo n.º 7
0
 public Rect toSize(Size container)
 {
     return(Rect.fromLTRB(
                left,
                top,
                container.width - right,
                container.height - bottom));
 }
Exemplo n.º 8
0
 public Rect toSize(Size container)
 {
     return(Rect.fromLTRB(
                this.left,
                this.top,
                container.width - this.right,
                container.height - this.bottom));
 }
Exemplo n.º 9
0
 public static Rect fromCenter(Offset center, float width, float height)
 {
     return(Rect.fromLTRB(
                center.dx - width / 2,
                center.dy - height / 2,
                center.dx + width / 2,
                center.dy + height / 2
                ));
 }
Exemplo n.º 10
0
 public GlyphInfo(CharacterInfo info)
 {
     this.rect          = Rect.fromLTRB(info.minX, -info.maxY, info.maxX, -info.minY);
     this.advance       = info.advance;
     this.glyphHeight   = info.glyphHeight;
     this.uvTopLeft     = info.uvTopLeft;
     this.uvTopRight    = info.uvTopRight;
     this.uvBottomLeft  = info.uvBottomLeft;
     this.uvBottomRight = info.uvBottomRight;
 }
Exemplo n.º 11
0
        public override void paint(
            PaintingContext context,
            Offset offset,
            RenderBox parentBox               = null,
            SliderThemeData sliderTheme       = null,
            Animation <float> enableAnimation = null,
            Offset thumbCenter = null,
            bool?isEnabled     = null,
            bool?isDiscrete    = null)
        {
            if (sliderTheme.trackHeight == 0)
            {
                return;
            }

            ColorTween activeTrackColorTween = new ColorTween(begin: sliderTheme.disabledActiveTrackColor,
                                                              end: sliderTheme.activeTrackColor);
            ColorTween inactiveTrackColorTween = new ColorTween(begin: sliderTheme.disabledInactiveTrackColor,
                                                                end: sliderTheme.inactiveTrackColor);
            Paint activePaint = new Paint {
                color = activeTrackColorTween.evaluate(enableAnimation)
            };
            Paint inactivePaint = new Paint {
                color = inactiveTrackColorTween.evaluate(enableAnimation)
            };
            Paint leftTrackPaint  = activePaint;
            Paint rightTrackPaint = inactivePaint;

            float horizontalAdjustment = 0.0f;

            if (!isEnabled.Value)
            {
                float disabledThumbRadius = sliderTheme.thumbShape.getPreferredSize(false, isDiscrete).width / 2.0f;
                float gap = this.disabledThumbGapWidth * (1.0f - enableAnimation.value);
                horizontalAdjustment = disabledThumbRadius + gap;
            }

            Rect trackRect = this.getPreferredRect(
                parentBox: parentBox,
                offset: offset,
                sliderTheme: sliderTheme,
                isEnabled: isEnabled,
                isDiscrete: isDiscrete
                );

            Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, thumbCenter.dx - horizontalAdjustment,
                                                  trackRect.bottom);

            context.canvas.drawRect(leftTrackSegment, leftTrackPaint);

            Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx + horizontalAdjustment, trackRect.top,
                                                   trackRect.right, trackRect.bottom);

            context.canvas.drawRect(rightTrackSegment, rightTrackPaint);
        }
Exemplo n.º 12
0
        void paintBackground(Canvas canvas, PaintRecord record, Offset baseOffset)
        {
            if (record.style.background == null)
            {
                return;
            }

            var  metrics = record.metrics;
            Rect rect    = Rect.fromLTRB(0, metrics.ascent, record.runWidth, metrics.descent);

            rect = rect.shift(record.shiftedOffset(baseOffset));
            canvas.drawRect(rect, record.style.background);
        }
Exemplo n.º 13
0
        Rect _getRectFromUpstream(int offset, Rect caretPrototype)
        {
            string flattenedText = _text.toPlainText(includePlaceholders: false);
            var    prevCodeUnit  = _text.codeUnitAt(Mathf.Max(0, offset - 1));

            if (prevCodeUnit == null)
            {
                return(null);
            }

            bool needsSearch = _isUtf16Surrogate(prevCodeUnit.Value) || _text.codeUnitAt(offset) == _zwjUtf16 ||
                               _isUnicodeDirectionality(prevCodeUnit);
            int            graphemeClusterLength = needsSearch ? 2 : 1;
            List <TextBox> boxes = null;

            while ((boxes == null || boxes.isEmpty()) && flattenedText != null)
            {
                int prevRuneOffset = offset - graphemeClusterLength;
                boxes = _paragraph.getBoxesForRange(prevRuneOffset, offset, boxHeightStyle: BoxHeightStyle.strut);
                if (boxes.isEmpty())
                {
                    if (!needsSearch)
                    {
                        break;
                    }

                    if (prevRuneOffset < -flattenedText.Length)
                    {
                        break;
                    }

                    graphemeClusterLength *= 2;
                    continue;
                }

                TextBox   box = boxes[0];
                const int NEWLINE_CODE_UNIT = 10;
                if (prevCodeUnit == NEWLINE_CODE_UNIT)
                {
                    return(Rect.fromLTRB(_emptyOffset.dx, box.bottom,
                                         _emptyOffset.dx, box.bottom + box.bottom - box.top));
                }

                float caretEnd = box.end;
                float dx       = box.direction == TextDirection.rtl ? caretEnd - caretPrototype.width : caretEnd;
                return(Rect.fromLTRB(Mathf.Min(dx, _paragraph.width()), box.top,
                                     Mathf.Min(dx, _paragraph.width()), box.bottom));
            }

            return(null);
        }
Exemplo n.º 14
0
        public static Rect transformRect(Matrix4x4 transform, Rect rect)
        {
            Offset point1 = transformPoint(transform, rect.topLeft);
            Offset point2 = transformPoint(transform, rect.topRight);
            Offset point3 = transformPoint(transform, rect.bottomLeft);
            Offset point4 = transformPoint(transform, rect.bottomRight);

            return(Rect.fromLTRB(
                       _min4(point1.dx, point2.dx, point3.dx, point4.dx),
                       _min4(point1.dy, point2.dy, point3.dy, point4.dy),
                       _max4(point1.dx, point2.dx, point3.dx, point4.dx),
                       _max4(point1.dy, point2.dy, point3.dy, point4.dy)
                       ));
        }
Exemplo n.º 15
0
        internal static Rect _safeTransformRect(Matrix4 transform, Rect rect)
        {
            float[] storage  = transform.storage;
            bool    isAffine = storage[3] == 0.0 &&
                               storage[7] == 0.0 &&
                               storage[15] == 1.0;

            _minMax = _minMax ?? new float[4];

            _accumulate(storage, rect.left, rect.top, true, isAffine);
            _accumulate(storage, rect.right, rect.top, false, isAffine);
            _accumulate(storage, rect.left, rect.bottom, false, isAffine);
            _accumulate(storage, rect.right, rect.bottom, false, isAffine);

            return(Rect.fromLTRB(_minMax[0], _minMax[1], _minMax[2], _minMax[3]));
        }
Exemplo n.º 16
0
        public void addPerformanceOverlay(int enabledOptions, Rect bounds)
        {
            if (this._currentLayer == null)
            {
                return;
            }

            var layer = new PerformanceOverlayLayer(enabledOptions);

            layer.paintBounds = Rect.fromLTRB(
                bounds.left,
                bounds.top,
                bounds.right,
                bounds.bottom
                );
            this._currentLayer.add(layer);
        }
Exemplo n.º 17
0
        public void doLayout(float offset, string text, int start, int count, TextStyle style)
        {
            this._text = text;
            this._advances.Clear();
            this._positions.Clear();
            this._count = count;
            var font = FontManager.instance.getOrCreate(style.fontFamily).font;

            font.RequestCharactersInTexture(this._text.Substring(start, count),
                                            style.UnityFontSize,
                                            style.UnityFontStyle);

            this._advance = 0;
            this._bounds  = null;
            for (int i = 0; i < count; i++)
            {
                int           charIndex = start + i;
                var           ch        = text[charIndex];
                CharacterInfo characterInfo;
                font.GetCharacterInfo(ch, out characterInfo, style.UnityFontSize, style.UnityFontStyle);

                var rect = Rect.fromLTRB(characterInfo.minX, -characterInfo.maxY, characterInfo.maxX,
                                         -characterInfo.minY);
                rect = rect.translate(this._advance, 0);
                if (this._bounds == null || this._bounds.isEmpty)
                {
                    this._bounds = rect;
                }
                else
                {
                    this._bounds = this._bounds.expandToInclude(rect);
                }

                this._positions.Add(this._advance);
                float advance = characterInfo.advance;
                if (ch == '\t')
                {
                    advance = this._tabStops.nextTab((this._advance + offset)) - this._advance;
                }

                this._advances.Add(advance);
                this._advance += advance;
            }
        }
Exemplo n.º 18
0
        Rect _getRectFromDownStream(int offset, Rect caretPrototype)
        {
            string flattenedText = _text.toPlainText(includePlaceholders: false);
            var    nextCodeUnit  =
                _text.codeUnitAt(Mathf.Min(offset, flattenedText == null ? 0 : flattenedText.Length - 1));

            if (nextCodeUnit == null)
            {
                return(null);
            }

            bool           needsSearch           = _isUtf16Surrogate(nextCodeUnit.Value) || nextCodeUnit == _zwjUtf16;
            int            graphemeClusterLength = needsSearch ? 2 : 1;
            List <TextBox> boxes = null;

            while ((boxes == null || boxes.isEmpty()) && flattenedText != null)
            {
                int nextRuneOffset = offset + graphemeClusterLength;
                boxes = _paragraph.getBoxesForRange(offset, nextRuneOffset, boxHeightStyle: BoxHeightStyle.strut);
                if (boxes.isEmpty())
                {
                    if (!needsSearch)
                    {
                        break;
                    }

                    if (nextRuneOffset >= flattenedText.Length << 1)
                    {
                        break;
                    }

                    graphemeClusterLength *= 2;
                    continue;
                }

                TextBox box        = boxes[boxes.Count - 1];
                float   caretStart = box.start;
                float   dx         = box.direction == TextDirection.rtl ? caretStart - caretPrototype.width : caretStart;
                return(Rect.fromLTRB(Mathf.Min(dx, _paragraph.width()), box.top,
                                     Mathf.Min(dx, _paragraph.width()), box.bottom));
            }

            return(null);
        }
Exemplo n.º 19
0
        public override void paint(Canvas canvas, Size size)
        {
            float selectedItemOffset = getSelectedItemOffset();

            FloatTween top = new FloatTween(
                begin: selectedItemOffset.clamp(0.0f, size.height - material_._kMenuItemHeight),
                end: 0.0f
                );

            FloatTween bottom = new FloatTween(
                begin: (top.begin + material_._kMenuItemHeight).clamp(material_._kMenuItemHeight,
                                                                      size.height),
                end: size.height
                );

            Rect rect = Rect.fromLTRB(0.0f, top.evaluate(resize), size.width, bottom.evaluate(resize));

            _painter.paint(canvas, rect.topLeft, new ImageConfiguration(size: rect.size));
        }
Exemplo n.º 20
0
        public override void paint(Canvas canvas, Size size)
        {
            float selectedItemOffset = this.selectedIndex ?? 0 * DropdownConstants._kMenuItemHeight +
                                       Constants.kMaterialListPadding.top;
            FloatTween top = new FloatTween(
                begin: selectedItemOffset.clamp(0.0f, size.height - DropdownConstants._kMenuItemHeight),
                end: 0.0f
                );

            FloatTween bottom = new FloatTween(
                begin: (top.begin + DropdownConstants._kMenuItemHeight).clamp(DropdownConstants._kMenuItemHeight,
                                                                              size.height),
                end: size.height
                );

            Rect rect = Rect.fromLTRB(0.0f, top.evaluate(this.resize), size.width, bottom.evaluate(this.resize));

            this._painter.paint(canvas, rect.topLeft, new ImageConfiguration(size: rect.size));
        }
Exemplo n.º 21
0
 public Rect toRect() {
     return Rect.fromLTRB(this.left, this.top, this.right, this.bottom);
 }
Exemplo n.º 22
0
        public static Rect transformRect(Matrix4 transform, Rect rect)
        {
            float[] storage = transform.storage;
            float   x       = rect.left;
            float   y       = rect.top;
            float   w       = rect.right - x;
            float   h       = rect.bottom - y;

            if (!w.isFinite() || !h.isFinite())
            {
                return(_safeTransformRect(transform, rect));
            }


            float wx = storage[0] * w;
            float hx = storage[4] * h;
            float rx = storage[0] * x + storage[4] * y + storage[12];

            float wy = storage[1] * w;
            float hy = storage[5] * h;
            float ry = storage[1] * x + storage[5] * y + storage[13];

            if (storage[3] == 0.0f && storage[7] == 0.0f && storage[15] == 1.0f)
            {
                float left  = rx;
                float right = rx;
                if (wx < 0)
                {
                    left += wx;
                }
                else
                {
                    right += wx;
                }

                if (hx < 0)
                {
                    left += hx;
                }
                else
                {
                    right += hx;
                }

                float top    = ry;
                float bottom = ry;
                if (wy < 0)
                {
                    top += wy;
                }
                else
                {
                    bottom += wy;
                }

                if (hy < 0)
                {
                    top += hy;
                }
                else
                {
                    bottom += hy;
                }

                return(Rect.fromLTRB(left, top, right, bottom));
            }
            else
            {
                float ww = storage[3] * w;
                float hw = storage[7] * h;
                float rw = storage[3] * x + storage[7] * y + storage[15];

                float ulx = rx / rw;
                float uly = ry / rw;
                float urx = (rx + wx) / (rw + ww);
                float ury = (ry + wy) / (rw + ww);
                float llx = (rx + hx) / (rw + hw);
                float lly = (ry + hy) / (rw + hw);
                float lrx = (rx + wx + hx) / (rw + ww + hw);
                float lry = (ry + wy + hy) / (rw + ww + hw);

                return(Rect.fromLTRB(
                           _min4(ulx, urx, llx, lrx),
                           _min4(uly, ury, lly, lry),
                           _max4(ulx, urx, llx, lrx),
                           _max4(uly, ury, lly, lry)
                           ));
            }
        }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 24
0
        bool _applyClip(Rect queryBounds)
        {
            var         layer       = this._currentLayer;
            var         layerBounds = layer.layerBounds;
            ReducedClip reducedClip = new ReducedClip(layer.clipStack, layerBounds, queryBounds);

            if (reducedClip.isEmpty())
            {
                return(false);
            }

            var scissor      = reducedClip.scissor;
            var physicalRect = Rect.fromLTRB(0, 0, layer.width, layer.height);

            if (scissor == layerBounds)
            {
                this._tryAddScissor(layer, null);
            }
            else
            {
                var deviceScissor = Rect.fromLTRB(
                    scissor.left - layerBounds.left, layerBounds.bottom - scissor.bottom,
                    scissor.right - layerBounds.left, layerBounds.bottom - scissor.top
                    ).scale(layer.width / layerBounds.width, layer.height / layerBounds.height);
                deviceScissor = deviceScissor.roundOut();
                deviceScissor = deviceScissor.intersect(physicalRect);

                if (deviceScissor.isEmpty)
                {
                    return(false);
                }

                this._tryAddScissor(layer, deviceScissor);
            }

            var maskGenID = reducedClip.maskGenID();

            if (this._mustRenderClip(maskGenID, reducedClip.scissor))
            {
                if (maskGenID == ClipStack.wideOpenGenID)
                {
                    layer.ignoreClip = true;
                }
                else
                {
                    layer.ignoreClip = false;

                    var boundsMesh = new MeshMesh(reducedClip.scissor);
                    layer.draws.Add(CanvasShader.stencilClear(layer, boundsMesh));

                    foreach (var maskElement in reducedClip.maskElements)
                    {
                        layer.draws.Add(CanvasShader.stencil0(layer, maskElement.mesh));
                        layer.draws.Add(CanvasShader.stencil1(layer, boundsMesh));
                    }
                }

                this._setLastClipGenId(maskGenID, reducedClip.scissor);
            }

            return(true);
        }
Exemplo n.º 25
0
        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
                                         ));
        }
Exemplo n.º 26
0
        public override void paint(PaintingContext context, Offset offset)
        {
            Canvas canvas = context.canvas;

            float      trackLength            = this.size.width - 2 * _overlayRadius;
            float      value                  = this._state.positionController.value;
            ColorTween activeTrackEnableColor = new ColorTween(begin: this._sliderTheme.disabledActiveTrackColor,
                                                               end: this._sliderTheme.activeTrackColor);
            ColorTween inactiveTrackEnableColor = new ColorTween(begin: this._sliderTheme.disabledInactiveTrackColor,
                                                                 end: this._sliderTheme.inactiveTrackColor);
            ColorTween activeTickMarkEnableColor = new ColorTween(begin: this._sliderTheme.disabledActiveTickMarkColor,
                                                                  end: this._sliderTheme.activeTickMarkColor);
            ColorTween inactiveTickMarkEnableColor =
                new ColorTween(begin: this._sliderTheme.disabledInactiveTickMarkColor,
                               end: this._sliderTheme.inactiveTickMarkColor);

            Paint activeTrackPaint = new Paint {
                color = activeTrackEnableColor.evaluate(this._enableAnimation)
            };
            Paint inactiveTrackPaint = new Paint {
                color = inactiveTrackEnableColor.evaluate(this._enableAnimation)
            };
            Paint activeTickMarkPaint = new Paint {
                color = activeTickMarkEnableColor.evaluate(this._enableAnimation)
            };
            Paint inactiveTickMarkPaint = new Paint
            {
                color = inactiveTickMarkEnableColor.evaluate(this._enableAnimation)
            };

            float visualPosition     = value;
            Paint leftTrackPaint     = activeTrackPaint;
            Paint rightTrackPaint    = inactiveTrackPaint;
            Paint leftTickMarkPaint  = activeTickMarkPaint;
            Paint rightTickMarkPaint = inactiveTickMarkPaint;

            float trackRadius = _trackHeight / 2.0f;
            float thumbGap    = 2.0f;

            float trackVerticalCenter = offset.dy + (this.size.height) / 2.0f;
            float trackLeft           = offset.dx + _overlayRadius;
            float trackTop            = trackVerticalCenter - trackRadius;
            float trackBottom         = trackVerticalCenter + trackRadius;
            float trackRight          = trackLeft + trackLength;
            float trackActive         = trackLeft + trackLength * visualPosition;
            float thumbRadius         =
                this._sliderTheme.thumbShape.getPreferredSize(this.isInteractive, this.isDiscrete).width / 2.0f;
            float trackActiveLeft = Mathf.Max(0.0f,
                                              trackActive - thumbRadius - thumbGap * (1.0f - this._enableAnimation.value));
            float trackActiveRight =
                Mathf.Min(trackActive + thumbRadius + thumbGap * (1.0f - this._enableAnimation.value), trackRight);
            Rect trackLeftRect  = Rect.fromLTRB(trackLeft, trackTop, trackActiveLeft, trackBottom);
            Rect trackRightRect = Rect.fromLTRB(trackActiveRight, trackTop, trackRight, trackBottom);

            Offset thumbCenter = new Offset(trackActive, trackVerticalCenter);

            if (visualPosition > 0.0)
            {
                canvas.drawRect(trackLeftRect, leftTrackPaint);
            }

            if (visualPosition < 1.0)
            {
                canvas.drawRect(trackRightRect, rightTrackPaint);
            }

            this._paintOverlay(canvas, thumbCenter);

            this._paintTickMarks(
                canvas,
                trackLeftRect,
                trackRightRect,
                leftTickMarkPaint,
                rightTickMarkPaint
                );

            if (this.isInteractive && this.label != null &&
                this._valueIndicatorAnimation.status != AnimationStatus.dismissed)
            {
                if (this.showValueIndicator)
                {
                    this._sliderTheme.valueIndicatorShape.paint(
                        context,
                        thumbCenter,
                        activationAnimation: this._valueIndicatorAnimation,
                        enableAnimation: this._enableAnimation,
                        isDiscrete: this.isDiscrete,
                        labelPainter: this._labelPainter,
                        parentBox: this,
                        sliderTheme: this._sliderTheme,
                        value: this._value
                        );
                }
            }

            this._sliderTheme.thumbShape.paint(
                context,
                thumbCenter,
                activationAnimation: this._valueIndicatorAnimation,
                enableAnimation: this._enableAnimation,
                isDiscrete: this.isDiscrete,
                labelPainter: this._labelPainter,
                parentBox: this,
                sliderTheme: this._sliderTheme,
                value: this._value
                );
        }
Exemplo n.º 27
0
        public override void paint(PaintingContext context, Offset offset)
        {
            base.paint(context, offset);
            Offset      bottomRight = size.bottomRight(offset);
            Rect        outer       = Rect.fromLTRB(offset.dx, offset.dy, bottomRight.dx, bottomRight.dy);
            Rect        center      = outer.deflate(horizontalBorderSide.width / 2.0f);
            const float sweepAngle  = Mathf.PI / 2.0f;

            RRect rrect = RRect.fromRectAndCorners(
                center,
                topLeft: borderRadius.topLeft,
                topRight: borderRadius.topRight,
                bottomLeft: borderRadius.bottomLeft,
                bottomRight: borderRadius.bottomRight
                ).scaleRadii();

            Rect tlCorner = Rect.fromLTWH(
                rrect.left,
                rrect.top,
                rrect.tlRadiusX * 2.0f,
                rrect.tlRadiusY * 2.0f
                );
            Rect blCorner = Rect.fromLTWH(
                rrect.left,
                rrect.bottom - (rrect.blRadiusY * 2.0f),
                rrect.blRadiusX * 2.0f,
                rrect.blRadiusY * 2.0f
                );
            Rect trCorner = Rect.fromLTWH(
                rrect.right - (rrect.trRadiusX * 2.0f),
                rrect.top,
                rrect.trRadiusX * 2.0f,
                rrect.trRadiusY * 2.0f
                );
            Rect brCorner = Rect.fromLTWH(
                rrect.right - (rrect.brRadiusX * 2.0f),
                rrect.bottom - (rrect.brRadiusY * 2.0f),
                rrect.brRadiusX * 2.0f,
                rrect.brRadiusY * 2.0f
                );

            Paint leadingPaint = leadingBorderSide.toPaint();

            switch (textDirection)
            {
            case TextDirection.ltr: {
                if (isLastButton)
                {
                    Path leftPath = new Path();
                    leftPath.moveTo(rrect.left, rrect.bottom + leadingBorderSide.width / 2);
                    leftPath.lineTo(rrect.left, rrect.top - leadingBorderSide.width / 2);
                    context.canvas.drawPath(leftPath, leadingPaint);

                    Paint endingPaint = trailingBorderSide.toPaint();
                    Path  endingPath  = new Path();
                    endingPath.moveTo(rrect.left + horizontalBorderSide.width / 2.0f, rrect.top);
                    endingPath.lineTo(rrect.right - rrect.trRadiusX, rrect.top);
                    endingPath.addArc(trCorner, Mathf.PI * 3.0f / 2.0f, sweepAngle);
                    endingPath.lineTo(rrect.right, rrect.bottom - rrect.brRadiusY);
                    endingPath.addArc(brCorner, 0, sweepAngle);
                    endingPath.lineTo(rrect.left + horizontalBorderSide.width / 2.0f, rrect.bottom);
                    context.canvas.drawPath(endingPath, endingPaint);
                }
                else if (isFirstButton)
                {
                    Path leadingPath = new Path();
                    leadingPath.moveTo(outer.right, rrect.bottom);
                    leadingPath.lineTo(rrect.left + rrect.blRadiusX, rrect.bottom);
                    leadingPath.addArc(blCorner, Mathf.PI / 2.0f, sweepAngle);
                    leadingPath.lineTo(rrect.left, rrect.top + rrect.tlRadiusY);
                    leadingPath.addArc(tlCorner, Mathf.PI, sweepAngle);
                    leadingPath.lineTo(outer.right, rrect.top);
                    context.canvas.drawPath(leadingPath, leadingPaint);
                }
                else
                {
                    Path leadingPath = new Path();
                    leadingPath.moveTo(rrect.left, rrect.bottom + leadingBorderSide.width / 2);
                    leadingPath.lineTo(rrect.left, rrect.top - leadingBorderSide.width / 2);
                    context.canvas.drawPath(leadingPath, leadingPaint);

                    Paint horizontalPaint = horizontalBorderSide.toPaint();
                    Path  horizontalPaths = new Path();
                    horizontalPaths.moveTo(rrect.left + horizontalBorderSide.width / 2.0f, rrect.top);
                    horizontalPaths.lineTo(outer.right - rrect.trRadiusX, rrect.top);
                    horizontalPaths.moveTo(rrect.left + horizontalBorderSide.width / 2.0f + rrect.tlRadiusX,
                                           rrect.bottom);
                    horizontalPaths.lineTo(outer.right - rrect.trRadiusX, rrect.bottom);
                    context.canvas.drawPath(horizontalPaths, horizontalPaint);
                }

                break;
            }

            case TextDirection.rtl: {
                if (isLastButton)
                {
                    Path leadingPath = new Path();
                    leadingPath.moveTo(rrect.right, rrect.bottom + leadingBorderSide.width / 2);
                    leadingPath.lineTo(rrect.right, rrect.top - leadingBorderSide.width / 2);
                    context.canvas.drawPath(leadingPath, leadingPaint);

                    Paint endingPaint = trailingBorderSide.toPaint();
                    Path  endingPath  = new Path();
                    endingPath.moveTo(rrect.right - horizontalBorderSide.width / 2.0f, rrect.top);
                    endingPath.lineTo(rrect.left + rrect.tlRadiusX, rrect.top);
                    endingPath.addArc(tlCorner, Mathf.PI * 3.0f / 2.0f, -sweepAngle);
                    endingPath.lineTo(rrect.left, rrect.bottom - rrect.blRadiusY);
                    endingPath.addArc(blCorner, Mathf.PI, -sweepAngle);
                    endingPath.lineTo(rrect.right - horizontalBorderSide.width / 2.0f, rrect.bottom);
                    context.canvas.drawPath(endingPath, endingPaint);
                }
                else if (isFirstButton)
                {
                    Path leadingPath = new Path();
                    leadingPath.moveTo(outer.left, rrect.bottom);
                    leadingPath.lineTo(rrect.right - rrect.brRadiusX, rrect.bottom);
                    leadingPath.addArc(brCorner, Mathf.PI / 2.0f, -sweepAngle);
                    leadingPath.lineTo(rrect.right, rrect.top + rrect.trRadiusY);
                    leadingPath.addArc(trCorner, 0, -sweepAngle);
                    leadingPath.lineTo(outer.left, rrect.top);
                    context.canvas.drawPath(leadingPath, leadingPaint);
                }
                else
                {
                    Path leadingPath = new Path();
                    leadingPath.moveTo(rrect.right, rrect.bottom + leadingBorderSide.width / 2);
                    leadingPath.lineTo(rrect.right, rrect.top - leadingBorderSide.width / 2);
                    context.canvas.drawPath(leadingPath, leadingPaint);

                    Paint horizontalPaint = horizontalBorderSide.toPaint();
                    Path  horizontalPaths = new Path();
                    horizontalPaths.moveTo(rrect.right - horizontalBorderSide.width / 2.0f, rrect.top);
                    horizontalPaths.lineTo(outer.left - rrect.tlRadiusX, rrect.top);
                    horizontalPaths.moveTo(rrect.right - horizontalBorderSide.width / 2.0f + rrect.trRadiusX,
                                           rrect.bottom);
                    horizontalPaths.lineTo(outer.left - rrect.tlRadiusX, rrect.bottom);
                    context.canvas.drawPath(horizontalPaths, horizontalPaint);
                }

                break;
            }
            }
        }
Exemplo n.º 28
0
 public Rect inflateRect(Rect rect)
 {
     return(Rect.fromLTRB(
                rect.left - left, rect.top - top,
                rect.right + right, rect.bottom + bottom));
 }
Exemplo n.º 29
0
 public Rect deflateRect(Rect rect)
 {
     return(Rect.fromLTRB(
                rect.left + left, rect.top + top,
                rect.right - right, rect.bottom - bottom));
 }