解决多指批注问题
This commit is contained in:
parent
4b65ef1e88
commit
0902c0cd0d
|
|
@ -283,6 +283,35 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
|
||||||
// 定时器超时时间,单位为毫秒
|
// 定时器超时时间,单位为毫秒
|
||||||
static const int timeoutDuration = 300;
|
static const int timeoutDuration = 300;
|
||||||
|
|
||||||
|
void toTimer(ValueNotifier<List<dynamic>> vnHandWritings) {
|
||||||
|
timer?.cancel();
|
||||||
|
timer = Timer(const Duration(milliseconds: timeoutDuration), () {
|
||||||
|
if (_activePointers > 2) {
|
||||||
|
_activePointers = 0;
|
||||||
|
if (vnHandWritings.value.last != null) {
|
||||||
|
vnHandWritings.value.add(null); // 增加空点以分隔不同的线段
|
||||||
|
sateData.handwritings = vnHandWritings.value; // 添加笔迹数据
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 获取最后一个点的坐标位置
|
||||||
|
Offset? getLastDrop(List<dynamic> vals, int index) {
|
||||||
|
Offset? lastDrop;
|
||||||
|
if (vals.isNotEmpty) {
|
||||||
|
lastDrop = vals[index] as Offset?;
|
||||||
|
// if (lastDrop == null) {
|
||||||
|
// index -= 1;
|
||||||
|
// if (index > -1) {
|
||||||
|
// lastDrop = getLastDrop(vals, index);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
return lastDrop;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theMaxHeight = useState<double>(maxHeight);
|
final theMaxHeight = useState<double>(maxHeight);
|
||||||
|
|
@ -431,16 +460,17 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
|
||||||
// 处理单个触摸点按下的逻辑
|
// 处理单个触摸点按下的逻辑
|
||||||
_activePointers = _activePointers + 1;
|
_activePointers = _activePointers + 1;
|
||||||
print("+++进入:onPointerDown $_activePointers");
|
print("+++进入:onPointerDown $_activePointers");
|
||||||
timer?.cancel();
|
toTimer(vnHandWritings);
|
||||||
timer = Timer(const Duration(milliseconds: timeoutDuration), () {
|
// timer?.cancel();
|
||||||
if (_activePointers > 0) {
|
// timer = Timer(const Duration(milliseconds: timeoutDuration), () {
|
||||||
_activePointers = 0;
|
// if (_activePointers > 2) {
|
||||||
if (vnHandWritings.value.last != null) {
|
// _activePointers = 0;
|
||||||
vnHandWritings.value.add(null); // 增加空点以分隔不同的线段
|
// if (vnHandWritings.value.last != null) {
|
||||||
sateData.handwritings = vnHandWritings.value; // 添加笔迹数据
|
// vnHandWritings.value.add(null); // 增加空点以分隔不同的线段
|
||||||
}
|
// sateData.handwritings = vnHandWritings.value; // 添加笔迹数据
|
||||||
}
|
// }
|
||||||
});
|
// }
|
||||||
|
// });
|
||||||
sateData.panQuestView = true;
|
sateData.panQuestView = true;
|
||||||
},
|
},
|
||||||
onPointerUp: (PointerUpEvent details) {
|
onPointerUp: (PointerUpEvent details) {
|
||||||
|
|
@ -460,7 +490,7 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
|
||||||
onPointerMove: (PointerMoveEvent event) {
|
onPointerMove: (PointerMoveEvent event) {
|
||||||
print("进入:onPointerMove $_activePointers");
|
print("进入:onPointerMove $_activePointers");
|
||||||
if (_activePointers != 1) return;
|
if (_activePointers != 1) return;
|
||||||
timer?.cancel();
|
toTimer(vnHandWritings);
|
||||||
if (!annotationState.pen.value) return;
|
if (!annotationState.pen.value) return;
|
||||||
|
|
||||||
Offset localPosition = event.localPosition; // 相对
|
Offset localPosition = event.localPosition; // 相对
|
||||||
|
|
@ -500,6 +530,12 @@ class QuestionImageView extends HookWidget with EventBusMixin<BottomOperationBar
|
||||||
(dy - max(0, imageHeightOffsetStart) + ((zoomFile.imageHeightOffsetStart == null || zoomFile.imageHeightOffsetStart! <= 0.1) ? (sateData.zoomOffset?.dy.abs() ?? 0) : 0)) / theScale,
|
(dy - max(0, imageHeightOffsetStart) + ((zoomFile.imageHeightOffsetStart == null || zoomFile.imageHeightOffsetStart! <= 0.1) ? (sateData.zoomOffset?.dy.abs() ?? 0) : 0)) / theScale,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// 判断当前点和上一个点的距离 判断是否是多指
|
||||||
|
var lastDrop = getLastDrop(vnHandWritings.value, vnHandWritings.value.length-1);
|
||||||
|
if (lastDrop != null && ((lastDrop.dx - localPosition.dx).abs() > 40 || (lastDrop.dy - localPosition.dy).abs() > 40)) {
|
||||||
|
/// 当前X点和上一个x点相差 大于10判定为多个手指
|
||||||
|
return;
|
||||||
|
}
|
||||||
// print("最终位置 : $localPosition");
|
// print("最终位置 : $localPosition");
|
||||||
vnHandWritings.value = List.from(vnHandWritings.value)..add(localPosition);
|
vnHandWritings.value = List.from(vnHandWritings.value)..add(localPosition);
|
||||||
sateData.handwritings = vnHandWritings.value;
|
sateData.handwritings = vnHandWritings.value;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue