123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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/view/gesture/mouse_gesture.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import '../positioned_cursor.dart';
- /// 文本注释拖拽目标面板
- class AnnotationLabelDragTargetPanel extends StatefulWidget {
- const AnnotationLabelDragTargetPanel({Key? key}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _PanelState();
- }
- class _PanelState extends State<AnnotationLabelDragTargetPanel> {
- late final application = Get.find<IApplication>();
- final mouseState = Get.find<IMouseState>();
- CursorDisplayType displayType = CursorDisplayType.none;
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return DragTarget<String>(
- builder: (context, candidateData, rejectedData) {
- return GestureDetector(
- onPanDown: (details) {
- application.createPointInfo(
- details.localPosition,
- PointInfoType.mouseDown,
- );
- application.switchAnnotation(AnnotationType.input);
- },
- child: MouseRegion(
- cursor: SystemMouseCursors.none,
- onHover: (event) {
- mouseState.mousePosition = event.localPosition;
- },
- onEnter: (e) {
- setState(() {
- displayType = CursorDisplayType.normal;
- });
- },
- onExit: (e) {
- setState(() {
- displayType = CursorDisplayType.none;
- });
- },
- child: Stack(
- children: [
- _buildCursor(),
- ],
- ),
- ),
- );
- },
- onMove: (details) {
- _notifyPosition(context, details.offset, PointInfoType.mouseMove);
- },
- onAcceptWithDetails: (details) {
- _notifyPosition(context, details.offset, PointInfoType.mouseUp);
- },
- );
- }
- void _notifyPosition(
- BuildContext context,
- Offset offset,
- PointInfoType type,
- ) {
- final localOffset = _findLocalPosition(context, offset);
- mouseState.mousePosition = localOffset;
- application.createPointInfo(localOffset, type);
- }
- Offset _findLocalPosition(BuildContext context, Offset globalPosition) {
- final renderBox = context.findRenderObject() as RenderBox?;
- if (renderBox == null) return globalPosition;
- return renderBox.globalToLocal(globalPosition);
- }
- Widget _buildCursor() {
- switch (displayType) {
- case CursorDisplayType.none:
- return Container();
- case CursorDisplayType.normal:
- return const PositionedCursor();
- default:
- return const PositionedCursor();
- }
- }
- @override
- void dispose() {
- super.dispose();
- }
- }
|