update controls for widget rotation/panning/bg image
This commit is contained in:
@@ -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<GestureDetectingFilamentView> {
|
||||
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()
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user