mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Merge pull request #8207 from dotCooCoo/fix/issue-8090
Fix #8090: the Eyedropper samples into picked gradient mesh points
This commit is contained in:
@@ -615,6 +615,141 @@ fn clicking_an_image_samples_its_pixel() {
|
||||
assert_eq!(node(&s, dst).appearance.fill_paint().color(), Some(Color::rgb8(128, 128, 64)), "5 x 5 average of both pixels");
|
||||
}
|
||||
|
||||
/// Gradient mesh points picked with Direct Selection or the Mesh tool take the color the
|
||||
/// Eyedropper then samples from an image or from other art, each sample one undo step, and only
|
||||
/// they change: the mesh's other points and its appearance stay as they were (#8090).
|
||||
#[test]
|
||||
fn picked_mesh_points_take_the_eyedropper_sample() {
|
||||
let mut s = session();
|
||||
// Two pixels, orange and teal, 100 pt each, at (300, 0).
|
||||
let rgba = [[255u8, 128, 0, 255], [0, 128, 128, 255]].concat();
|
||||
let img = craft_image_codecs::Image::from_raw(2, 1, craft_image_codecs::ChannelLayout::Rgba, craft_image_codecs::SampleType::U8, rgba).unwrap();
|
||||
let png = craft_image_codecs::encode(&img, craft_image_codecs::Format::Png, &craft_image_codecs::EncodeOptions::default()).unwrap();
|
||||
s.edit("Place", |d, _| {
|
||||
d.images.insert("px".into(), ImageBlob::png(png.to_vec()));
|
||||
let l = d.layers[0].id;
|
||||
let id = d.alloc_id();
|
||||
let xf = vectorcraft_geom::Affine::translate((300.0, 0.0)) * vectorcraft_geom::Affine::scale(100.0);
|
||||
let im = ImageObject { key: "px".into(), width: 2, height: 1, xf, link: None, placement: Default::default(), pixels: None };
|
||||
d.insert(Some(l), 0, Node::new(id, NodeKind::Image(Box::new(im)))).map_err(|e| crate::EngineError::Other(e.to_string()))
|
||||
})
|
||||
.unwrap();
|
||||
let m = rect(&mut s, 10.0);
|
||||
s.execute("object.mesh.create", &json!({"ids": [m.0], "rows": 1, "cols": 1})).unwrap();
|
||||
let red = rect(&mut s, 100.0);
|
||||
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
|
||||
let colors = |s: &Session| match node(s, m).kind {
|
||||
NodeKind::Mesh(g) => g.points.iter().map(|p| p.color).collect::<Vec<_>>(),
|
||||
k => panic!("not a mesh: {k:?}"),
|
||||
};
|
||||
let white = colors(&s)[0];
|
||||
assert!(colors(&s).iter().all(|c| *c == white && *c != Color::rgb8(255, 0, 0)));
|
||||
let appearance = node(&s, m).appearance;
|
||||
let v = ViewInfo::default();
|
||||
let pick = |s: &mut Session, tool: &str, i: usize, shift: bool| {
|
||||
s.select_tool(tool, v).unwrap();
|
||||
let q = match node(s, m).kind {
|
||||
NodeKind::Mesh(g) => g.points[i].p,
|
||||
k => panic!("not a mesh: {k:?}"),
|
||||
};
|
||||
let mods = Mods { shift, ..Default::default() };
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, q.x, q.y).with_mods(mods), v).unwrap();
|
||||
}
|
||||
};
|
||||
let (teal, orange) = (Color::rgb8(0, 128, 128), Color::rgb8(255, 128, 0));
|
||||
s.execute("select.set", &json!({"ids": [m.0]})).unwrap();
|
||||
pick(&mut s, "directSelection", 0, false);
|
||||
let undo = undo_len(&s);
|
||||
click(&mut s, 450.0, 50.0, Mods::default());
|
||||
assert_eq!(colors(&s), [teal, white, white, white], "the picked point takes the image's color");
|
||||
assert_eq!(node(&s, m).appearance, appearance, "the mesh's appearance stays");
|
||||
assert_eq!(undo_len(&s), undo + 1, "one undo step");
|
||||
// The Eyedropper keeps the picks: a Shift-click samples into the point again.
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 350.0, 50.0).with_mods(Mods { shift: true, ..Default::default() }), v).unwrap();
|
||||
assert_eq!(colors(&s), [orange, white, white, white]);
|
||||
assert_eq!(undo_len(&s), undo + 2);
|
||||
// A sample of the color the point already has changes nothing and adds no step.
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 350.0, 50.0), v).unwrap();
|
||||
assert_eq!(undo_len(&s), undo + 2, "no step when nothing changes");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(colors(&s), [teal, white, white, white]);
|
||||
// Two points picked with the Mesh tool both take a plain click's sample of other art, and the
|
||||
// art keeps its fill.
|
||||
pick(&mut s, "mesh", 1, false);
|
||||
pick(&mut s, "mesh", 3, true);
|
||||
let undo = undo_len(&s);
|
||||
click(&mut s, 125.0, 35.0, Mods::default());
|
||||
let r = Color::rgb8(255, 0, 0);
|
||||
assert_eq!(colors(&s), [teal, r, white, r]);
|
||||
assert_eq!(undo_len(&s), undo + 1, "one undo step for every picked point");
|
||||
assert_eq!(node(&s, m).appearance, appearance);
|
||||
assert_eq!(node(&s, red).appearance.fill_paint().color(), Some(r));
|
||||
// Back in the Mesh tool the two points are still picked: a fill color recolors just them.
|
||||
s.select_tool("mesh", v).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap();
|
||||
let b = Color::rgb8(0, 0, 255);
|
||||
assert_eq!(colors(&s), [teal, b, white, b], "the picks go back to the Mesh tool");
|
||||
// Without picked points a click on an image samples into the whole selected mesh as before.
|
||||
s.select_tool("selection", v).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [m.0]})).unwrap();
|
||||
click(&mut s, 450.0, 50.0, Mods::default());
|
||||
assert_eq!(colors(&s), [teal, b, white, b], "the points keep their colors");
|
||||
assert_ne!(node(&s, m).appearance, appearance);
|
||||
}
|
||||
|
||||
/// A Cmd-click with the Direct Selection tool the Eyedropper lends picks gradient mesh points for
|
||||
/// the Eyedropper: the lent tool starts from the Eyedropper's picks, so a Shift-click adds to
|
||||
/// them, and the Eyedropper samples into what the lent tool left picked (#8090).
|
||||
#[test]
|
||||
fn mesh_points_picked_through_the_lent_tool_take_the_eyedropper_sample() {
|
||||
let mut s = session();
|
||||
// Two pixels, orange and teal, 100 pt each, at (300, 0).
|
||||
let rgba = [[255u8, 128, 0, 255], [0, 128, 128, 255]].concat();
|
||||
let img = craft_image_codecs::Image::from_raw(2, 1, craft_image_codecs::ChannelLayout::Rgba, craft_image_codecs::SampleType::U8, rgba).unwrap();
|
||||
let png = craft_image_codecs::encode(&img, craft_image_codecs::Format::Png, &craft_image_codecs::EncodeOptions::default()).unwrap();
|
||||
s.edit("Place", |d, _| {
|
||||
d.images.insert("px".into(), ImageBlob::png(png.to_vec()));
|
||||
let l = d.layers[0].id;
|
||||
let id = d.alloc_id();
|
||||
let xf = vectorcraft_geom::Affine::translate((300.0, 0.0)) * vectorcraft_geom::Affine::scale(100.0);
|
||||
let im = ImageObject { key: "px".into(), width: 2, height: 1, xf, link: None, placement: Default::default(), pixels: None };
|
||||
d.insert(Some(l), 0, Node::new(id, NodeKind::Image(Box::new(im)))).map_err(|e| crate::EngineError::Other(e.to_string()))
|
||||
})
|
||||
.unwrap();
|
||||
let m = rect(&mut s, 10.0);
|
||||
s.execute("object.mesh.create", &json!({"ids": [m.0], "rows": 1, "cols": 1})).unwrap();
|
||||
let colors = |s: &Session| match node(s, m).kind {
|
||||
NodeKind::Mesh(g) => g.points.iter().map(|p| p.color).collect::<Vec<_>>(),
|
||||
k => panic!("not a mesh: {k:?}"),
|
||||
};
|
||||
let white = colors(&s)[0];
|
||||
let v = ViewInfo::default();
|
||||
let press = |s: &mut Session, i: usize, mods: Mods| {
|
||||
let q = match node(s, m).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), v).unwrap();
|
||||
}
|
||||
};
|
||||
let (teal, orange) = (Color::rgb8(0, 128, 128), Color::rgb8(255, 128, 0));
|
||||
s.execute("select.set", &json!({"ids": [m.0]})).unwrap();
|
||||
s.select_tool("directSelection", v).unwrap();
|
||||
press(&mut s, 0, Mods::default());
|
||||
s.select_tool("eyedropper", v).unwrap();
|
||||
// Cmd-click point 3: Direct Selection, lent, picks it in place of point 0.
|
||||
press(&mut s, 3, Mods { cmd: true, ..Default::default() });
|
||||
assert_eq!(s.tool_id(), "eyedropper");
|
||||
click(&mut s, 450.0, 50.0, Mods::default());
|
||||
assert_eq!(colors(&s), [white, white, white, teal], "the point the lent tool picked takes the sample");
|
||||
// Cmd+Shift-click point 0 adds it to the Eyedropper's pick.
|
||||
press(&mut s, 0, Mods { cmd: true, shift: true, ..Default::default() });
|
||||
click(&mut s, 350.0, 50.0, Mods::default());
|
||||
assert_eq!(colors(&s), [orange, white, white, orange], "both picked points take the sample");
|
||||
}
|
||||
|
||||
/// A CMYK document with one image of `px` (one row, 100 pt a pixel) at (300, 0).
|
||||
fn cmyk_doc_with_image(px: &[[u8; 4]]) -> Session {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -173,6 +173,12 @@ 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")
|
||||
.then(|| self.tool.options().get("meshPoints").cloned())
|
||||
.flatten()
|
||||
.filter(|v| v.as_array().is_some_and(|a| !a.is_empty()));
|
||||
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
|
||||
self.apply_actions(acts)?;
|
||||
self.keep_tool_settings();
|
||||
@@ -180,6 +186,9 @@ impl Session {
|
||||
if let Some(selection) = text_selection {
|
||||
self.tool.set_option("textSelection", &selection);
|
||||
}
|
||||
if let Some(points) = mesh_points {
|
||||
self.tool.set_option("meshPoints", &points);
|
||||
}
|
||||
if vectorcraft_tools::catalog::is_selection_tool(id) {
|
||||
self.last_selection_tool = Some(self.tool.id());
|
||||
self.select_whole_instance(id);
|
||||
@@ -258,7 +267,13 @@ impl Session {
|
||||
// The lending tool does not see the press: it counts as a press elsewhere for the clicks a
|
||||
// double-click or triple-click compares.
|
||||
self.tool.press_elsewhere();
|
||||
let lent = self.make_tool(id);
|
||||
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" {
|
||||
let points = self.tool.options().get("meshPoints").cloned().unwrap_or_else(|| Value::Array(vec![]));
|
||||
lent.set_option("meshPoints", &points);
|
||||
}
|
||||
self.selection_at_lend = self.active().map(|d| (d.uid, d.selection.clone()));
|
||||
self.lender = Some(std::mem::replace(&mut self.tool, lent));
|
||||
Ok((PointerEvent { mods: Mods { cmd: false, ..ev.mods }, ..*ev }, settled))
|
||||
@@ -269,10 +284,17 @@ 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();
|
||||
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
|
||||
let r = self.apply_actions(acts);
|
||||
self.keep_tool_settings();
|
||||
self.tool = lender;
|
||||
if let Some(points) = mesh_points {
|
||||
self.tool.set_option("meshPoints", &points);
|
||||
}
|
||||
// A gesture that left the selection as it found it (a Shift marquee over nothing) picked
|
||||
// nothing: the selection keeps what it was, the Pen's last anchor or an earlier pick.
|
||||
let left = self.active().map(|d| (d.uid, d.selection.clone()));
|
||||
|
||||
@@ -167,6 +167,13 @@ impl Tool for PolygonalLassoTool {
|
||||
self.mesh.options()
|
||||
}
|
||||
|
||||
/// Pick the gradient mesh points the Eyedropper held (`meshPoints`).
|
||||
fn set_option(&mut self, key: &str, value: &serde_json::Value) {
|
||||
if key == "meshPoints" {
|
||||
self.mesh.set_options(value);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let mut out = self.mesh.overlays(cx, &|id| cx.selection.contains(id));
|
||||
let mut line = self.vertices.clone();
|
||||
|
||||
@@ -762,6 +762,13 @@ impl Tool for DirectSelectionTool {
|
||||
fn options(&self) -> Value {
|
||||
self.mesh.options()
|
||||
}
|
||||
/// Direct Selection picks the gradient mesh points the Eyedropper held (`meshPoints`); Group
|
||||
/// Selection, which selects whole objects, does not.
|
||||
fn set_option(&mut self, key: &str, value: &Value) {
|
||||
if key == "meshPoints" && !self.group {
|
||||
self.mesh.set_options(value);
|
||||
}
|
||||
}
|
||||
/// Escape during a drag (anchors, handles, segments, objects, type areas, blend spines, mesh
|
||||
/// points, corner widgets, the brackets of type on a path, a marquee) cancels it: what it moved
|
||||
/// goes back and the tool waits for the next press (#1743).
|
||||
|
||||
@@ -360,6 +360,12 @@ impl Tool for MeshTool {
|
||||
fn options(&self) -> serde_json::Value {
|
||||
self.edit.options()
|
||||
}
|
||||
/// Pick the gradient mesh points the Eyedropper held (`meshPoints`).
|
||||
fn set_option(&mut self, key: &str, value: &serde_json::Value) {
|
||||
if key == "meshPoints" {
|
||||
self.edit.set_options(value);
|
||||
}
|
||||
}
|
||||
fn busy(&self) -> bool {
|
||||
self.edit.dragging()
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@ pub fn grid_of(n: &Node) -> Option<Cow<'_, GradientMesh>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `{id, index}` entries of a `meshPoints` option ([`MeshEdit::options`]); malformed entries
|
||||
/// are left out.
|
||||
pub fn points_of(value: &Value) -> Vec<(NodeId, usize)> {
|
||||
let Some(v) = value.as_array() else { return vec![] };
|
||||
v.iter().filter_map(|p| Some((NodeId(p.get("id")?.as_u64()?), usize::try_from(p.get("index")?.as_u64()?).ok()?))).collect()
|
||||
}
|
||||
|
||||
/// Can `n` have an editable grid ([`grid_of`])? Its kind alone answers, without building the grid.
|
||||
pub fn may_have_grid(n: &Node) -> bool {
|
||||
match &n.kind {
|
||||
@@ -317,6 +324,16 @@ impl MeshEdit {
|
||||
json!({"meshPoints": self.picked.iter().map(|(id, index)| json!({"id": id.0, "index": index})).collect::<Vec<_>>()})
|
||||
}
|
||||
|
||||
/// Pick the points a `meshPoints` option lists (see [`points_of`]), with none focused: the
|
||||
/// points the Eyedropper held when the tool switched back.
|
||||
pub fn set_options(&mut self, value: &Value) {
|
||||
if self.drag.is_some() {
|
||||
return;
|
||||
}
|
||||
self.picked = points_of(value).into_iter().collect();
|
||||
(self.focus, self.click) = (None, None);
|
||||
}
|
||||
|
||||
/// The picked points of the meshes `shown` accepts, filled, and the focused point's handles
|
||||
/// (lines and ends).
|
||||
pub fn overlays(&self, cx: &ToolContext, shown: &dyn Fn(NodeId) -> bool) -> Vec<Overlay> {
|
||||
@@ -647,4 +664,21 @@ mod tests {
|
||||
assert_eq!(out, vec![Action::Exec("select.set".into(), json!({"ids": [m.0]})), Action::Begin("Move Mesh Points".into())]);
|
||||
assert_eq!(picked(&t), set(&[(100.0, 100.0), (150.0, 100.0), (100.0, 150.0), (150.0, 150.0)]));
|
||||
}
|
||||
|
||||
/// The tools that pick mesh points pick again the points a `meshPoints` option lists (those the
|
||||
/// Eyedropper held), leaving malformed entries out; Group Selection picks none.
|
||||
#[test]
|
||||
fn mesh_point_tools_take_back_the_eyedroppers_picks() {
|
||||
let points = json!([{"id": 7, "index": 2}, {"id": 7}, {"id": 7, "index": 0}]);
|
||||
for id in ["mesh", "directSelection", "lasso", crate::addons::polygonal_lasso::ID] {
|
||||
let mut t = crate::create(id);
|
||||
t.set_option("meshPoints", &points);
|
||||
assert_eq!(picked(&*t), [0, 2], "{id}");
|
||||
t.set_option("meshPoints", &json!([]));
|
||||
assert!(picked(&*t).is_empty(), "{id}");
|
||||
}
|
||||
let mut t = crate::create("groupSelection");
|
||||
t.set_option("meshPoints", &points);
|
||||
assert!(picked(&*t).is_empty(), "Group Selection");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
//! samples the colour under the cursor into the selected gradient stop (`paint.sampleColor
|
||||
//! {stop}`) and switches back to that tool.
|
||||
//!
|
||||
//! Gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso before switching
|
||||
//! to the Eyedropper stay picked (its `meshPoints` option), and go back to one of those tools
|
||||
//! switched to next. While a selected, editable mesh has picked points, a click or Shift-click on an image or
|
||||
//! other art samples the color under the cursor into those points alone (`paint.sampleColor
|
||||
//! {stroke: false, ids}` with those meshes, which recolors the points through `paint.setFill`).
|
||||
//!
|
||||
//! Brush Options' Key Color eyedropper sets `brushKeyColor` and `stop`: the next click samples into
|
||||
//! the open dialog (`brushKeyColor` UI request) and switches back.
|
||||
//!
|
||||
@@ -45,6 +51,28 @@ pub struct EyedropperTool {
|
||||
text_selection: crate::text::TypeTool,
|
||||
/// Brush Options › Key Color (Hue Shift): sample into the dialog, then [`Self::stop`].
|
||||
brush_key_color: bool,
|
||||
/// The gradient mesh points the tool switched from had picked, each a mesh and a point index.
|
||||
mesh_points: Vec<(NodeId, usize)>,
|
||||
}
|
||||
|
||||
/// The point of each of `points` that a selected, editable gradient mesh in `cx` has.
|
||||
fn live_points<'a>(cx: &'a ToolContext, points: &'a [(NodeId, usize)]) -> impl Iterator<Item = (NodeId, Point)> + 'a {
|
||||
let editable = cx.doc.editable();
|
||||
points.iter().filter(move |(id, _)| cx.selection.contains(*id) && editable(*id)).filter_map(|(id, index)| {
|
||||
let Some(NodeKind::Mesh(m)) = cx.doc.node(*id).map(|n| &n.kind) else { return None };
|
||||
Some((*id, m.points.get(*index)?.p))
|
||||
})
|
||||
}
|
||||
|
||||
/// The selected, editable gradient meshes in `cx` with one of `points` picked, in range, each once.
|
||||
fn picked_meshes(cx: &ToolContext, points: &[(NodeId, usize)]) -> Vec<NodeId> {
|
||||
let mut ids: Vec<NodeId> = vec![];
|
||||
for (id, _) in live_points(cx, points) {
|
||||
if !ids.contains(&id) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
ids
|
||||
}
|
||||
|
||||
/// The colour of `paint` at `p` (gradients are sampled along their vector, radial ones honouring
|
||||
@@ -518,11 +546,20 @@ impl Tool for EyedropperTool {
|
||||
return vec![Action::Exec("appearance.copyFrom".into(), json!({ "source": src.0, how: true }))];
|
||||
}
|
||||
let image = matches!(n.kind, NodeKind::Image(_));
|
||||
if !(ev.mods.shift || stop.is_some() || image) {
|
||||
// Picked mesh points take only a color sampled from other art or an image: the sample goes
|
||||
// to them as a fill, and to nothing else that is selected. A click on a mesh with picked
|
||||
// points is handled as before.
|
||||
let meshes = if stop.is_none() { picked_meshes(cx, &self.mesh_points) } else { vec![] };
|
||||
let meshes = if meshes.contains(&src) { vec![] } else { meshes };
|
||||
if !(ev.mods.shift || stop.is_some() || image || !meshes.is_empty()) {
|
||||
return vec![Action::Exec("appearance.copyFrom".into(), json!({ "source": src.0 }))];
|
||||
}
|
||||
let Some(c) = sample_color_at(cx, ev.pos) else { return vec![] };
|
||||
let color = color_json(&c);
|
||||
if !meshes.is_empty() {
|
||||
let ids: Vec<u64> = meshes.iter().map(|id| id.0).collect();
|
||||
return vec![Action::Exec("paint.sampleColor".into(), json!({ "color": color, "stroke": false, "ids": ids }))];
|
||||
}
|
||||
let Some((back, i)) = stop else { return vec![Action::Exec("paint.sampleColor".into(), json!({ "color": color }))] };
|
||||
let out = vec![Action::Exec("paint.sampleColor".into(), json!({ "color": color, "stop": i })), Action::SwitchTool(back.clone())];
|
||||
self.stop = None;
|
||||
@@ -536,15 +573,21 @@ impl Tool for EyedropperTool {
|
||||
if let Some(o) = options.as_object_mut() {
|
||||
o.insert("stop".into(), json!(self.stop));
|
||||
o.insert("brushKeyColor".into(), json!(self.brush_key_color));
|
||||
if !self.mesh_points.is_empty() {
|
||||
let points: Vec<Value> = self.mesh_points.iter().map(|(id, index)| json!({"id": id.0, "index": index})).collect();
|
||||
o.insert("meshPoints".into(), Value::Array(points));
|
||||
}
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
/// Accept a stop target or the selection transferred from the Type tool.
|
||||
/// Accept a stop target, or the selection or the mesh points picked, transferred from the
|
||||
/// Type tool or a tool that picks mesh points.
|
||||
fn set_option(&mut self, key: &str, value: &Value) {
|
||||
match key {
|
||||
"stop" => self.stop = value.as_str().map(str::to_string),
|
||||
"brushKeyColor" => self.brush_key_color = value.as_bool().unwrap_or(false),
|
||||
"meshPoints" => self.mesh_points = crate::meshedit::points_of(value),
|
||||
"textSelection" => self.text_selection.set_option(key, value),
|
||||
_ => {}
|
||||
}
|
||||
@@ -555,9 +598,13 @@ impl Tool for EyedropperTool {
|
||||
self.text_selection.after_command(cx)
|
||||
}
|
||||
|
||||
/// Keep the sampled character range highlighted without activating text input.
|
||||
/// Keep the sampled character range highlighted without activating text input, and the picked
|
||||
/// points of selected gradient meshes filled, as the tools that picked them show them.
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
if self.text_selection.options().get("editing").is_some_and(|v| !v.is_null()) { self.text_selection.overlays(cx) } else { vec![] }
|
||||
let mut out =
|
||||
if self.text_selection.options().get("editing").is_some_and(|v| !v.is_null()) { self.text_selection.overlays(cx) } else { vec![] };
|
||||
out.extend(live_points(cx, &self.mesh_points).map(|(_, p)| Overlay::Anchor { p, color: crate::draw2::FEEDBACK, filled: true, size: 5.0 }));
|
||||
out
|
||||
}
|
||||
|
||||
fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {
|
||||
@@ -637,6 +684,82 @@ mod tests {
|
||||
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 400.0, 400.0)).is_empty());
|
||||
}
|
||||
|
||||
/// With points of a selected gradient mesh picked, a click on other art samples the color under
|
||||
/// the cursor into those points as a fill, as a Shift-click does. Unselected, or with the picks
|
||||
/// out of range, on a locked mesh, or on the mesh itself, the click copies the appearance as
|
||||
/// before; Alt still applies in reverse.
|
||||
#[test]
|
||||
fn picked_mesh_points_take_the_color_a_click_samples() {
|
||||
use vectorcraft_doc::{Document, GradientMesh};
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
let l = d.layers[0].id;
|
||||
let mesh = d.alloc_id();
|
||||
let grid = GradientMesh::from_surface(1, 1, &|u, v| Point::new(100.0 + 100.0 * u, 100.0 + 100.0 * v), &|_, _| Color::WHITE);
|
||||
d.insert(Some(l), 0, Node::new(mesh, NodeKind::Mesh(grid))).unwrap();
|
||||
let red = d.alloc_id();
|
||||
let mut art = (*filled_rect(Rect::new(300.0, 100.0, 350.0, 150.0), Paint::solid(Color::rgb(1.0, 0.0, 0.0)))).clone();
|
||||
art.id = red;
|
||||
d.insert(Some(l), usize::MAX, art).unwrap();
|
||||
let p = paint();
|
||||
let mut s = Selection::default();
|
||||
s.set([mesh]);
|
||||
let mut t = EyedropperTool::default();
|
||||
t.set_option("meshPoints", &json!([{"id": mesh.0, "index": 1}, {"id": "x"}, {"id": mesh.0, "index": 3}]));
|
||||
assert_eq!(t.options()["meshPoints"], json!([{"id": mesh.0, "index": 1}, {"id": mesh.0, "index": 3}]), "malformed entries are left out");
|
||||
// The picked points show filled while the mesh is selected.
|
||||
let anchors: Vec<Point> = t
|
||||
.overlays(&cx(&d, &s, &p))
|
||||
.into_iter()
|
||||
.filter_map(|o| match o {
|
||||
Overlay::Anchor { p, filled: true, .. } => Some(p),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(anchors, [Point::new(200.0, 100.0), Point::new(200.0, 200.0)]);
|
||||
assert!(t.overlays(&cx(&d, &Selection::default(), &p)).is_empty());
|
||||
let click = |t: &mut EyedropperTool, s: &Selection, m: Mods| {
|
||||
t.pointer(&cx(&d, s, &p), &PointerEvent::new(PointerKind::Down, 325.0, 125.0).with_mods(m))
|
||||
};
|
||||
let sample = vec![Action::Exec(
|
||||
"paint.sampleColor".into(),
|
||||
json!({"color": color_json(&Color::rgb(1.0, 0.0, 0.0)), "stroke": false, "ids": [mesh.0]}),
|
||||
)];
|
||||
assert_eq!(click(&mut t, &s, Mods::default()), sample);
|
||||
assert_eq!(click(&mut t, &s, Mods { shift: true, ..Default::default() }), sample);
|
||||
// Other selected art does not take the sample.
|
||||
let mut both = Selection::default();
|
||||
both.set([mesh, red]);
|
||||
assert_eq!(click(&mut t, &both, Mods::default()), sample, "only the picked mesh");
|
||||
let alt = click(&mut t, &s, Mods { alt: true, ..Default::default() });
|
||||
assert_eq!(alt, vec![Action::Exec("appearance.copyFrom".into(), json!({"source": red.0, "reverse": true}))]);
|
||||
// The mesh deselected, the picks stand for nothing.
|
||||
let copy = vec![Action::Exec("appearance.copyFrom".into(), json!({"source": red.0}))];
|
||||
assert_eq!(click(&mut t, &Selection::default(), Mods::default()), copy);
|
||||
// Selected again, as Direct Selection keeps them, the picks take the sample again.
|
||||
assert_eq!(click(&mut t, &s, Mods::default()), sample, "the mesh selected again");
|
||||
// A click on the picked mesh itself (with no solid fill) copies its appearance as before, and
|
||||
// a Shift-click samples into the active fill as before.
|
||||
let mut unfilled = paint();
|
||||
unfilled.fill = Paint::None;
|
||||
let on_mesh =
|
||||
|t: &mut EyedropperTool, m: Mods| t.pointer(&cx(&d, &s, &unfilled), &PointerEvent::new(PointerKind::Down, 150.0, 150.0).with_mods(m));
|
||||
let own = vec![Action::Exec("appearance.copyFrom".into(), json!({"source": mesh.0}))];
|
||||
assert_eq!(on_mesh(&mut t, Mods::default()), own, "a click on the mesh");
|
||||
let shift = on_mesh(&mut t, Mods { shift: true, ..Default::default() });
|
||||
assert_eq!(shift, vec![Action::Exec("paint.sampleColor".into(), json!({"color": color_json(&Color::WHITE)}))], "a Shift-click on the mesh");
|
||||
// A locked mesh's picks stand for nothing.
|
||||
let mut locked = d.clone();
|
||||
locked.node_mut(mesh).unwrap().locked = true;
|
||||
let a = t.pointer(&cx(&locked, &s, &p), &PointerEvent::new(PointerKind::Down, 325.0, 125.0));
|
||||
assert_eq!(a, copy, "a locked mesh");
|
||||
assert!(t.overlays(&cx(&locked, &s, &p)).is_empty());
|
||||
t.set_option("meshPoints", &json!([{"id": mesh.0, "index": 4}]));
|
||||
assert_eq!(click(&mut t, &s, Mods::default()), copy, "a point the mesh does not have");
|
||||
t.set_option("meshPoints", &json!([]));
|
||||
assert!(t.options().get("meshPoints").is_none());
|
||||
assert_eq!(click(&mut t, &s, Mods::default()), copy);
|
||||
}
|
||||
|
||||
/// On a clip group's mask edge, where the art it clips lies over it, the eyedropper copies the
|
||||
/// art's appearance, not the unpainted clipping path's (the selection tools take the path there).
|
||||
#[test]
|
||||
|
||||
@@ -165,6 +165,13 @@ impl Tool for LassoTool {
|
||||
self.mesh.options()
|
||||
}
|
||||
|
||||
/// Pick the gradient mesh points the Eyedropper held (`meshPoints`).
|
||||
fn set_option(&mut self, key: &str, value: &Value) {
|
||||
if key == "meshPoints" {
|
||||
self.mesh.set_options(value);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let mut out = self.mesh.overlays(cx, &|id| cx.selection.contains(id));
|
||||
if self.active && self.points.len() >= 2 {
|
||||
|
||||
+6
-1
@@ -12235,7 +12235,12 @@ 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}…]`). On gradient meshes a solid fill colour (`paint.setFill`, from the
|
||||
(`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
|
||||
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
|
||||
Alt-click and Shift+Alt-click anywhere, are unchanged. On gradient meshes a solid fill colour (`paint.setFill`, from the
|
||||
Color panel, Swatches or the Eyedropper) recolours just the picked points, and when every target of
|
||||
`transparency.set` is a gradient mesh with points picked, its `opacity` fades those points instead of the objects
|
||||
(`transparency.info` then shows their opacity, `null` when it differs). Both are one undo step, and neither goes to the
|
||||
|
||||
@@ -1671,6 +1671,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **A point on a mesh's outline is on the mesh:** a point exactly on the outline of a gradient mesh (within a millionth of a point) locates on the edge it lies on, on all four sides alike and with no tolerance, as it already did on the top and left edges, so `object.mesh.addLine` and Create Gradient Mesh `at` a point on the bottom or right edge add their lines there instead of reporting the point outside, and the Eyedropper samples the mesh's color there; a point just outside still needs `tolerance`. Tests: `mesh_locate_takes_a_point_on_any_side_of_the_outline` in `crates/doc/src/live.rs`, `mesh_add_line_exactly_on_the_edge_needs_no_tolerance` in `crates/engine/src/tests/live.rs`. Scores and hours unchanged.
|
||||
- **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.
|
||||
- **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`.
|
||||
|
||||
Reference in New Issue
Block a user