keepCenter method
void
keepCenter()
@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();
}