@@ -573,14 +573,43 @@ enum ImageRepeat {
573
573
noRepeat
574
574
}
575
575
576
+ Iterable <Rect > _generateImageTileRects (Rect outputRect, Rect fundamentalRect, ImageRepeat repeat) sync * {
577
+ if (repeat == ImageRepeat .noRepeat) {
578
+ yield fundamentalRect;
579
+ return ;
580
+ }
581
+
582
+ int startX = 0 ;
583
+ int startY = 0 ;
584
+ int stopX = 0 ;
585
+ int stopY = 0 ;
586
+ double strideX = fundamentalRect.width;
587
+ double strideY = fundamentalRect.height;
588
+
589
+ if (repeat == ImageRepeat .repeat || repeat == ImageRepeat .repeatX) {
590
+ startX = ((outputRect.left - fundamentalRect.left) / strideX).floor ();
591
+ stopX = ((outputRect.right - fundamentalRect.right) / strideX).ceil ();
592
+ }
593
+
594
+ if (repeat == ImageRepeat .repeat || repeat == ImageRepeat .repeatY) {
595
+ startY = ((outputRect.top - fundamentalRect.top) / strideY).floor ();
596
+ stopY = ((outputRect.bottom - fundamentalRect.bottom) / strideY).ceil ();
597
+ }
598
+
599
+ for (int i = startX; i <= stopX; ++ i) {
600
+ for (int j = startY; j <= stopY; ++ j)
601
+ yield fundamentalRect.shift (new Offset (i * strideX, j * strideY));
602
+ }
603
+ }
604
+
576
605
/// Paint an image into the given rectangle in the canvas
577
606
void paintImage ({
578
607
Canvas canvas,
579
608
Rect rect,
580
609
ui.Image image,
581
610
ColorFilter colorFilter,
582
611
ImageFit fit,
583
- repeat: ImageRepeat .noRepeat,
612
+ ImageRepeat repeat: ImageRepeat .noRepeat,
584
613
Rect centerSlice,
585
614
double alignX,
586
615
double alignY
@@ -640,18 +669,21 @@ void paintImage({
640
669
// as we apply a nine-patch stretch.
641
670
assert (sourceSize == inputSize);
642
671
}
643
- // TODO(abarth): Implement |repeat|.
644
672
Paint paint = new Paint ()..isAntiAlias = false ;
645
673
if (colorFilter != null )
646
674
paint.colorFilter = colorFilter;
647
675
double dx = (outputSize.width - destinationSize.width) * (alignX ?? 0.5 );
648
676
double dy = (outputSize.height - destinationSize.height) * (alignY ?? 0.5 );
649
677
Point destinationPosition = rect.topLeft + new Offset (dx, dy);
650
678
Rect destinationRect = destinationPosition & destinationSize;
651
- if (centerSlice == null )
652
- canvas.drawImageRect (image, Point .origin & sourceSize, destinationRect, paint);
653
- else
654
- canvas.drawImageNine (image, centerSlice, destinationRect, paint);
679
+ if (centerSlice == null ) {
680
+ Rect sourceRect = Point .origin & sourceSize;
681
+ for (Rect tileRect in _generateImageTileRects (rect, destinationRect, repeat))
682
+ canvas.drawImageRect (image, sourceRect, tileRect, paint);
683
+ } else {
684
+ for (Rect tileRect in _generateImageTileRects (rect, destinationRect, repeat))
685
+ canvas.drawImageNine (image, centerSlice, tileRect, paint);
686
+ }
655
687
}
656
688
657
689
/// A background image for a box.
0 commit comments