From 060df5f16e734d0b2f1c14185bfc7ab6fa4542bd Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Mon, 5 Sep 2022 12:39:17 +1000 Subject: [PATCH] update controls for widget rotation/panning/bg image --- lib/gesture_detecting_filament_view.dart | 70 +++++++++++++++--------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/gesture_detecting_filament_view.dart b/lib/gesture_detecting_filament_view.dart index 321d9f51..8ed5a60f 100644 --- a/lib/gesture_detecting_filament_view.dart +++ b/lib/gesture_detecting_filament_view.dart @@ -2,9 +2,15 @@ import 'package:flutter/material.dart'; import 'filament_controller.dart'; import 'filament_widget.dart'; -class GestureDetectingFilamentView extends StatefulWidget { - final FilamentController controller; +enum GestureType { + RotateCamera, + PanCamera, + PanBackground +} +class GestureDetectingFilamentView extends StatefulWidget { + + final FilamentController controller; final bool showControls; const GestureDetectingFilamentView( @@ -17,7 +23,15 @@ class GestureDetectingFilamentView extends StatefulWidget { class _GestureDetectingFilamentViewState extends State { - bool _rotate = false; + + GestureType gestureType = GestureType.PanCamera; + + final _icons = { + GestureType.PanBackground:Icons.image, + GestureType.PanCamera:Icons.pan_tool, + GestureType.RotateCamera:Icons.rotate_90_degrees_ccw + }; + late Future Function(double x, double y) _functionStart; late Future Function(double x, double y) _functionUpdate; late Future Function() _functionEnd; @@ -31,14 +45,27 @@ class _GestureDetectingFilamentViewState } void _setFunction() { - if (_rotate) { - _functionStart = widget.controller.rotateStart; - _functionUpdate = widget.controller.rotateUpdate; - _functionEnd = widget.controller.rotateEnd; - } else { - _functionStart = widget.controller.panStart; - _functionUpdate = widget.controller.panUpdate; - _functionEnd = widget.controller.panEnd; + switch(gestureType) { + case GestureType.RotateCamera: + _functionStart = widget.controller.rotateStart; + _functionUpdate = widget.controller.rotateUpdate; + _functionEnd = widget.controller.rotateEnd; + break; + case GestureType.PanCamera: + _functionStart = widget.controller.panStart; + _functionUpdate = widget.controller.panUpdate; + _functionEnd = widget.controller.panEnd; + break; + case GestureType.PanBackground: + _functionStart = (x,y) async { + + }; + _functionUpdate = (x,y) async { + // print("Updating ${"); + }; + _functionEnd = () async { + + }; } } @@ -62,7 +89,6 @@ class _GestureDetectingFilamentViewState if (d.pointerCount == 2) { // _lastScale = d. } else { - // print("start ${d.focalPoint}"); _functionStart(d.focalPoint.dx, d.focalPoint.dy); } }, @@ -70,7 +96,6 @@ class _GestureDetectingFilamentViewState if (d.pointerCount == 2) { _lastScale = 0; } else { - // print("end ${d.velocity}"); _functionEnd(); } }, @@ -79,17 +104,11 @@ class _GestureDetectingFilamentViewState if (_lastScale == 0) { _lastScale = d.scale; } else { - // var zoomFactor = ; - // if(zoomFactor < 0) { - // zoomFactor *= 10; - // } - // print(zoomFactor); - print(d.horizontalScale); - // print(d.focalPoint.dx); - widget.controller.zoom(d.scale > 1 ? 10 : -10); + widget.controller.zoom(d.scale > 1 ? 5 : -5); } } else { // print("update ${d.focalPoint}"); + print(d.focalPointDelta); _functionUpdate(d.focalPoint.dx, d.focalPoint.dy); } }, @@ -100,16 +119,15 @@ class _GestureDetectingFilamentViewState child: GestureDetector( onTap: () { setState(() { - _rotate = !_rotate; + var curIdx = GestureType.values.indexOf(gestureType); + var nextIdx = curIdx == GestureType.values.length - 1 ? 0 : curIdx + 1 ; + gestureType = GestureType.values[nextIdx]; _setFunction(); }); }, child: Container( padding: const EdgeInsets.all(50), - child: Icon(Icons.rotate_90_degrees_ccw, - color: _rotate - ? Colors.white - : Colors.white.withOpacity(0.5))), + child: Icon(_icons[gestureType], color:Colors.green)), )) : Container() ]);