drawAtlas method
Draws part of an image - the atlas
- onto the canvas.
This method allows for optimization when you only want to draw part of an image on the canvas, such as when using sprites or zooming. It is more efficient than using clips or masks directly.
All parameters must not be null.
See also:
- drawRawAtlas, which takes its arguments as typed data lists rather than objects.
Implementation
void drawAtlas(Image atlas,
List<RSTransform> transforms,
List<Rect> rects,
List<Color> colors,
BlendMode blendMode,
Rect cullRect,
Paint paint) {
assert(atlas != null); // atlas is checked on the engine side
assert(transforms != null);
assert(rects != null);
assert(colors != null);
assert(blendMode != null);
assert(paint != null);
final int rectCount = rects.length;
if (transforms.length != rectCount)
throw ArgumentError('"transforms" and "rects" lengths must match.');
if (colors.isNotEmpty && colors.length != rectCount)
throw ArgumentError('If non-null, "colors" length must match that of "transforms" and "rects".');
final Float32List rstTransformBuffer = Float32List(rectCount * 4);
final Float32List rectBuffer = Float32List(rectCount * 4);
for (int i = 0; i < rectCount; ++i) {
final int index0 = i * 4;
final int index1 = index0 + 1;
final int index2 = index0 + 2;
final int index3 = index0 + 3;
final RSTransform rstTransform = transforms[i];
final Rect rect = rects[i];
assert(_rectIsValid(rect));
rstTransformBuffer[index0] = rstTransform.scos;
rstTransformBuffer[index1] = rstTransform.ssin;
rstTransformBuffer[index2] = rstTransform.tx;
rstTransformBuffer[index3] = rstTransform.ty;
rectBuffer[index0] = rect.left;
rectBuffer[index1] = rect.top;
rectBuffer[index2] = rect.right;
rectBuffer[index3] = rect.bottom;
}
final Int32List colorBuffer = colors.isEmpty ? null : _encodeColorList(colors);
final Float32List cullRectBuffer = cullRect?._value32;
_drawAtlas(
paint._objects, paint._data, atlas, rstTransformBuffer, rectBuffer,
colorBuffer, blendMode.index, cullRectBuffer
);
}