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 _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(Canvas canvas, Offset offset, ImageConfiguration configuration) { LinearGradient gradient = _decoration.edgeGradient; if (gradient == null) { return; } TextDirection textDirection = configuration.textDirection; float deltaX = 0.0f; switch (textDirection) { case TextDirection.rtl: deltaX = configuration.size.width; break; case TextDirection.ltr: deltaX = -configuration.size.width; break; } Rect rect = (offset & configuration.size).translate(deltaX, 0.0f); Paint paint = new Paint() { shader = gradient.createShader(rect, textDirection: textDirection) }; canvas.drawRect(rect, paint); }
// describeSemanticsConfiguration todo void _paintCaret(Canvas canvas, Offset effectiveOffset) { D.assert(this._textLayoutLastWidth == this.constraints.maxWidth); var caretOffset = this._textPainter.getOffsetForCaret(this._selection.extendPos, this._caretPrototype); var paint = new Paint() { color = this._cursorColor }; var caretRect = this._caretPrototype.shift(caretOffset + effectiveOffset); if (this.cursorRadius == null) { canvas.drawRect(caretRect, paint); } else { RRect caretRRect = RRect.fromRectAndRadius(caretRect, this.cursorRadius); canvas.drawRRect(caretRRect, paint); } if (!caretRect.Equals(this._lastCaretRect)) { this._lastCaretRect = caretRect; if (this.onCaretChanged != null) { this.onCaretChanged(caretRect); } } }
public override void paint(Canvas canvas, Size size) { if (!this._prepared) { this._prepare(); } canvas.translate(this._translationX(size.width), this._translationY(size.height)); canvas.rotate(this._rotation); canvas.drawRect(BannerConstants._kRect, this._paintShadow); canvas.drawRect(BannerConstants._kRect, this._paintBanner); const float width = BannerConstants._kOffset * 2.0f; this._textPainter.layout(minWidth: width, maxWidth: width); this._textPainter.paint(canvas, BannerConstants._kRect.topLeft + new Offset(0.0f, (BannerConstants._kRect.height - this._textPainter.height) / 2.0f)); }
void _paintDividerBetweenContentAndActions(Canvas canvas, Offset offset) { canvas.drawRect( Rect.fromLTWH( offset.dx, offset.dy + this.contentSection.size.height, this.size.width, this._dividerThickness ), this._dividerPaint ); }
public override void paint(Canvas canvas, Size size) { Paint paint = new Paint(); paint.color = this.color; float radius = size.width / 2.0f; canvas.drawCircle(new Offset(radius, radius), radius, paint); canvas.drawRect(Rect.fromLTWH(0.0f, 0.0f, radius, radius), paint); }
public override void paint(Canvas canvas, Size size) { Paint paint = new Paint(); paint.color = this.backgroundColor; paint.style = PaintingStyle.fill; canvas.drawRect(Offset.zero & size, paint); paint.color = this.valueColor; void drawBar(float x, float width) { if (width <= 0.0f) { return; } float left = x; canvas.drawRect(new Offset(left, 0.0f) & new Size(width, size.height), paint); } if (this.value != null) { drawBar(0.0f, this.value.Value.clamp(0.0f, 1.0f) * size.width); } else { float x1 = size.width * line1Tail.transform(this.animationValue ?? 0.0f); float width1 = size.width * line1Head.transform(this.animationValue ?? 0.0f) - x1; float x2 = size.width * line2Tail.transform(this.animationValue ?? 0.0f); float width2 = size.width * line2Head.transform(this.animationValue ?? 0.0f) - x2; drawBar(x1, width1); drawBar(x2, width2); } }
void _paintSelection(Canvas canvas, Offset effectiveOffset) { D.assert(this._textLayoutLastWidth == this.constraints.maxWidth); D.assert(this._selectionRects != null); var paint = new Paint() { color = this._selectionColor }; foreach (var box in this._selectionRects) { canvas.drawRect(box.toRect().shift(effectiveOffset), paint); } }
void _paintHorizontalThumb(Canvas canvas, Size size, float thumbOffset, float thumbExtent) { Offset thumbOrigin = new Offset(thumbOffset, size.height - this.thickness); Size thumbSize = new Size(thumbExtent, this.thickness); Rect thumbRect = thumbOrigin & thumbSize; if (this.radius == null) { canvas.drawRect(thumbRect, this._paint); } else { canvas.drawRRect(RRect.fromRectAndRadius(thumbRect, this.radius), this._paint); } }
void _paintVerticalThumb(Canvas canvas, Size size, float thumbOffset, float thumbExtent) { Offset thumbOrigin = new Offset(this._getThumbX(size), thumbOffset); Size thumbSize = new Size(this.thickness, thumbExtent); Rect thumbRect = thumbOrigin & thumbSize; if (this.radius == null) { canvas.drawRect(thumbRect, this._paint); } else { canvas.drawRRect(RRect.fromRectAndRadius(thumbRect, this.radius), this._paint); } }
public override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { LinearGradient gradient = this._decoration.edgeGradient; if (gradient == null) { return; } float deltaX = -configuration.size.width; Rect rect = (offset & configuration.size).translate(deltaX, 0.0f); Paint paint = new Paint(); paint.shader = gradient.createShader(rect); canvas.drawRect(rect, paint); }
void _paintThumbCrossAxis(Canvas canvas, Size size, float thumbOffset, float thumbExtent, AxisDirection direction) { float x = 0; float y = 0; Size thumbSize = Size.zero; switch (direction) { case AxisDirection.down: thumbSize = new Size(thickness, thumbExtent); x = textDirection == TextDirection.rtl ? crossAxisMargin + padding.left : size.width - thickness - crossAxisMargin - padding.right; y = thumbOffset; break; case AxisDirection.up: thumbSize = new Size(thickness, thumbExtent); x = textDirection == TextDirection.rtl ? crossAxisMargin + padding.left : size.width - thickness - crossAxisMargin - padding.right; y = thumbOffset; break; case AxisDirection.left: thumbSize = new Size(thumbExtent, thickness); x = thumbOffset; y = size.height - thickness - crossAxisMargin - padding.bottom; break; case AxisDirection.right: thumbSize = new Size(thumbExtent, thickness); x = thumbOffset; y = size.height - thickness - crossAxisMargin - padding.bottom; break; } _thumbRect = new Offset(x, y) & thumbSize; if (radius == null) { canvas.drawRect(_thumbRect, _paint); } else { canvas.drawRRect(RRect.fromRectAndRadius(_thumbRect, radius), _paint); } }
public static void debugPaintPadding(Canvas canvas, Rect outerRect, Rect innerRect, float outlineWidth = 2.0f) { assert(() => { if (innerRect != null && !innerRect.isEmpty) { _debugDrawDoubleRect(canvas, outerRect, innerRect, new Color(0x900090FF)); _debugDrawDoubleRect(canvas, innerRect.inflate(outlineWidth).intersect(outerRect), innerRect, new Color(0xFF0090FF)); } else { Paint paint = new Paint(); paint.color = new Color(0x90909090); canvas.drawRect(outerRect, paint); } return(true); }); }
public override void paint(Canvas canvas, Size size) { var paint = new Paint(); paint.style = PaintingStyle.fill; var chart = this.animation.value; foreach (var bar in chart.bars) { paint.color = bar.color; canvas.drawRect( Rect.fromLTWH( bar.x, size.height - bar.height, bar.width, bar.height ), paint ); } }
void _paintBox(Canvas canvas, Rect rect, Paint paint) { switch (this._decoration.shape) { case BoxShape.circle: D.assert(this._decoration.borderRadius == null); Offset center = rect.center; float radius = rect.shortestSide / 2.0f; canvas.drawCircle(center, radius, paint); break; case BoxShape.rectangle: if (this._decoration.borderRadius == null) { canvas.drawRect(rect, paint); } else { canvas.drawRRect(this._decoration.borderRadius.toRRect(rect), paint); } break; } }
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 ); }
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(); }