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) { foreach (_Circle circle in this.circles) { Paint paint = new Paint(); paint.color = circle.color; Rect rect = Rect.fromLTWH(0.0f, 0.0f, size.width, size.height); canvas.clipRect(rect); float leftFraction = circle.horizontalLeadingOffset; Offset center = new Offset(leftFraction * size.width, size.height / 2.0f); FloatTween radiusTween = new FloatTween( begin: 0.0f, end: _maxRadius(center, size) ); canvas.drawCircle( center, radiusTween.evaluate(circle.animation), paint ); } }
public void paint(Canvas canvas, Size size) { if (_glowOpacity.value == 0.0f) { return; } float baseGlowScale = size.width > size.height ? size.height / size.width : 1.0f; float radius = size.width * 3.0f / 2.0f; float height = Mathf.Min(size.height, size.width * _widthToHeightFactor); float scaleY = _glowSize.value * baseGlowScale; Rect rect = Rect.fromLTWH(0.0f, 0.0f, size.width, height); Offset center = new Offset((size.width / 2.0f) * (0.5f + _displacement), height - radius); Paint paint = new Paint(); paint.color = color.withOpacity(_glowOpacity.value); canvas.save(); canvas.scale(1.0f, scaleY); canvas.clipRect(rect); canvas.drawCircle(center, radius, 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(); } }