Skip to content

Commit

Permalink
WIP trying to fix #27.
Browse files Browse the repository at this point in the history
  • Loading branch information
xclud committed May 9, 2021
1 parent 42bbe3e commit 151ea3a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/src/crop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class _CropState extends State<Crop> 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,
Expand All @@ -112,6 +120,49 @@ class _CropState extends State<Crop> 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;

Expand Down

0 comments on commit 151ea3a

Please sign in to comment.