diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index c39c88cbbb..d92bcb7d71 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -112,6 +112,7 @@ mod live; mod livecorners; mod maskview; pub(super) mod menucmds; +mod mesh_picks; mod nativefile; mod newart; mod newdoc; diff --git a/crates/engine/src/tests/mesh_picks.rs b/crates/engine/src/tests/mesh_picks.rs new file mode 100644 index 0000000000..93556481da --- /dev/null +++ b/crates/engine/src/tests/mesh_picks.rs @@ -0,0 +1,127 @@ +//! Gradient mesh points picked with one of the tools that pick them (the Mesh tool, Direct +//! Selection, the Lasso, the Polygonal Lasso) stay picked when another of them is chosen, or lent +//! for a Cmd-click, so a fill color then recolors just them. + +use serde_json::json; +use vectorcraft_color::Color; +use vectorcraft_doc::NodeKind; +use vectorcraft_tools::{Mods, PointerEvent, PointerKind}; + +use crate::*; + +/// A session with a selected 1 x 1 gradient mesh (four white points) at (10, 10), 50 pt square. +fn mesh_session() -> (Session, NodeId) { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap(); + let m = NodeId(s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap()); + s.execute("object.mesh.create", &json!({"ids": [m.0], "rows": 1, "cols": 1})).unwrap(); + s.execute("select.set", &json!({"ids": [m.0]})).unwrap(); + (s, m) +} + +fn colors(s: &Session, m: NodeId) -> Vec { + match &s.doc().unwrap().doc.node(m).unwrap().kind { + NodeKind::Mesh(g) => g.points.iter().map(|p| p.color).collect(), + k => panic!("not a mesh: {k:?}"), + } +} + +/// Click mesh point `i` of `m` with the active tool. +fn press(s: &mut Session, m: NodeId, i: usize, mods: Mods) { + let q = match &s.doc().unwrap().doc.node(m).unwrap().kind { + NodeKind::Mesh(g) => g.points[i].p, + k => panic!("not a mesh: {k:?}"), + }; + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, q.x, q.y).with_mods(mods), ViewInfo::default()).unwrap(); + } +} + +/// A point picked with the Mesh tool stays picked through Direct Selection, the Lasso and the +/// Polygonal Lasso and back to the Mesh tool: each fill color recolors just that point. +#[test] +fn mesh_point_picks_carry_between_the_mesh_point_tools() { + let (mut s, m) = mesh_session(); + let v = ViewInfo::default(); + let white = colors(&s, m)[0]; + s.select_tool("mesh", v).unwrap(); + press(&mut s, m, 0, Mods::default()); + for (tool, hex, c) in [ + ("directSelection", "#0000ff", Color::rgb8(0, 0, 255)), + ("lasso", "#00ff00", Color::rgb8(0, 255, 0)), + ("polygonalLasso", "#ff0000", Color::rgb8(255, 0, 0)), + ("directSelection", "#ffff00", Color::rgb8(255, 255, 0)), + ("mesh", "#00ffff", Color::rgb8(0, 255, 255)), + ] { + s.select_tool(tool, v).unwrap(); + s.execute("paint.setFill", &json!({"color": hex})).unwrap(); + assert_eq!(colors(&s, m), [c, white, white, white], "{tool} recolors only the picked point"); + } +} + +/// A point picked with Direct Selection stays picked for the Mesh tool. +#[test] +fn direct_selection_picks_carry_to_the_mesh_tool() { + let (mut s, m) = mesh_session(); + let v = ViewInfo::default(); + let white = colors(&s, m)[0]; + s.select_tool("directSelection", v).unwrap(); + press(&mut s, m, 2, Mods::default()); + s.select_tool("mesh", v).unwrap(); + s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap(); + assert_eq!(colors(&s, m), [white, white, Color::rgb8(0, 0, 255), white]); +} + +/// The Selection tool picks no mesh points: after it, the Mesh tool starts with none picked, and a +/// fill color leaves every point as it was. +#[test] +fn a_tool_that_picks_no_mesh_points_drops_the_picks() { + let (mut s, m) = mesh_session(); + let v = ViewInfo::default(); + let before = colors(&s, m); + s.select_tool("mesh", v).unwrap(); + press(&mut s, m, 0, Mods::default()); + s.select_tool("selection", v).unwrap(); + s.execute("select.set", &json!({"ids": [m.0]})).unwrap(); + s.select_tool("mesh", v).unwrap(); + s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap(); + assert_eq!(colors(&s, m), before, "no point is picked"); +} + +/// A plain Lasso click away from the art deselects it and unpicks the points the Mesh tool picked, +/// so the Mesh tool chosen next has none picked. +#[test] +fn a_lasso_click_that_deselects_unpicks_the_mesh_points() { + let (mut s, m) = mesh_session(); + let v = ViewInfo::default(); + let before = colors(&s, m); + s.select_tool("mesh", v).unwrap(); + press(&mut s, m, 0, Mods::default()); + s.select_tool("lasso", v).unwrap(); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 500.0, 500.0), v).unwrap(); + } + assert!(s.doc().unwrap().selection.objects.is_empty(), "the click deselects the mesh"); + s.execute("select.set", &json!({"ids": [m.0]})).unwrap(); + s.select_tool("mesh", v).unwrap(); + s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap(); + assert_eq!(colors(&s, m), before, "no point is picked"); +} + +/// Direct Selection lent to the Mesh tool for a Cmd-click starts from the Mesh tool's picks, so a +/// Shift-click adds to them, and gives back what it left picked. +#[test] +fn the_lent_direct_selection_carries_the_mesh_tools_picks() { + let (mut s, m) = mesh_session(); + let v = ViewInfo::default(); + let white = colors(&s, m)[0]; + // Cmd lends the selection tool chosen last. + s.select_tool("directSelection", v).unwrap(); + s.select_tool("mesh", v).unwrap(); + press(&mut s, m, 0, Mods::default()); + press(&mut s, m, 3, Mods { cmd: true, shift: true, ..Default::default() }); + assert_eq!(s.tool_id(), "mesh"); + s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap(); + let b = Color::rgb8(0, 0, 255); + assert_eq!(colors(&s, m), [b, white, white, b], "both points stay picked"); +} diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 7b1caffb7c..7c1af811ed 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -186,12 +186,13 @@ impl Session { let text_selection = ((id == "eyedropper" && is_type(self.tool.id())) || (self.tool.id() == "eyedropper" && is_type(id))) .then(|| self.tool.options()) .filter(|o| o.get("editing").is_some_and(|v| !v.is_null()) && o.get("start") != o.get("end")); - // The gradient mesh points the Mesh tool, Direct Selection or the Lasso picked stay picked - // for the Eyedropper, which samples into them (#8090), and for the tool after it. - let mesh_points = (id == "eyedropper" || self.tool.id() == "eyedropper") + // The gradient mesh points the Mesh tool, Direct Selection, the Lasso or the Polygonal Lasso + // picked stay picked when another of these tools or the Eyedropper, which samples into + // them (#8090), is chosen: a fill color then recolors just them. None stay picked when + // none were. + let mesh_points = (Self::picks_mesh_points(id) && Self::picks_mesh_points(self.tool.id())) .then(|| self.tool.options().get("meshPoints").cloned()) - .flatten() - .filter(|v| v.as_array().is_some_and(|a| !a.is_empty())); + .flatten(); self.deactivate_tool(view)?; self.keep_tool_settings(); self.tool = self.make_tool(id); @@ -208,6 +209,13 @@ impl Session { Ok(()) } + /// Does tool `id` pick gradient mesh points (its `meshPoints` option): the Mesh tool, Direct + /// Selection, the Lasso, the Polygonal Lasso and the Eyedropper? Group Selection, which + /// selects whole objects, does not. + fn picks_mesh_points(id: &str) -> bool { + matches!(id, "mesh" | "directSelection" | "lasso" | "polygonalLasso" | "eyedropper") + } + /// Deactivate the tool and apply the actions it returns. In a batch, a Cancel is left out: the /// batch settled the tool's drag when it began, and the open interaction holds the batch's /// steps, which the batch keeps or rolls back as a whole. @@ -292,9 +300,9 @@ impl Session { // double-click or triple-click compares. self.tool.press_elsewhere(); let mut lent = self.make_tool(id); - // The gradient mesh points the Eyedropper holds are the lent tool's picks, which a Shift - // click adds to (#8090). - if self.tool.id() == "eyedropper" { + // The gradient mesh points the lending tool picked (the Mesh tool's, the Lasso's, the + // Eyedropper's) are the lent tool's picks, which a Shift click adds to (#8090). + if Self::picks_mesh_points(self.tool.id()) && Self::picks_mesh_points(id) { let points = self.tool.options().get("meshPoints").cloned().unwrap_or_else(|| Value::Array(vec![])); lent.set_option("meshPoints", &points); } @@ -312,10 +320,14 @@ impl Session { /// Cmd+click that takes the type being edited out of the selection ends its edit (#3779). pub(crate) fn give_back_tool(&mut self, view: ViewInfo) -> Result<()> { let Some(lender) = self.lender.take() else { return Ok(()) }; - // The points the lent tool left picked go back to the Eyedropper, none when it unpicked - // them all (#8090). Group Selection picks no mesh points, so the Eyedropper keeps its own. - let mesh_points = - (lender.id() == "eyedropper" && self.tool.id() != "groupSelection").then(|| self.tool.options().get("meshPoints").cloned()).flatten(); + // The points the lent tool left picked go back to the tool it was lent to when that tool + // picks mesh points, none when it unpicked them all (#8090). Group Selection and the + // Selection tool pick no mesh points, so the tool keeps its own. Unchanged picks are not + // set again, so the Mesh tool keeps the point whose handles it shows. + let mesh_points = (Self::picks_mesh_points(lender.id()) && Self::picks_mesh_points(self.tool.id())) + .then(|| self.tool.options().get("meshPoints").cloned()) + .flatten() + .filter(|p| lender.options().get("meshPoints") != Some(p)); let r = self.deactivate_tool(view); self.keep_tool_settings(); self.tool = lender; diff --git a/crates/tools/src/addons/polygonal_lasso.rs b/crates/tools/src/addons/polygonal_lasso.rs index b212943117..2810b0b309 100644 --- a/crates/tools/src/addons/polygonal_lasso.rs +++ b/crates/tools/src/addons/polygonal_lasso.rs @@ -167,7 +167,7 @@ impl Tool for PolygonalLassoTool { self.mesh.options() } - /// Pick the gradient mesh points the Eyedropper held (`meshPoints`). + /// Pick the gradient mesh points the tool chosen before held (`meshPoints`). fn set_option(&mut self, key: &str, value: &serde_json::Value) { if key == "meshPoints" { self.mesh.set_options(value); diff --git a/crates/tools/src/direct.rs b/crates/tools/src/direct.rs index cd4432c3c8..c889671a6e 100644 --- a/crates/tools/src/direct.rs +++ b/crates/tools/src/direct.rs @@ -823,7 +823,7 @@ impl Tool for DirectSelectionTool { fn options(&self) -> Value { self.mesh.options() } - /// Direct Selection picks the gradient mesh points the Eyedropper held (`meshPoints`); Group + /// Direct Selection picks the gradient mesh points the tool chosen before held (`meshPoints`); Group /// Selection, which selects whole objects, does not. /// The session sets `lentByCmd` on the tool Cmd/Ctrl lends for one gesture /// ([`DirectSelectionTool::mirrors`]). diff --git a/crates/tools/src/meshblend.rs b/crates/tools/src/meshblend.rs index c9ab307028..89e640d48e 100644 --- a/crates/tools/src/meshblend.rs +++ b/crates/tools/src/meshblend.rs @@ -360,7 +360,7 @@ impl Tool for MeshTool { fn options(&self) -> serde_json::Value { self.edit.options() } - /// Pick the gradient mesh points the Eyedropper held (`meshPoints`). + /// Pick the gradient mesh points the tool chosen before held (`meshPoints`). fn set_option(&mut self, key: &str, value: &serde_json::Value) { if key == "meshPoints" { self.edit.set_options(value); diff --git a/crates/tools/src/meshedit.rs b/crates/tools/src/meshedit.rs index 71ae329c4c..2dbeaf07a7 100644 --- a/crates/tools/src/meshedit.rs +++ b/crates/tools/src/meshedit.rs @@ -325,7 +325,7 @@ impl MeshEdit { } /// Pick the points a `meshPoints` option lists (see [`points_of`]), with none focused: the - /// points the Eyedropper held when the tool switched back. + /// points the tool chosen before (another mesh-point tool or the Eyedropper) held. pub fn set_options(&mut self, value: &Value) { if self.drag.is_some() { return; diff --git a/crates/tools/src/xform/wand.rs b/crates/tools/src/xform/wand.rs index d2074e386e..d6e3192266 100644 --- a/crates/tools/src/xform/wand.rs +++ b/crates/tools/src/xform/wand.rs @@ -145,7 +145,12 @@ impl Tool for LassoTool { let poly = std::mem::take(&mut self.points); let (add, sub) = (ev.mods.shift, ev.mods.alt); if poly.len() < 3 { - return if add || sub { vec![] } else { vec![Action::Exec("select.none".into(), json!({}))] }; + if add || sub { + return vec![]; + } + // The click deselects everything, so no mesh point stays picked. + self.mesh.unfocus(); + return vec![Action::Exec("select.none".into(), json!({}))]; } vec![lasso_select(cx, &mut self.mesh, &poly, add, sub)] } @@ -165,7 +170,7 @@ impl Tool for LassoTool { self.mesh.options() } - /// Pick the gradient mesh points the Eyedropper held (`meshPoints`). + /// Pick the gradient mesh points the tool chosen before held (`meshPoints`). fn set_option(&mut self, key: &str, value: &Value) { if key == "meshPoints" { self.mesh.set_options(value); diff --git a/docs/mcp.md b/docs/mcp.md index 282d889a42..85247a0c87 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14195,8 +14195,11 @@ away); its click on a gradient mesh's line picks the line's two ends, and a click inside a patch picks the four points around it. The picked points show filled. Dragging one of them moves them all as one undo step (`object.mesh.movePoints`), a click on one of several picked points picks it alone, and the arrow keys nudge them by the keyboard increment. The active tool lists them in its options -(`tool.setOption {}` returns them as `meshPoints: [{id, index}…]`). Switching to the Eyedropper keeps them picked, its -options list them too, and the Mesh tool, Direct Selection or a Lasso chosen next picks them again. While a selected, editable mesh has +(`tool.setOption {}` returns them as `meshPoints: [{id, index}…]`). Switching between the Mesh tool, Direct Selection, +the Lasso, the Polygonal Lasso and the Eyedropper keeps them picked, and so does a Cmd/Ctrl-click with the selection +tool one of them lends; any other tool, Group Selection included, drops them. A plain Lasso click away from the art +(`select.none`) unpicks them. The Eyedropper's options list them too. +While a selected, editable mesh has points picked, an Eyedropper click or Shift-click on an image or other art samples the color under the pointer into those points alone as `paint.sampleColor {color, stroke: false, ids}` with the meshes that have points picked: one undo step, none when the color is unchanged. Other selected objects keep their paint. A click on one of those meshes, and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 685db22712..8c037c7ef2 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1907,6 +1907,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Several mesh points at once (#4207, #4208, #4170):** the Mesh tool and Direct Selection pick several points of a gradient mesh or mesh envelope: Shift-click adds a point or takes a picked one away, Direct Selection's marquee picks the points inside it (Shift toggles them) and selects their meshes, and its click on a mesh line picks the line's two ends and one inside a patch the four points around it. The picked points show filled; dragging one moves them all as one undo step and the arrow keys nudge them (`object.mesh.movePoints {id, points, dx, dy}` or `{items, dx, dy}`), and a click on one of several picked points picks it alone. A solid fill colour (`paint.setFill`: Color panel, Swatches, Eyedropper) recolours every picked point, and the Transparency panel's Opacity fades them instead of the object, the panel showing their opacity (blank when it differs); `object.mesh.setPointColor` takes `points` or `items`. Public reference: [Edit mesh objects](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-meshes/edit-mesh-objects.html) (Shift selects multiple mesh points; a fill colour colours the selected point), [Macworld, gradient mesh](https://www.macworld.com/article/202693/gmesh2.html) (Direct Selection: a mesh line selects the points at both ends, a patch the points around it, Shift-click adds or removes points), [Peachpit](https://www.peachpit.com/articles/article.aspx?p=1638270) (each mesh point can have its own colour or transparency). Tests: `shift_clicks_pick_mesh_points_that_drag_and_nudge_together` and `direct_selection_picks_mesh_points_by_marquee_line_and_patch` in `crates/tools/src/meshedit.rs`, `picked_mesh_points_take_the_fill_opacity_and_drag_together` in `crates/engine/src/tests/editcolors.rs`, `mesh_points_move_and_colour_together` in `crates/engine/src/tests/live.rs`. Scores and hours unchanged. - **Picked mesh points in the panels** (VectorCraft's own rule): with points of a gradient mesh picked by the Mesh tool, Direct Selection or the Lasso, the Fill proxy, the Color panel and the Color Wheel show the first picked point's color, so their sliders keep the color a drag sets, and "?" shows when the picked points' colors differ. The Control bar shows the first picked point's opacity. Tests: `the_fill_proxy_shows_the_picked_mesh_points_color`, `the_fill_proxy_follows_where_the_fill_goes_with_an_appearance_row_active` and `the_fill_proxy_counts_picked_mesh_points_beside_other_objects` in `crates/engine/src/tests/xform.rs`, `picked_mesh_points_are_the_color_the_panel_shows_and_edits` in `crates/ui-egui/src/panels/color/tests.rs`, `picking_mesh_points_shows_their_opacity` in `crates/ui-egui/src/panels/transparency.rs`. Scores and hours unchanged. - **The Eyedropper samples into picked mesh points (#8090):** mesh points picked with the Mesh tool, Direct Selection or the Lasso stay picked after switching to the Eyedropper and go back to one of those tools chosen next, and a click or Shift-click on an image or other art then samples the color under the pointer into every picked point as one undo step, leaving the mesh's other points and its appearance as they were. VectorCraft's own rules: a plain click on vector art samples its color into the points instead of copying its appearance, other selected objects keep their paint, and a click on a mesh with points picked works as before. Public references: [Edit mesh objects](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-meshes/edit-mesh-objects.html) (a mesh point is recolored by selecting it and choosing a fill color), [Appearance attributes](https://helpx.adobe.com/illustrator/using/appearance-attributes.html) (Shift-click samples the color from a part of a mesh object or a placed image and applies it to the selected fill). Tests: `picked_mesh_points_take_the_eyedropper_sample` in `crates/engine/src/tests/eyedropper.rs`, `picked_mesh_points_take_the_color_a_click_samples` in `crates/tools/src/xform/eyedropper.rs`, `mesh_point_tools_take_back_the_eyedroppers_picks` in `crates/tools/src/meshedit.rs`. Scores and hours unchanged. +- **Picked mesh points survive a tool switch:** mesh points picked with the Mesh tool, Direct Selection, the Lasso or the Polygonal Lasso stay picked when another of these tools or the Eyedropper is chosen, and when one of them lends Direct Selection for a Cmd/Ctrl-click, so a fill color chosen afterward recolors just those points. A plain Lasso click away from the art deselects it and unpicks them. Any other tool, Group Selection included, drops them. Public references: [Edit mesh objects](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-meshes/edit-mesh-objects.html) (a mesh point picked with the Mesh tool is recolored by choosing a fill color in the Swatches or Color panel), [Archived help guide, page 202](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=202) (the Mesh tool and Direct Selection both move mesh points). Carrying the picks between the tools is VectorCraft's own rule. Tests: `crates/engine/src/tests/mesh_picks.rs`. Scores and hours unchanged. - **Image Trace Flat Logo mode:** a fourth mode beside Black and White, Grayscale and Color, for flat-colour logos. Each pixel is read as a blend of the logo's colours (found automatically or named), the blend is interpolated smoothly and every outline is placed where two colours are equally present, so edges are accurate to a fraction of a pixel. Outlines are then cleaned: corners the blur rounded are put back, near-straight runs and near-circular arcs become exact lines and arcs, the rest is fitted with as few Béziers as the tolerance allows, touching colours overlap by a hair so no gap opens, and an outline that strays from the raw contour is fitted plainly instead. Gradients and photos are refused with advice to use Color. Line art whose only solid area is white paper (strokes a pixel or two wide) takes its colours from the strokes' cores, with the lighter shades along a stroke's anti-aliased edge folded into its ink; a page whose ink (a channel at least 48 below white) covers under 1% of it traces to nothing, as blank paper does. *Measured* (a local experiment, not run in CI): a flat-colour logo's vector original was rendered down to a soft 199 × 100 px transparent PNG, traced, and the result compared with the original at 1600 px wide. The built-in colour presets (6 Colors, 16 Colors, High Fidelity Photo, Low Fidelity Photo) had a mean edge error of 2.5 to 3.4 px and region overlap of 0.88 to 0.91; Flat Logo had 0.78 px and 0.966 (0.48 px and 0.975 from a crisp source), in about 0.1 s. Limits: flat-colour art only; needle-thin sharp tips are shortened by about 1.7 source pixels because the blur erases them; it works at no more than 1024 px on the long side (larger images are averaged down first); only one logo family has been scored against a vector original. - **Image Trace, Flat Logo named colors only:** with `logoColors` named, `"logoWhite": false` traces those colors only, so white areas take the nearest of them and no white is added; a named white is kept, and enclosed transparent areas stay holes; code-drawn tests in `crates/trace` and `crates/engine`. - **Image Trace, Flat Logo flat-art check with named colors:** with `logoColors` named, whether the image is flat art is judged by its own colors, as many as are named, with white, or as the Colors setting gives, whichever is more. Named colors 20 levels off a flat badge's colors still trace it, a hatch on a light ground gives the same result with close and far named colors, a gradient's refusal score does not depend on how far the named colors are from it, and areas of colors that were not named are traced in the named colors instead of being refused; code-drawn tests in `crates/trace`.