From 847cea15d6cea913de2f7c27d9610b947681592e Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Thu, 17 Sep 2015 14:36:48 -0700 Subject: [PATCH] Ensure that the item under the focal point stays in the same place despite zooming --- examples/widgets/scale.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/widgets/scale.dart b/examples/widgets/scale.dart index 5478a032b31..9e480e5ccff 100644 --- a/examples/widgets/scale.dart +++ b/examples/widgets/scale.dart @@ -31,13 +31,16 @@ class ScaleApp extends App { void _handleScaleUpdate(double scale, Point focalPoint) { setState(() { - _zoom = _previousZoom * scale; - _offset = _previousOffset + (focalPoint - _startingFocalPoint) / _zoom; + _zoom = (_previousZoom * scale); + + // Ensure that item under the focal point stays in the same place despite zooming + Offset normalizedOffset = (_startingFocalPoint.toOffset() - _previousOffset) / _previousZoom; + _offset = focalPoint.toOffset() - normalizedOffset * _zoom; }); } void paint(PaintingCanvas canvas, Size size) { - Point center = size.center(Point.origin) + _offset * _zoom; + Point center = (size.center(Point.origin).toOffset() * _zoom + _offset).toPoint(); double radius = size.width / 2.0 * _zoom; Gradient gradient = new RadialGradient( center: center, radius: radius,