import 'package:flutter/painting.dart'; import 'package:fis_measure/interfaces/date_types/point.dart'; import 'package:fis_measure/interfaces/enums/annotation.dart'; import 'package:fis_measure/interfaces/process/workspace/application.dart'; import 'package:fis_measure/interfaces/process/workspace/point_info.dart'; import 'package:fis_measure/utils/canvas.dart'; import 'package:fis_measure/values/colors.dart'; import 'package:get/get.dart'; import 'annotation.dart'; /// 自定义文本注释 class InputAnnotation extends AnnotationItem { InputAnnotation() : super(AnnotationType.input); @override bool onExecuteMouse(PointInfo args) { if (state == AnnotationStates.finish || state == AnnotationStates.waiting) { if (args.pointType == PointInfoType.mouseDown) { feature = InputAnnotationItemFeature(this, args); state = AnnotationStates.running; } return false; } if (state == AnnotationStates.running) { if (args.pointType != PointInfoType.mouseDown) return false; _finishOnce(); feature = InputAnnotationItemFeature(this, args); state = AnnotationStates.running; } return true; } @override bool onExecuteTouch(PointInfo args) { // TODO: implement onExecuteTouch throw UnimplementedError(); } void _finishOnce() { if (text != null && text!.isNotEmpty) { if (feature != null) { feature!.text = text; doFeatureFinish(true); } else { doFeatureFinish(false); } } else { doFeatureFinish(false); } text = null; } @override void finishLast() { _finishOnce(); } } class InputAnnotationItemFeature extends AnnotationItemFeature { String? text; InputAnnotationItemFeature(InputAnnotation ref, DPoint offset) : super(ref) { text = ref.text; points.add(offset); } @override void paint(Canvas canvas, Size size) { if (text == null) return; double fontSize = 14 * Get.find().displayScaleRatio; final style = TextStyle( fontSize: fontSize, color: MeasureColors.Primary, ); final offset = convert2ViewPoint(size, position); canvas.drawText( text!, offset.toOffset(), style: style, ); } }