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_controller.dart';
|
||||||
import 'filament_widget.dart';
|
import 'filament_widget.dart';
|
||||||
|
|
||||||
class GestureDetectingFilamentView extends StatefulWidget {
|
enum GestureType {
|
||||||
final FilamentController controller;
|
RotateCamera,
|
||||||
|
PanCamera,
|
||||||
|
PanBackground
|
||||||
|
}
|
||||||
|
|
||||||
|
class GestureDetectingFilamentView extends StatefulWidget {
|
||||||
|
|
||||||
|
final FilamentController controller;
|
||||||
final bool showControls;
|
final bool showControls;
|
||||||
|
|
||||||
const GestureDetectingFilamentView(
|
const GestureDetectingFilamentView(
|
||||||
@@ -17,7 +23,15 @@ class GestureDetectingFilamentView extends StatefulWidget {
|
|||||||
|
|
||||||
class _GestureDetectingFilamentViewState
|
class _GestureDetectingFilamentViewState
|
||||||
extends State<GestureDetectingFilamentView> {
|
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) _functionStart;
|
||||||
late Future Function(double x, double y) _functionUpdate;
|
late Future Function(double x, double y) _functionUpdate;
|
||||||
late Future Function() _functionEnd;
|
late Future Function() _functionEnd;
|
||||||
@@ -31,14 +45,27 @@ class _GestureDetectingFilamentViewState
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _setFunction() {
|
void _setFunction() {
|
||||||
if (_rotate) {
|
switch(gestureType) {
|
||||||
_functionStart = widget.controller.rotateStart;
|
case GestureType.RotateCamera:
|
||||||
_functionUpdate = widget.controller.rotateUpdate;
|
_functionStart = widget.controller.rotateStart;
|
||||||
_functionEnd = widget.controller.rotateEnd;
|
_functionUpdate = widget.controller.rotateUpdate;
|
||||||
} else {
|
_functionEnd = widget.controller.rotateEnd;
|
||||||
_functionStart = widget.controller.panStart;
|
break;
|
||||||
_functionUpdate = widget.controller.panUpdate;
|
case GestureType.PanCamera:
|
||||||
_functionEnd = widget.controller.panEnd;
|
_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) {
|
if (d.pointerCount == 2) {
|
||||||
// _lastScale = d.
|
// _lastScale = d.
|
||||||
} else {
|
} else {
|
||||||
// print("start ${d.focalPoint}");
|
|
||||||
_functionStart(d.focalPoint.dx, d.focalPoint.dy);
|
_functionStart(d.focalPoint.dx, d.focalPoint.dy);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -70,7 +96,6 @@ class _GestureDetectingFilamentViewState
|
|||||||
if (d.pointerCount == 2) {
|
if (d.pointerCount == 2) {
|
||||||
_lastScale = 0;
|
_lastScale = 0;
|
||||||
} else {
|
} else {
|
||||||
// print("end ${d.velocity}");
|
|
||||||
_functionEnd();
|
_functionEnd();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -79,17 +104,11 @@ class _GestureDetectingFilamentViewState
|
|||||||
if (_lastScale == 0) {
|
if (_lastScale == 0) {
|
||||||
_lastScale = d.scale;
|
_lastScale = d.scale;
|
||||||
} else {
|
} else {
|
||||||
// var zoomFactor = ;
|
widget.controller.zoom(d.scale > 1 ? 5 : -5);
|
||||||
// if(zoomFactor < 0) {
|
|
||||||
// zoomFactor *= 10;
|
|
||||||
// }
|
|
||||||
// print(zoomFactor);
|
|
||||||
print(d.horizontalScale);
|
|
||||||
// print(d.focalPoint.dx);
|
|
||||||
widget.controller.zoom(d.scale > 1 ? 10 : -10);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// print("update ${d.focalPoint}");
|
// print("update ${d.focalPoint}");
|
||||||
|
print(d.focalPointDelta);
|
||||||
_functionUpdate(d.focalPoint.dx, d.focalPoint.dy);
|
_functionUpdate(d.focalPoint.dx, d.focalPoint.dy);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -100,16 +119,15 @@ class _GestureDetectingFilamentViewState
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_rotate = !_rotate;
|
var curIdx = GestureType.values.indexOf(gestureType);
|
||||||
|
var nextIdx = curIdx == GestureType.values.length - 1 ? 0 : curIdx + 1 ;
|
||||||
|
gestureType = GestureType.values[nextIdx];
|
||||||
_setFunction();
|
_setFunction();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(50),
|
padding: const EdgeInsets.all(50),
|
||||||
child: Icon(Icons.rotate_90_degrees_ccw,
|
child: Icon(_icons[gestureType], color:Colors.green)),
|
||||||
color: _rotate
|
|
||||||
? Colors.white
|
|
||||||
: Colors.white.withOpacity(0.5))),
|
|
||||||
))
|
))
|
||||||
: Container()
|
: Container()
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user