|
|
|
|
|
|
public static class DecorationImageUtil |
|
|
|
{ |
|
|
|
public static void paintImage(Canvas canvas, Rect rect, ui.Image image, BoxFit fit, Rect centerSlice, Alignment alignment = null, |
|
|
|
ImageRepeat repeat = ImageRepeat.noRepeat, bool flipHorizontally = false) // todo more parameters
|
|
|
|
ImageRepeat repeat = ImageRepeat.noRepeat, bool flipHorizontally = false) |
|
|
|
{ |
|
|
|
if (rect.isEmpty) |
|
|
|
return; |
|
|
|
|
|
|
double dy = halfHeightDelta + alignment.y * halfHeightDelta; |
|
|
|
Offset destinationPosition = rect.topLeft.translate(dx, dy); |
|
|
|
Rect destinationRect = destinationPosition & destinationSize; |
|
|
|
// todo repeat and flip
|
|
|
|
// bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally;
|
|
|
|
// if (needSave)
|
|
|
|
// canvas.save();
|
|
|
|
// if (repeat != ImageRepeat.noRepeat)
|
|
|
|
// canvas.clipRect(rect);
|
|
|
|
bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally; |
|
|
|
if (needSave) |
|
|
|
canvas.save(); |
|
|
|
if (repeat != ImageRepeat.noRepeat) |
|
|
|
canvas.clipRect(rect); |
|
|
|
// todo flip
|
|
|
|
// if (flipHorizontally) {
|
|
|
|
// dx = -(rect.left + rect.width / 2.0);
|
|
|
|
// canvas.translate(-dx, 0.0);
|
|
|
|
|
|
|
fittedSizes.source, Offset.zero & inputSize |
|
|
|
); |
|
|
|
foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) { |
|
|
|
// canvas.drawImageRect(sourceRect, tileRect, paint, image);
|
|
|
|
canvas.drawImageRect(sourceRect, tileRect, paint, image); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// todo
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// if (needSave)
|
|
|
|
// canvas.restore();
|
|
|
|
if (needSave) |
|
|
|
canvas.restore(); |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, |
|
|
|
|
|
|
{ |
|
|
|
for (int j = startY; j <= stopY; ++j) |
|
|
|
tileRects.Add(fundamentalRect.shift(new Offset(i * strideX, j * strideY))); |
|
|
|
// yield return fundamentalRect.shift(new Offset(i * strideX, j * strideY));
|
|
|
|
} |
|
|
|
|
|
|
|
return tileRects; |
|
|
|