calibration_gesture.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
  3. import 'package:fis_measure/values/colors.dart';
  4. import 'package:fis_measure/view/cursor.dart';
  5. import 'package:flutter/material.dart';
  6. /// 参考校准线手势画布
  7. class StandardLineCalibrationGesture extends StatefulWidget {
  8. const StandardLineCalibrationGesture(this.controller, {Key? key})
  9. : super(key: key);
  10. final IStandardLineCalibrationController controller;
  11. @override
  12. State<StandardLineCalibrationGesture> createState() => _GestureState();
  13. }
  14. class _GestureState extends State<StandardLineCalibrationGesture> {
  15. // ignore: constant_identifier_names
  16. static const C_CURSOR_SIZE = 16.0;
  17. Offset position = Offset.zero;
  18. @override
  19. Widget build(BuildContext context) {
  20. final controller = widget.controller;
  21. return MouseRegion(
  22. cursor: SystemMouseCursors.none,
  23. onHover: (event) {
  24. setState(() {
  25. _updatePosition(event.localPosition);
  26. controller.executeGesturePoint(
  27. event.localPosition,
  28. PointInfoType.mouseMove,
  29. );
  30. });
  31. },
  32. child: GestureDetector(
  33. onTapDown: (details) {
  34. controller.executeGesturePoint(
  35. details.localPosition,
  36. PointInfoType.mouseDown,
  37. );
  38. },
  39. onTapUp: (details) {
  40. controller.executeGesturePoint(
  41. details.localPosition,
  42. PointInfoType.mouseUp,
  43. );
  44. },
  45. child: Stack(
  46. children: [
  47. Positioned(
  48. // top: position.dy - 16,
  49. // left: position.dx - 16,
  50. top: position.dy,
  51. left: position.dx,
  52. child: const MeasureCursor(
  53. type: MeasureCursorType.cursor01,
  54. size: C_CURSOR_SIZE,
  55. color: MeasureColors.Primary,
  56. ),
  57. ),
  58. ],
  59. ),
  60. ),
  61. );
  62. }
  63. void _updatePosition(Offset offset) {
  64. const side = C_CURSOR_SIZE / 2;
  65. double dx = offset.dx - side;
  66. double dy = offset.dy - side;
  67. if (dx < 0) dx = 0;
  68. if (dy < 0) dy = 0;
  69. position = Offset(dx, dy);
  70. }
  71. }