createTilingInfo function

  1. @visibleForTesting
ImageTilingInfo createTilingInfo(
  1. ImageRepeat repeat,
  2. Rect rect,
  3. Rect destinationRect,
  4. Rect sourceRect
)

Create the ImageTilingInfo for a given ImageRepeat, canvas rect, destinationRect, and sourceRect.

Implementation

@visibleForTesting
ImageTilingInfo createTilingInfo(ImageRepeat repeat, Rect rect, Rect destinationRect, Rect sourceRect) {
  assert(repeat != ImageRepeat.noRepeat);
  final TileMode tmx = (repeat == ImageRepeat.repeatX || repeat == ImageRepeat.repeat)
    ? TileMode.repeated
    : TileMode.decal;
  final TileMode tmy = (repeat == ImageRepeat.repeatY || repeat == ImageRepeat.repeat)
    ? TileMode.repeated
    : TileMode.decal;
  final Rect data = _generateImageTileRects(rect, destinationRect, repeat).first;
  final Matrix4 transform = Matrix4.identity()
    ..scale(data.width / sourceRect.width, data.height / sourceRect.height)
    ..setTranslationRaw(data.topLeft.dx, data.topLeft.dy, 0);

  return ImageTilingInfo(
    tmx: tmx,
    tmy: tmy,
    transform: transform,
  );
}