applyTransformForPivot method

void applyTransformForPivot(
  1. Canvas canvas
)

Call this method in your paint method if you want the origin of your drawing to be the top left corner of the node's bounding box.

If you use this method you will need to save and restore your canvas at the beginning and end of your paint method.

void paint(Canvas canvas) {
  canvas.save();
  applyTransformForPivot(canvas);

  // Do painting here

  canvas.restore();
}

Implementation

void applyTransformForPivot(Canvas canvas) {
  if (pivot.dx != 0 || pivot.dy != 0) {
    double pivotInPointsX = size.width * pivot.dx;
    double pivotInPointsY = size.height * pivot.dy;
    canvas.translate(-pivotInPointsX, -pivotInPointsY);
  }
}