feat(touch): 单指点选+按住移动动作、端点把手拖拽改时长(触屏目标加大);空白单指不平移

- 选中动作后两端绘制白色把手,端点抓取半径触屏 28px(桌面保持 8px 精确),命中容差 14px

- 短条两端都够得着时抓离手指更近的一端,居中则整体移动

- 触屏空白单指不再平移画布(单指只做选择/编辑,双指捏合缩放+平移);Windows 操作模式不变

- 重建签名 APK
This commit is contained in:
admin
2026-10-07 22:44:28 +08:00
parent 2b04705ba8
commit e99f144793
6 changed files with 88 additions and 26 deletions
+42 -18
View File
@@ -7,6 +7,7 @@
// · 点选、双击新建、拖拽移动相位、拖拽端点改持续角、Shift 拖拽改层;
// · 空白区域拖拽平移、Ctrl + 滚轮缩放;
// · 右键上下文菜单。
import 'dart:io' show Platform;
import 'dart:math' as math;
import 'package:flutter/gestures.dart';
@@ -85,6 +86,15 @@ class _CanvasViewState extends State<CanvasView> {
/// 捏合开始时的焦点(逻辑坐标),作为缩放锚点。
Offset _pinchFocalLogical = Offset.zero;
/// 是否触屏平台(Android / iOS):端点拖拽容差加大、空白单指不平移。
bool get _touch => Platform.isAndroid || Platform.isIOS;
/// 命中容差:触屏用更大的目标,桌面保持精确。
double get _hitSlop => _touch ? 14 : 4;
/// 动作端点(两端把手)的抓取半径:触屏显著加大,避免误判为平移。
double get _grabRadius => _touch ? 28 : 8;
/// 控制器快捷访问器。
AppController get c => widget.controller;
@@ -97,7 +107,7 @@ class _CanvasViewState extends State<CanvasView> {
final List<PhaseZone> zones = c.project.phaseZones;
int best = -1;
bool bestStart = false;
double bestDist = 9;
double bestDist = _touch ? 24 : 9;
for (int i = 0; i < zones.length; i++) {
final double xs = layout.xFor(zones[i].startAngle);
final double xe = layout.xFor(zones[i].endAngle);
@@ -256,8 +266,8 @@ class _CanvasViewState extends State<CanvasView> {
void _onTapDown(TapDownDetails d, Size size) {
final Offset p = _toLogical(d.localPosition, size);
final Action? hit = c.project.viewState.mode == ViewMode.bar
? BarLayout(c.project, size).hitTest(p)
: CircularLayout(c.project, size).hitTest(p);
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop);
// Ctrl(或 Shift)点击:切换该动作的选中状态,实现多选。
final bool toggle = HardwareKeyboard.instance.isControlPressed ||
HardwareKeyboard.instance.isShiftPressed;
@@ -277,8 +287,8 @@ class _CanvasViewState extends State<CanvasView> {
}
}
final Action? hit = c.project.viewState.mode == ViewMode.bar
? BarLayout(c.project, size).hitTest(p)
: CircularLayout(c.project, size).hitTest(p);
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop);
// 双击动作色块 / 圆弧:进入该动作的编辑对话框。
if (hit != null) {
showDialog<void>(
@@ -298,8 +308,10 @@ class _CanvasViewState extends State<CanvasView> {
}
/// 拖拽开始:判断落点是否命中动作。
/// 条形视图下靠近动作右端 8px 视为“调整持续角”,否则为“平移相位”;
/// 圆周视图下统一为“平移相位”。未命中则进入画布平移模式。
/// 条形视图下靠近动作端部([_grabRadius],触屏显著加大)视为“调整持续角 / 起始角”,
/// 否则为“平移相位”;圆周视图同理。未命中动作时:
/// - 桌面:进入画布平移模式;
/// - 触屏:不平移(单指只做选择 / 编辑,平移缩放交给双指)。
void _onPanStart(Offset p, Size size) {
if (c.project.viewState.mode == ViewMode.bar) {
final BarLayout layout = BarLayout(c.project, size);
@@ -313,14 +325,25 @@ class _CanvasViewState extends State<CanvasView> {
_startPointer = p;
return;
}
final Action? hit = layout.hitTest(p);
final Action? hit = layout.hitTest(p, slop: _hitSlop);
if (hit != null) {
final Rect r = layout.rectFor(hit);
final bool nearRight = (p.dx - r.right).abs() <= 8;
final bool nearLeft = (p.dx - r.left).abs() <= 8;
_mode = nearRight
? _DragMode.resize
: (nearLeft ? _DragMode.resizeStart : _DragMode.move);
final double dr = (p.dx - r.right).abs();
final double dl = (p.dx - r.left).abs();
final bool nearRight = dr <= _grabRadius;
final bool nearLeft = dl <= _grabRadius;
if (nearRight && nearLeft) {
// 两端都够得着(短条):抓离手指更近的一端;几乎居中则整体移动。
_mode = dr < dl - 6
? _DragMode.resize
: (dl < dr - 6 ? _DragMode.resizeStart : _DragMode.move);
} else if (nearRight) {
_mode = _DragMode.resize;
} else if (nearLeft) {
_mode = _DragMode.resizeStart;
} else {
_mode = _DragMode.move;
}
_dragAction = hit;
_startPointer = p;
_startAngle = hit.startAngle;
@@ -330,12 +353,12 @@ class _CanvasViewState extends State<CanvasView> {
}
} else {
final CircularLayout layout = CircularLayout(c.project, size);
final Action? hit = layout.hitTest(p);
final Action? hit = layout.hitTest(p, slop: _hitSlop);
if (hit != null) {
final double a = angleOf(layout.center, p);
final double rad = (p - layout.center).distance;
// 距端点约 9px 以内视为拖拽端点(改起止角),否则整体旋转。
final double tolDeg = math.atan2(9, math.max(rad, 1)) * 180 / math.pi;
// 距端点 [grabRadius] 以内视为拖拽端点(改起止角),否则整体旋转。
final double tolDeg = math.atan2(_grabRadius, math.max(rad, 1)) * 180 / math.pi;
final bool nearStart = _angleNear(a, hit.startAngle, tolDeg);
final bool nearEnd = _angleNear(a, math.min(hit.endAngle, 360), tolDeg);
_mode = nearStart
@@ -368,9 +391,10 @@ class _CanvasViewState extends State<CanvasView> {
c.movePhaseZoneBoundary(_zoneIndex, _zoneIsStart, angle);
return;
}
// 未命中动作:整幅画布跟随指针平移。
// 未命中动作:桌面端整幅画布跟随指针平移;触屏端不平移
// (单指只做选择 / 编辑,平移与缩放交给双指捏合)。
if (_dragAction == null) {
c.panBy(screenDelta);
if (!_touch) c.panBy(screenDelta);
return;
}
final bool shift = HardwareKeyboard.instance.isShiftPressed;