From c7afafc3aace2fbe2fa35b891daaed8816a4aa20 Mon Sep 17 00:00:00 2001 From: "DESKTOP-I3JPKHK\\wy" <1111> Date: Mon, 29 Sep 2025 17:22:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(homework=5Freview):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=89=B9=E6=B3=A8=E7=BB=98=E5=88=B6=E4=B8=8E=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E6=8D=A2=E7=AE=97=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=B5=81=E7=95=85=E5=BA=A6=20-=20=E6=89=B9=E6=B3=A8=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=94=B9=E4=B8=BA=20Path=20=E8=81=9A=E5=90=88?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=80=A7=E7=BB=98=E5=88=B6=20-=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E9=AB=98=E9=A2=91=20print=EF=BC=8C=E5=BC=80=E5=90=AF?= =?UTF-8?q?=20CustomPaint=20isComplex/willChange=20-=20=E6=97=A0=E5=8F=98?= =?UTF-8?q?=E6=8D=A2=E6=97=B6=E8=B7=B3=E8=BF=87=E9=80=86=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=20-=20=E5=9B=9E=E6=BB=9A=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84?= =?UTF-8?q?=20RepaintBoundary/=E4=BD=8E=E8=BF=87=E6=BB=A4=20-=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20Path=20=E5=88=A4=E7=A9=BA=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/question_paper_view.dart | 65 +++++++++++++++---- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/making_school_asignment_app/lib/page/home_page/children/homework_review/components/question_paper_view.dart b/making_school_asignment_app/lib/page/home_page/children/homework_review/components/question_paper_view.dart index a4e76e7..141067d 100644 --- a/making_school_asignment_app/lib/page/home_page/children/homework_review/components/question_paper_view.dart +++ b/making_school_asignment_app/lib/page/home_page/children/homework_review/components/question_paper_view.dart @@ -518,7 +518,7 @@ class QuestionImageView extends HookWidget with EventBusMixin 0) { activePointers.value = activePointers.value - 1; } - print("---进入:onPointerUp ${activePointers.value}"); + // 移除高频日志,避免导致掉帧 timerRef.value?.cancel(); if (!annotationState.pen.value) return; @@ -526,7 +526,7 @@ class QuestionImageView extends HookWidget with EventBusMixin 图片坐标(通过逆矩阵) - final inv = Matrix4.inverted(matrix); - final v = inv.transform3(Vector3(localPosition.dx, localPosition.dy, 0)); - localPosition = Offset(v.x, v.y); + // final inv = Matrix4.inverted(matrix); + // final v = inv.transform3(Vector3(localPosition.dx, localPosition.dy, 0)); + // localPosition = Offset(v.x, v.y); + + /// 屏幕坐标 -> 图片坐标(通过逆矩阵)。当无缩放/平移时走快速路径,避免不必要求逆 + /// 它们是 Matrix4 内部 4x4 矩阵的平移分量(列主序存储)。 + /// storage[12] 是平移的 x 分量,storage[13] 是平移的 y 分量(storage[14] 则是 z)。 + /// 因为 Matrix4 采用列主序,索引计算为 index = col * 4 + row,平移在第 4 列的前 3 行,所以是 12、13、14。 + /// 用途:当 theScale == 1.0 && storage[12] == 0.0 && storage[13] == 0.0 时,可判定无缩放/平移,走快速路径跳过逆矩阵。 + final double tx = matrix.storage[12]; + final double ty = matrix.storage[13]; + if (theScale == 1.0 && tx == 0.0 && ty == 0.0) { + // identity 变换,局部坐标无需转换 + } else { + final inv = Matrix4.inverted(matrix); + final v = inv.transform3(Vector3(localPosition.dx, localPosition.dy, 0)); + localPosition = Offset(v.x, v.y); + } // 在图片坐标系做边界校验(更直观):0..maxWidth、0..actualHeight if (localPosition.dy < 0 || localPosition.dy > actualHeight) return; @@ -625,7 +640,8 @@ class QuestionImageView extends HookWidget with EventBusMixin points = ctrl.value; + if (points.isEmpty) return; + + Path path = Path(); + Offset? previous; + for (int i = 0; i < points.length; i++) { + final Offset? current = points[i] as Offset?; + if (current == null) { + // 提交当前子路径 + if (path.computeMetrics().isNotEmpty) { + canvas.drawPath(path, paintBrush); + } + path = Path(); + previous = null; + continue; } + if (previous == null) { + path.moveTo(current.dx, current.dy); + } else { + path.lineTo(current.dx, current.dy); + } + previous = current; + } + // 绘制最后的子路径 + if (path.computeMetrics().isNotEmpty) { + canvas.drawPath(path, paintBrush); } }