diff --git a/marking_app/lib/common/model/job/test_questions_image_info.dart b/marking_app/lib/common/model/job/test_questions_image_info.dart index e9a1e7c..23539ea 100644 --- a/marking_app/lib/common/model/job/test_questions_image_info.dart +++ b/marking_app/lib/common/model/job/test_questions_image_info.dart @@ -35,8 +35,17 @@ class TestQuestionsImageInfo extends Object { double? imageHeightOffsetend; - TestQuestionsImageInfo( - {required this.width, required this.height, required this.url, required this.boxWidth, required this.boxHeight, this.pixelRatio = 1}) { + double zoom; // 图片放大比例 + + TestQuestionsImageInfo({ + required this.width, + required this.height, + required this.url, + required this.boxWidth, + required this.boxHeight, + this.pixelRatio = 1, + this.zoom = 1, + }) { // print('图片宽度:$width'); // print('图片高度:$height'); @@ -46,11 +55,11 @@ class TestQuestionsImageInfo extends Object { pixelRatio = width / boxWidth; scale = boxWidth / width; - scaleHeight = scale! * height; - scaleWidth = scale! * width; + scaleHeight = scale! * height * zoom; + scaleWidth = scale! * width * zoom; if (scaleHeight != null) { - imageHeightOffsetStart = (boxHeight - scaleHeight!) / 2; + imageHeightOffsetStart = boxHeight <= scaleHeight! ? 0 : (boxHeight - scaleHeight!) / 2; imageHeightOffsetend = imageHeightOffsetStart! + scaleHeight!; } } diff --git a/marking_app/lib/components/PictureOverview.dart b/marking_app/lib/components/PictureOverview.dart index cbb2a97..19aab63 100644 --- a/marking_app/lib/components/PictureOverview.dart +++ b/marking_app/lib/components/PictureOverview.dart @@ -106,6 +106,8 @@ class PictureOverviewState extends ConsumerState with CommonMix // 用于记录绘图结果的变量 Offset? globalPosition; // 是否正在绘制 MarkingHistoryZoomInfo? zoomInfo; + bool illegalArea = false; // 非法区域(批阅笔迹不在试题图片中) + final GlobalKey _zoomKey = GlobalKey>(); @override void initState() { @@ -141,7 +143,7 @@ class PictureOverviewState extends ConsumerState with CommonMix bool flieExist = temFile!.existsSync(); if (flieExist) temFile!.delete(); } - if (zoomOffset != null) saveZoomPosition(); + // if (zoomOffset != null) saveZoomPosition(); } catch (e) {} super.dispose(); } @@ -230,6 +232,7 @@ class PictureOverviewState extends ConsumerState with CommonMix } void onPanUpPosition(Offset val) async { + // 手指在移动 非物体移动的位置 print('**************** 正在移动位置 YYY:${val.dy}'); print('**************** 正在移动位置 XXX:${val.dx}'); zoomOffset = val; @@ -251,14 +254,17 @@ class PictureOverviewState extends ConsumerState with CommonMix markingUserId: widget.markingUserId, ); zoomInfo = info; + if (double.parse(zoom.toStringAsFixed(2)) <= 1) zoom = 1; if (imagInfoModel != null) { + // 根据缩放比例重置被放大的图片的尺寸 imagInfoModel = TestQuestionsImageInfo( // 获取图片的宽高 boxHeight: imagInfoModel!.boxHeight, boxWidth: imagInfoModel!.boxWidth, url: imagInfoModel!.url, - height: imagInfoModel!.height * zoom, - width: imagInfoModel!.width * zoom, + height: imagInfoModel!.height, + width: imagInfoModel!.width, + zoom: zoom, ); } FastData.getInstance().setMarkingZoomInfo(info); @@ -333,39 +339,70 @@ class PictureOverviewState extends ConsumerState with CommonMix globalPosition = details.localPosition; Offset localPosition = globalPosition!; - if (imagInfoModel != null && - (localPosition.dy < imagInfoModel!.imageHeightOffsetStart! || localPosition.dy > imagInfoModel!.imageHeightOffsetend!)) { - // 笔迹画出图片区域 直接断笔 - var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser)); - var newVal1 = ref.read(drawMarkingProvider).offsets..add(null); - ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal, newVal1)); - return; - } + print('绝对位置:X:${details.position.dx}; Y:${details.position.dy}'); + print('相对位置:X:${globalPosition!.dx}; Y:${globalPosition!.dy}'); + + // if (imagInfoModel != null && + // (localPosition.dy < imagInfoModel!.imageHeightOffsetStart! || localPosition.dy > imagInfoModel!.imageHeightOffsetend!)) { + // // 笔迹画出图片区域 直接断笔 + // var dataVal = ref.read(drawMarkingProvider).data; + // if (dataVal.length - 1 > -1 && dataVal[dataVal.length - 1].data != null) { + // var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser)); + // var newVal1 = ref.read(drawMarkingProvider).offsets..add(null); + // ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal, newVal1)); + // } + // illegalArea = true; + // return; + // } + // illegalArea = false; // Offset localPosition = (context.findRenderObject() as RenderBox).globalToLocal(details.localPosition); // if (widget.graffitiSwitch.openBrush || widget.graffitiSwitch.openEraser) { // if (imagInfoModel?.scaleHeight != null) { // localPosition = Offset(localPosition.dx, localPosition.dy - imagInfoModel!.scaleHeight!); // } + var zoomState = _zoomKey.currentState; + if (zoomState != null) { + print(zoomState); + } double remainingHeight = imagInfoModel!.imageHeightOffsetStart!; // 剩余高度 var _scaleY = (zoomInfo?.scale ?? 1); if (remainingHeight > 1) { localPosition = Offset(localPosition.dx, localPosition.dy - remainingHeight); + + // if (zoomOffset != null) { + // // var density = (imagInfoModel!.boxWidth / imagInfoModel!.scaleWidth!); + // localPosition = Offset(localPosition.dx/, localPosition.dy); + // } + } else { + if (zoomOffset != null) { + localPosition = Offset(localPosition.dx, localPosition.dy + zoomOffset!.dy.abs()); + } } - if (zoomOffset != null) { - localPosition = Offset(details.position.dx, localPosition.dy); + if (imagInfoModel?.zoom != null && imagInfoModel?.zoom != 1) { + // 计算视图被放大比例 还原笔迹坐标 + localPosition = Offset(localPosition.dx / imagInfoModel!.zoom, localPosition.dy / imagInfoModel!.zoom); + if (zoomOffset != null) { + // 如果滚动条有触动就加上滚动条滚动的位置 + var density = (imagInfoModel!.boxWidth / imagInfoModel!.scaleWidth!); + localPosition = Offset(localPosition.dx + zoomOffset!.dx.abs() / imagInfoModel!.zoom, localPosition.dy); + } } - print('移动位置 zoomOffset==>dx:${zoomOffset?.dx}'); - print('移动位置 zoomOffset==>dy:${zoomOffset?.dy}'); + // if (zoomInfo != null) { + // localPosition = Offset(details.position.dx, localPosition.dy); + // } - print('缩放的比例:${_scaleY}'); - print('原本的dy:${globalPosition?.dy}'); - print('原本的dx:${globalPosition?.dx}'); - print('本来的Y轴:${localPosition.dy}'); - print('还原后的Y轴:${localPosition.dy * _scaleY}'); + // print('移动位置 zoomOffset==>dx:${zoomOffset?.dx}'); + // print('移动位置 zoomOffset==>dy:${zoomOffset?.dy}'); + + // print('缩放的比例:${_scaleY}'); + // print('原本的dy:${globalPosition?.dy}'); + // print('原本的dx:${globalPosition?.dx}'); + // print('本来的Y轴:${localPosition.dy}'); + // print('还原后的Y轴:${localPosition.dy * _scaleY}'); var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser, data: localPosition)); var newVal1 = ref.read(drawMarkingProvider).offsets..add(localPosition); @@ -377,7 +414,10 @@ class PictureOverviewState extends ConsumerState with CommonMix onPointerUp: (PointerUpEvent details) { print('离开.............'); if (btnEnum != ReviewMarksBottomBtnsEnum.HANDWRITING) return; + globalPosition = null; + // 如果在空白区域 非试题图片区域就返回 + if (illegalArea) return; // if (graffitiSwitch.openBrush || graffitiSwitch.openEraser) { // var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser)); // ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal)); @@ -390,6 +430,7 @@ class PictureOverviewState extends ConsumerState with CommonMix child: IgnorePointer( ignoring: btnEnum != ReviewMarksBottomBtnsEnum.DRAG, child: Zoom( + key: _zoomKey, // initTotalZoomOut: true, child: ExamPaperDrawing( key: examPaperDrawingKey, @@ -399,9 +440,9 @@ class PictureOverviewState extends ConsumerState with CommonMix decoration: const BoxDecoration(color: const Color.fromRGBO(249, 250, 254, 1)), ), maxZoomWidth: containerWidth, - canvasColor: Colors.transparent, + canvasColor: Colors.red, backgroundColor: Colors.transparent, - maxZoomHeight: imagInfoModel?.scaleHeight, + maxZoomHeight: imagInfoModel?.scaleHeight != null ? (imagInfoModel!.scaleHeight! / imagInfoModel!.zoom) : null, initScale: initScale ?? 1, initPosition: zoomOffset, onScaleUpdate: onScaleUpdate,