基本完成工作

This commit is contained in:
1147192855@qq.com 2024-05-09 19:55:25 +08:00
parent 060ac01fde
commit a13cab2c96
2 changed files with 77 additions and 27 deletions

View File

@ -35,8 +35,17 @@ class TestQuestionsImageInfo extends Object {
double? imageHeightOffsetend; double? imageHeightOffsetend;
TestQuestionsImageInfo( double zoom; //
{required this.width, required this.height, required this.url, required this.boxWidth, required this.boxHeight, this.pixelRatio = 1}) {
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('图片宽度:$width');
// print('图片高度:$height'); // print('图片高度:$height');
@ -46,11 +55,11 @@ class TestQuestionsImageInfo extends Object {
pixelRatio = width / boxWidth; pixelRatio = width / boxWidth;
scale = boxWidth / width; scale = boxWidth / width;
scaleHeight = scale! * height; scaleHeight = scale! * height * zoom;
scaleWidth = scale! * width; scaleWidth = scale! * width * zoom;
if (scaleHeight != null) { if (scaleHeight != null) {
imageHeightOffsetStart = (boxHeight - scaleHeight!) / 2; imageHeightOffsetStart = boxHeight <= scaleHeight! ? 0 : (boxHeight - scaleHeight!) / 2;
imageHeightOffsetend = imageHeightOffsetStart! + scaleHeight!; imageHeightOffsetend = imageHeightOffsetStart! + scaleHeight!;
} }
} }

View File

@ -106,6 +106,8 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
// //
Offset? globalPosition; // Offset? globalPosition; //
MarkingHistoryZoomInfo? zoomInfo; MarkingHistoryZoomInfo? zoomInfo;
bool illegalArea = false; //
final GlobalKey _zoomKey = GlobalKey<State<Zoom>>();
@override @override
void initState() { void initState() {
@ -141,7 +143,7 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
bool flieExist = temFile!.existsSync(); bool flieExist = temFile!.existsSync();
if (flieExist) temFile!.delete(); if (flieExist) temFile!.delete();
} }
if (zoomOffset != null) saveZoomPosition(); // if (zoomOffset != null) saveZoomPosition();
} catch (e) {} } catch (e) {}
super.dispose(); super.dispose();
} }
@ -230,6 +232,7 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
} }
void onPanUpPosition(Offset val) async { void onPanUpPosition(Offset val) async {
//
print('**************** 正在移动位置 YYY:${val.dy}'); print('**************** 正在移动位置 YYY:${val.dy}');
print('**************** 正在移动位置 XXX:${val.dx}'); print('**************** 正在移动位置 XXX:${val.dx}');
zoomOffset = val; zoomOffset = val;
@ -251,14 +254,17 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
markingUserId: widget.markingUserId, markingUserId: widget.markingUserId,
); );
zoomInfo = info; zoomInfo = info;
if (double.parse(zoom.toStringAsFixed(2)) <= 1) zoom = 1;
if (imagInfoModel != null) { if (imagInfoModel != null) {
//
imagInfoModel = TestQuestionsImageInfo( imagInfoModel = TestQuestionsImageInfo(
// //
boxHeight: imagInfoModel!.boxHeight, boxHeight: imagInfoModel!.boxHeight,
boxWidth: imagInfoModel!.boxWidth, boxWidth: imagInfoModel!.boxWidth,
url: imagInfoModel!.url, url: imagInfoModel!.url,
height: imagInfoModel!.height * zoom, height: imagInfoModel!.height,
width: imagInfoModel!.width * zoom, width: imagInfoModel!.width,
zoom: zoom,
); );
} }
FastData.getInstance().setMarkingZoomInfo(info); FastData.getInstance().setMarkingZoomInfo(info);
@ -333,39 +339,70 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
globalPosition = details.localPosition; globalPosition = details.localPosition;
Offset localPosition = globalPosition!; Offset localPosition = globalPosition!;
if (imagInfoModel != null && print('绝对位置X:${details.position.dx}; Y:${details.position.dy}');
(localPosition.dy < imagInfoModel!.imageHeightOffsetStart! || localPosition.dy > imagInfoModel!.imageHeightOffsetend!)) { print('相对位置X:${globalPosition!.dx}; Y:${globalPosition!.dy}');
//
var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser)); // if (imagInfoModel != null &&
var newVal1 = ref.read(drawMarkingProvider).offsets..add(null); // (localPosition.dy < imagInfoModel!.imageHeightOffsetStart! || localPosition.dy > imagInfoModel!.imageHeightOffsetend!)) {
ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal, newVal1)); // //
return; // 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); // Offset localPosition = (context.findRenderObject() as RenderBox).globalToLocal(details.localPosition);
// if (widget.graffitiSwitch.openBrush || widget.graffitiSwitch.openEraser) { // if (widget.graffitiSwitch.openBrush || widget.graffitiSwitch.openEraser) {
// if (imagInfoModel?.scaleHeight != null) { // if (imagInfoModel?.scaleHeight != null) {
// localPosition = Offset(localPosition.dx, localPosition.dy - imagInfoModel!.scaleHeight!); // localPosition = Offset(localPosition.dx, localPosition.dy - imagInfoModel!.scaleHeight!);
// } // }
var zoomState = _zoomKey.currentState;
if (zoomState != null) {
print(zoomState);
}
double remainingHeight = imagInfoModel!.imageHeightOffsetStart!; // double remainingHeight = imagInfoModel!.imageHeightOffsetStart!; //
var _scaleY = (zoomInfo?.scale ?? 1); var _scaleY = (zoomInfo?.scale ?? 1);
if (remainingHeight > 1) { if (remainingHeight > 1) {
localPosition = Offset(localPosition.dx, localPosition.dy - remainingHeight); 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) { if (zoomOffset != null) {
localPosition = Offset(details.position.dx, localPosition.dy); localPosition = Offset(localPosition.dx, localPosition.dy + zoomOffset!.dy.abs());
}
} }
print('移动位置 zoomOffset==>dx${zoomOffset?.dx}'); if (imagInfoModel?.zoom != null && imagInfoModel?.zoom != 1) {
print('移动位置 zoomOffset==>dy${zoomOffset?.dy}'); //
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('缩放的比例:${_scaleY}'); // if (zoomInfo != null) {
print('原本的dy${globalPosition?.dy}'); // localPosition = Offset(details.position.dx, localPosition.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 newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser, data: localPosition));
var newVal1 = ref.read(drawMarkingProvider).offsets..add(localPosition); var newVal1 = ref.read(drawMarkingProvider).offsets..add(localPosition);
@ -377,7 +414,10 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
onPointerUp: (PointerUpEvent details) { onPointerUp: (PointerUpEvent details) {
print('离开.............'); print('离开.............');
if (btnEnum != ReviewMarksBottomBtnsEnum.HANDWRITING) return; if (btnEnum != ReviewMarksBottomBtnsEnum.HANDWRITING) return;
globalPosition = null; globalPosition = null;
//
if (illegalArea) return;
// if (graffitiSwitch.openBrush || graffitiSwitch.openEraser) { // if (graffitiSwitch.openBrush || graffitiSwitch.openEraser) {
// var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser)); // var newVal = ref.read(drawMarkingProvider).data..add(GestureRecording(eraser: graffitiSwitch.openEraser));
// ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal)); // ref.read(drawMarkingProvider.notifier).setState(DrawMarkingVal(newVal));
@ -390,6 +430,7 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
child: IgnorePointer( child: IgnorePointer(
ignoring: btnEnum != ReviewMarksBottomBtnsEnum.DRAG, ignoring: btnEnum != ReviewMarksBottomBtnsEnum.DRAG,
child: Zoom( child: Zoom(
key: _zoomKey,
// initTotalZoomOut: true, // initTotalZoomOut: true,
child: ExamPaperDrawing( child: ExamPaperDrawing(
key: examPaperDrawingKey, key: examPaperDrawingKey,
@ -399,9 +440,9 @@ class PictureOverviewState extends ConsumerState<PictureOverview> with CommonMix
decoration: const BoxDecoration(color: const Color.fromRGBO(249, 250, 254, 1)), decoration: const BoxDecoration(color: const Color.fromRGBO(249, 250, 254, 1)),
), ),
maxZoomWidth: containerWidth, maxZoomWidth: containerWidth,
canvasColor: Colors.transparent, canvasColor: Colors.red,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
maxZoomHeight: imagInfoModel?.scaleHeight, maxZoomHeight: imagInfoModel?.scaleHeight != null ? (imagInfoModel!.scaleHeight! / imagInfoModel!.zoom) : null,
initScale: initScale ?? 1, initScale: initScale ?? 1,
initPosition: zoomOffset, initPosition: zoomOffset,
onScaleUpdate: onScaleUpdate, onScaleUpdate: onScaleUpdate,