mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 09:35:43 +00:00
Merge pull request #7291 from dotCooCoo/feat/live-paint-bucket-multi-click
Live Paint: double-click floods across unstroked edges, triple-click paints the same paint
This commit is contained in:
@@ -117,7 +117,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Live Paint Bucket",
|
||||
[],
|
||||
None,
|
||||
"{group?: id | ids?|id?: [id…] (paths to make live first, as livePaint.make does), point: [x,y], points?: [[x,y]…] (a drag polyline starting at point; 1 to 4096 finite canvas points; fills every crossed face of the same group), continuation?: [[[x,y]…]…] (further path chunks of 1 to 4096 finite canvas points each; each starts at the preceding chunk's last point; requires points), color?|swatch?|gradient?|none? (default: current fill; a color in #rrggbbaa or #rgba is refused), tint?: 0..100, keepModel?: bool (both as paint.setFill)} fill the face containing point, skipping hidden faces; when every face it reaches already has the paint, nothing changes (no undo step, and the recent colors stay as they are) → {group, face}",
|
||||
"{group?: id | ids?|id?: [id…] (paths to make live first, as livePaint.make does), point: [x,y], points?: [[x,y]…] (a drag polyline starting at point; 1 to 4096 finite canvas points; fills every crossed face of the same group), continuation?: [[[x,y]…]…] (further path chunks of 1 to 4096 finite canvas points each; each starts at the preceding chunk's last point; requires points), scope?: \"one\" (default: the face alone) | \"connected\" (a double-click: also each face reached across edges that are hidden or draw no stroke, as a flood from the face; a stroked edge, a hidden face or a Gap Detection gap stops it) | \"samePaint\" (a triple-click: also every face of the group whose fill is match; \"connected\" and \"samePaint\" are refused with points), match?: paint (as the document stores it, the `fill` of a face's appearance; scope samePaint only; default: the face's fill), color?|swatch?|gradient?|none? (default: current fill; a color in #rrggbbaa or #rgba is refused), tint?: 0..100, keepModel?: bool (both as paint.setFill)} fill the face containing point, skipping hidden faces; when every face it reaches already has the paint, nothing changes (no undo step, and the recent colors stay as they are) → {group, face, count (faces reached)}",
|
||||
has_doc,
|
||||
lp_fill
|
||||
),
|
||||
@@ -126,7 +126,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Live Paint Bucket (Stroke)",
|
||||
[],
|
||||
None,
|
||||
"{group: id, point: [x,y], color?|swatch?|none? (default: current stroke), width?: pt (default: current weight), tolerance?: pt (4), tint?: 0..100, keepModel?: bool (both as paint.setFill)} paint the edge nearest point; when it already has the paint and the width, nothing changes (no undo step, and the recent colors stay as they are) → {group, edge}",
|
||||
"{group: id, point: [x,y], color?|swatch?|none? (default: current stroke), width?: pt (default: current weight), tolerance?: pt (4), scope?: \"one\" (default: the edge alone) | \"connected\" (a double-click: also each edge joined to it, end to end, through edges that draw with stroke paint match) | \"samePaint\" (a triple-click: also every edge of the group that draws with stroke paint match), match?: paint (as the document stores it; scope connected or samePaint only; default: the stroke paint the edge draws with; an edge draws with the paint of its topmost stroke that is shown, with paint, above 0 pt and not fully transparent, and with none when the edge is fully transparent or has no such stroke), tint?: 0..100, keepModel?: bool (both as paint.setFill)} paint the edge nearest point, skipping hidden edges: each edge reached takes the paint and width in its topmost stroke that is shown, or in a new stroke above the others when it has none; when every edge it reaches already has the paint and the width there, nothing changes (no undo step, and the recent colors stay as they are) → {group, edge, count (edges reached)}",
|
||||
has_doc,
|
||||
lp_stroke_edge
|
||||
),
|
||||
|
||||
@@ -363,9 +363,52 @@ pub(super) fn lp_gap_options(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({ "ids": ids_json(&targets), "faces": faces, "gaps": gaps_json(&gaps), "closed": closed }))
|
||||
}
|
||||
|
||||
/// Which parts a Live Paint Bucket click paints besides the one under the pointer.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum LpScope {
|
||||
/// The part under the pointer alone (a click).
|
||||
One,
|
||||
/// A face and the faces reached from it across edges that draw no stroke ([`b::flood_faces`]),
|
||||
/// or an edge and the edges joined to it end to end that draw with the same stroke paint
|
||||
/// ([`b::connected_edges`], [`b::lp_stroke_paint`]) (a double-click).
|
||||
Connected,
|
||||
/// Every face with the same fill, or every edge that draws with the same stroke paint, in the
|
||||
/// group (a triple-click).
|
||||
SamePaint,
|
||||
}
|
||||
|
||||
/// The `scope` of `livePaint.fill` and `livePaint.strokeEdge`: `one` when left out or null.
|
||||
fn scope_param(p: &Value, c: &str) -> Result<LpScope> {
|
||||
match p.get("scope").filter(|v| !v.is_null()) {
|
||||
None => Ok(LpScope::One),
|
||||
Some(v) => match v.as_str() {
|
||||
Some("one") => Ok(LpScope::One),
|
||||
Some("connected") => Ok(LpScope::Connected),
|
||||
Some("samePaint") => Ok(LpScope::SamePaint),
|
||||
_ => Err(bad(c, "scope must be \"one\", \"connected\" or \"samePaint\"")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// The `match` of `livePaint.fill` and `livePaint.strokeEdge`: a paint as the document stores it,
|
||||
/// None when left out or null. With `allowed` false (a scope that compares no paints) a `match` is
|
||||
/// an error naming `scopes`, the scopes it applies to.
|
||||
fn match_param(p: &Value, c: &str, allowed: bool, scopes: &str) -> Result<Option<super::Paint>> {
|
||||
let Some(v) = p.get("match").filter(|v| !v.is_null()) else { return Ok(None) };
|
||||
if !allowed {
|
||||
return Err(bad(c, format!("match applies only with scope {scopes}")));
|
||||
}
|
||||
serde_json::from_value::<super::Paint>(v.clone()).map(Some).map_err(|_| bad(c, "match must be a paint as the document stores it"))
|
||||
}
|
||||
|
||||
pub(super) fn lp_fill(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "livePaint.fill";
|
||||
let pt = point_param(p, "point").filter(|q| finite(*q)).ok_or_else(|| bad(C, "missing point [x,y]"))?;
|
||||
let scope = scope_param(p, C)?;
|
||||
let like = match_param(p, C, scope == LpScope::SamePaint, "\"samePaint\"")?;
|
||||
if scope != LpScope::One && p.get("points").is_some() {
|
||||
return Err(bad(C, "scope applies to a click: leave out points"));
|
||||
}
|
||||
let parse_chunk = |input: &Value, start: Point| -> Result<Vec<Point>> {
|
||||
let values = input
|
||||
.as_array()
|
||||
@@ -400,7 +443,8 @@ pub(super) fn lp_fill(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let group = object_param(p, "group", C)?;
|
||||
let roots = if group.is_none() { root_ids(s, p)? } else { vec![] };
|
||||
// The faces the click or drag paints in Live Paint group `gid`: the visible face at the point,
|
||||
// and every visible face the drag crosses; → (the face at the point, the faces).
|
||||
// the faces its scope adds, and every visible face the drag crosses; → (the face at the point,
|
||||
// the faces).
|
||||
let targets_in = |d: &Document, gid: NodeId| -> Result<(NodeId, std::collections::BTreeSet<NodeId>)> {
|
||||
let fid = d
|
||||
.node(gid)
|
||||
@@ -408,6 +452,18 @@ pub(super) fn lp_fill(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
.map(|f| f.id)
|
||||
.ok_or_else(|| EngineError::Other("no Live Paint face at that point".into()))?;
|
||||
let mut targets = std::collections::BTreeSet::from([fid]);
|
||||
if scope != LpScope::One {
|
||||
let n = d.node(gid).ok_or(EngineError::NoNode(gid))?;
|
||||
if scope == LpScope::Connected {
|
||||
targets.extend(b::flood_faces(n, fid));
|
||||
} else {
|
||||
let like = match &like {
|
||||
Some(m) => m.clone(),
|
||||
None => d.node(fid).ok_or(EngineError::NoNode(fid))?.appearance.fill_paint(),
|
||||
};
|
||||
targets.extend(b::faces(n).into_iter().filter(|f| f.visible && f.appearance.fill_paint() == like).map(|f| f.id));
|
||||
}
|
||||
}
|
||||
if let Some(points) = points {
|
||||
let n = d.node(gid).ok_or(EngineError::NoNode(gid))?;
|
||||
// Use the existing region-crossing probes, so even a face narrower than the distance
|
||||
@@ -457,34 +513,36 @@ pub(super) fn lp_fill(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
};
|
||||
let (g, face) = match live {
|
||||
let (g, face, count) = match live {
|
||||
Some(gid) => {
|
||||
let (fid, targets) = targets_in(&s.doc()?.doc, gid)?;
|
||||
let count = targets.len();
|
||||
// Faces that already have the paint stay as they are: when every face has it, nothing
|
||||
// changes and no undo step is recorded.
|
||||
let d = &s.doc()?.doc;
|
||||
let unpainted: Vec<NodeId> = targets.into_iter().filter(|t| d.node(*t).is_none_or(|f| f.appearance.fill_paint() != paint)).collect();
|
||||
if unpainted.is_empty() {
|
||||
return Ok(json!({ "group": gid.0, "face": fid.0 }));
|
||||
return Ok(json!({ "group": gid.0, "face": fid.0, "count": count }));
|
||||
}
|
||||
s.edit("Live Paint Bucket", |d, _| {
|
||||
for target in unpainted {
|
||||
d.node_mut(target).ok_or(EngineError::NoNode(target))?.appearance.set_fill(paint.clone());
|
||||
}
|
||||
Ok((gid, fid))
|
||||
Ok((gid, fid, count))
|
||||
})?
|
||||
}
|
||||
None => s.edit("Live Paint Bucket", |d, sel| {
|
||||
let gid = make_live(d, sel, &roots)?.0;
|
||||
let (fid, targets) = targets_in(d, gid)?;
|
||||
let count = targets.len();
|
||||
for target in targets {
|
||||
d.node_mut(target).ok_or(EngineError::NoNode(target))?.appearance.set_fill(paint.clone());
|
||||
}
|
||||
Ok((gid, fid))
|
||||
Ok((gid, fid, count))
|
||||
})?,
|
||||
};
|
||||
s.remember_paint(&paint);
|
||||
Ok(json!({ "group": g.0, "face": face.0 }))
|
||||
Ok(json!({ "group": g.0, "face": face.0, "count": count }))
|
||||
}
|
||||
|
||||
pub(super) fn lp_stroke_edge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
@@ -498,31 +556,72 @@ pub(super) fn lp_stroke_edge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad(C, "width out of range"));
|
||||
}
|
||||
let tol = number_or(p, "tolerance", 4.0, C)?.clamp(0.0, 1000.0);
|
||||
let (eid, unchanged) = {
|
||||
let scope = scope_param(p, C)?;
|
||||
let like = match_param(p, C, scope != LpScope::One, "\"connected\" or \"samePaint\"")?;
|
||||
let (eid, count, changed) = {
|
||||
let d = &s.doc()?.doc;
|
||||
let n = d.node(g).filter(|n| is_live_paint(n)).ok_or_else(|| bad(C, format!("{g} is not a Live Paint group")))?;
|
||||
let e = b::visible_edge_near(n, pt, tol).ok_or_else(|| EngineError::Other("no Live Paint edge near that point".into()))?;
|
||||
// An edge that already has the paint and the width (or has no stroke and gets none) stays as
|
||||
// it is, and no undo step is recorded.
|
||||
let unchanged = match e.appearance.stroke() {
|
||||
Some(st) => st.paint == paint && st.width == width,
|
||||
None => paint.is_none(),
|
||||
let start = b::visible_edge_near(n, pt, tol).ok_or_else(|| EngineError::Other("no Live Paint edge near that point".into()))?;
|
||||
let eid = start.id;
|
||||
let like = like.unwrap_or_else(|| b::lp_stroke_paint(start));
|
||||
let targets = match scope {
|
||||
LpScope::One => vec![eid],
|
||||
LpScope::Connected => b::connected_edges(n, eid, &like),
|
||||
LpScope::SamePaint => std::iter::once(eid)
|
||||
.chain(b::edges(n).into_iter().filter(|e| e.visible && e.id != eid && b::lp_stroke_paint(e) == like).map(|e| e.id))
|
||||
.collect(),
|
||||
};
|
||||
(e.id, unchanged)
|
||||
let count = targets.len();
|
||||
// An edge whose shown stroke already has the paint and the width (or that has no shown stroke
|
||||
// and gets none) stays as it is; when every edge does, nothing changes and no undo step is
|
||||
// recorded.
|
||||
let changed: Vec<NodeId> = targets
|
||||
.into_iter()
|
||||
.filter(|t| {
|
||||
d.node(*t).is_none_or(|e| match shown_stroke(e) {
|
||||
Some(st) => !(st.paint == paint && st.width == width),
|
||||
None => !paint.is_none(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
(eid, count, changed)
|
||||
};
|
||||
if unchanged {
|
||||
return Ok(json!({ "group": g.0, "edge": eid.0 }));
|
||||
if changed.is_empty() {
|
||||
return Ok(json!({ "group": g.0, "edge": eid.0, "count": count }));
|
||||
}
|
||||
let edge = s.edit("Live Paint Bucket", |d, _| {
|
||||
let e = d.node_mut(eid).ok_or(EngineError::NoNode(eid))?;
|
||||
e.appearance.set_stroke(paint.clone());
|
||||
if let Some(st) = e.appearance.stroke_mut() {
|
||||
st.width = width;
|
||||
s.edit("Live Paint Bucket", |d, _| {
|
||||
for target in &changed {
|
||||
let e = d.node_mut(*target).ok_or(EngineError::NoNode(*target))?;
|
||||
match shown_stroke_mut(e) {
|
||||
Some(st) => {
|
||||
st.paint = paint.clone();
|
||||
st.width = width;
|
||||
}
|
||||
None => e.appearance.items.push(super::AppearanceItem::Stroke(super::StrokeLayer::new(paint.clone(), width))),
|
||||
}
|
||||
}
|
||||
Ok(eid)
|
||||
Ok(())
|
||||
})?;
|
||||
s.remember_paint(&paint);
|
||||
Ok(json!({ "group": g.0, "edge": edge.0 }))
|
||||
Ok(json!({ "group": g.0, "edge": eid.0, "count": count }))
|
||||
}
|
||||
|
||||
/// The stroke `livePaint.strokeEdge` paints on Live Paint edge `e`: its topmost stroke that is
|
||||
/// shown. None when it has no stroke or every stroke is hidden; the command then adds a stroke
|
||||
/// above the others.
|
||||
fn shown_stroke(e: &Node) -> Option<&super::StrokeLayer> {
|
||||
e.appearance.items.iter().rev().find_map(|i| match i {
|
||||
super::AppearanceItem::Stroke(s) if s.visible => Some(s),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// [`shown_stroke`], to change.
|
||||
fn shown_stroke_mut(e: &mut Node) -> Option<&mut super::StrokeLayer> {
|
||||
e.appearance.items.iter_mut().rev().find_map(|i| match i {
|
||||
super::AppearanceItem::Stroke(s) if s.visible => Some(s),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Every fill and stroke row of face or edge `n`, bottom first, as `livePaint.info` lists them. A
|
||||
|
||||
@@ -2781,7 +2781,7 @@ fn live_paint_fill_same_paint_is_no_op() {
|
||||
let mut before = snapshot(&s);
|
||||
let click = s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50], "color": "#00ff00"})).unwrap();
|
||||
let face = vectorcraft_tools::builder::face_at(&node(&s, g), Point::new(75.0, 50.0)).unwrap().id;
|
||||
assert_eq!(click, json!({"group": g.0, "face": face.0}), "the usual reply");
|
||||
assert_eq!(click, json!({"group": g.0, "face": face.0, "count": 1}), "the usual reply");
|
||||
assert_unchanged(&mut s, &mut before, "a click on a face with the paint");
|
||||
s.execute("livePaint.fill", &drag).unwrap();
|
||||
assert_unchanged(&mut s, &mut before, "a drag over faces with the paint");
|
||||
@@ -2850,6 +2850,42 @@ fn live_paint_stroke_edge_same_paint_and_width_is_no_op() {
|
||||
assert_eq!(history_state(&s).0, before.1.0 + 1);
|
||||
}
|
||||
|
||||
/// With `scope`, faces and edges that already have the paint (and the width) are skipped: when
|
||||
/// every face or edge the call reaches has it, nothing changes, and when some do, only the others
|
||||
/// are painted, in one undo step. `count` is every face or edge reached.
|
||||
#[test]
|
||||
fn live_paint_scoped_fill_and_stroke_skip_parts_with_the_paint() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "points": [[25, 50], [125, 50]], "color": "#00ff00"})).unwrap();
|
||||
let edges =
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [100, 50], "scope": "samePaint", "color": "#ff0000", "width": 3})).unwrap();
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
let same = json!({"group": g.0, "point": [75, 50], "scope": "samePaint", "color": "#00ff00"});
|
||||
assert_eq!(s.execute("livePaint.fill", &same).unwrap()["count"], 3);
|
||||
assert_unchanged(&mut s, &mut before, "a samePaint fill where every face has the paint");
|
||||
let again = json!({"group": g.0, "point": [100, 50], "scope": "samePaint", "color": "#ff0000", "width": 3});
|
||||
assert_eq!(s.execute("livePaint.strokeEdge", &again).unwrap()["count"], edges["count"]);
|
||||
assert_unchanged(&mut s, &mut before, "a samePaint stroke where every edge has the paint and the width");
|
||||
// One face of the three without the paint: only it is filled, in one undo step.
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let red = Paint::solid(Color::from_hex("#ff0000").unwrap());
|
||||
s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "color": "#ff0000"})).unwrap();
|
||||
let depth = history_state(&s).0;
|
||||
let like = serde_json::to_value(&green).unwrap();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "scope": "samePaint", "match": like, "color": "#00ff00"})).unwrap();
|
||||
assert_eq!(r["count"], 3);
|
||||
assert_eq!(history_state(&s).0, depth + 1);
|
||||
let fill_at = |s: &Session, x: f64| vectorcraft_tools::builder::face_at(&node(s, g), Point::new(x, 50.0)).unwrap().appearance.fill_paint();
|
||||
for x in [25.0, 75.0, 125.0] {
|
||||
assert_eq!(fill_at(&s, x), green, "{x}");
|
||||
}
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(fill_at(&s, 25.0), red);
|
||||
assert_eq!((fill_at(&s, 75.0), fill_at(&s, 125.0)), (green.clone(), green));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_gap_options_same_values_are_no_op() {
|
||||
let mut s = session();
|
||||
@@ -3012,6 +3048,472 @@ fn live_paint_fill_skips_hidden_faces() {
|
||||
assert!(!node(&s, hidden).visible);
|
||||
}
|
||||
|
||||
/// A Live Paint group of 50 pt squares side by side, 50 pt tall, with their left sides at each of
|
||||
/// `xs`.
|
||||
fn live_squares(s: &mut Session, xs: &[f64]) -> NodeId {
|
||||
let ids: Vec<u64> = xs.iter().map(|&x| rect(s, x, 0.0, 50.0, 50.0).0).collect();
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
/// The ids of the faces of `g` that hold `p`, in the order given.
|
||||
fn faces_at(s: &Session, g: NodeId, ps: &[(f64, f64)]) -> Vec<NodeId> {
|
||||
ps.iter().map(|&(x, y)| vectorcraft_tools::builder::face_at(&node(s, g), Point::new(x, y)).unwrap().id).collect()
|
||||
}
|
||||
|
||||
/// The edges of `g` whose bounds lie within `r`.
|
||||
fn edges_in(s: &Session, g: NodeId, r: Rect) -> Vec<NodeId> {
|
||||
let r = r.inflate(1e-6, 1e-6);
|
||||
vectorcraft_tools::builder::edges(&node(s, g))
|
||||
.iter()
|
||||
.filter(|e| e.geometric_bounds().is_some_and(|bb| r.contains(Point::new(bb.x0, bb.y0)) && r.contains(Point::new(bb.x1, bb.y1))))
|
||||
.map(|e| e.id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Give `ids` stroke paint `paint` at weight 1 (none: no stroke), and `fill` to the faces in `faces`.
|
||||
fn paint_parts(s: &mut Session, ids: &[NodeId], paint: &Paint, faces: &[(NodeId, Paint)]) {
|
||||
s.edit("t", |d, _| {
|
||||
for id in ids {
|
||||
let n = d.node_mut(*id).unwrap();
|
||||
n.appearance.set_stroke(paint.clone());
|
||||
if let Some(st) = n.appearance.stroke_mut() {
|
||||
st.width = 1.0;
|
||||
}
|
||||
}
|
||||
for (id, fill) in faces {
|
||||
d.node_mut(*id).unwrap().appearance.set_fill(fill.clone());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn fill_of(s: &Session, id: NodeId) -> Paint {
|
||||
node(s, id).appearance.fill_paint()
|
||||
}
|
||||
|
||||
/// A double-click on a face fills it and the faces reached across edges that draw no stroke; a
|
||||
/// stroked edge and a hidden face stop the flood.
|
||||
#[test]
|
||||
fn live_paint_bucket_double_click_floods_across_unstroked_edges() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0, 100.0, 150.0]);
|
||||
let [a, b, c, d] = faces_at(&s, g, &[(25.0, 25.0), (75.0, 25.0), (125.0, 25.0), (175.0, 25.0)])[..] else { panic!("four faces") };
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 201.0, 51.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let stroked = edges_in(&s, g, Rect::new(150.0, 0.0, 150.0, 50.0));
|
||||
assert!(!stroked.is_empty());
|
||||
paint_parts(&mut s, &stroked, &Paint::solid(Color::rgb(0.0, 0.0, 0.0)), &[]);
|
||||
let white = fill_of(&s, d);
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
assert_ne!(white, green);
|
||||
let depth = s.doc().unwrap().history.undo.len();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!((&r["face"], &r["count"]), (&json!(a.0), &json!(3)));
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [green.clone(), green.clone(), green.clone(), white.clone()]);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), depth + 1, "one undo step");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!([a, b, c].iter().all(|f| fill_of(&s, *f) != green));
|
||||
// A hidden face is not filled and does not pass the flood on.
|
||||
s.execute("object.setProps", &json!({"ids": [b.0], "visible": false})).unwrap();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 1);
|
||||
assert_eq!([a, b, c].map(|f| fill_of(&s, f) == green), [true, false, false]);
|
||||
while s.doc().unwrap().history.undo.len() > depth {
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
}
|
||||
// The tool: two clicks and the double-click that follows them.
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
s.paint.fill = green.clone();
|
||||
for kind in [PointerKind::Down, PointerKind::Up, PointerKind::Down, PointerKind::Up, PointerKind::DoubleClick] {
|
||||
s.pointer(&PointerEvent::new(kind, 125.0, 25.0), v).unwrap();
|
||||
}
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [green.clone(), green.clone(), green, white]);
|
||||
}
|
||||
|
||||
/// An edge that draws no stroke (fully transparent, or with its stroke hidden) lets a flood across
|
||||
/// although it stores a stroke paint, and an edge scope compares the stroke paint each edge draws
|
||||
/// with.
|
||||
#[test]
|
||||
fn live_paint_bucket_scopes_follow_the_stroke_an_edge_draws() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0, 100.0]);
|
||||
let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0));
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 151.0, 51.0));
|
||||
paint_parts(&mut s, &all, &black, &[]);
|
||||
let clear = edges_in(&s, g, Rect::new(50.0, 0.0, 50.0, 50.0));
|
||||
let hidden = edges_in(&s, g, Rect::new(100.0, 0.0, 100.0, 50.0));
|
||||
assert!(!clear.is_empty() && !hidden.is_empty());
|
||||
s.edit("t", |d, _| {
|
||||
for id in &clear {
|
||||
d.node_mut(*id).unwrap().opacity = 0.0;
|
||||
}
|
||||
for id in &hidden {
|
||||
d.node_mut(*id).unwrap().appearance.stroke_mut().unwrap().visible = false;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 3, "the flood crosses both middle edges");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let stroke = |s: &mut Session, at: [f64; 2]| {
|
||||
let r = s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": at, "color": "#00ff00", "width": 3, "scope": "samePaint"})).unwrap();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
r["count"].clone()
|
||||
};
|
||||
assert_eq!(stroke(&mut s, [25.0, 0.0]), json!(all.len() - clear.len() - hidden.len()), "the edges that draw black");
|
||||
assert_eq!(stroke(&mut s, [50.0, 25.0]), json!(clear.len() + hidden.len()), "the edges that draw no stroke");
|
||||
// With the top edge between them fully transparent too, the connected scope walks from the edge
|
||||
// at x = 50 through it to the edge at x = 100, and reaches no edge that draws black.
|
||||
let top = edges_in(&s, g, Rect::new(50.0, 0.0, 100.0, 0.0));
|
||||
assert_eq!(top.len(), 1);
|
||||
s.edit("t", |d, _| {
|
||||
d.node_mut(top[0]).unwrap().opacity = 0.0;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let r =
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [50, 25], "color": "#00ff00", "width": 3, "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], json!(clear.len() + top.len() + hidden.len()));
|
||||
}
|
||||
|
||||
/// `livePaint.strokeEdge` paints an edge's topmost stroke that is shown, so the edge then draws
|
||||
/// with the paint; an edge whose strokes are all hidden takes a new stroke above them. Painting
|
||||
/// again changes nothing.
|
||||
#[test]
|
||||
fn live_paint_stroke_edge_paints_the_shown_stroke() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0]);
|
||||
let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0));
|
||||
let red = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 51.0));
|
||||
paint_parts(&mut s, &all, &black, &[]);
|
||||
let middle = edges_in(&s, g, Rect::new(50.0, 0.0, 50.0, 50.0));
|
||||
let left: Vec<NodeId> = edges_in(&s, g, Rect::new(0.0, 0.0, 50.0, 50.0)).into_iter().filter(|e| !middle.contains(e)).collect();
|
||||
let (&[m], &[l]) = (&middle[..], &left[..]) else { panic!("one middle edge and one other edge round the left face") };
|
||||
// The middle edge draws red under a hidden black stroke; every stroke of the left face's other
|
||||
// edge is hidden.
|
||||
s.edit("t", |d, _| {
|
||||
let n = d.node_mut(m).unwrap();
|
||||
n.appearance.items.insert(0, AppearanceItem::Stroke(vectorcraft_doc::appearance::StrokeLayer::new(red.clone(), 1.0)));
|
||||
n.appearance.stroke_mut().unwrap().visible = false;
|
||||
d.node_mut(l).unwrap().appearance.stroke_mut().unwrap().visible = false;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let drawn = |s: &Session, id: NodeId| vectorcraft_tools::builder::lp_stroke_paint(&node(s, id));
|
||||
assert_eq!(drawn(&s, m), red);
|
||||
let paint = |s: &mut Session, at: [f64; 2]| {
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": at, "color": "#00ff00", "width": 2})).unwrap();
|
||||
};
|
||||
for (id, at) in [(m, [50.0, 25.0]), (l, [0.0, 25.0])] {
|
||||
paint(&mut s, at);
|
||||
assert_eq!(drawn(&s, id), green, "{id}");
|
||||
let depth = history_state(&s).0;
|
||||
paint(&mut s, at);
|
||||
assert_eq!(history_state(&s).0, depth, "painting {id} again");
|
||||
}
|
||||
assert_eq!(node(&s, m).appearance.items.len(), 2, "the hidden stroke stays as it was");
|
||||
assert_eq!(node(&s, l).appearance.items.len(), 2, "a new stroke above the hidden one");
|
||||
}
|
||||
|
||||
/// With Cmd held, the Live Paint Bucket's presses go to the selection tool Cmd lends, and the
|
||||
/// double-click and triple-click that follow them paint nothing.
|
||||
#[test]
|
||||
fn live_paint_bucket_cmd_double_and_triple_click_paint_nothing() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0, 100.0]);
|
||||
let faces = faces_at(&s, g, &[(25.0, 25.0), (75.0, 25.0), (125.0, 25.0)]);
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 151.0, 51.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let before: Vec<Paint> = faces.iter().map(|f| fill_of(&s, *f)).collect();
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
s.paint.fill = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
let (down, up) = (PointerKind::Down, PointerKind::Up);
|
||||
for kind in [down, up, down, up, PointerKind::DoubleClick, down, up, PointerKind::TripleClick] {
|
||||
s.pointer(&PointerEvent::new(kind, 75.0, 25.0).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
assert_eq!(faces.iter().map(|f| fill_of(&s, *f)).collect::<Vec<_>>(), before);
|
||||
assert_eq!(s.tool_id(), "livePaintBucket");
|
||||
}
|
||||
|
||||
/// The flood crosses curved edges, and reaches a face 0.012 pt wide.
|
||||
#[test]
|
||||
fn live_paint_bucket_double_click_floods_curved_and_narrow_faces() {
|
||||
let mut s = session();
|
||||
let ids: Vec<u64> = [0.0, 60.0]
|
||||
.iter()
|
||||
.map(|&x| s.execute("shape.ellipse", &json!({"x": x, "y": 0, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap())
|
||||
.collect();
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 161.0, 101.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [20, 50], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 3, "both lunes and the lens between them");
|
||||
|
||||
let mut s = session();
|
||||
let ids = [rect(&mut s, 0.0, 0.0, 50.0, 50.0).0, rect(&mut s, 49.988, 0.0, 50.0, 50.0).0];
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let [a, sliver, c] = faces_at(&s, g, &[(25.0, 25.0), (49.994, 25.0), (75.0, 25.0)])[..] else { panic!("three faces") };
|
||||
assert!(a != sliver && sliver != c);
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 51.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 3);
|
||||
assert_eq!([a, sliver, c].map(|f| fill_of(&s, f)), [green.clone(), green.clone(), green]);
|
||||
}
|
||||
|
||||
/// The flood crosses a hidden edge, and an edge that a Gap Detection gap meets partway along, but
|
||||
/// not the gap.
|
||||
#[test]
|
||||
fn live_paint_bucket_double_click_floods_across_hidden_edges_and_past_gaps() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0]);
|
||||
let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0));
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 51.0));
|
||||
paint_parts(&mut s, &all, &black, &[]);
|
||||
let fill = |s: &mut Session, g: NodeId, at: [f64; 2]| {
|
||||
s.execute("livePaint.fill", &json!({"group": g.0, "point": at, "color": "#00ff00", "scope": "connected"})).unwrap()["count"].clone()
|
||||
};
|
||||
assert_eq!(fill(&mut s, g, [25.0, 25.0]), 1, "a stroked edge stops the flood");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let middle = edges_in(&s, g, Rect::new(50.0, 0.0, 50.0, 50.0));
|
||||
s.execute("object.setProps", &json!({"ids": middle.iter().map(|e| e.0).collect::<Vec<_>>(), "visible": false})).unwrap();
|
||||
assert_eq!(fill(&mut s, g, [25.0, 25.0]), 2, "a hidden edge does not");
|
||||
|
||||
// Square B (100..200 by 0..100) over square C (100..200 by 100..200), and a line down the middle
|
||||
// of B that stops 2 pt short of their shared edge: Gap Detection closes it, so B is two faces
|
||||
// that each run along part of the shared edge, which is one edge segment.
|
||||
let mut s = session();
|
||||
let mut ids = vec![rect(&mut s, 100.0, 0.0, 100.0, 100.0).0, rect(&mut s, 100.0, 100.0, 100.0, 100.0).0];
|
||||
let line = s.execute("path.create", &json!({"anchors": [{"x": 150, "y": 0}, {"x": 150, "y": 98}]})).unwrap();
|
||||
ids.push(line["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("livePaint.gapOptions", &json!({"id": g.0, "detect": true, "size": "small"})).unwrap();
|
||||
let [b1, b2, c] = faces_at(&s, g, &[(125.0, 50.0), (175.0, 50.0), (150.0, 150.0)])[..] else { panic!("three faces") };
|
||||
assert!(b1 != b2 && b2 != c && b1 != c);
|
||||
let all = edges_in(&s, g, Rect::new(99.0, -1.0, 201.0, 201.0));
|
||||
paint_parts(&mut s, &all, &black, &[]);
|
||||
let shared = edges_in(&s, g, Rect::new(100.0, 100.0, 200.0, 100.0));
|
||||
assert!(!shared.is_empty());
|
||||
paint_parts(&mut s, &shared, &Paint::None, &[]);
|
||||
assert_eq!(fill(&mut s, g, [150.0, 150.0]), 3, "from C across the shared edge to both faces of B");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
// With the line and the shared edge stroked, only the gap lies between the two faces of B.
|
||||
paint_parts(&mut s, &shared, &black, &[]);
|
||||
assert_eq!(fill(&mut s, g, [125.0, 50.0]), 1, "the flood does not pass the gap");
|
||||
|
||||
// B alone, its outline drawing no stroke and the line stroked: the two faces of B run along
|
||||
// different parts of the outline's bottom segment, on the same side, and the flood does not
|
||||
// join them there.
|
||||
let mut s = session();
|
||||
let mut ids = vec![rect(&mut s, 100.0, 0.0, 100.0, 100.0).0];
|
||||
let line = s.execute("path.create", &json!({"anchors": [{"x": 150, "y": 0}, {"x": 150, "y": 98}]})).unwrap();
|
||||
ids.push(line["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("livePaint.gapOptions", &json!({"id": g.0, "detect": true, "size": "small"})).unwrap();
|
||||
assert_eq!(vectorcraft_tools::builder::faces(&node(&s, g)).len(), 2);
|
||||
let all = edges_in(&s, g, Rect::new(99.0, -1.0, 201.0, 101.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let line = edges_in(&s, g, Rect::new(150.0, 0.0, 150.0, 98.0));
|
||||
assert!(!line.is_empty() && line.len() < all.len());
|
||||
paint_parts(&mut s, &line, &black, &[]);
|
||||
assert_eq!(fill(&mut s, g, [125.0, 50.0]), 1, "the gap parts the two faces along the bottom");
|
||||
}
|
||||
|
||||
/// The flood crosses an edge into each face along it when a face's outline runs along the edge in
|
||||
/// one segment and the edge is split where another line meets it.
|
||||
#[test]
|
||||
fn live_paint_bucket_double_click_floods_along_edges_split_at_a_junction() {
|
||||
// A square with a line across its middle, and a line from the top at x = 30 that crosses it and
|
||||
// stops 20 pt below. The bottom face's outline runs along the middle line in one segment, from
|
||||
// x = 0 to 100; the middle line's edges are split at x = 30.
|
||||
let mut s = session();
|
||||
let mut ids = vec![rect(&mut s, 0.0, 0.0, 100.0, 100.0).0];
|
||||
for anchors in [json!([{"x": 0, "y": 50}, {"x": 100, "y": 50}]), json!([{"x": 30, "y": 0}, {"x": 30, "y": 70}])] {
|
||||
ids.push(s.execute("path.create", &json!({ "anchors": anchors })).unwrap()["id"].as_u64().unwrap());
|
||||
}
|
||||
s.execute("select.set", &json!({"ids": ids})).unwrap();
|
||||
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let [left, right, bottom] = faces_at(&s, g, &[(15.0, 25.0), (65.0, 25.0), (65.0, 75.0)])[..] else { panic!("three faces") };
|
||||
assert!(left != right && right != bottom && left != bottom);
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 101.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[]);
|
||||
let down = edges_in(&s, g, Rect::new(30.0, 0.0, 30.0, 70.0));
|
||||
assert!(!down.is_empty() && down.len() < all.len());
|
||||
paint_parts(&mut s, &down, &Paint::solid(Color::rgb(0.0, 0.0, 0.0)), &[]);
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [65, 75], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 3, "from the bottom face to both faces above the line");
|
||||
assert_eq!([left, right, bottom].map(|f| fill_of(&s, f)), [green.clone(), green.clone(), green.clone()]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [15, 25], "color": "#00ff00", "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], 3, "from the upper left face down to the bottom face and up again");
|
||||
}
|
||||
|
||||
/// A triple-click on a face fills every face of the group with that face's fill, joined to it or
|
||||
/// not. Through the tool, the fill compared is the face's fill before the first click.
|
||||
#[test]
|
||||
fn live_paint_bucket_triple_click_fills_every_face_of_the_same_fill() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0, 100.0, 150.0]);
|
||||
let [a, b, c, d] = faces_at(&s, g, &[(25.0, 25.0), (75.0, 25.0), (125.0, 25.0), (175.0, 25.0)])[..] else { panic!("four faces") };
|
||||
let (red, blue) = (Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::solid(Color::rgb(0.0, 0.0, 1.0)));
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 201.0, 51.0));
|
||||
paint_parts(&mut s, &all, &Paint::None, &[(a, red.clone()), (b, blue.clone()), (c, red.clone()), (d, red.clone())]);
|
||||
let stroked = edges_in(&s, g, Rect::new(100.0, 0.0, 100.0, 50.0));
|
||||
paint_parts(&mut s, &stroked, &Paint::solid(Color::rgb(0.0, 0.0, 0.0)), &[]);
|
||||
let depth = s.doc().unwrap().history.undo.len();
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "samePaint"})).unwrap();
|
||||
assert_eq!(r["count"], 3);
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [green.clone(), blue.clone(), green.clone(), green.clone()]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
// The tool: the first click fills the face, the double-click floods across x = 50 into B, and
|
||||
// the triple-click fills the faces that were red.
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
s.paint.fill = green.clone();
|
||||
for kind in [
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::DoubleClick,
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::TripleClick,
|
||||
] {
|
||||
s.pointer(&PointerEvent::new(kind, 25.0, 25.0), v).unwrap();
|
||||
}
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [green.clone(), green.clone(), green.clone(), green.clone()]);
|
||||
// A match given by the caller is the fill compared.
|
||||
while s.doc().unwrap().history.undo.len() > depth {
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
}
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [red.clone(), blue.clone(), red.clone(), red.clone()]);
|
||||
let r = s
|
||||
.execute(
|
||||
"livePaint.fill",
|
||||
&json!({"group": g.0, "point": [25, 25], "color": "#00ff00", "scope": "samePaint", "match": serde_json::to_value(&blue).unwrap()}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(r["count"], 2);
|
||||
assert_eq!([a, b, c, d].map(|f| fill_of(&s, f)), [green.clone(), green, red.clone(), red]);
|
||||
}
|
||||
|
||||
/// A triple-click whose first click makes the Live Paint group from the selected paths matches the
|
||||
/// fill the face was made with.
|
||||
#[test]
|
||||
fn live_paint_bucket_triple_click_after_making_the_group_matches_the_made_fill() {
|
||||
let mut s = session();
|
||||
let ids: Vec<NodeId> = [0.0, 100.0, 200.0].iter().map(|&x| rect(&mut s, x, 0.0, 50.0, 50.0)).collect();
|
||||
let (red, blue) = (Color::rgb(1.0, 0.0, 0.0), Color::rgb(0.0, 0.0, 1.0));
|
||||
for (id, c) in ids.iter().zip([red, red, blue]) {
|
||||
set_fill(&mut s, *id, c);
|
||||
}
|
||||
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
s.paint.fill = green.clone();
|
||||
for kind in [
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::DoubleClick,
|
||||
PointerKind::Down,
|
||||
PointerKind::Up,
|
||||
PointerKind::TripleClick,
|
||||
] {
|
||||
s.pointer(&PointerEvent::new(kind, 25.0, 25.0), v).unwrap();
|
||||
}
|
||||
let g = vectorcraft_tools::builder::live_paint_at(&s.doc().unwrap().doc, Point::new(25.0, 25.0)).expect("the clicks made a group");
|
||||
let faces = faces_at(&s, g, &[(25.0, 25.0), (125.0, 25.0), (225.0, 25.0)]);
|
||||
assert_eq!(faces.iter().map(|f| fill_of(&s, *f)).collect::<Vec<_>>(), [green.clone(), green, Paint::solid(blue)]);
|
||||
}
|
||||
|
||||
/// A double-click on an edge paints the edges joined to it that have its stroke, and a
|
||||
/// triple-click every edge of the group with that stroke; an edge with another stroke is left.
|
||||
#[test]
|
||||
fn live_paint_bucket_double_and_triple_click_paint_joined_and_same_stroke_edges() {
|
||||
let mut s = session();
|
||||
let g = live_squares(&mut s, &[0.0, 50.0, 200.0]);
|
||||
let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0));
|
||||
let red = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let joined = edges_in(&s, g, Rect::new(0.0, 0.0, 100.0, 50.0));
|
||||
let apart = edges_in(&s, g, Rect::new(200.0, 0.0, 250.0, 50.0));
|
||||
let middle = edges_in(&s, g, Rect::new(50.0, 0.0, 50.0, 50.0));
|
||||
assert!(!apart.is_empty() && !middle.is_empty());
|
||||
paint_parts(&mut s, &joined, &black, &[]);
|
||||
paint_parts(&mut s, &apart, &black, &[]);
|
||||
paint_parts(&mut s, &middle, &red, &[]);
|
||||
let stroke = |s: &Session, ids: &[NodeId]| ids.iter().map(|id| node(s, *id).appearance.stroke_paint()).collect::<Vec<_>>();
|
||||
let outer: Vec<NodeId> = joined.iter().copied().filter(|e| !middle.contains(e)).collect();
|
||||
let r =
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [25, 0], "color": "#00ff00", "width": 3, "scope": "connected"})).unwrap();
|
||||
assert_eq!(r["count"], outer.len());
|
||||
assert!(stroke(&s, &outer).iter().all(|p| *p == green));
|
||||
assert!(outer.iter().all(|e| node(&s, *e).appearance.stroke_width() == 3.0));
|
||||
assert!(stroke(&s, &middle).iter().all(|p| *p == red), "another stroke is left");
|
||||
assert!(stroke(&s, &apart).iter().all(|p| *p == black), "edges not joined are left");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let r = s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [25, 0], "color": "#00ff00", "scope": "samePaint"})).unwrap();
|
||||
assert_eq!(r["count"], outer.len() + apart.len());
|
||||
assert!(stroke(&s, &outer).iter().chain(&stroke(&s, &apart)).all(|p| *p == green));
|
||||
assert!(stroke(&s, &middle).iter().all(|p| *p == red));
|
||||
// A hidden edge is not painted.
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("object.setProps", &json!({"ids": [apart[0].0], "visible": false})).unwrap();
|
||||
let r = s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [25, 0], "color": "#00ff00", "scope": "samePaint"})).unwrap();
|
||||
assert_eq!(r["count"], outer.len() + apart.len() - 1);
|
||||
assert_eq!(node(&s, apart[0]).appearance.stroke_paint(), black);
|
||||
}
|
||||
|
||||
/// A `scope` that is not one of the three, a `match` that is not a paint or is given with a scope
|
||||
/// that compares none, and a scope with a drag's points are refused; nothing changes.
|
||||
#[test]
|
||||
fn live_paint_scope_and_match_are_checked() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let none = serde_json::to_value(Paint::None).unwrap();
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let depth = s.doc().unwrap().history.undo.len();
|
||||
for (cmd, p) in [
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "scope": "all"})),
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "scope": 2})),
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "match": none})),
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "scope": "connected", "match": none})),
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "scope": "samePaint", "match": "red"})),
|
||||
("livePaint.fill", json!({"group": g.0, "point": [75, 50], "scope": "connected", "points": [[75, 50], [125, 50]]})),
|
||||
("livePaint.strokeEdge", json!({"group": g.0, "point": [100, 50], "scope": "Connected"})),
|
||||
("livePaint.strokeEdge", json!({"group": g.0, "point": [100, 50], "scope": "one", "match": none})),
|
||||
("livePaint.strokeEdge", json!({"group": g.0, "point": [100, 50], "scope": "samePaint", "match": {"type": "plaid"}})),
|
||||
] {
|
||||
assert!(s.execute(cmd, &p).is_err(), "{cmd} {p}");
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().doc, before);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), depth);
|
||||
// "one" and null are a click's scope.
|
||||
for scope in [json!("one"), Value::Null] {
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50], "scope": scope})).unwrap();
|
||||
assert_eq!(r["count"], 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_release_and_expand() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -651,7 +651,7 @@ impl Session {
|
||||
match ev.kind {
|
||||
PointerKind::Down | PointerKind::Drag => self.pointer_held = true,
|
||||
PointerKind::Up | PointerKind::Move => self.pointer_held = false,
|
||||
PointerKind::DoubleClick => {}
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick => {}
|
||||
}
|
||||
match ev.kind {
|
||||
PointerKind::Down => {
|
||||
|
||||
@@ -81,6 +81,7 @@ pub(crate) fn pointer_kind(k: &str) -> Option<PointerKind> {
|
||||
"up" => PointerKind::Up,
|
||||
"move" => PointerKind::Move,
|
||||
"doubleclick" | "dblclick" => PointerKind::DoubleClick,
|
||||
"tripleclick" => PointerKind::TripleClick,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -238,7 +239,7 @@ impl Headless {
|
||||
.map(|(e, backquote)| {
|
||||
let mods = packet_mods(e)?.unwrap_or(base);
|
||||
let kind = s(e, "kind").unwrap_or("");
|
||||
let kind = pointer_kind(kind).ok_or_else(|| format!("unknown pointer kind `{kind}` (down|drag|up|move|doubleclick)"))?;
|
||||
let kind = pointer_kind(kind).ok_or_else(|| format!("unknown pointer kind `{kind}` (down|drag|up|move|doubleclick|tripleclick)"))?;
|
||||
PointerEvent::json_check(e)?;
|
||||
if s(e, "space") == Some("screen") {
|
||||
return Err("screen-space pointer events need the desktop app; use document coordinates".to_string());
|
||||
|
||||
@@ -16,6 +16,7 @@ mod gradient;
|
||||
mod limits;
|
||||
mod links;
|
||||
mod liquify;
|
||||
mod livepaint;
|
||||
mod pen;
|
||||
mod persp;
|
||||
mod place;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//! The Live Paint Bucket through MCP: `pointer_gesture` sends a triple-click as `tripleclick`.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::{Backend, Headless, call_tool};
|
||||
|
||||
fn ok(h: &mut Headless, name: &str, args: Value) -> Value {
|
||||
let r = call_tool(h, name, &args);
|
||||
assert!(!r.is_error, "{name} {args}: {r:?}");
|
||||
serde_json::from_str(r.content[0]["text"].as_str().unwrap()).unwrap_or(Value::Null)
|
||||
}
|
||||
|
||||
fn run(h: &mut Headless, command: &str, params: Value) -> Value {
|
||||
ok(h, "run_command", json!({"command": command, "params": params}))
|
||||
}
|
||||
|
||||
/// The fill of each face of Live Paint group `g`, left to right.
|
||||
fn fills(h: &mut Headless, g: &Value) -> Vec<Value> {
|
||||
let info = run(h, "livePaint.info", json!({"group": g}));
|
||||
let mut faces = info["faces"].as_array().unwrap().clone();
|
||||
faces.sort_by(|a, b| a["bounds"][0].as_f64().unwrap().total_cmp(&b["bounds"][0].as_f64().unwrap()));
|
||||
faces.iter().map(|f| f["fill"].clone()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_triple_click_fills_every_face_of_the_same_fill() {
|
||||
let mut h = Headless::new();
|
||||
h.call("engine.execute", json!({"command": "file.new", "params": {"width": 300, "height": 300}})).unwrap();
|
||||
let a = run(&mut h, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50}))["id"].clone();
|
||||
let b = run(&mut h, "shape.rectangle", json!({"x": 100, "y": 0, "width": 50, "height": 50}))["id"].clone();
|
||||
let g = run(&mut h, "livePaint.make", json!({"ids": [a, b]}))["id"].clone();
|
||||
for x in [25, 125] {
|
||||
run(&mut h, "livePaint.fill", json!({"group": g, "point": [x, 25], "color": "#ff0000"}));
|
||||
}
|
||||
let red = fills(&mut h, &g);
|
||||
assert_eq!(red[0], red[1]);
|
||||
// With nothing selected, the current fill changes and the group keeps its faces' fills.
|
||||
run(&mut h, "select.none", json!({}));
|
||||
run(&mut h, "paint.setFill", json!({"color": "#00ff00"}));
|
||||
assert_eq!(fills(&mut h, &g), red);
|
||||
let ev = |kind: &str| json!({"kind": kind, "x": 25, "y": 25});
|
||||
let clicks = [ev("down"), ev("up"), ev("down"), ev("up"), ev("doubleclick"), ev("down"), ev("up")];
|
||||
ok(&mut h, "pointer_gesture", json!({"tool": "livePaintBucket", "events": clicks}));
|
||||
let after_two = fills(&mut h, &g);
|
||||
assert_eq!(after_two[1], red[1], "the face apart is left by the clicks and the double-click");
|
||||
assert_ne!(after_two[0], red[0]);
|
||||
ok(&mut h, "pointer_gesture", json!({"events": [ev("tripleclick")]}));
|
||||
assert_eq!(fills(&mut h, &g), [after_two[0].clone(), after_two[0].clone()], "both faces were red");
|
||||
}
|
||||
|
||||
/// With Space held (`mods.space`), the Live Paint Bucket's clicks, double-click and triple-click
|
||||
/// paint nothing.
|
||||
#[test]
|
||||
fn clicks_with_space_held_paint_nothing() {
|
||||
let mut h = Headless::new();
|
||||
h.call("engine.execute", json!({"command": "file.new", "params": {"width": 300, "height": 300}})).unwrap();
|
||||
let a = run(&mut h, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50}))["id"].clone();
|
||||
let b = run(&mut h, "shape.rectangle", json!({"x": 100, "y": 0, "width": 50, "height": 50}))["id"].clone();
|
||||
let g = run(&mut h, "livePaint.make", json!({"ids": [a, b]}))["id"].clone();
|
||||
for x in [25, 125] {
|
||||
run(&mut h, "livePaint.fill", json!({"group": g, "point": [x, 25], "color": "#ff0000"}));
|
||||
}
|
||||
run(&mut h, "select.none", json!({}));
|
||||
run(&mut h, "paint.setFill", json!({"color": "#00ff00"}));
|
||||
let red = fills(&mut h, &g);
|
||||
let ev = |kind: &str| json!({"kind": kind, "x": 25, "y": 25});
|
||||
let clicks = [ev("down"), ev("up"), ev("down"), ev("up"), ev("doubleclick"), ev("down"), ev("up"), ev("tripleclick")];
|
||||
ok(&mut h, "pointer_gesture", json!({"tool": "livePaintBucket", "mods": {"space": true}, "events": clicks}));
|
||||
assert_eq!(fills(&mut h, &g), red);
|
||||
// Without Space, the same clicks paint.
|
||||
ok(&mut h, "pointer_gesture", json!({"events": [ev("down"), ev("up")]}));
|
||||
assert_ne!(fills(&mut h, &g)[0], red[0]);
|
||||
}
|
||||
@@ -205,7 +205,7 @@ pub fn tool_definitions() -> Vec<Value> {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": obj(json!({
|
||||
"kind": {"type": "string", "enum": ["down", "drag", "up", "move", "doubleclick"]},
|
||||
"kind": {"type": "string", "enum": ["down", "drag", "up", "move", "doubleclick", "tripleclick"]},
|
||||
"x": num("Document x (pt)"),
|
||||
"y": num("Document y (pt)"),
|
||||
"mods": mods_schema(),
|
||||
|
||||
@@ -145,7 +145,7 @@ fn dispatch(b: &mut dyn Backend, name: &str, a: &Args) -> Result<ToolResult, Str
|
||||
for (i, e) in events.iter().enumerate() {
|
||||
let kind = e.get("kind").and_then(Value::as_str).unwrap_or("");
|
||||
if crate::headless::pointer_kind(kind).is_none() {
|
||||
return Err(format!("event {i}: unknown kind `{kind}` (down, drag, up, move, doubleclick)"));
|
||||
return Err(format!("event {i}: unknown kind `{kind}` (down, drag, up, move, doubleclick, tripleclick)"));
|
||||
}
|
||||
if !e.get("x").is_some_and(Value::is_number) || !e.get("y").is_some_and(Value::is_number) {
|
||||
return Err(format!("event {i}: numeric `x` and `y` required"));
|
||||
|
||||
@@ -311,6 +311,7 @@ impl Tool for CornerTool {
|
||||
None => vec![],
|
||||
}
|
||||
}
|
||||
PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ impl Tool for ExtendPathTool {
|
||||
// Back where it started: nothing to keep.
|
||||
if length == 0.0 { vec![Action::Cancel] } else { vec![preview, Action::Commit] }
|
||||
}
|
||||
PointerKind::DoubleClick => vec![],
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ impl Tool for ParametricShapeTool {
|
||||
self.hover(cx, ev.pos);
|
||||
}
|
||||
match ev.kind {
|
||||
PointerKind::Move => vec![],
|
||||
PointerKind::Move | PointerKind::TripleClick => vec![],
|
||||
PointerKind::Down => {
|
||||
let tol = cx.point_tol();
|
||||
let grip = selected(cx).and_then(|(id, s)| {
|
||||
|
||||
@@ -96,7 +96,7 @@ impl Tool for SlideAnchorTool {
|
||||
// Back where it started: nothing to keep.
|
||||
if t == 0.0 { vec![Action::Cancel] } else { vec![preview, Action::Commit] }
|
||||
}
|
||||
PointerKind::DoubleClick => vec![],
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -527,6 +527,7 @@ impl Tool for SmartPenTool {
|
||||
}
|
||||
_ => vec![],
|
||||
},
|
||||
PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ pub use live_paint::{
|
||||
use live_paint::{check_live_paint_options, lp_color, lp_rgb_color};
|
||||
pub use lookup::{
|
||||
EDGE_NAME, FACE_NAME, Face, LIVE_PAINT_NAME, LIVE_PAINT_PREFIX, LP_JOIN_TOL, SOURCES_NAME, builder_members, connected_edges, drawn_outlines,
|
||||
edge_near, edges, face_at, faces, flood_faces, is_live_paint, leaf_shapes, live_paint_at, live_paint_takes, node_outline, outline_snap,
|
||||
path_contains, shape_builder_shapes, shapes_for, sources, visible_edge_near, visible_face_at,
|
||||
edge_near, edges, face_at, faces, flood_faces, is_live_paint, leaf_shapes, live_paint_at, live_paint_takes, lp_stroke_paint, node_outline,
|
||||
outline_snap, path_contains, shape_builder_shapes, shapes_for, sources, visible_edge_near, visible_face_at,
|
||||
};
|
||||
pub use map::{
|
||||
BuilderMap, HATCH, HIGHLIGHT_RED, Hit, MergeGeometry, MergeInput, PreparedMerge, Rest, Touched, hatch, maps_built, merge_geometry, merge_inputs,
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use super::cache::RegionCache;
|
||||
use super::lookup::{
|
||||
connected_edges, flood_faces, is_live_paint, live_paint_at, live_paint_at_where, lp_stroke_paint, visible_edge_near, visible_face_at,
|
||||
connected_edges, flood_faces, is_live_paint, leaf_shapes, live_paint_at, live_paint_at_where, lp_stroke_paint, node_outline, visible_edge_near,
|
||||
visible_face_at,
|
||||
};
|
||||
use super::map::{HIGHLIGHT_RED, sorted_roots};
|
||||
use super::{
|
||||
Action, Arc, BezPath, CLICK_TOL_PX, Cursor, Document, EDGE_NAME, FACE_NAME, FillRule, Mods, Node, NodeId, Overlay, Point, PointerEvent,
|
||||
PointerKind, Rect, Tool, ToolContext, ToolKey, Value, color_swatches, json, json_ids, path_contains, pick_swatch, plain, swatch_chips,
|
||||
};
|
||||
use vectorcraft_color::Paint;
|
||||
|
||||
// ---------- Live Paint Bucket ----------
|
||||
|
||||
@@ -174,6 +176,17 @@ enum LpPaint {
|
||||
/// highlighted. The cursor is a filled bucket where a click fills a face, a brush where it paints
|
||||
/// an edge and an empty bucket where it paints nothing; with Alt it is the Eyedropper.
|
||||
///
|
||||
/// A double-click on a face fills it and the faces reached from it across edges that draw no
|
||||
/// stroke (`scope: "connected"`); on an edge it paints the edges joined to it that have its stroke.
|
||||
/// A triple-click on a face fills every face of the group with the face's fill, and on an edge it
|
||||
/// paints every edge of the group with the edge's stroke (`scope: "samePaint"`). Each click of a
|
||||
/// double-click or triple-click paints as it arrives, as its own undo step, and the paint compared
|
||||
/// is the one the face or edge had before the first of its clicks that painted it. A first click
|
||||
/// that made the Live Paint group counts when the face it filled is the clicked face. Shift and the
|
||||
/// options choose a face or an edge as for a click; with Alt or Cmd/Ctrl held a double-click or
|
||||
/// triple-click paints nothing. With Space held for the view tools, a click, double-click or triple-click paints
|
||||
/// nothing and no face or edge is highlighted.
|
||||
///
|
||||
/// The Left and Right arrow keys without Shift, Alt or Cmd/Ctrl set the active paint (the fill,
|
||||
/// or the stroke when the Stroke proxy is in front) to the color swatch before or after it in the
|
||||
/// Swatches panel, wrapping around; from a color that is no swatch, Right picks the first swatch
|
||||
@@ -184,10 +197,13 @@ enum LpPaint {
|
||||
pub struct LivePaintBucketTool {
|
||||
pub(super) cache: RegionCache,
|
||||
pub(super) hover: LpHover,
|
||||
/// Where the pointer last moved, and whether Shift and Alt were held.
|
||||
at: Option<(Point, bool, bool)>,
|
||||
/// Where the pointer last moved, and the modifiers held there.
|
||||
at: Option<(Point, Mods)>,
|
||||
/// The fill command and polyline previewed from the press's snapshot.
|
||||
fill_drag: Option<(Value, Vec<Vec<Point>>)>,
|
||||
/// The last [`LP_PRESSES`] presses, oldest first: the face or edge each one painted, with its
|
||||
/// paint before that press, or None for a press that painted no face or edge.
|
||||
presses: Vec<Option<LpPress>>,
|
||||
fills: bool,
|
||||
strokes: bool,
|
||||
highlight: bool,
|
||||
@@ -200,6 +216,40 @@ pub struct LivePaintBucketTool {
|
||||
picked: [Option<usize>; 2],
|
||||
}
|
||||
|
||||
/// The face or edge a Live Paint Bucket press paints.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct LpPress {
|
||||
/// The face or edge; None for the face of the Live Paint group the press makes.
|
||||
part: Option<NodeId>,
|
||||
/// Where the press was.
|
||||
at: Point,
|
||||
/// Its fill (a face), or the stroke paint it draws with ([`lp_stroke_paint`], an edge), before
|
||||
/// the press.
|
||||
before: Paint,
|
||||
/// The other faces or edges the double-click that followed the press reached, each with its
|
||||
/// fill or drawn stroke paint before the double-click.
|
||||
also: Vec<(NodeId, Paint)>,
|
||||
}
|
||||
|
||||
/// The fill of the face under `p` in the Live Paint group that `roots` make: the fill of the
|
||||
/// front-most of their paths whose closed subpaths hold `p`, else none. Open subpaths bound no face.
|
||||
fn made_face_fill(doc: &Document, roots: &[NodeId], p: Point) -> Paint {
|
||||
let mut leaves = vec![];
|
||||
for n in roots.iter().filter_map(|id| doc.node(*id)) {
|
||||
leaf_shapes(n, &mut leaves);
|
||||
}
|
||||
let holds = |l: &Node| {
|
||||
node_outline(l).is_some_and(|(path, rule)| {
|
||||
let closed = vectorcraft_geom::PathData::new(path.subpaths.into_iter().filter(|sp| sp.closed && sp.anchors.len() >= 2).collect());
|
||||
!closed.is_empty() && path_contains(&closed, rule, p)
|
||||
})
|
||||
};
|
||||
leaves.iter().rev().find(|l| holds(l)).map_or(Paint::None, |l| l.appearance.fill_paint())
|
||||
}
|
||||
|
||||
/// How many presses the Live Paint Bucket keeps: the three of a triple-click.
|
||||
const LP_PRESSES: usize = 3;
|
||||
|
||||
/// Maximum points in one Live Paint fill path chunk.
|
||||
pub const LP_FILL_CHUNK_POINTS: usize = 4096;
|
||||
|
||||
@@ -210,6 +260,7 @@ impl Default for LivePaintBucketTool {
|
||||
hover: LpHover::None,
|
||||
at: None,
|
||||
fill_drag: None,
|
||||
presses: Vec::new(),
|
||||
fills: true,
|
||||
strokes: false,
|
||||
highlight: true,
|
||||
@@ -274,14 +325,109 @@ impl LivePaintBucketTool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The highlight at `p` for a pointer with Shift and Alt held as given: none with Alt or with
|
||||
/// Highlight off, else the face or edge a click there paints. With Highlight off the selection's
|
||||
/// map is still made, for the cursor ([`Self::paints_at`]).
|
||||
fn hover_at(&mut self, cx: &ToolContext, p: Point, shift: bool, alt: bool) -> LpHover {
|
||||
if alt {
|
||||
/// Note a press: what it paints, None when it paints no face or edge.
|
||||
fn note_press(&mut self, press: Option<LpPress>) {
|
||||
if self.presses.len() == LP_PRESSES {
|
||||
self.presses.remove(0);
|
||||
}
|
||||
self.presses.push(press);
|
||||
}
|
||||
|
||||
/// Note a press at `at` that paints face or edge (`edge`) `n`.
|
||||
fn note_part(&mut self, n: &Node, edge: bool, at: Point) {
|
||||
let before = if edge { lp_stroke_paint(n) } else { n.appearance.fill_paint() };
|
||||
self.note_press(Some(LpPress { part: Some(n.id), at, before, also: vec![] }));
|
||||
}
|
||||
|
||||
/// Note that the double-click after the last press also reaches `parts` of group `group`, with
|
||||
/// the paint each has now (a face's fill, or an edge's drawn stroke paint with `edge`).
|
||||
fn note_reached(&mut self, group: &Node, parts: Vec<NodeId>, edge: bool) {
|
||||
let Some(Some(last)) = self.presses.last_mut() else { return };
|
||||
let reached: std::collections::HashSet<NodeId> = parts.into_iter().filter(|id| last.part != Some(*id)).collect();
|
||||
last.also = group
|
||||
.children()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|c| reached.contains(&c.id))
|
||||
.map(|n| (n.id, if edge { lp_stroke_paint(n) } else { n.appearance.fill_paint() }))
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// The paint `part` had before the first press of a click sequence of `clicks` presses that
|
||||
/// painted `part`, or before the double-click after a press when that double-click reached it
|
||||
/// (the sequence's first press counts when it made the group `part` is in and the face it
|
||||
/// filled there is `part`); `now` when the last press did not paint it.
|
||||
fn before(&self, cx: &ToolContext, part: NodeId, clicks: usize, now: Paint) -> Paint {
|
||||
let Some(run) = self.presses.len().checked_sub(clicks).and_then(|from| self.presses.get(from..)) else { return now };
|
||||
let made_part = |q: &LpPress| live_paint_at(cx.doc, q.at).and_then(|g| visible_face_at(cx.doc.node(g)?, q.at)).is_some_and(|f| f.id == part);
|
||||
let on_part = |i: usize, q: &LpPress| q.part == Some(part) || (i == 0 && q.part.is_none() && made_part(q));
|
||||
if !run.last().and_then(Option::as_ref).is_some_and(|q| on_part(run.len() - 1, q)) {
|
||||
return now;
|
||||
}
|
||||
for (i, q) in run.iter().enumerate() {
|
||||
let Some(q) = q else { continue };
|
||||
if on_part(i, q) {
|
||||
return q.before.clone();
|
||||
}
|
||||
if let Some((_, paint)) = q.also.iter().find(|(id, _)| *id == part) {
|
||||
return paint.clone();
|
||||
}
|
||||
}
|
||||
now
|
||||
}
|
||||
|
||||
/// What a double-click (`scope` "connected", 2 `clicks`) or a triple-click ("samePaint", 3) at
|
||||
/// `p` runs: the command a click there runs, with `scope`, and the paint it compares as `match`.
|
||||
/// A double-click notes the other faces or edges it reaches, for the triple-click's `match`.
|
||||
fn multi_click(&mut self, cx: &ToolContext, p: Point, mods: Mods, scope: &str, clicks: usize) -> Vec<Action> {
|
||||
// With Alt held, with Space held for the view tools, or with Cmd/Ctrl held (its presses went
|
||||
// to the selection tool Cmd lends), a double-click or triple-click paints nothing.
|
||||
if mods.alt || mods.space || mods.cmd {
|
||||
return vec![];
|
||||
}
|
||||
let point = json!([p.x, p.y]);
|
||||
let paint = self.paints(mods.shift);
|
||||
if matches!(paint, LpPaint::Strokes | LpPaint::Both)
|
||||
&& let Some((g, Some(e))) = lp_part_at(cx.doc, p, cx.tol(4.0), true, &|id| lp_visible(cx, id))
|
||||
{
|
||||
let mut v = json!({ "group": g.0, "point": point, "tolerance": cx.tol(4.0), "scope": scope });
|
||||
let like = self.before(cx, e.id, clicks, lp_stroke_paint(e));
|
||||
if clicks == 2
|
||||
&& let Some(group) = cx.doc.node(g)
|
||||
{
|
||||
self.note_reached(group, connected_edges(group, e.id, &like), true);
|
||||
}
|
||||
if let Ok(like) = serde_json::to_value(like) {
|
||||
v["match"] = like;
|
||||
}
|
||||
return vec![Action::Exec("livePaint.strokeEdge".into(), v)];
|
||||
}
|
||||
if !matches!(paint, LpPaint::Fills | LpPaint::Both) {
|
||||
return vec![];
|
||||
}
|
||||
let Some((g, f)) = live_paint_at(cx.doc, p).and_then(|g| Some((g, visible_face_at(cx.doc.node(g)?, p)?))) else { return vec![] };
|
||||
let mut v = json!({ "group": g.0, "point": point, "scope": scope });
|
||||
if clicks == 2
|
||||
&& let Some(group) = cx.doc.node(g)
|
||||
{
|
||||
self.note_reached(group, flood_faces(group, f.id), false);
|
||||
}
|
||||
if scope == "samePaint"
|
||||
&& let Ok(like) = serde_json::to_value(self.before(cx, f.id, clicks, f.appearance.fill_paint()))
|
||||
{
|
||||
v["match"] = like;
|
||||
}
|
||||
vec![Action::Exec("livePaint.fill".into(), v)]
|
||||
}
|
||||
|
||||
/// The highlight at `p` for a pointer with the modifiers `mods`: none with Alt, with Space held
|
||||
/// for the view tools or with Highlight off, else the face or edge a click there paints. With
|
||||
/// Highlight off the selection's map is still made, for the cursor ([`Self::paints_at`]).
|
||||
fn hover_at(&mut self, cx: &ToolContext, p: Point, mods: Mods) -> LpHover {
|
||||
if mods.alt || mods.space {
|
||||
return LpHover::None;
|
||||
}
|
||||
let target = self.target_at(cx, p, shift);
|
||||
let target = self.target_at(cx, p, mods.shift);
|
||||
if self.highlight { target } else { LpHover::None }
|
||||
}
|
||||
|
||||
@@ -356,13 +502,19 @@ impl Tool for LivePaintBucketTool {
|
||||
}
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
self.at = Some((p, ev.mods.shift, ev.mods.alt));
|
||||
self.hover = self.hover_at(cx, p, ev.mods.shift, ev.mods.alt);
|
||||
self.at = Some((p, ev.mods));
|
||||
self.hover = self.hover_at(cx, p, ev.mods);
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Down => {
|
||||
self.hover = LpHover::None;
|
||||
// With Space held for the view tools, a press paints nothing.
|
||||
if ev.mods.space {
|
||||
self.note_press(None);
|
||||
return vec![];
|
||||
}
|
||||
if ev.mods.alt {
|
||||
self.note_press(None);
|
||||
if ev.mods.shift {
|
||||
return crate::xform::eyedropper::sample_color_at(cx, p).map_or_else(Vec::new, |color| {
|
||||
vec![Action::Exec("paint.sampleColor".into(), json!({ "color": crate::params::color_json(&color), "ids": [] }))]
|
||||
@@ -387,36 +539,49 @@ impl Tool for LivePaintBucketTool {
|
||||
let point = json!([p.x, p.y]);
|
||||
let paint = self.paints(ev.mods.shift);
|
||||
if matches!(paint, LpPaint::Strokes | LpPaint::Both)
|
||||
&& let Some((g, Some(_))) = lp_part_at(cx.doc, p, cx.tol(4.0), true, &|id| lp_visible(cx, id))
|
||||
&& let Some((g, Some(e))) = lp_part_at(cx.doc, p, cx.tol(4.0), true, &|id| lp_visible(cx, id))
|
||||
{
|
||||
self.note_part(e, true, p);
|
||||
return vec![Action::Exec("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": point, "tolerance": cx.tol(4.0) }))];
|
||||
}
|
||||
if !matches!(paint, LpPaint::Fills | LpPaint::Both) {
|
||||
self.note_press(None);
|
||||
return vec![];
|
||||
}
|
||||
if let Some(g) = live_paint_at(cx.doc, p) {
|
||||
match cx.doc.node(g).and_then(|n| visible_face_at(n, p)) {
|
||||
Some(f) => self.note_part(f, false, p),
|
||||
None => self.note_press(None),
|
||||
}
|
||||
return self.begin_fill(json!({ "group": g.0, "point": point }), p);
|
||||
}
|
||||
if self.cache.at(cx, p).is_some() {
|
||||
let roots = sorted_roots(cx.doc, &cx.selection.objects);
|
||||
self.note_press(Some(LpPress { part: None, at: p, before: made_face_fill(cx.doc, &roots, p), also: vec![] }));
|
||||
return self.begin_fill(json!({ "ids": json_ids(&roots), "point": point }), p);
|
||||
}
|
||||
self.note_press(None);
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Drag => self.drag_fill(p),
|
||||
PointerKind::Up => {
|
||||
// The swatch preview shows again at the release point.
|
||||
self.at = Some((p, ev.mods.shift, ev.mods.alt));
|
||||
self.at = Some((p, ev.mods));
|
||||
let mut acts = self.drag_fill(p);
|
||||
if self.fill_drag.take().is_some() {
|
||||
acts.push(Action::Commit);
|
||||
}
|
||||
acts
|
||||
}
|
||||
_ => vec![],
|
||||
PointerKind::DoubleClick => self.multi_click(cx, p, ev.mods, "connected", 2),
|
||||
PointerKind::TripleClick => self.multi_click(cx, p, ev.mods, "samePaint", 3),
|
||||
}
|
||||
}
|
||||
|
||||
fn history_moved(&mut self) {
|
||||
self.presses.clear();
|
||||
}
|
||||
|
||||
/// Escape during a fill drag cancels it. Left and Right pick the color swatch before or after
|
||||
/// the active paint, while no drag is on.
|
||||
fn key(&mut self, cx: &ToolContext, key: ToolKey, mods: Mods) -> Vec<Action> {
|
||||
@@ -455,6 +620,7 @@ impl Tool for LivePaintBucketTool {
|
||||
}
|
||||
|
||||
fn deactivate(&mut self, _cx: &ToolContext) -> Vec<Action> {
|
||||
self.presses.clear();
|
||||
if self.fill_drag.take().is_some() { vec![Action::Commit] } else { vec![] }
|
||||
}
|
||||
|
||||
@@ -469,7 +635,8 @@ impl Tool for LivePaintBucketTool {
|
||||
// No chips during a fill drag, or while Alt makes the tool sample with the eyedropper.
|
||||
if self.preview
|
||||
&& !self.busy()
|
||||
&& let Some((at, _, false)) = self.at
|
||||
&& let Some((at, mods)) = self.at
|
||||
&& !mods.alt
|
||||
{
|
||||
out.extend(swatch_chips(cx, at, Self::active_paint(cx), self.picked[Self::picked_slot(cx)], true));
|
||||
}
|
||||
@@ -520,8 +687,8 @@ impl Tool for LivePaintBucketTool {
|
||||
// of a Live Paint group the hover takes no map.
|
||||
loop {
|
||||
self.cache.settle(wait);
|
||||
if let Some((p, shift, alt)) = self.at {
|
||||
self.hover = self.hover_at(cx, p, shift, alt);
|
||||
if let Some((p, mods)) = self.at {
|
||||
self.hover = self.hover_at(cx, p, mods);
|
||||
}
|
||||
if !wait || !self.cache.waiting() {
|
||||
break;
|
||||
@@ -776,6 +943,9 @@ impl Tool for LivePaintSelectionTool {
|
||||
(false, false) => vec![Action::Exec("select.set".into(), json!({ "ids": json_ids(&ids) }))],
|
||||
}
|
||||
}
|
||||
// The tool takes no action on a triple-click; its third press and release select as a
|
||||
// click does.
|
||||
PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ fn lp_cells_around(p: Point) -> impl Iterator<Item = (i64, i64)> {
|
||||
/// The stroke paint Live Paint edge `edge` draws with: the paint of its topmost stroke that is shown
|
||||
/// with a paint, a weight above 0 and an opacity above 0, or [`Paint::None`] when the edge is fully
|
||||
/// transparent or has no such stroke.
|
||||
pub(super) fn lp_stroke_paint(edge: &Node) -> Paint {
|
||||
pub fn lp_stroke_paint(edge: &Node) -> Paint {
|
||||
if edge.opacity <= 0.0 {
|
||||
return Paint::None;
|
||||
}
|
||||
|
||||
@@ -1124,6 +1124,287 @@ fn bucket_click_fills_face_and_shift_click_strokes_edge() {
|
||||
assert_eq!(id, "livePaint.strokeEdge");
|
||||
}
|
||||
|
||||
/// A double-click runs a click's command with `scope: "connected"` and a triple-click with
|
||||
/// `"samePaint"`, matching the paint the face or edge had before the first click there.
|
||||
#[test]
|
||||
fn bucket_double_and_triple_click_widen_what_a_click_paints() {
|
||||
let (d, gid, f2, e) = live_group_doc();
|
||||
let red = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(1.0, 0.0, 0.0));
|
||||
let mut painted = d.clone();
|
||||
painted.node_mut(f2).unwrap().appearance.set_fill(red.clone());
|
||||
painted.node_mut(e).unwrap().appearance.set_stroke(red.clone());
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let (cx, later) = (cx(&d, &s, &p), cx(&painted, &s, &p));
|
||||
let face_before = serde_json::to_value(d.node(f2).unwrap().appearance.fill_paint()).unwrap();
|
||||
let edge_before = serde_json::to_value(d.node(e).unwrap().appearance.stroke_paint()).unwrap();
|
||||
let red_json = serde_json::to_value(&red).unwrap();
|
||||
assert_ne!(face_before, red_json);
|
||||
assert_ne!(edge_before, red_json);
|
||||
let fill = |scope: &str, like: Option<&Value>| {
|
||||
let mut v = json!({ "group": gid.0, "point": [75.0, 25.0], "scope": scope });
|
||||
if let Some(like) = like {
|
||||
v["match"] = like.clone();
|
||||
}
|
||||
vec![Action::Exec("livePaint.fill".into(), v)]
|
||||
};
|
||||
let click = |t: &mut LivePaintBucketTool, cx: &ToolContext, x: f64, m: Mods| {
|
||||
t.pointer(cx, &ev(PointerKind::Down, x, 25.0).with_mods(m));
|
||||
t.pointer(cx, &ev(PointerKind::Up, x, 25.0).with_mods(m));
|
||||
};
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
// The clicks paint the face as they arrive; the triple-click matches the fill from before them.
|
||||
click(&mut t, &cx, 75.0, Mods::default());
|
||||
click(&mut t, &later, 75.0, Mods::default());
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::DoubleClick, 75.0, 25.0)), fill("connected", None));
|
||||
click(&mut t, &later, 75.0, Mods::default());
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::TripleClick, 75.0, 25.0)), fill("samePaint", Some(&face_before)));
|
||||
// A new click there starts again from the fill it finds.
|
||||
click(&mut t, &later, 75.0, Mods::default());
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::TripleClick, 75.0, 25.0)), fill("samePaint", Some(&red_json)));
|
||||
// A click before the triple-click's own three is not part of it.
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
click(&mut t, &cx, 75.0, Mods::default());
|
||||
for _ in 0..3 {
|
||||
click(&mut t, &later, 75.0, Mods::default());
|
||||
}
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::TripleClick, 75.0, 25.0)), fill("samePaint", Some(&red_json)));
|
||||
// Shift: the edge, matching its stroke from before the first click.
|
||||
let shift = Mods { shift: true, ..Default::default() };
|
||||
let stroke = |scope: &str, like: &Value| {
|
||||
vec![Action::Exec(
|
||||
"livePaint.strokeEdge".into(),
|
||||
json!({ "group": gid.0, "point": [51.0, 25.0], "tolerance": 4.0, "scope": scope, "match": like }),
|
||||
)]
|
||||
};
|
||||
click(&mut t, &cx, 51.0, shift);
|
||||
click(&mut t, &later, 51.0, shift);
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::DoubleClick, 51.0, 25.0).with_mods(shift)), stroke("connected", &edge_before));
|
||||
click(&mut t, &later, 51.0, shift);
|
||||
assert_eq!(t.pointer(&later, &ev(PointerKind::TripleClick, 51.0, 25.0).with_mods(shift)), stroke("samePaint", &edge_before));
|
||||
// With Alt or Space held, or with both options off, a double-click or triple-click paints nothing.
|
||||
let alt = Mods { alt: true, ..Default::default() };
|
||||
let space = Mods { space: true, ..Default::default() };
|
||||
for k in [PointerKind::DoubleClick, PointerKind::TripleClick] {
|
||||
assert!(t.pointer(&cx, &ev(k, 75.0, 25.0).with_mods(alt)).is_empty(), "{k:?}");
|
||||
assert!(t.pointer(&cx, &ev(k, 75.0, 25.0).with_mods(Mods { cmd: true, ..Default::default() })).is_empty(), "{k:?} with Cmd");
|
||||
assert!(t.pointer(&cx, &ev(k, 75.0, 25.0).with_mods(space)).is_empty(), "{k:?} with Space");
|
||||
assert!(t.pointer(&cx, &ev(k, 51.0, 25.0).with_mods(Mods { shift: true, ..space })).is_empty(), "{k:?} with Shift and Space");
|
||||
}
|
||||
// A press with Space held paints nothing either.
|
||||
for m in [space, Mods { shift: true, ..space }] {
|
||||
for (k, x) in [(PointerKind::Down, 75.0), (PointerKind::Up, 75.0), (PointerKind::Down, 51.0), (PointerKind::Up, 51.0)] {
|
||||
assert!(t.pointer(&cx, &ev(k, x, 25.0).with_mods(m)).is_empty(), "{k:?} at {x} with {m:?}");
|
||||
}
|
||||
}
|
||||
t.set_option("paintFills", &json!(false));
|
||||
for k in [PointerKind::DoubleClick, PointerKind::TripleClick] {
|
||||
assert!(t.pointer(&cx, &ev(k, 75.0, 25.0)).is_empty(), "{k:?}");
|
||||
}
|
||||
// Outside every face, nothing is painted.
|
||||
t.set_option("paintFills", &json!(true));
|
||||
assert!(t.pointer(&cx, &ev(PointerKind::DoubleClick, 400.0, 400.0)).is_empty());
|
||||
}
|
||||
|
||||
/// A triple-click whose third click lands on a face the double-click's flood filled matches that
|
||||
/// face's fill from before the double-click.
|
||||
#[test]
|
||||
fn bucket_triple_click_on_a_face_the_double_click_flooded_matches_its_earlier_fill() {
|
||||
let (mut d, gid, f2, _) = live_group_doc();
|
||||
let red = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(1.0, 0.0, 0.0));
|
||||
let blue = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(0.0, 0.0, 1.0));
|
||||
let f1 = crate::builder::face_at(d.node(gid).unwrap(), Point::new(25.0, 25.0)).unwrap().id;
|
||||
for f in [f1, f2] {
|
||||
d.node_mut(f).unwrap().appearance.set_fill(red.clone());
|
||||
}
|
||||
let mut first = d.clone();
|
||||
first.node_mut(f1).unwrap().appearance.set_fill(blue.clone());
|
||||
let mut flooded = first.clone();
|
||||
flooded.node_mut(f2).unwrap().appearance.set_fill(blue.clone());
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let (start, first, flooded) = (cx(&d, &s, &p), cx(&first, &s, &p), cx(&flooded, &s, &p));
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
let click = |t: &mut LivePaintBucketTool, cx: &ToolContext, x: f64| {
|
||||
t.pointer(cx, &ev(PointerKind::Down, x, 25.0));
|
||||
t.pointer(cx, &ev(PointerKind::Up, x, 25.0));
|
||||
};
|
||||
click(&mut t, &start, 25.0);
|
||||
click(&mut t, &first, 25.0);
|
||||
t.pointer(&first, &ev(PointerKind::DoubleClick, 25.0, 25.0));
|
||||
click(&mut t, &flooded, 75.0);
|
||||
let like = serde_json::to_value(&red).unwrap();
|
||||
assert_eq!(
|
||||
t.pointer(&flooded, &ev(PointerKind::TripleClick, 75.0, 25.0)),
|
||||
vec![Action::Exec("livePaint.fill".into(), json!({ "group": gid.0, "point": [75.0, 25.0], "scope": "samePaint", "match": like }))]
|
||||
);
|
||||
}
|
||||
|
||||
/// On an edge that stores a stroke paint but draws none (its stroke hidden, or the edge fully
|
||||
/// transparent), a double-click or triple-click matches no paint, with or without the clicks
|
||||
/// before it.
|
||||
#[test]
|
||||
fn bucket_multi_click_on_an_edge_matches_the_paint_it_draws() {
|
||||
let (mut d, gid, _, e) = live_group_doc();
|
||||
d.node_mut(e).unwrap().appearance.set_stroke(vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(0.0, 0.0, 0.0)));
|
||||
let mut hidden = d.clone();
|
||||
hidden.node_mut(e).unwrap().appearance.stroke_mut().unwrap().visible = false;
|
||||
let mut clear = d.clone();
|
||||
clear.node_mut(e).unwrap().opacity = 0.0;
|
||||
let none = serde_json::to_value(vectorcraft_color::Paint::None).unwrap();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let shift = Mods { shift: true, ..Default::default() };
|
||||
let stroke = |scope: &str| {
|
||||
vec![Action::Exec(
|
||||
"livePaint.strokeEdge".into(),
|
||||
json!({ "group": gid.0, "point": [51.0, 25.0], "tolerance": 4.0, "scope": scope, "match": none }),
|
||||
)]
|
||||
};
|
||||
for doc in [&hidden, &clear] {
|
||||
let cx = cx(doc, &s, &p);
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::DoubleClick, 51.0, 25.0).with_mods(shift)), stroke("connected"));
|
||||
for _ in 0..3 {
|
||||
t.pointer(&cx, &ev(PointerKind::Down, 51.0, 25.0).with_mods(shift));
|
||||
t.pointer(&cx, &ev(PointerKind::Up, 51.0, 25.0).with_mods(shift));
|
||||
}
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::TripleClick, 51.0, 25.0).with_mods(shift)), stroke("samePaint"));
|
||||
}
|
||||
}
|
||||
|
||||
/// A triple-click whose first click makes the Live Paint group matches the fill of the face the
|
||||
/// group makes there: an open path in front, whose outline bounds no face, does not give it.
|
||||
#[test]
|
||||
fn bucket_triple_click_on_a_made_group_skips_open_paths() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_geom::{PathData, SubPath};
|
||||
let (red, blue) = (Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::solid(Color::rgb(0.0, 0.0, 1.0)));
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
let l = d.layers[0].id;
|
||||
let back = d.alloc_id();
|
||||
let mut look = Appearance::default_art();
|
||||
look.set_fill(red.clone());
|
||||
d.insert(Some(l), 0, Node::path(back, shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)), look)).unwrap();
|
||||
// An open U around (75, 25), filled blue.
|
||||
let u = [Point::new(60.0, 5.0), Point::new(60.0, 45.0), Point::new(90.0, 45.0), Point::new(90.0, 5.0)];
|
||||
let front = d.alloc_id();
|
||||
let mut look = Appearance::default_art();
|
||||
look.set_fill(blue);
|
||||
d.insert(Some(l), 1, Node::path(front, PathData::single(SubPath::polyline(&u, false)), look)).unwrap();
|
||||
// The face the planar map makes there takes its fill from the square, as the group's would.
|
||||
let shapes: Vec<vectorcraft_pathops::Shape> = [back, front]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(k, id)| node_outline(d.node(*id)?).map(|(path, rule)| vectorcraft_pathops::Shape::new(path, rule, k as u64)))
|
||||
.collect();
|
||||
let (regions, _) = vectorcraft_pathops::live_paint(&shapes);
|
||||
let face = regions.iter().find(|r| r.contains(Point::new(75.0, 25.0))).expect("a face at (75, 25)");
|
||||
assert_eq!(face.top(), Some(0), "the square is the face's top shape");
|
||||
let mut s = Selection::default();
|
||||
s.set([back, front]);
|
||||
let p = paint();
|
||||
let (made, ..) = live_group_doc();
|
||||
let none = Selection::default();
|
||||
let (cx, later) = (cx(&d, &s, &p), cx(&made, &none, &p));
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
t.pointer(&cx, &ev(PointerKind::Down, 75.0, 25.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Up, 75.0, 25.0));
|
||||
for _ in 0..2 {
|
||||
t.pointer(&later, &ev(PointerKind::Down, 75.0, 25.0));
|
||||
t.pointer(&later, &ev(PointerKind::Up, 75.0, 25.0));
|
||||
}
|
||||
let acts = t.pointer(&later, &ev(PointerKind::TripleClick, 75.0, 25.0));
|
||||
let [Action::Exec(id, v)] = acts.as_slice() else { panic!("{acts:?}") };
|
||||
assert_eq!(id, "livePaint.fill");
|
||||
assert_eq!(v["match"], serde_json::to_value(&red).unwrap());
|
||||
}
|
||||
|
||||
/// A triple-click whose first click makes the Live Paint group on one face and whose other two
|
||||
/// clicks fill another face matches the fill the second face had before the first click on it,
|
||||
/// not the fill under the first click or the fill the clicks gave it.
|
||||
#[test]
|
||||
fn bucket_triple_click_after_making_the_group_on_another_face_matches_its_own_face() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
let (red, blue) = (Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::solid(Color::rgb(0.0, 0.0, 1.0)));
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
let l = d.layers[0].id;
|
||||
let square = d.alloc_id();
|
||||
let mut look = Appearance::default_art();
|
||||
look.set_fill(red.clone());
|
||||
d.insert(Some(l), 0, Node::path(square, shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 50.0)), look)).unwrap();
|
||||
let mut s = Selection::default();
|
||||
s.set([square]);
|
||||
let p = paint();
|
||||
let (made, _, f2, _) = live_group_doc();
|
||||
let mut painted = made.clone();
|
||||
painted.node_mut(f2).unwrap().appearance.set_fill(blue.clone());
|
||||
let none = Selection::default();
|
||||
let (cx, later, after) = (cx(&d, &s, &p), cx(&made, &none, &p), cx(&painted, &none, &p));
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
// The first click makes the group and fills the face at (25, 25); the next two fill (75, 25),
|
||||
// the first of them painting it blue.
|
||||
t.pointer(&cx, &ev(PointerKind::Down, 25.0, 25.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Up, 25.0, 25.0));
|
||||
for ctx in [&later, &after] {
|
||||
t.pointer(ctx, &ev(PointerKind::Down, 75.0, 25.0));
|
||||
t.pointer(ctx, &ev(PointerKind::Up, 75.0, 25.0));
|
||||
}
|
||||
let acts = t.pointer(&after, &ev(PointerKind::TripleClick, 75.0, 25.0));
|
||||
let [Action::Exec(id, v)] = acts.as_slice() else { panic!("{acts:?}") };
|
||||
assert_eq!(id, "livePaint.fill");
|
||||
let own = serde_json::to_value(made.node(f2).unwrap().appearance.fill_paint()).unwrap();
|
||||
assert_ne!(own, serde_json::to_value(&red).unwrap());
|
||||
assert_ne!(own, serde_json::to_value(&blue).unwrap());
|
||||
assert_eq!(v["match"], own);
|
||||
}
|
||||
|
||||
/// A triple-click whose clicks land on one face, another face, then the first face again matches
|
||||
/// the fill the first face had before the first click on it, not the fill that click gave it.
|
||||
#[test]
|
||||
fn bucket_triple_click_with_a_click_on_another_face_between_matches_the_first_fill() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
let red = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
|
||||
let (d, gid, f2, _) = live_group_doc();
|
||||
let mut painted = d.clone();
|
||||
painted.node_mut(f2).unwrap().appearance.set_fill(red.clone());
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let (cx, later) = (cx(&d, &s, &p), cx(&painted, &s, &p));
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
// The first click paints the face at (75, 25) red; the second fills the face at (25, 25).
|
||||
for (ctx, x) in [(&cx, 75.0), (&later, 25.0), (&later, 75.0)] {
|
||||
t.pointer(ctx, &ev(PointerKind::Down, x, 25.0));
|
||||
t.pointer(ctx, &ev(PointerKind::Up, x, 25.0));
|
||||
}
|
||||
let acts = t.pointer(&later, &ev(PointerKind::TripleClick, 75.0, 25.0));
|
||||
let own = serde_json::to_value(d.node(f2).unwrap().appearance.fill_paint()).unwrap();
|
||||
assert_ne!(own, serde_json::to_value(&red).unwrap());
|
||||
assert_eq!(
|
||||
acts,
|
||||
vec![Action::Exec("livePaint.fill".into(), json!({ "group": gid.0, "point": [75.0, 25.0], "scope": "samePaint", "match": own }))]
|
||||
);
|
||||
}
|
||||
|
||||
/// With Space held for the view tools, the pointer outlines no face or edge, as a press there
|
||||
/// paints nothing.
|
||||
#[test]
|
||||
fn bucket_highlights_nothing_with_space_held() {
|
||||
let (d, ..) = live_group_doc();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let mut t = LivePaintBucketTool::default();
|
||||
let outlined = |t: &LivePaintBucketTool| t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Path { .. }));
|
||||
let space = Mods { space: true, ..Default::default() };
|
||||
for (x, m) in [(75.0, space), (51.0, Mods { shift: true, ..space })] {
|
||||
t.pointer(&cx, &ev(PointerKind::Move, x, 25.0).with_mods(m));
|
||||
assert!(!outlined(&t), "at {x} with {m:?}");
|
||||
}
|
||||
t.pointer(&cx, &ev(PointerKind::Move, 75.0, 25.0));
|
||||
assert!(outlined(&t));
|
||||
}
|
||||
|
||||
/// After a fill drag, the cursor swatch preview shows at the release point, not where the pointer
|
||||
/// last moved before the press.
|
||||
#[test]
|
||||
@@ -2292,6 +2573,22 @@ fn live_paint_selection_double_click_selects_connected_faces_or_edges() {
|
||||
assert!(dbl(&mut t, 25.0, 1.0, alt).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_selection_triple_click_adds_nothing_to_its_clicks() {
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
let (_, [a, ..], _) = live_strip(&mut d);
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let mut t = LivePaintSelectionTool::default();
|
||||
// The third click's press and release select the face under the pointer, as a click does.
|
||||
assert_eq!(lp_click(&mut t, &cx, ev(PointerKind::Down, 25.0, 25.0)), vec![Action::Exec("select.set".into(), json!({ "ids": [a.0] }))]);
|
||||
for m in [Mods::default(), Mods { alt: true, ..Default::default() }, Mods { shift: true, ..Default::default() }] {
|
||||
assert!(t.pointer(&cx, &ev(PointerKind::TripleClick, 25.0, 25.0).with_mods(m)).is_empty());
|
||||
assert!(t.pointer(&cx, &ev(PointerKind::TripleClick, 25.0, 1.0).with_mods(m)).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_selection_double_click_skips_locked_groups_and_art_outside_isolation() {
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
|
||||
@@ -169,6 +169,7 @@ impl Tool for CropImageTool {
|
||||
PointerKind::Up => self.drag = None,
|
||||
PointerKind::DoubleClick => return self.apply(cx),
|
||||
PointerKind::Move => self.last = ev.pos,
|
||||
PointerKind::TripleClick => {}
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ impl Tool for PuppetWarpTool {
|
||||
}
|
||||
None => vec![],
|
||||
},
|
||||
PointerKind::DoubleClick => vec![],
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
/// Delete/Backspace remove the selected pins; with none selected they are the shortcut's
|
||||
|
||||
@@ -300,6 +300,7 @@ impl Tool for WidthTool {
|
||||
self.hover = Self::spot_at(cx, p);
|
||||
vec![]
|
||||
}
|
||||
PointerKind::TripleClick => vec![],
|
||||
PointerKind::DoubleClick => {
|
||||
let Some(spot) = Self::spot_at(cx, p) else { return vec![] };
|
||||
let Some((w, _)) = Self::hit(cx, &spot, p) else {
|
||||
|
||||
@@ -653,6 +653,7 @@ impl Tool for CurvatureTool {
|
||||
self.pts[i].1 = !self.pts[i].1;
|
||||
vec![Action::Exec("path.curvature".into(), self.params())]
|
||||
}
|
||||
PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
fn notify(&mut self, cx: &ToolContext, what: &str) {
|
||||
|
||||
@@ -29,6 +29,9 @@ pub enum PointerKind {
|
||||
/// Moved with no button (hover).
|
||||
Move,
|
||||
DoubleClick,
|
||||
/// The third click of a triple-click, after its press and release (the second click's
|
||||
/// release sends [`PointerKind::DoubleClick`]).
|
||||
TripleClick,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
@@ -449,7 +449,7 @@ impl Tool for PenTool {
|
||||
}
|
||||
vec![Action::Commit]
|
||||
}
|
||||
PointerKind::DoubleClick => vec![],
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
fn key(&mut self, cx: &ToolContext, key: ToolKey, _m: Mods) -> Vec<Action> {
|
||||
|
||||
@@ -68,7 +68,7 @@ impl Tool for PrintTilingTool {
|
||||
self.drag = None;
|
||||
vec![Action::Exec("print.tiling.set".into(), json!({ "reset": true }))]
|
||||
}
|
||||
PointerKind::Move => vec![],
|
||||
PointerKind::Move | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ impl Tool for TypeTool {
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
PointerKind::TripleClick => vec![],
|
||||
PointerKind::Move => {
|
||||
// The type being edited is no target: its guides would only point at itself.
|
||||
self.snap.hover(cx, ev.pos, self.editing.as_slice(), None);
|
||||
|
||||
@@ -387,7 +387,7 @@ impl Tool for TouchTypeTool {
|
||||
Some(d) if d.began => vec![Action::Commit],
|
||||
_ => vec![],
|
||||
},
|
||||
PointerKind::DoubleClick | PointerKind::Move => vec![],
|
||||
PointerKind::DoubleClick | PointerKind::TripleClick | PointerKind::Move => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -582,7 +582,7 @@ impl Tool for GradientTool {
|
||||
let at = a.stop_point(cx, i).unwrap_or(ev.pos);
|
||||
vec![Self::select_stop(i), Action::Dialog("gradientStop".into(), json!({ "index": i, "x": at.x, "y": at.y }))]
|
||||
}
|
||||
PointerKind::Move => vec![],
|
||||
PointerKind::Move | PointerKind::TripleClick => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -272,6 +272,7 @@ impl Tool for TransformTool {
|
||||
None => vec![],
|
||||
}
|
||||
}
|
||||
PointerKind::TripleClick => vec![],
|
||||
PointerKind::Move => {
|
||||
if self.drag.is_none() {
|
||||
self.hover = if cx.selection.is_empty() { vec![] } else { snap_pick(cx, p).1 };
|
||||
|
||||
@@ -179,6 +179,12 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
{
|
||||
double_click(app, ui, &f, p);
|
||||
}
|
||||
if resp.triple_clicked()
|
||||
&& !f.modal
|
||||
&& let Some(p) = at
|
||||
{
|
||||
triple_click(app, ui, &f, p);
|
||||
}
|
||||
if drag.is_some() || pointer.is_moving() || mods_changed {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
@@ -591,6 +597,23 @@ fn double_click(app: &mut VectorcraftApp, ui: &Ui, f: &Pointing, p: Pos2) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A triple-click at `p`: the tool gets it, unless it is on an artboard's name.
|
||||
fn triple_click(app: &mut VectorcraftApp, ui: &Ui, f: &Pointing, p: Pos2) {
|
||||
let Pointing { m, space, xf, view, .. } = *f;
|
||||
if artboard_name_at(app, ui, &xf, p).is_some() {
|
||||
return;
|
||||
}
|
||||
let ev = PointerEvent {
|
||||
kind: PointerKind::TripleClick,
|
||||
pos: xf.to_doc(p),
|
||||
mods: mods(m, space),
|
||||
backquote: ui.input(|i| i.key_down(egui::Key::Backtick)),
|
||||
pressure: 1.0,
|
||||
pen: None,
|
||||
};
|
||||
dispatch(app, &ev, view);
|
||||
}
|
||||
|
||||
/// Where `button` went up in this frame, if it did.
|
||||
fn release_pos(ui: &Ui, button: egui::PointerButton) -> Option<Pos2> {
|
||||
ui.input(|i| {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! - `ui.menu.list`: flattened menu tree
|
||||
//! - `ui.contextMenu.list`: the canvas context menu for the current selection, flattened
|
||||
//! - `ui.tool.select {tool}`, `ui.tool.list`
|
||||
//! - `ui.pointer {events:[{kind: down|drag|up|move|doubleclick, x, y, backquote?, space?: "doc"|"screen"}], mods?, backquote?}`:
|
||||
//! - `ui.pointer {events:[{kind: down|drag|up|move|doubleclick|tripleclick, x, y, backquote?, space?: "doc"|"screen"}], mods?, backquote?}`:
|
||||
//! drive the active tool through the same path as the mouse, after the synthetic input sent
|
||||
//! before it was applied
|
||||
//! - `ui.key {key, shift?, alt?, cmd?}` / `ui.text {text}`: synthetic keyboard input
|
||||
@@ -1895,7 +1895,7 @@ fn rotate_view_pointer(
|
||||
PointerKind::Up => {
|
||||
app.control_rotate_press = None;
|
||||
}
|
||||
PointerKind::Move | PointerKind::DoubleClick => {}
|
||||
PointerKind::Move | PointerKind::DoubleClick | PointerKind::TripleClick => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1963,6 +1963,7 @@ fn pointer_events_inner(app: &mut VectorcraftApp, ctx: &egui::Context, req: &Con
|
||||
"up" => PointerKind::Up,
|
||||
"move" => PointerKind::Move,
|
||||
"doubleclick" | "dblclick" => PointerKind::DoubleClick,
|
||||
"tripleclick" => PointerKind::TripleClick,
|
||||
other => return Err(format!("unknown pointer kind `{other}`")),
|
||||
};
|
||||
PointerEvent::json_check(e)?;
|
||||
|
||||
@@ -96,7 +96,7 @@ the two can still win that race.
|
||||
| `ui.menu.list` / `ui.menu.invoke` | `{command, params}` | the full menu tree / invoke an item |
|
||||
| `ui.contextMenu.list` | | the canvas context menu for the current selection, flattened like `ui.menu.list` (`path` holds its submenus). `ui.click {x, y, button: "right"}` on the canvas opens it, after selecting the object there unless it is already selected. With the Artboard tool it lists the artboard entries (see `docs/mcp.md`), after selecting the artboard there unless it is already selected. While a menu opened over locked objects is open, it has an `Unlock` submenu with one item for each locked object under the pointer, topmost first and at most 20, labeled with the object's name, which runs `layer.setProps {ids: [id], locked: false}`. A locked group gets one item, and the locked objects inside it get none. Hidden objects, objects on hidden, locked or template layers, and in isolation mode objects outside the isolated group get no item |
|
||||
| `ui.tool.select` / `ui.tool.list` | `{tool}` | |
|
||||
| `ui.pointer` | `{events:[{kind: down|drag|up|move|doubleclick, x, y, space?: "doc"|"screen", mods?}]}` | drive the active tool exactly like the mouse: `mods.cmd` held at a press with any tool but a selection tool drags with the selection tool chosen last (Direct Selection with the Pen until one is), and the release gives the tool back as it was; the reply lists `selection`, `key` (the key object, null without one) and `tool`. With the Shape Builder or the Live Paint Bucket and a selection of more than 128 segments, the app finds the regions off the UI thread, so a `move` replies before the region under the pointer is highlighted, and the highlight shows in the first frame after the regions are found. With the Shape Builder and such a selection, the app also merges off the UI thread: the reply to the events that end a click or drag comes once the merge is applied. A click or drag made before the regions are found does not wait for them; the app records it and makes it once they are found. Until then the canvas keeps drawing, with the touched regions highlighted and the busy pointer. A click or drag sent meanwhile, with `mods.cmd` too, and the Shape Builder's arrow keys are made after the merge in the order sent, and the reply to such a request comes once its events are made and any merge they start is applied; a request of `move` events alone is answered at once. A command that can edit, select, save or redraw the documents (an edit, an undo, a selection, a save or an export, a tool option, another tool, another document, closing, a dialog's preview, a menu item, a command of the app's own such as `ui.recolorDialog`, the proof and separations views, a preference, added fonts) waits for the merge and the input sent before it, and runs after them; queries that only read, such as `document.inspect`, run at once on the document before the merge |
|
||||
| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick\|tripleclick, x, y, space?: "doc"\|"screen", mods?}]}` | drive the active tool exactly like the mouse (`doubleclick` follows the second click's `up`, and `tripleclick` the third's): `mods.cmd` held at a press with any tool but a selection tool drags with the selection tool chosen last (Direct Selection with the Pen until one is), and the release gives the tool back as it was; the reply lists `selection`, `key` (the key object, null without one) and `tool`. With the Shape Builder or the Live Paint Bucket and a selection of more than 128 segments, the app finds the regions off the UI thread, so a `move` replies before the region under the pointer is highlighted, and the highlight shows in the first frame after the regions are found. With the Shape Builder and such a selection, the app also merges off the UI thread: the reply to the events that end a click or drag comes once the merge is applied. A click or drag made before the regions are found does not wait for them; the app records it and makes it once they are found. Until then the canvas keeps drawing, with the touched regions highlighted and the busy pointer. A click or drag sent meanwhile, with `mods.cmd` too, and the Shape Builder's arrow keys are made after the merge in the order sent, and the reply to such a request comes once its events are made and any merge they start is applied; a request of `move` events alone is answered at once. A command that can edit, select, save or redraw the documents (an edit, an undo, a selection, a save or an export, a tool option, another tool, another document, closing, a dialog's preview, a menu item, a command of the app's own such as `ui.recolorDialog`, the proof and separations views, a preference, added fonts) waits for the merge and the input sent before it, and runs after them; queries that only read, such as `document.inspect`, run at once on the document before the merge |
|
||||
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | synthetic keyboard input |
|
||||
| `ui.move` | `{x, y}` | screen-point pointer move |
|
||||
| `ui.click` / `ui.drag` | `{x, y, button?, count?, shift?, alt?, ctrl?, cmd?}` / `{x, y, toX, toY, steps?, count?, button?, shift?, alt?, ctrl?, cmd?}` | egui pointer input; see synthetic input budgets above |
|
||||
|
||||
+29
-3
@@ -647,8 +647,8 @@ sampler.
|
||||
| `inspect_document` | `{depth?, childLimit?, ids?, kind?, limit?, offset?}` | Artboards (with `color`, `#rrggbb`, for one with a background color), layer tree (ids, kinds, bounds, paint), selection, history, tool. A type node's `fill`, `stroke` and `strokeWidth` are the paint its characters show (its first run's); fills and strokes of the type object itself come as `objectFill`, `objectStroke` and `objectStrokeWidth`. Paint comes as a label (`"#ff0000"`, `"None"`, `"G1 40% (#ff9999)"` for a swatch at a tint); `paint.proxies` gives it as an object. |
|
||||
| `inspect_ui` | `{}` | UI state. Remote mode only. |
|
||||
| `select_tool` | `{tool}` | `selection`, `directSelection`, `pen`, `rectangle`, `ellipse`, `polygon`, `star`, `lineSegment`, … |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`. `backquote` is the held state for each event; the top-level value supplies its default, and a `backquote` that is not a boolean is an error. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`. `backquote` is the held state for each event; the top-level value supplies its default. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. Remote, the events wait until the keys and other input sent before them (`press_key`, `type_text`) have reached the app, so a key pressed between two calls of one drag applies before the release. When that input is dropped because the document, a dialog or the focus changed first, the call fails and its events are not sent. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default, and a `backquote` that is not a boolean is an error. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. Remote, the events wait until the keys and other input sent before them (`press_key`, `type_text`) have reached the app, so a key pressed between two calls of one drag applies before the release. When that input is dropped because the document, a dialog or the focus changed first, the call fails and its events are not sent. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `draw_path` | `{points \| d, closed?, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `points` is `[[x,y],…]` or `[{x,y,in?,out?,smooth?},…]`. `d` is SVG path data. The options are below. |
|
||||
| `draw_shape` | `{shape, …geometry, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `rectangle`/`ellipse`: `x,y,width,height` (plus `radius` for corners). `polygon`: `cx,cy,radius,sides`. `star`: `cx,cy,radius1,radius2,points`. Polygons and stars take `rotation` in degrees clockwise (0: a corner or point straight up). `line`: `x1,y1,x2,y2`. |
|
||||
| `set_paint` | `{fill?, stroke?, strokeWidth?, ids?}` | Applies to the selection (or `ids`) and becomes the default for new art. Returns `{applied, objects}`: `objects` is the number of objects painted, as the `objects` of the `paint.setFill`, `paint.setStroke` and `stroke.set` replies (the largest of them): a selected group counts the objects inside it. When it is 0, a `note` says that only the paint for new art changed. |
|
||||
@@ -3772,6 +3772,31 @@ already walks Image Trace. Short agent entry points:
|
||||
`livePaint.strokeEdge` when an edge is within 4 screen pixels of the pointer and `livePaint.fill` otherwise, and
|
||||
Shift-click runs `livePaint.fill`. With both off, a click runs nothing. With `highlight` off, the face or edge under
|
||||
the pointer is not outlined.
|
||||
A double-click runs the command a click there runs with `scope: "connected"`, and a triple-click with
|
||||
`scope: "samePaint"`; Alt held runs nothing, and so does Cmd/Ctrl (`mods.cmd`), whose presses go to the selection
|
||||
tool Cmd lends. With Space held (`mods.space`, the view tools), a press, a
|
||||
double-click or a triple-click runs nothing, and a move outlines no face or edge. On a face, `connected` fills the face and every face reached from it
|
||||
across edges that draw no stroke (an edge that is hidden or fully transparent, or whose strokes are each hidden,
|
||||
without paint, 0 pt wide or fully transparent); a stroked edge, a hidden face, a gap
|
||||
that Gap Detection closes and the group's outside stop it. `samePaint` fills every face
|
||||
of the group, joined to it or not, whose fill is the `match` paint. On an edge, `connected` paints the edge and the
|
||||
edges joined to it end to end that draw with the stroke paint `match`, and `samePaint` paints every edge of the
|
||||
group that draws with that stroke paint; the stroke's weight is not compared. An edge draws with the paint of its
|
||||
topmost stroke that is shown, with paint, above 0 pt and not fully transparent, and with none when the edge is fully
|
||||
transparent or has no such stroke. Each click of a double-click or triple-click runs as it
|
||||
arrives and is its own undo step. `match` is the paint the face or edge had before the first of the double-click's
|
||||
two clicks or the triple-click's three that painted it, or before the double-click when the triple-click's double-click
|
||||
reached it, so the clicks before the last do not change what it matches;
|
||||
a first click that made the Live Paint group counts when the face it filled is the clicked face. Hidden faces and edges are not painted. An edge takes the
|
||||
paint and weight in its topmost stroke that is shown, or in a new stroke above the others when it has none. These rules
|
||||
for what faces and edges join and what paints match are VectorCraft's own. The help page describes the gestures:
|
||||
https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html.
|
||||
`livePaint.fill {scope}` and `livePaint.strokeEdge {scope}` take `scope` as `"one"` (the default), `"connected"` or
|
||||
`"samePaint"`; any other value is an error and changes nothing. `match` is a paint in the model JSON that
|
||||
`document.node {id}` writes for an appearance's paints (`{"type": "none"}` for none), taken only with a scope that compares paints, and
|
||||
defaults to the face's fill or the stroke paint the edge draws with. `livePaint.fill` refuses a `scope` other than `"one"` with
|
||||
`points`. Both replies add `count`, the number of faces or edges the click reaches, including those that already had the
|
||||
paint.
|
||||
With the Live Paint Bucket selected and no drag in progress, Left and Right without Shift, Alt or Cmd/Ctrl (which
|
||||
keep their shortcuts) run `paint.setFill {swatch, ids: []}` (or
|
||||
`paint.setStroke` when the Stroke proxy is in front) with the color swatch before or after the active paint in the
|
||||
@@ -3788,7 +3813,8 @@ already walks Image Trace. Short agent entry points:
|
||||
objects; otherwise it returns an error and does not merge the objects.
|
||||
A Live Paint command that changes nothing records no undo step, keeps the redo steps, leaves a saved document saved
|
||||
and replies as usual: `livePaint.fill` (a click, or a Bucket drag) when every face it reaches already has the paint,
|
||||
`livePaint.strokeEdge` when the edge already has the paint and the width, `livePaint.gapOptions` (and the Gap Options
|
||||
`livePaint.strokeEdge` when the topmost shown stroke of each edge it reaches already has the paint and the width,
|
||||
`livePaint.gapOptions` (and the Gap Options
|
||||
dialog's OK) when every group already has the options and `closeGaps` finds no gap, and `livePaint.make` or
|
||||
`livePaint.merge` given one Live Paint group alone, which they select. Such a fill or stroke also leaves the recent
|
||||
colors and the last color as they are. `livePaint.gapOptions` makes a group's faces again, with new ids, only when it adds a path or when Gap Detection is turned on or off or given a new size while it is on.
|
||||
|
||||
@@ -1526,6 +1526,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
Object › Live Paint › Merge adds the other selected paths and Live Paint groups to the bottom selected Live Paint group ([Live Paint groups](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/live-paint-groups.html)), which keeps its id, the paint of its faces and edges, and its name, lock, visibility, transparency, appearance, opacity mask and graphic style link. Object › Live Paint › Make with a Live Paint group selected, and a Live Paint Bucket click on a selected path beside a selected Live Paint group, add the paths to that group the same way. Make, Merge and the Live Paint Bucket take paths, compound paths and groups of them; with type, an image or another object among the selection they report that it has to be converted to paths first and change nothing, as type and raster images can't go into a Live Paint group directly ([Create Live Paint groups](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/create-live-paint-groups.html)); before, such an object went among the group's hidden sources and vanished from the canvas. Evidence: `tests_build::live_paint_refuses_type_and_images_and_changes_nothing`.
|
||||
With the Live Paint Bucket selected, Alt-click on vector art samples its fill, stroke and stroke weight into the paint defaults ([Paint with the Live Paint Bucket tool](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html)). On a placed image it samples the image pixel as a solid fill with no stroke. Alt+Shift-click samples only the color under the pointer, including an intermediate gradient color or image pixels, into the active fill or stroke ([Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)). Neither click paints or changes the selection or selected art, and the next Bucket click paints with the sampled paint. Evidence: `tests_build::live_paint_bucket_alt_sample_paints_next_face_without_changing_selection`.
|
||||
Double-clicking the Live Paint Bucket opens Live Paint Bucket Options ([Paint with the Live Paint Bucket tool](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html)): Paint Fills (on) and Paint Strokes (off) set whether a click paints faces, edges or both, Highlight turns the outline of the face or edge under the pointer on or off, and Color and Width set it (red and 4 px by default). Faces are outlined at the Width and edges at half of it, as the page says faces are highlighted with a thick line and edges with a thin line. With both on, a click paints the edge within 4 px of the pointer, else the face, and Shift switches to Paint Fills only; with one on, Shift switches to the other. The options last across tool switches and are saved with the preferences (`tool.setOption {tool: "livePaintBucket"}`). Evidence: `builder::tests::{bucket_options_choose_what_a_click_paints, bucket_options_set_the_highlight, bucket_highlights_an_edge_thinner_than_a_face}`, `dialogs::live_paint_bucket::tests::double_clicking_the_tool_opens_its_options_and_ok_sets_them`.
|
||||
Live Paint Bucket double-click and triple-click, as [the help page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html) describes them: a double-click on a face fills it and the faces reached across edges that draw no stroke, and on an edge it paints the edges joined to it with the same stroke; a triple-click fills every face of the group with the face's fill, or paints every edge with the edge's stroke (`livePaint.fill` and `livePaint.strokeEdge` `{scope: "connected" | "samePaint", match?}`; `pointer_gesture` and `ui.pointer` take `tripleclick`). Each click paints as it arrives, as its own undo step, and the paint compared is the one the face or edge had before the first of its clicks that painted it; a first click that made the Live Paint group counts when the face it filled is the clicked face. With Space held for the view tools, a click, double-click or triple-click paints nothing and no face or edge is outlined, and with Cmd/Ctrl held a double-click or triple-click paints nothing. Which faces and edges join and which paints match are VectorCraft's own rules. Evidence: `tests_build::{live_paint_bucket_double_click_floods_across_unstroked_edges, live_paint_bucket_double_click_floods_curved_and_narrow_faces, live_paint_bucket_double_click_floods_across_hidden_edges_and_past_gaps, live_paint_bucket_triple_click_fills_every_face_of_the_same_fill, live_paint_bucket_triple_click_after_making_the_group_matches_the_made_fill, live_paint_bucket_double_and_triple_click_paint_joined_and_same_stroke_edges, live_paint_scope_and_match_are_checked}`, `builder::tests::{bucket_double_and_triple_click_widen_what_a_click_paints, bucket_triple_click_after_making_the_group_on_another_face_matches_its_own_face, bucket_triple_click_with_a_click_on_another_face_between_matches_the_first_fill, bucket_highlights_nothing_with_space_held}`, `tests::build::{live_paint_scoped_fill_and_stroke_skip_parts_with_the_paint, live_paint_bucket_cmd_double_and_triple_click_paint_nothing}`, `tests::livepaint::{a_triple_click_fills_every_face_of_the_same_fill, clicks_with_space_held_paint_nothing}` (MCP).
|
||||
Live Paint Bucket Options has Cursor Swatch Preview, as the [help page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html) lists: with the Bucket selected, the active fill or stroke shows above the pointer between the color swatches before and after it in the Swatches panel, and the Left and Right arrow keys pick the swatch before or after it, as the page describes. The selected art keeps its paint. As VectorCraft's own rules, the option is on at first, the arrows step the stroke when the Stroke proxy is in front, they wrap around at the ends and still step with the preview off, a color that is no swatch shows alone until Right picks the first swatch or Left the last, and the arrows do nothing during a fill drag or with no color swatch. Evidence: `tests::build::{live_paint_bucket_arrow_keys_step_the_active_paint_through_the_swatches, live_paint_bucket_arrow_keys_handle_unmatched_paint_few_swatches_and_drags, live_paint_bucket_arrow_keys_pass_swatches_of_the_same_color_for_fill_and_stroke, swatch_arrow_keys_leave_modified_arrows_to_the_shortcuts}`.
|
||||
Live Paint Make preserves the front-most covering source's fill when compound paths share a curved boundary, and Expand keeps the face fills. Regression evidence: `planar::tests::coincident_curves_keep_their_source_faces` checks source order, winding, fill rules and nearby boundaries; `tests::build::live_paint_make_and_expand_keep_abutting_compound_colors` checks native compound paths, Make, Expand and Undo/Redo. This preserves VectorCraft's source-fill rule without changing arrangement precision.
|
||||
Object › Live Paint › Expand keeps the faces and edges that draw on the canvas, with all their fill and stroke rows, so the expanded paths look as the painted group did ([Create Live Paint groups](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/create-live-paint-groups.html)). As VectorCraft's own rule, a face or edge draws when it is shown, its opacity is above 0, and any of its fill or stroke rows is shown, has paint and an opacity above 0 (a stroke also needs a weight above 0), whichever row is on top: a painted lower row under an unpainted top row is kept, and a part whose only painted row is hidden is removed. Merge copies the fill and stroke rows, visibility, opacity and blending mode of each face that draws by this rule, and of each edge, to the rebuilt parts, with their gradients kept at their fit on the old outline and without the strokes' pen pressure, tilt, bearing and rotation. Evidence: `tests::build::{live_paint_expand_keeps_the_faces_and_edges_that_draw, live_paint_merge_carries_the_faces_that_draw, live_paint_merge_leaves_pen_pressure_behind, live_paint_merge_keeps_the_fit_of_carried_gradients, live_paint_merge_keeps_the_visibility_opacity_and_blending_of_carried_parts}`.
|
||||
|
||||
Reference in New Issue
Block a user