alignPivot method

void alignPivot([
  1. Alignment alignment = painting.Alignment.center
])

Adjusts the pivot point of this display object to a new location defined by the given alignment parameter, which defaults to Alignment.center. This method calculates the bounds of the object and aligns the pivot point based on the provided alignment parameter. The alignment is represented by an Alignment object, where the x and y values range from -1.0 to 1.0. For example, an Alignment of (-1.0, -1.0) represents the top left corner, while an Alignment of (1.0, 1.0) represents the bottom right corner. The pivot point represents the center point for rotations and scaling, and by default it is set to (0,0), which means that the object is rotated and scaled around the top-left corner. This method is useful to adjust the pivot point to a more suitable location before performing rotations or scaling operations. If the bounds of the object are empty, no adjustment is made to the pivot point. The resulting pivot point is stored in the pivotX and pivotY properties of this display object.

Implementation

void alignPivot([painting.Alignment alignment = painting.Alignment.center]) {
  var bounds = getBounds(this, _sHelperRect)!;

  if (bounds.isEmpty) return;
  var ax = 0.5 + alignment.x / 2;
  var ay = 0.5 + alignment.y / 2;

  pivotX = bounds.x + bounds.width * ax;
  pivotY = bounds.y + bounds.height * ay;
}