fix(交互/渲染): 手写笔拖拽、换泳道与依赖标签排版

- 触屏单指拖拽改走原始指针事件(绕开手势竞技场),手写笔拖拽端点更稳
- 端点把手优先命中:精确点在把手上也能选中并拖拽
- 换泳道不再因目标泳道时间重叠而拒绝(消除“磁吸回弹”),斜向拖拽也能换道
- 依赖标签:FS/SS 缩短、字号收小、去掉五角星;条形图上下/左右自动避让,
  圆周图沿半径自动避让,避免标签互相压盖
- 条形动作条 22→18px、泳道间距上限 52→58;圆周环宽略收窄、环间距上限提高
- 图例:关键路径改为「线条加粗光晕」示例
This commit is contained in:
2026-10-08 14:34:04 +08:00
parent 76d1ce0d9a
commit 5e30ab17a2
6 changed files with 292 additions and 82 deletions
+10 -8
View File
@@ -105,11 +105,12 @@ class BarLayout {
/// 参数 [project]:项目数据;[size]:可用画布尺寸。
/// 副作用:初始化 [pitch]。
BarLayout(this.project, this.size) {
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**泳道数**均分并夹取到 [44, 52],
// 让相邻泳道之间的空隙刚好容纳依赖箭头与其图注。
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**泳道数**均分并夹取到 [44, 58],
// 让相邻泳道之间的空隙能容纳依赖连线及其标签(上限定得高一些,
// 泳道少时获得更多垂直间隙,减少标签相互压盖)。
final int n = lanes.length;
final double usable = size.height - topPad - bottomReserve;
pitch = n == 0 ? 52 : (usable / n).clamp(44, 52);
pitch = n == 0 ? 58 : (usable / n).clamp(44, 58);
}
/// 布局所依据的项目数据。
@@ -124,8 +125,8 @@ class BarLayout {
/// 顶部留白(为标题/刻度等预留)。
static const double topPad = 210;
/// 单个动作条的高度(像素):单行文字即可,条块更苗条。
static const double barH = 22;
/// 单个动作条的高度(像素):单行文字即可,条块更苗条(留出更多泳道间隙放依赖标签)。
static const double barH = 18;
/// 行的视觉参考高度(像素)。
static const double rowVisual = 36;
@@ -222,9 +223,10 @@ class CircularLayout {
final double maxR = math.min(size.width, size.height) / 2 - 74;
// 在 r0 与 maxR 之间均分各轨道,环间距夹取到 [32, 52]:
// 让相邻环之间留出足够空隙放置依赖箭头与图注。
pitch = layers <= 1 ? 44 : ((maxR - r0) / (layers - 1)).clamp(32, 52);
// 动作环带宽度:只求容纳文字(约 15–18px),环更窄、环间空隙更宽。
ringWidth = (pitch * 0.45).clamp(15, 18);
pitch = layers <= 1 ? 46 : ((maxR - r0) / (layers - 1)).clamp(32, 56);
// 动作环带宽度:只求容纳文字(约 15–18px),环更窄、环间空隙更宽,
// 便于在环间放置依赖标签(减少与动作名、其它标签的压盖)。
ringWidth = (pitch * 0.42).clamp(14, 17);
}
/// 布局所依据的项目数据。
+62 -20
View File
@@ -426,6 +426,8 @@ class BarPainter extends CustomPainter {
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
};
int k = 0;
// 依赖标签先收集、后统一避让放置(见方法末尾 _placeChips)。
final List<_ChipSpec> chips = <_ChipSpec>[];
for (final Action to in ordered) {
for (final Dependency d in to.deps) {
final Action? from = project.actionById(d.fromId);
@@ -434,8 +436,14 @@ class BarPainter extends CustomPainter {
final int ib = index[to.id] ?? 0;
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
final String label = d.type == DepType.fs ? 'FS 顺序' : 'SS +${d.offsetAngle.toStringAsFixed(0)}°';
final double chipW = _tp(label, 9.5, col, FontWeight.w600).width + 14 + (crit ? 15 : 0);
// 标签缩短 + 字号收小,减少占位与相互遮挡(关键路径已由线条光晕表示)。
final String label = switch (d.type) {
DepType.fs => 'FS',
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
DepType.ff => 'FF',
DepType.sf => 'SF',
};
final double chipW = _tp(label, 8.5, col, FontWeight.w600).width + 12;
final Rect ra = layout.rectFor(from);
final Rect rb = layout.rectFor(to);
const double barHalf = BarLayout.barH / 2;
@@ -533,11 +541,12 @@ class BarPainter extends CustomPainter {
..color = col.withValues(alpha: 0.95),
);
_arrow(canvas, arrowTip, arrowDir, col);
// 标签置于依赖线旁,避免压住箭头。
_chip(canvas, Offset(chipX, chipY), label, col, crit);
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
chips.add(_ChipSpec(Offset(chipX, chipY), label, col));
k++;
}
}
_placeChips(canvas, chips);
}
/// 在 [tip] 处绘制指向 [dir] 方向的实心三角箭头。
@@ -555,16 +564,41 @@ class BarPainter extends CustomPainter {
canvas.drawPath(p, Paint()..color = col);
}
/// 绘制依赖类型标签胶囊。
/// 统一放置并绘制依赖标签,避免标签之间相互重叠。
///
/// 参数 [center]:胶囊中心;[label]:文字;[col]:边框与文字色;
/// [crit]:为真时在左侧追加星形关键标记,并把胶囊加宽。
void _chip(Canvas canvas, Offset center, String label, Color col, bool crit) {
// 图注字号与刻度文字接近,整体更紧凑。
final TextPainter tp = _tp(label, 9.5, col, FontWeight.w600);
final double w = tp.width + 14 + (crit ? 15 : 0);
const double h = 15;
final Rect r = Rect.fromCenter(center: center, width: w, height: h);
/// 对每个标签依次尝试:原位 → 上下错开 → 上下再错开 → 左右错开 → 斜向错开,
/// 取第一个不与已放置标签相交的位置,实现“智能避让”。标签内不再绘制五角星
/// (关键路径改用线条光晕表示),字号与色块同时收小,画面更干净。
void _placeChips(Canvas canvas, List<_ChipSpec> chips) {
final List<Rect> placed = <Rect>[];
for (final _ChipSpec chip in chips) {
final TextPainter tp = _tp(chip.label, 8.5, chip.color, FontWeight.w600);
final double w = tp.width + 12;
const double h = 14;
final List<Offset> trials = <Offset>[
Offset.zero,
Offset(0, -(h + 3)), Offset(0, h + 3),
Offset(0, -2 * (h + 3)), Offset(0, 2 * (h + 3)),
Offset(0, -3 * (h + 3)), Offset(0, 3 * (h + 3)),
Offset(w + 6, 0), Offset(-w - 6, 0),
Offset(w + 6, -(h + 3)), Offset(-w - 6, -(h + 3)),
Offset(w + 6, h + 3), Offset(-w - 6, h + 3),
];
Rect r = Rect.fromCenter(center: chip.center, width: w, height: h);
for (final Offset t in trials) {
final Rect cand = r.shift(t);
if (!placed.any((Rect o) => o.inflate(1.5).overlaps(cand))) {
r = cand;
break;
}
}
placed.add(r);
_chipRect(canvas, r, tp, chip.color);
}
}
/// 按给定矩形绘制一颗标签胶囊(无星标)。
void _chipRect(Canvas canvas, Rect r, TextPainter tp, Color col) {
canvas.drawRRect(
RRect.fromRectAndRadius(r, const Radius.circular(5)),
Paint()..color = tokens.chip,
@@ -576,13 +610,7 @@ class BarPainter extends CustomPainter {
..strokeWidth = 1
..color = col,
);
if (crit) {
canvas.drawCircle(Offset(r.left + 8, center.dy), 6, Paint()..color = tokens.crit);
_text(canvas, '★', Offset(r.left + 8, center.dy), color: tokens.onAccent, size: 9, align: TextAlign.center);
tp.paint(canvas, Offset(r.left + 16, center.dy - tp.height / 2));
} else {
tp.paint(canvas, Offset(r.left + 7, center.dy - tp.height / 2));
}
tp.paint(canvas, Offset(r.left + 6, r.center.dy - tp.height / 2));
}
/// 构造并布局一个 [TextPainter]。
@@ -653,3 +681,17 @@ class BarPainter extends CustomPainter {
@override
bool shouldRepaint(covariant BarPainter old) => true;
}
/// 依赖标签的待放置描述:中心点、文本与颜色。
///
/// 在依赖遍历中收集,随后由 `BarPainter._placeChips` 统一做避让放置。
class _ChipSpec {
const _ChipSpec(this.center, this.label, this.color);
/// 期望的标签中心(逻辑坐标)。
final Offset center;
/// 标签文本(如 `FS` / `SS+30°`)。
final String label;
/// 边框与文字颜色(按依赖类型区分)。
final Color color;
}
+50 -11
View File
@@ -131,11 +131,14 @@ class CircularPainter extends CustomPainter {
// 依赖连线先于动作弧绘制,使其位于弧之下、不被遮挡。
if (project.viewState.showDeps) {
final List<_ArcChip> chips = <_ArcChip>[];
for (final Action to in project.actions) {
for (final Dependency d in to.deps) {
_dep(canvas, layout, d);
final _ArcChip? chip = _dep(canvas, layout, d);
if (chip != null) chips.add(chip);
}
}
_placeArcChips(canvas, layout, chips);
}
// 逐个绘制动作弧。
@@ -381,10 +384,10 @@ class CircularPainter extends CustomPainter {
/// - 相邻层取两层半径均值作为 [rC];层差大于 1 时改用最外圈 `rMax+24` 绕行。
/// - [large]/[cw] 决定圆弧走大弧还是小弧、顺时针还是逆时针。
/// - 关键依赖先画低透明度粗描边,再画主线,最后放置 `A→B 类型` 胶囊。
void _dep(Canvas canvas, CircularLayout layout, Dependency d) {
_ArcChip? _dep(Canvas canvas, CircularLayout layout, Dependency d) {
final Action? A = project.actionById(d.fromId);
final Action? B = project.actionById(d.toId);
if (A == null || B == null) return;
if (A == null || B == null) return null;
final Offset c = layout.center;
final double rA = layout.radiusFor(A.layer);
final double rB = layout.radiusFor(B.layer);
@@ -455,14 +458,34 @@ class CircularPainter extends CustomPainter {
String label = d.type == DepType.fs ? 'FS' : 'SS+${d.offsetAngle.toStringAsFixed(0)}°';
if (d.type == DepType.ff) label = 'FF';
if (d.type == DepType.sf) label = 'SF';
// 依赖标签沿圆弧切向排布(与动作名一致),呈现“圆弧效果”。
final double arcLen = 2 * math.pi * chipR * 0.9;
_arcLabel(canvas, c, chipR, chipDeg, '${A.id}→${B.id} $label', col, 10,
math.max(math.min(arcLen, 200), 40));
if (crit) {
final Offset sp = polar(c, chipR, chipDeg);
canvas.drawCircle(sp.translate(-46, 0), 7, Paint()..color = tokens.crit);
_text(canvas, '★', sp.translate(-46, 0), color: tokens.onAccent, size: 9, align: TextAlign.center, weight: FontWeight.w700);
// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips]),
// 字号收小、取消五角星,避免多个依赖(尤其 FS 与 SS 并存)互相压盖。
return _ArcChip(chipR, chipDeg, '${A.id}→${B.id} $label', col);
}
/// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。
///
/// 估算每个标签的占位矩形(文本长度 × 字号),若与已放置标签相交则按
/// +14 / −14 / +28 / −28 … 的步长沿半径方向挪动,直到找到空位。
void _placeArcChips(Canvas canvas, CircularLayout layout, List<_ArcChip> chips) {
final Offset c = layout.center;
final List<Rect> placed = <Rect>[];
const double size = 8.5;
for (final _ArcChip chip in chips) {
final double w = chip.text.runes.length * size * 0.62 + 8;
final double h = size * 1.7;
double r = chip.r;
Rect rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
for (int i = 1; i <= 10; i++) {
if (!placed.any((Rect o) => o.inflate(1.5).overlaps(rect))) break;
final double step = 14.0 * ((i + 1) ~/ 2);
r = chip.r + (i.isOdd ? step : -step);
rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
}
placed.add(rect);
final double arcLen = 2 * math.pi * r * 0.9;
_arcLabel(canvas, c, r, chip.deg, chip.text, chip.color, size,
math.max(math.min(arcLen, 200), 40));
}
}
@@ -626,3 +649,19 @@ class CircularPainter extends CustomPainter {
@override
bool shouldRepaint(covariant CircularPainter old) => true;
}
/// 圆周视图依赖标签的待放置描述:半径、角度、文本与颜色。
///
/// 先在依赖遍历中收集,再由 [CircularPainter] 统一做径向避让绘制。
class _ArcChip {
const _ArcChip(this.r, this.deg, this.text, this.color);
/// 期望的标签半径(像素)。
final double r;
/// 期望的标签角度(度,0° = 12 点钟、顺时针)。
final double deg;
/// 标签文本(如 `A1→A2 SS+30°`)。
final String text;
/// 文本颜色(按依赖类型区分)。
final Color color;
}
+6 -8
View File
@@ -704,8 +704,9 @@ class AppController extends ChangeNotifier {
/// 将动作 [id] 移动到第 [targetLane] 条泳道 / 轨道(上下拖拽换道)。
///
/// 泳道可容纳多个动作;仅当目标泳道内存在**时间重叠**的动作时才拒绝,
/// 并给出状态提示(与音频轨道“不能重叠”的语义一致)。
/// 不再因「目标泳道在该时间段已有动作」而拒绝:换道是高频拖拽操作,一旦拒绝,
/// 动作会被“磁吸”回原泳道(表现为拖不动)。现允许放入并在状态栏提示时间重叠,
/// 由用户自行调整相位;[canPlaceInLane] 仍用于拖拽时的可视化提示。
void moveActionLane(String id, int targetLane) {
final Action? moving = _project.actionById(id);
if (moving == null) return;
@@ -715,13 +716,10 @@ class AppController extends ChangeNotifier {
o.id != id &&
o.layer == lane &&
angleRangesOverlap(moving.startAngle, moving.endAngle, o.startAngle, o.endAngle));
if (overlap) {
_status = '轨道 L${lane + 1} 在该时间段已有动作,无法放入';
notifyListeners();
return;
}
updateAction(id, (Action x) => x.copyWith(layer: lane, row: lane),
status: '移至轨道 L${lane + 1}');
status: overlap
? '移至轨道 L${lane + 1}(与该轨道动作时间重叠)'
: '移至轨道 L${lane + 1}');
}
/// 目标泳道 [lane] 是否能容纳动作 [id](不与其内动作时间重叠)。
+22 -19
View File
@@ -355,16 +355,16 @@ class _DepTypeLegend extends StatelessWidget {
const SizedBox(height: 10),
row(_SampleLine(color: t.fs, dash: false, arrow: true), 'FS 严格顺序(完成后启动)'),
row(_SampleLine(color: t.ss, dash: true, arrow: true), 'SS 并行重叠(可提前启动)'),
row(_SampleLine(color: t.fs, dash: false, arrow: false, star: true), '关键路径(累计最长链)'),
row(_SampleLine(color: t.fs, dash: false, arrow: false, glow: true), '关键路径(线条加粗光晕)'),
],
),
);
}
}
/// 图例中的示例线段:可组合实线/虚线、箭头与关键路径星标。
/// 图例中的示例线段:可组合实线/虚线、箭头与关键路径光晕。
class _SampleLine extends StatelessWidget {
const _SampleLine({required this.color, required this.dash, required this.arrow, this.star = false});
const _SampleLine({required this.color, required this.dash, required this.arrow, this.glow = false});
/// 线条颜色。
final Color color;
@@ -372,22 +372,22 @@ class _SampleLine extends StatelessWidget {
final bool dash;
/// 是否绘制箭头。
final bool arrow;
/// 是否绘制关键路径星标。
final bool star;
/// 是否为关键路径样式(线条加粗光晕)。
final bool glow;
/// 用 [_SamplePainter] 绘制示例线段。
@override
Widget build(BuildContext context) {
return SizedBox(
height: 16,
child: CustomPaint(painter: _SamplePainter(color, dash, arrow, star)),
child: CustomPaint(painter: _SamplePainter(color, dash, arrow, glow)),
);
}
}
/// 示例线段绘制器:按参数绘制实/虚线、箭头与星标。
/// 示例线段绘制器:按参数绘制实/虚线、箭头与关键路径光晕。
class _SamplePainter extends CustomPainter {
_SamplePainter(this.color, this.dash, this.arrow, this.star);
_SamplePainter(this.color, this.dash, this.arrow, this.glow);
/// 线条颜色。
final Color color;
@@ -395,10 +395,10 @@ class _SamplePainter extends CustomPainter {
final bool dash;
/// 是否绘制箭头。
final bool arrow;
/// 是否绘制关键路径星标。
final bool star;
/// 是否为关键路径样式(线条加粗光晕)。
final bool glow;
/// 绘制示例线段本体、箭头及可选星标。
/// 绘制示例线段本体、箭头及可选光晕。
@override
void paint(Canvas canvas, Size size) {
final Paint p = Paint()
@@ -406,6 +406,17 @@ class _SamplePainter extends CustomPainter {
..strokeWidth = 2.4
..strokeCap = StrokeCap.round;
final double y = size.height / 2;
// 关键路径:先铺一层加粗低透明度光晕,再画主线(与画布绘制一致)。
if (glow) {
canvas.drawLine(
Offset(0, y),
Offset(size.width - 10, y),
Paint()
..color = color.withValues(alpha: 0.2)
..strokeWidth = 7
..strokeCap = StrokeCap.round,
);
}
if (dash) {
for (double x = 0; x < size.width - 10; x += 8) {
canvas.drawLine(Offset(x, y), Offset(math.min(x + 4, size.width - 10), y), p);
@@ -421,14 +432,6 @@ class _SamplePainter extends CustomPainter {
..close();
canvas.drawPath(a, Paint()..color = color);
}
if (star) {
canvas.drawCircle(Offset(size.width - 8, y), 7.5, Paint()..color = const Color(0xFF4CC9F0));
final TextPainter tp = TextPainter(
text: const TextSpan(text: '★', style: TextStyle(color: Colors.black, fontSize: 10, fontWeight: FontWeight.w700)),
textDirection: TextDirection.ltr,
)..layout();
tp.paint(canvas, Offset(size.width - 8 - tp.width / 2, y - tp.height / 2));
}
}
/// 示例线段始终重绘(开销极小)。
+142 -16
View File
@@ -86,6 +86,12 @@ class _CanvasViewState extends State<CanvasView> {
/// 捏合开始时的焦点(逻辑坐标),作为缩放锚点。
Offset _pinchFocalLogical = Offset.zero;
/// 触屏单指拖拽占用的原始指针 id(-1 表示空闲)。
///
/// 触屏平台(含手写笔)的单指拖拽走 [Listener] 原始指针事件:绕开手势竞技场
/// 与「精确指针」极小的滑移阈值,避免手写笔拖拽端点时被点按/双点按抢走判定。
int _rawPointer = -1;
/// 是否触屏平台(Android / iOS):端点拖拽容差加大、空白单指不平移。
bool get _touch => Platform.isAndroid || Platform.isIOS;
@@ -138,6 +144,53 @@ class _CanvasViewState extends State<CanvasView> {
return -1;
}
/// 命中动作两端的「把手」圆点:返回 `(动作, 是否起始端)`,未命中返回 null。
///
/// 把手绘制在动作端点(条形 = 条带左右两端、圆周 = 弧两端),可能略在动作本体
/// 之外;精确指针(手写笔)直接点在把手上时,仅靠动作命中测试会落空,因此这里
/// 单独做一次把手邻近命中,半径与 [_grabRadius] 一致。
(Action, bool)? _hitHandle(Offset p, Size size) {
Action? best;
bool bestStart = false;
double bestDist = _grabRadius;
if (c.project.viewState.mode == ViewMode.bar) {
final BarLayout layout = BarLayout(c.project, size);
for (final Action a in c.project.actions) {
final Rect r = layout.rectFor(a);
final double ds = (p - Offset(r.left, r.center.dy)).distance;
final double de = (p - Offset(r.right, r.center.dy)).distance;
if (ds < bestDist) {
bestDist = ds;
best = a;
bestStart = true;
}
if (de < bestDist) {
bestDist = de;
best = a;
bestStart = false;
}
}
} else {
final CircularLayout layout = CircularLayout(c.project, size);
for (final Action a in c.project.actions) {
final double r = layout.radiusFor(a.layer);
final double ds = (p - polar(layout.center, r, a.startAngle)).distance;
final double de = (p - polar(layout.center, r, math.min(a.endAngle, 360))).distance;
if (ds < bestDist) {
bestDist = ds;
best = a;
bestStart = true;
}
if (de < bestDist) {
bestDist = de;
best = a;
bestStart = false;
}
}
}
return best == null ? null : (best, bestStart);
}
/// 更新鼠标指针样式:靠近分区边界或动作端点时显示左右拖拽箭头。
void _updateCursor(Offset local, Size size) {
final Offset p = _toLogical(local, size);
@@ -265,9 +318,12 @@ 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, slop: _hitSlop)
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop);
// 端点把手优先命中:精确点在把手上时也选中该动作,避免误清空选中。
final (Action, bool)? handle = _hitHandle(p, size);
final Action? hit = handle?.$1 ??
(c.project.viewState.mode == ViewMode.bar
? 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;
@@ -325,6 +381,18 @@ class _CanvasViewState extends State<CanvasView> {
_startPointer = p;
return;
}
// 端点把手优先:精确指针(手写笔)点在把手上时可能略在动作体之外,
// 先按把手邻近命中,直接进入「改时长 / 改起始角」模式。
final (Action, bool)? handle = _hitHandle(p, size);
if (handle != null) {
_mode = handle.$2 ? _DragMode.resizeStart : _DragMode.resize;
_dragAction = handle.$1;
_startPointer = p;
_startAngle = handle.$1.startAngle;
_startDuration = handle.$1.durationAngle;
c.select(handle.$1.id);
return;
}
final Action? hit = layout.hitTest(p, slop: _hitSlop);
if (hit != null) {
final Rect r = layout.rectFor(hit);
@@ -353,6 +421,18 @@ class _CanvasViewState extends State<CanvasView> {
}
} else {
final CircularLayout layout = CircularLayout(c.project, size);
// 弧端点把手优先命中(同条形视图)。
final (Action, bool)? handle = _hitHandle(p, size);
if (handle != null) {
_mode = handle.$2 ? _DragMode.resizeStart : _DragMode.resize;
_dragAction = handle.$1;
_startPointer = p;
_startAngle = handle.$1.startAngle;
_startDuration = handle.$1.durationAngle;
_startAnglePointer = angleOf(layout.center, p);
c.select(handle.$1.id);
return;
}
final Action? hit = layout.hitTest(p, slop: _hitSlop);
if (hit != null) {
final double a = angleOf(layout.center, p);
@@ -402,7 +482,6 @@ class _CanvasViewState extends State<CanvasView> {
// 条形视图:水平位移按时间轴跨度换算为相位角。
final BarLayout layout = BarLayout(c.project, size);
final double dx = p.dx - _startPointer.dx;
final double dy = p.dy - _startPointer.dy;
if (_mode == _DragMode.resize) {
// 拖右端:固定起始角,改结束角(弱吸附 + 虚线参考)。
final double rawEnd = _startAngle + _startDuration + dx / layout.span * 360;
@@ -420,14 +499,19 @@ class _CanvasViewState extends State<CanvasView> {
(Action x) => x.copyWith(startAngle: ns, durationAngle: fixedEnd - ns),
status: '调整起始角',
);
} else if (dy.abs() > dx.abs() + 6 && dy.abs() > 12) {
// 以垂直为主:上下拖拽换泳道(同泳道可放多个不重叠动作)。
final int target = layout.laneAt(p.dy);
_dropLane = target;
_dropValid = c.canPlaceInLane(_dragAction!.id, target);
c.moveActionLane(_dragAction!.id, target);
} else {
// 整体移动:水平改起始相位 + 垂直跟随泳道,两者可同时进行。
// (原先要求「垂直分量明显大于水平」才换道,斜向拖拽几乎换不了道,
// 表现为“有一股磁吸力、拖不到别的泳道”。)
c.setActionStart(_dragAction!.id, _startAngle + dx / layout.span * 360);
final int curLane =
c.project.actionById(_dragAction!.id)?.layer ?? _dragAction!.layer;
final int target = layout.laneAt(p.dy);
if (target != curLane) {
_dropLane = target;
_dropValid = c.canPlaceInLane(_dragAction!.id, target);
c.moveActionLane(_dragAction!.id, target);
}
}
} else {
// 圆周视图:用指针相对圆心的角度差作为旋转增量,并归一化到 ±180°。
@@ -470,6 +554,39 @@ class _CanvasViewState extends State<CanvasView> {
_dropLane = null;
}
// ===================== 原始指针单指拖拽(触屏:手指 / 手写笔) =====================
/// 原始指针按下:触屏平台自按下瞬间接管单指拖拽。
///
/// 与手势体系解耦,手写笔(精确指针)与手指行为一致;若已有指针在拖拽时
/// 又落下第二根手指,则放弃单指拖拽,交回缩放手势做双指捏合。
void _onRawDown(PointerDownEvent e, Size size) {
if (!_touch) return;
if (_rawPointer == -1) {
_rawPointer = e.pointer;
_onPanStart(_toLogical(e.localPosition, size), size);
return;
}
if (e.pointer != _rawPointer) {
// 第二根手指落下:结束单指拖拽,改由 _onScaleStart 进入捏合。
_rawPointer = -1;
_onPanEnd();
}
}
/// 原始指针移动:单指拖拽(复用 [_onPanUpdate] 的编辑逻辑)。
void _onRawMove(PointerMoveEvent e, Size size) {
if (!_touch || e.pointer != _rawPointer) return;
_onPanUpdate(_toLogical(e.localPosition, size), e.localDelta, size);
}
/// 原始指针抬起 / 取消:结束单指拖拽。
void _onRawUp(PointerEvent e) {
if (!_touch || e.pointer != _rawPointer) return;
_rawPointer = -1;
_onPanEnd();
}
// ===================== 双指捏合缩放 / 平移 =====================
/// 进入捏合会话:记录起始缩放与逻辑焦点(作为缩放锚点)。
@@ -484,19 +601,20 @@ class _CanvasViewState extends State<CanvasView> {
_dropLane = null;
}
/// 缩放手势开始:单指沿用既有拖拽逻辑,双指进入捏合。
/// 缩放手势开始:双指进入捏合;桌面的单指针仍由该手势分发
/// (触屏单指已被 [_onRawDown] 原始指针通道接管,避免竞技场抢判定)。
void _onScaleStart(ScaleStartDetails d, Size size) {
final Offset p = _toLogical(d.localFocalPoint, size);
if (d.pointerCount >= 2) {
_beginPinch(p);
} else {
} else if (!_touch) {
_onPanStart(p, size);
}
}
/// 缩放手势更新:
/// - 双指:以捏合焦点为锚点同时缩放与平移(焦点处内容跟随手指);
/// - 单指:沿用原拖拽逻辑(平移相位 / 改时长 / 平移画布)。
/// - 单指:仅桌面走此路径(平移相位 / 改时长 / 平移画布)。
void _onScaleUpdate(ScaleUpdateDetails d, Size size) {
final Offset p = _toLogical(d.localFocalPoint, size);
if (d.pointerCount >= 2) {
@@ -509,7 +627,7 @@ class _CanvasViewState extends State<CanvasView> {
panX: d.localFocalPoint.dx - _pinchFocalLogical.dx * z,
panY: d.localFocalPoint.dy - _pinchFocalLogical.dy * z,
);
} else if (!_pinching) {
} else if (!_pinching && !_touch) {
_onPanUpdate(p, d.focalPointDelta, size);
}
}
@@ -633,14 +751,22 @@ class _CanvasViewState extends State<CanvasView> {
// 鼠标指针样式:靠近分区边界或动作端点时变为左右拖拽箭头。
return MouseRegion(
cursor: _cursor,
onHover: (PointerHoverEvent e) => _updateCursor(e.localPosition, size),
onHover: (PointerHoverEvent e) {
// 仅鼠标需要光标提示;手写笔悬停会持续触发,跳过无谓重建。
if (e.kind == PointerDeviceKind.mouse) _updateCursor(e.localPosition, size);
},
onExit: (_) {
if (_cursor != SystemMouseCursors.basic) {
setState(() => _cursor = SystemMouseCursors.basic);
}
},
// 指针信号监听:仅处理滚轮事件(缩放 / 平移)。
// 指针监听:滚轮(缩放 / 平移)+ 触屏单指拖拽
//(走原始指针事件,手指与手写笔行为一致,不受手势竞技场影响)。
child: Listener(
onPointerDown: (PointerDownEvent e) => _onRawDown(e, size),
onPointerMove: (PointerMoveEvent e) => _onRawMove(e, size),
onPointerUp: _onRawUp,
onPointerCancel: _onRawUp,
onPointerSignal: (PointerSignalEvent e) {
if (e is PointerScrollEvent) _onScroll(e, size);
},