feat(touch): 单指点选+按住移动动作、端点把手拖拽改时长(触屏目标加大);空白单指不平移
- 选中动作后两端绘制白色把手,端点抓取半径触屏 28px(桌面保持 8px 精确),命中容差 14px - 短条两端都够得着时抓离手指更近的一端,居中则整体移动 - 触屏空白单指不再平移画布(单指只做选择/编辑,双指捏合缩放+平移);Windows 操作模式不变 - 重建签名 APK
This commit is contained in:
@@ -190,11 +190,12 @@ class BarLayout {
|
||||
|
||||
/// 命中测试:返回坐标 [p] 处最上层的动作,未命中返回 null。
|
||||
///
|
||||
/// 从后往前遍历(后绘制的在上层),并向外膨胀 4px 提升可点性。
|
||||
Action? hitTest(Offset p) {
|
||||
/// 从后往前遍历(后绘制的在上层),并按 [slop] 向外膨胀矩形提升可点性
|
||||
/// (触屏平台可传入更大的容差)。
|
||||
Action? hitTest(Offset p, {double slop = 4}) {
|
||||
for (int i = ordered.length - 1; i >= 0; i--) {
|
||||
final Action a = ordered[i];
|
||||
final Rect r = rectFor(a).inflate(4);
|
||||
final Rect r = rectFor(a).inflate(slop);
|
||||
if (r.contains(p)) return a;
|
||||
}
|
||||
return null;
|
||||
@@ -281,16 +282,16 @@ class CircularLayout {
|
||||
/// 命中测试:返回坐标 [p] 命中的动作,未命中返回 null。
|
||||
///
|
||||
/// 算法:计算点相对圆心的距离 [d] 与角度 [a];遍历所有动作,先按径向
|
||||
/// 距离过滤(与所在环的偏差不超过半个环宽 + 3px),再判断角度是否落在
|
||||
/// 该动作弧段内;在候选中取径向偏差最小者。
|
||||
Action? hitTest(Offset p) {
|
||||
/// 距离过滤(与所在环的偏差不超过半个环宽 + [slop]),再判断角度是否落在
|
||||
/// 该动作弧段内;在候选中取径向偏差最小者(触屏平台可传入更大的容差)。
|
||||
Action? hitTest(Offset p, {double slop = 3}) {
|
||||
final double d = (p - center).distance;
|
||||
final double a = angleOf(center, p);
|
||||
Action? best;
|
||||
double bestDelta = double.infinity;
|
||||
for (final Action a2 in project.actions) {
|
||||
final double r = radiusFor(a2.layer);
|
||||
if ((d - r).abs() > ringWidth / 2 + 3) continue;
|
||||
if ((d - r).abs() > ringWidth / 2 + slop) continue;
|
||||
if (_inArc(a2, a)) {
|
||||
final double delta = (d - r).abs();
|
||||
if (delta < bestDelta) {
|
||||
|
||||
@@ -360,6 +360,11 @@ class BarPainter extends CustomPainter {
|
||||
..color = tokens.crit,
|
||||
);
|
||||
}
|
||||
// 选中时在两端绘制把手:提示可拖拽端点改时长(触屏目标更大、更好抓)。
|
||||
if (sel) {
|
||||
_handle(canvas, Offset(r.left, r.center.dy));
|
||||
_handle(canvas, Offset(r.right, r.center.dy));
|
||||
}
|
||||
if (a.wrap && u.autoSplitWrap) {
|
||||
final double wx = layout.xFor(a.endAngle - 360) - layout.plotLeft;
|
||||
final Rect tail = Rect.fromLTWH(layout.plotLeft, r.top, math.max(wx, 2), r.height);
|
||||
@@ -389,6 +394,19 @@ class BarPainter extends CustomPainter {
|
||||
color: tokens.dim, size: 10, align: TextAlign.right);
|
||||
}
|
||||
|
||||
/// 绘制端点把手:白边圆点,提示可拖拽端点改时长。
|
||||
void _handle(Canvas canvas, Offset o) {
|
||||
canvas.drawCircle(o, 6, Paint()..color = tokens.accent);
|
||||
canvas.drawCircle(
|
||||
o,
|
||||
6,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2
|
||||
..color = Colors.white,
|
||||
);
|
||||
}
|
||||
|
||||
/// 绘制动作依赖连线(正交折线)。
|
||||
///
|
||||
/// 算法要点:
|
||||
|
||||
@@ -349,6 +349,21 @@ class CircularPainter extends CustomPainter {
|
||||
..color = tokens.accent,
|
||||
);
|
||||
}
|
||||
// 选中时在弧两端绘制把手:提示可拖拽端点改持续角(触屏更好抓)。
|
||||
for (final Offset h in <Offset>[
|
||||
polar(c, r, a.startAngle),
|
||||
polar(c, r, math.min(a.endAngle, 360)),
|
||||
]) {
|
||||
canvas.drawCircle(h, 6, Paint()..color = tokens.accent);
|
||||
canvas.drawCircle(
|
||||
h,
|
||||
6,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2
|
||||
..color = Colors.white,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 文字沿圆弧排列并按弧长截断,保证始终位于动作色带之内。
|
||||
|
||||
+42
-18
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user