1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import 'dart:ui' as ui;
- import 'package:fis_measure/interfaces/date_types/point.dart';
- import 'package:fis_measure/interfaces/enums/annotation.dart';
- import 'package:fis_measure/interfaces/process/visuals/visual_area.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:flutter/material.dart';
- import 'package:flutter/painting.dart';
- import 'package:get/get.dart';
- import 'annotation.dart';
- /// 文本标签注释
- class LabelAnnotation extends AnnotationItem<LabelAnnotationItemFeature> {
- LabelAnnotation() : super(AnnotationType.label);
- @override
- bool onExecuteMouse(PointInfo args) {
- if (state == AnnotationStates.finish || state == AnnotationStates.waiting) {
- if (args.pointType == PointInfoType.mouseMove) {
- state = AnnotationStates.running;
- }
- return false;
- }
- if (state == AnnotationStates.running) {
- if (args.pointType == PointInfoType.mouseMove) return false;
- if (args.pointType == PointInfoType.mouseDown) {
- if (feature != null) {
- doFeatureFinish();
- }
- }
- if (args.pointType == PointInfoType.mouseUp) {
- feature = LabelAnnotationItemFeature(this, args);
- doFeatureFinish();
- }
- }
- return true;
- }
- @override
- bool onExecuteTouch(PointInfo args) {
- if (state == AnnotationStates.finish || state == AnnotationStates.waiting) {
- if (args.pointType == PointInfoType.touchMove) {
- state = AnnotationStates.running;
- }
- return false;
- }
- if (state == AnnotationStates.running) {
- if (args.pointType == PointInfoType.touchMove) return false;
- if (args.pointType == PointInfoType.touchUp) {
- feature = LabelAnnotationItemFeature(this, args);
- if (feature != null) {
- doFeatureFinish();
- }
- }
- }
- return true;
- }
- }
- class LabelAnnotationItemFeature extends AnnotationItemFeature {
- late final String? text;
- late final IVisualArea? visualArea;
- LabelAnnotationItemFeature(LabelAnnotation ref, PointInfo pointInfo)
- : super(ref) {
- text = ref.text;
- visualArea = pointInfo.hostVisualArea;
- points.add(pointInfo);
- }
- @override
- void paint(Canvas canvas, Size size) {
- if (text == null) return;
- double fontSize = 14 * Get.find<IApplication>().displayScaleRatio;
- final style = TextStyle(
- fontSize: fontSize,
- color: isActive ? MeasureColors.ActiveCaliper : MeasureColors.Primary,
- );
- final offset = convert2ViewPoint(size, position);
- canvas.drawText(
- text!,
- offset.toOffset(),
- style: style,
- );
- }
- }
|