draw method

void draw(
  1. Canvas c,
  2. double x,
  3. double y,
  4. double width,
  5. double height
)

Renders this nine box as a rectangle of coordinates (x, y) and size (width, height).

Implementation

void draw(Canvas c, double x, double y, double width, double height) {
  if (!sprite.loaded()) {
    return;
  }

  // corners
  _drawTile(c, _getDest(x, y), 0, 0);
  _drawTile(c, _getDest(x, y + height - destTileSize), 0, 2);
  _drawTile(c, _getDest(x + width - destTileSize, y), 2, 0);
  _drawTile(
      c, _getDest(x + width - destTileSize, y + height - destTileSize), 2, 2);

  // horizontal sides
  final mx = width - 2 * destTileSize;
  _drawTile(c, _getDest(x + destTileSize, y, width: mx), 1, 0);
  _drawTile(c,
      _getDest(x + destTileSize, y + height - destTileSize, width: mx), 1, 2);

  // vertical sides
  final my = height - 2 * destTileSize;
  _drawTile(c, _getDest(x, y + destTileSize, height: my), 0, 1);
  _drawTile(c,
      _getDest(x + width - destTileSize, y + destTileSize, height: my), 2, 1);

  // center
  _drawTile(
      c,
      _getDest(x + destTileSize, y + destTileSize, width: mx, height: my),
      1,
      1);
}