input_annotation.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/painting.dart';
  2. import 'package:fis_measure/interfaces/date_types/point.dart';
  3. import 'package:fis_measure/interfaces/enums/annotation.dart';
  4. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  5. import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
  6. import 'package:fis_measure/utils/canvas.dart';
  7. import 'package:fis_measure/values/colors.dart';
  8. import 'package:get/get.dart';
  9. import 'annotation.dart';
  10. /// 自定义文本注释
  11. class InputAnnotation extends AnnotationItem<InputAnnotationItemFeature> {
  12. InputAnnotation() : super(AnnotationType.input);
  13. @override
  14. bool onExecuteMouse(PointInfo args) {
  15. if (state == AnnotationStates.finish || state == AnnotationStates.waiting) {
  16. if (args.pointType == PointInfoType.mouseDown) {
  17. feature = InputAnnotationItemFeature(this, args);
  18. state = AnnotationStates.running;
  19. }
  20. return false;
  21. }
  22. if (state == AnnotationStates.running) {
  23. if (args.pointType != PointInfoType.mouseDown) return false;
  24. _finishOnce();
  25. feature = InputAnnotationItemFeature(this, args);
  26. state = AnnotationStates.running;
  27. }
  28. return true;
  29. }
  30. @override
  31. bool onExecuteTouch(PointInfo args) {
  32. // TODO: implement onExecuteTouch
  33. throw UnimplementedError();
  34. }
  35. void _finishOnce() {
  36. if (text != null && text!.isNotEmpty) {
  37. if (feature != null) {
  38. feature!.text = text;
  39. doFeatureFinish(true);
  40. } else {
  41. doFeatureFinish(false);
  42. }
  43. } else {
  44. doFeatureFinish(false);
  45. }
  46. text = null;
  47. }
  48. @override
  49. void finishLast() {
  50. _finishOnce();
  51. }
  52. }
  53. class InputAnnotationItemFeature extends AnnotationItemFeature {
  54. String? text;
  55. InputAnnotationItemFeature(InputAnnotation ref, DPoint offset) : super(ref) {
  56. text = ref.text;
  57. points.add(offset);
  58. }
  59. @override
  60. void paint(Canvas canvas, Size size) {
  61. if (text == null) return;
  62. double fontSize = 14 * Get.find<IApplication>().displayScaleRatio;
  63. final style = TextStyle(
  64. fontSize: fontSize,
  65. color: MeasureColors.Primary,
  66. );
  67. final offset = convert2ViewPoint(size, position);
  68. canvas.drawText(
  69. text!,
  70. offset.toOffset(),
  71. style: style,
  72. );
  73. }
  74. }