TxImageSpriteBlock constructor

TxImageSpriteBlock({
  1. required int msgCode,
  2. required TxSprite image,
  3. required int spriteLineHeight,
  4. bool progressiveRender = true,
  5. bool updatable = true,
})

Represents an image of a specified size sliced into a number of "sprite lines" of the full width of the image, and the specified height, and possibly a final sprite line of a different height. When sending TxImageSpriteBlock to Frame, the sendMessage() will send the header with block dimensions and sprite line height, and the user then sends each line[] as a TxSprite message with the same msgCode as the Block, and the frame app will use the line height to place each line. By sending each line separately we can display them as they arrive, as well as reducing overall memory requirement (each concat() call is smaller). Sending an ImageSpriteBlock with no lines is not intended usage.

Implementation

TxImageSpriteBlock({
  required super.msgCode,
  required TxSprite image,
  required int spriteLineHeight,
  bool progressiveRender = true,
  bool updatable = true
  }) : _image = image,
       _spriteLineHeight = spriteLineHeight,
       _progressiveRender = progressiveRender,
       _updatable = updatable {
  // process the full-sized sprite lines
  for (int i = 0; i < image.height ~/ spriteLineHeight; i++) {
    _spriteLines.add(
      TxSprite(
        msgCode: msgCode,
        width: image.width,
        height: spriteLineHeight,
        numColors: image.numColors,
        paletteData: image.paletteData,
        pixelData: image.pixelData.buffer.asUint8List(i * spriteLineHeight * image.width, spriteLineHeight * image.width)));
  }

  // if there is some final, shorter sprite line, process it too
  int finalHeight  = image.height % spriteLineHeight;
  if (finalHeight > 0) {
    _spriteLines.add(
      TxSprite(
        msgCode: msgCode,
        width: image.width,
        height: finalHeight,
        numColors: image.numColors,
        paletteData: image.paletteData,
        pixelData: image.pixelData.buffer.asUint8List(_spriteLines.length * spriteLineHeight * image.width, finalHeight * image.width)));
  }
}