keepCenter method

void keepCenter(
  1. double oldScale,
  2. double newScale,
  3. Size size,
  4. Offset localPosition,
  5. ValueNotifier<Offset> offset,
)

@en: When the canvas undergoes a zoom operation,
make the canvas zoom in and out with the mouse focus as the center.

@zh: 当画布产生缩放操作时,使画布以鼠标焦点为中心,进行缩放

Implementation

void keepCenter(
  double oldScale,
  double newScale,
  Size size,
  Offset localPosition,
  ValueNotifier<Offset> offset,
) {
  var oldLocal = globalToLocal(localPosition.toVector2(), scale: oldScale);
  var newLocal = globalToLocal(localPosition.toVector2(), scale: newScale);
  var delta = newLocal - oldLocal;
  var global = delta * newScale;
  offset.value += global.toOffset();
}