From 151ea3af8d8f12ba161d82e6e47722cf1a9de24d Mon Sep 17 00:00:00 2001 From: Mahdi Date: Mon, 10 May 2021 01:47:18 +0430 Subject: [PATCH] WIP trying to fix #27. --- lib/src/crop.dart | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/src/crop.dart b/lib/src/crop.dart index f86011e..b1140f5 100644 --- a/lib/src/crop.dart +++ b/lib/src/crop.dart @@ -96,6 +96,14 @@ class _CropState extends State with TickerProviderStateMixin { widget.controller._cropCallback = _crop; widget.controller.addListener(_reCenterImage); + WidgetsBinding.instance!.addPostFrameCallback((timeStamp) async { + await Future.delayed(Duration(seconds: 1)); + while (mounted) { + _recenter(); + await Future.delayed(Duration(milliseconds: 1000)); + } + }); + //Setup animation. _controller = AnimationController( vsync: this, @@ -112,6 +120,49 @@ class _CropState extends State with TickerProviderStateMixin { super.initState(); } + void _recenter() { + final sz = _key.currentContext!.size!; + final s = widget.controller._scale * widget.controller._getMinScale(); + final w = sz.width; + final h = sz.height; + final offset = _toVector2(widget.controller._offset); + final canvas = Rectangle.fromLTWH(0, 0, w, h); + final obb = Obb2( + center: offset + canvas.center, + width: w * s, + height: h * s, + rotation: widget.controller._rotation, + ); + + final bakedObb = obb.bake(); + + final ab0 = canvas.topEdge; + final bc0 = canvas.rightEdge; + final cd0 = canvas.bottomEdge; + final da0 = canvas.leftEdge; + + print(ab0); + print(bc0); + print(cd0); + print(da0); + + final ab1 = bakedObb.topEdge; + final bc1 = bakedObb.rightEdge; + final cd1 = bakedObb.bottomEdge; + final da1 = bakedObb.leftEdge; + + print(ab1); + print(bc1); + print(cd1); + print(da1); + + final da0da1 = da0.intersect(da1); + final bc0da1 = bc0.intersect(da1); + + print('DA0-DA1: $da0da1'); + print('BC0-DA1: $bc0da1'); + } + void _reCenterImage([bool animate = true]) { //final totalSize = _parent.currentContext.size;