void _paintSide(Canvas canvas, Size size, _GlowController controller, AxisDirection axisDirection, GrowthDirection growthDirection) { if (controller == null) { return; } switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) { case AxisDirection.up: controller.paint(canvas, size); break; case AxisDirection.down: canvas.save(); canvas.translate(0.0f, size.height); canvas.scale(1.0f, -1.0f); controller.paint(canvas, size); canvas.restore(); break; case AxisDirection.left: canvas.save(); canvas.rotate(piOver2); canvas.scale(1.0f, -1.0f); controller.paint(canvas, new Size(size.height, size.width)); canvas.restore(); break; case AxisDirection.right: canvas.save(); canvas.translate(size.width, 0.0f); canvas.rotate(piOver2); controller.paint(canvas, new Size(size.height, size.width)); canvas.restore(); break; } }
protected override void paintFeature(Canvas canvas, Matrix4 transform) { Paint paint = new Paint { color = this.color.withAlpha(this._alpha.value) }; Offset center = this._position; if (this._repositionToReferenceBox) { center = Offset.lerp(center, this.referenceBox.size.center(Offset.zero), this._radiusController.value); } Offset originOffset = transform.getAsTranslation(); canvas.save(); if (originOffset == null) { canvas.concat(transform.toMatrix3()); } else { canvas.translate(originOffset.dx, originOffset.dy); } if (this._clipCallback != null) { Rect rect = this._clipCallback(); if (this._customBorder != null) { canvas.clipPath(this._customBorder.getOuterPath(rect)); } else if (this._borderRadius != BorderRadius.zero) { canvas.clipRRect(RRect.fromRectAndCorners( rect, topLeft: this._borderRadius.topLeft, topRight: this._borderRadius.topRight, bottomLeft: this._borderRadius.bottomLeft, bottomRight: this._borderRadius.bottomRight)); } else { canvas.clipRect(rect); } } canvas.drawCircle(center, this._radius.value, paint); canvas.restore(); }
public override void paint(Canvas canvas, Size size) { canvas.scale(scale ?? 1.0f, scale ?? 1.0f); if (shouldMirror == true) { canvas.rotate(Mathf.PI); canvas.translate(-size.width, -size.height); } float clampedProgress = progress.value.clamp(0.0f, 1.0f); foreach (_PathFrames path in paths) { path.paint(canvas, color, uiPathFactory, clampedProgress); } }
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)); }
public override void paint(Canvas canvas, Size size) { Paint paint = new Paint(); canvas.save(); canvas.translate(size.width / 2.0f, size.height / 2.0f); int activeTick = (CupertinoActivityIndicatorUtils._kTickCount * position.value).floor(); for (int i = 0; i < CupertinoActivityIndicatorUtils._kTickCount; ++i) { int t = ((i + activeTick) % CupertinoActivityIndicatorUtils._kTickCount); paint.color = activeColor.withAlpha(CupertinoActivityIndicatorUtils._alphaValues[t]); canvas.drawRRect(tickFundamentalRRect, paint); canvas.rotate(-CupertinoActivityIndicatorUtils._kTwoPI / CupertinoActivityIndicatorUtils._kTickCount); } canvas.restore(); }
public override void paint(Canvas canvas, Size size) { Paint paint = new Paint(); canvas.save(); canvas.translate(size.width / 2.0f, size.height / 2.0f); int activeTick = (CupertinoActivityIndicatorUtils._kTickCount * this.position.value).floor(); for (int i = 0; i < CupertinoActivityIndicatorUtils._kTickCount; ++i) { float t = (((i + activeTick) % CupertinoActivityIndicatorUtils._kTickCount) / CupertinoActivityIndicatorUtils._kHalfTickCount).clamp(0, 1); paint.color = Color.lerp(a: CupertinoActivityIndicatorUtils._kActiveTickColor, b: CupertinoActivityIndicatorUtils._kTickColor, t: t); canvas.drawRRect(rect: this.tickFundamentalRRect, paint: paint); canvas.rotate(-CupertinoActivityIndicatorUtils._kTwoPI / CupertinoActivityIndicatorUtils._kTickCount); } canvas.restore(); }
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(); }
public static void paintImage( Canvas canvas = null, Rect rect = null, Image image = null, float scale = 1.0f, ColorFilter colorFilter = null, BoxFit?fit = null, Alignment alignment = null, Rect centerSlice = null, ImageRepeat repeat = ImageRepeat.noRepeat, bool flipHorizontally = false, bool invertColors = false, FilterQuality filterQuality = FilterQuality.low ) { D.assert(canvas != null); D.assert(rect != null); D.assert(image != null); alignment = alignment ?? Alignment.center; if (rect.isEmpty) { return; } Size outputSize = rect.size; Size inputSize = new Size(image.width, image.height); Offset sliceBorder = null; if (centerSlice != null) { sliceBorder = new Offset( centerSlice.left + inputSize.width - centerSlice.right, centerSlice.top + inputSize.height - centerSlice.bottom ); outputSize -= sliceBorder; inputSize -= sliceBorder; } fit = fit ?? (centerSlice == null ? BoxFit.scaleDown : BoxFit.fill); D.assert(centerSlice == null || (fit != BoxFit.none && fit != BoxFit.cover), () => $"centerSlice was used with a BoxFit {fit} that is not supported."); FittedSizes fittedSizes = FittedSizes.applyBoxFit(fit.Value, inputSize / scale, outputSize); Size sourceSize = fittedSizes.source * scale; Size destinationSize = fittedSizes.destination; if (centerSlice != null) { outputSize += sliceBorder; destinationSize += sliceBorder; D.assert(sourceSize == inputSize, () => $"centerSlice was used with a BoxFit {fit} that does not guarantee that the image is fully visible."); } if (repeat != ImageRepeat.noRepeat && destinationSize == outputSize) { repeat = ImageRepeat.noRepeat; } Paint paint = new Paint(); if (colorFilter != null) { paint.colorFilter = colorFilter; } if (sourceSize != destinationSize) { paint.filterQuality = filterQuality; } paint.invertColors = invertColors; float halfWidthDelta = (outputSize.width - destinationSize.width) / 2.0f; float halfHeightDelta = (outputSize.height - destinationSize.height) / 2.0f; float dx = halfWidthDelta + (flipHorizontally ? -alignment.x : alignment.x) * halfWidthDelta; float dy = halfHeightDelta + alignment.y * halfHeightDelta; Offset destinationPosition = rect.topLeft.translate(dx, dy); Rect destinationRect = destinationPosition & destinationSize; bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally; if (needSave) { canvas.save(); } if (flipHorizontally) { float dxInside = -(rect.left + rect.width / 2.0f); canvas.translate(-dxInside, 0.0f); canvas.scale(-1.0f, 1.0f); canvas.translate(dxInside, 0.0f); } if (repeat != ImageRepeat.noRepeat) { canvas.clipRect(rect); } if (centerSlice == null) { Rect sourceRect = alignment.inscribe( sourceSize, Offset.zero & inputSize ); if (repeat == ImageRepeat.noRepeat) { canvas.drawImageRect(image, sourceRect, destinationRect, paint); } else { foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) { canvas.drawImageRect(image, sourceRect, tileRect, paint); } } } else { if (repeat == ImageRepeat.noRepeat) { canvas.drawImageNine(image, centerSlice, destinationRect, paint); } else { foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) { canvas.drawImageNine(image, centerSlice, tileRect, paint); } } } if (needSave) { canvas.restore(); } }
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); }
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(); }