Gradient: a freeform line stays open over its object's stroke on a layer with Preview off

The check for whether the pointer is still on the object hit the object's
painted art with outline off, but the hit test turned outline back on for
a layer with Preview off, so a move onto the stroke past the fill ended
the line. A new HitOptions field, ignore_layer_preview, keeps the point
hit tests from switching to outline for such layers, and the freeform
check sets it. the_stroke_counts_as_the_object now runs with the layer's
Preview on and off.
This commit is contained in:
dotCooCoo
2026-11-20 17:07:31 -08:00
parent 2d0389c8fd
commit 873a5562a7
4 changed files with 38 additions and 20 deletions
+9 -3
View File
@@ -78,6 +78,9 @@ pub struct HitOptions {
/// Off, the empty part of the frame (away from its edge and its lines of type) takes no
/// clicks, so they reach the art behind (#7274).
pub area_type_interior: bool,
/// The point hit tests ([`hit_test`], [`hit_test_visible`] and [`hit_test_visible_skipping`])
/// hit the art on a layer whose Preview is off as painted, not in outline.
pub ignore_layer_preview: bool,
}
impl Default for HitOptions {
@@ -90,6 +93,7 @@ impl Default for HitOptions {
skip_guides: false,
clip_outlines: false,
area_type_interior: false,
ignore_layer_preview: false,
scope: None,
}
}
@@ -847,7 +851,7 @@ fn hit_test_skipping(doc: &Document, p: Point, opt: HitOptions, skip: &dyn Fn(No
continue;
}
chain.push(layer.id);
let opt = if matches!(layer.kind, NodeKind::Layer { preview: false, .. }) { HitOptions { outline: true, ..opt } } else { opt };
let opt = if !opt.ignore_layer_preview && previews_off(layer) { HitOptions { outline: true, ..opt } } else { opt };
if let Some(h) = hit_children(layer, p, opt, &symbols, skip, &mut chain, editable_only) {
return Some(finish(h));
}
@@ -1211,7 +1215,9 @@ fn hit_children(
chain.push(c.id);
let hit = plain(i == 0 && clip.is_some(), || match &c.kind {
// A sublayer whose Preview is off is clicked in outline, like an outline view.
NodeKind::Layer { preview: false, .. } => hit_children(c, p, HitOptions { outline: true, ..opt }, symbols, skip, chain, editable_only),
NodeKind::Layer { preview: false, .. } if !opt.ignore_layer_preview => {
hit_children(c, p, HitOptions { outline: true, ..opt }, symbols, skip, chain, editable_only)
}
NodeKind::Layer { .. } | NodeKind::Group { .. } | NodeKind::Intertwine { .. } => {
hit_children(c, p, opt, symbols, skip, chain, editable_only)
}
@@ -1325,7 +1331,7 @@ fn art_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, accept: &
match &n.kind {
NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } | NodeKind::Intertwine { children } => {
// A layer with Preview off is clicked in outline, as [`hit_children`] clicks it.
let opt = HitOptions { outline: opt.outline || previews_off(n), ..opt };
let opt = HitOptions { outline: opt.outline || !opt.ignore_layer_preview && previews_off(n), ..opt };
if n.clips()
&& let Some(clip) = children.first()
{
+1
View File
@@ -1463,6 +1463,7 @@ const SELECTING: HitOptions = HitOptions {
skip_guides: false,
clip_outlines: true,
area_type_interior: false,
ignore_layer_preview: false,
scope: None,
};
+1
View File
@@ -451,6 +451,7 @@ impl ToolContext<'_> {
skip_guides: !self.guides,
clip_outlines: false,
area_type_interior: false,
ignore_layer_preview: false,
}
}
+27 -17
View File
@@ -216,8 +216,9 @@ fn on_object(cx: &ToolContext, id: NodeId, p: Point) -> bool {
keep.insert(c.id);
});
keep.extend(ancestry);
// The art as painted, whatever the view and the path-only selection preferences.
let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ..cx.hit_options() };
// The art as painted, whatever the view, the layers' Preview and the path-only selection
// preferences.
let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ignore_layer_preview: true, ..cx.hit_options() };
hit_test_visible_skipping(cx.doc, p, opt, &|n| !keep.contains(&n)).is_some_and(|h| h.leaf == id || h.ancestry.contains(&id))
}
@@ -530,23 +531,32 @@ mod tests {
}
/// The object's stroke is part of the object: moving onto it past the filled area keeps the
/// line open, and moving past the stroke ends it.
/// line open, and moving past the stroke ends it. The same holds on a layer with Preview off.
#[test]
fn the_stroke_counts_as_the_object() {
let (mut d, s) = doc(FreeformMode::Lines);
let id = s.objects[0];
d.node_mut(id).unwrap().appearance.stroke_mut().unwrap().width = 20.0;
let p = paint();
let mut cx = cx(&d, &s, &p);
let mut t = GradientTool::default();
let add = |x: f64, y: f64, line: bool| Action::Exec("paint.freeform.addPoint".into(), json!({"at": [x, y], "line": line, "stroke": false}));
assert_eq!(click(&mut t, &cx, 140.0, 150.0), vec![add(140.0, 150.0, false)]);
cx.freeform_point = Some(2);
t.pointer(&cx, &ev(PointerKind::Move, 206.0, 150.0));
assert!(t.claims_key(&cx, ToolKey::Escape), "on the stroke the line stays open");
assert_eq!(click(&mut t, &cx, 160.0, 150.0), vec![add(160.0, 150.0, true)]);
t.pointer(&cx, &ev(PointerKind::Move, 230.0, 150.0));
assert!(!t.claims_key(&cx, ToolKey::Escape), "past the stroke the line has ended");
for preview in [true, false] {
let (mut d, s) = doc(FreeformMode::Lines);
let id = s.objects[0];
d.node_mut(id).unwrap().appearance.stroke_mut().unwrap().width = 20.0;
let l = d.layers[0].id;
if let vectorcraft_doc::NodeKind::Layer { preview: p, .. } = &mut d.node_mut(l).unwrap().kind {
*p = preview;
}
let p = paint();
let mut cx = cx(&d, &s, &p);
let mut t = GradientTool::default();
cx.freeform_point = Some(2);
// The line starts from the existing point.
assert!(click(&mut t, &cx, 150.0, 180.0).is_empty());
t.pointer(&cx, &ev(PointerKind::Move, 206.0, 150.0));
assert!(t.claims_key(&cx, ToolKey::Escape), "on the stroke the line stays open (Preview {preview})");
if preview {
let add = Action::Exec("paint.freeform.addPoint".into(), json!({"at": [160.0, 150.0], "line": true, "stroke": false}));
assert_eq!(click(&mut t, &cx, 160.0, 150.0), vec![add]);
}
t.pointer(&cx, &ev(PointerKind::Move, 230.0, 150.0));
assert!(!t.claims_key(&cx, ToolKey::Escape), "past the stroke the line has ended (Preview {preview})");
}
}
/// In a clipping mask, the part of the object the mask hides is outside it: moving there ends