123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import 'package:fis_measure/interfaces/date_types/rect_region.dart';
- import 'package:fis_measure/view/gesture/cross_position_indicator.dart';
- import 'package:fis_measure/view/gesture/mouse_gesture.dart';
- import 'package:fis_measure/values/colors.dart';
- import 'package:fis_measure/view/cursor.dart';
- import 'package:flutter/material.dart';
- // 鼠标指示器(无需测量,无需控制器)
- class MouseGestureAreaForRoi extends StatefulWidget {
- const MouseGestureAreaForRoi({super.key, this.onMouseDown, this.onMouseMove});
- final ValueChanged<Offset>? onMouseDown;
- final ValueChanged<Offset>? onMouseMove;
- @override
- State<MouseGestureAreaForRoi> createState() => _MouseGestureAreaForRoiState();
- }
- class _MouseGestureAreaForRoiState extends State<MouseGestureAreaForRoi> {
- Offset? cursorPosition;
- CursorDisplayType displayType = CursorDisplayType.none;
- RectRegion tissueTMPixelRegion = RectRegion();
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onTapDown: (details) {
- widget.onMouseDown?.call(details.localPosition);
- },
- onPanUpdate: (details) {
- setState(() {
- cursorPosition = details.localPosition;
- });
- widget.onMouseMove?.call(details.localPosition);
- },
- child: MouseRegion(
- cursor: SystemMouseCursors.none,
- onHover: (event) {
- setState(() {
- cursorPosition = event.localPosition;
- });
- widget.onMouseMove?.call(event.localPosition);
- // _handleAreaChange(event.localPosition);
- },
- onEnter: (e) {
- setState(() {
- displayType = CursorDisplayType.normal;
- });
- },
- onExit: (e) {
- setState(() {
- displayType = CursorDisplayType.none;
- });
- },
- child: Stack(
- children: [
- _buildCursor(),
- // if (isShowRightClickTip && displayType != CursorDisplayType.none)
- // _buildTip(),
- ],
- ),
- ),
- );
- }
- Widget _buildCursor() {
- switch (displayType) {
- case CursorDisplayType.none:
- return Container();
- case CursorDisplayType.normal:
- return _buildPositionedCursor(cursorPosition);
- case CursorDisplayType.cross:
- return CrossIndicator(
- areaRegion: Rect.fromLTRB(
- tissueTMPixelRegion.left,
- tissueTMPixelRegion.top,
- tissueTMPixelRegion.right,
- tissueTMPixelRegion.bottom),
- );
- }
- }
- Widget _buildPositionedCursor(Offset? cursorPosition) {
- if (cursorPosition == null) return Container();
- /// FIXME 更多参数需要通过刷新来传入
- final cursorSize = 12;
- final cursorScaleRatio = 2.0;
- final offset = cursorScaleRatio * cursorSize / 2;
- final dx = cursorPosition.dx - offset;
- final dy = cursorPosition.dy - offset;
- return Positioned(
- left: dx,
- top: dy,
- child: MeasureCursor(
- type: MeasureCursorType.cursor01,
- size: cursorSize * cursorScaleRatio,
- color: MeasureColors.Primary,
- ),
- );
- }
- }
|