From d2aede7c6ecc4b575492f86c0fd88578249e6e3e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 21:44:13 -0800 Subject: [PATCH 1/4] Eyedropper: Object Highlighting outlines the object a click would act on With Smart Guides' Object Highlighting on, the Eyedropper now outlines the object under the pointer that a click there would act on, with the 1.5 px layer-color outline the selection tools draw. It follows the keys held: a plain click's source (locked and template art included, as the Eyedropper reads them), the selected gradient mesh a click recolors, the editable object an Alt-click gives the selection's attributes to, and for a Shift-click the object whose color is sampled (a blend or an envelope where its art is drawn, the art below where it leaves a gap). Empty canvas and hidden art show no outline. The tool finds that object with the same code its click uses: the click is planned once (Tool::hover_object, Session::hover_object) and the color sampler returns the object the color came from. The canvas keeps the object found until the pointer, the keys, the document, the selection or the tool's settings change, since finding it can sample a color. With Space held, a press pans the view, so no tool outlines an object under the pointer; the selection tools showed one before. --- crates/engine/src/tooling.rs | 12 +- crates/tools/src/lib.rs | 6 + crates/tools/src/xform/eyedropper.rs | 258 +++++++++++++++++++------- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/caches.rs | 4 + crates/ui-egui/src/canvas.rs | 4 +- crates/ui-egui/src/canvas/overlays.rs | 87 ++++++++- crates/ui-egui/src/canvas/tests.rs | 136 ++++++++++++++ docs/target-app-parity.md | 1 + 9 files changed, 427 insertions(+), 82 deletions(-) diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 7b1caffb7c..9642718bf7 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -1,7 +1,7 @@ //! Hosting the active tool: pointer/key events → actions → commands. use serde_json::{Map, Value}; -use vectorcraft_doc::Selection; +use vectorcraft_doc::{NodeId, Selection}; use vectorcraft_geom::Point; use vectorcraft_tools::distort::perspective::widget::WidgetPlace; use vectorcraft_tools::draw2::FEEDBACK; @@ -1323,6 +1323,16 @@ impl Session { if self.precise_cursors() { c.precise() } else { c } } + /// The object a click of the active tool at `p` with `mods` would act on + /// ([`vectorcraft_tools::Tool::hover_object`]), for Smart Guides › Object Highlighting. None + /// while Cmd lends a selection tool to the press. + pub fn hover_object(&mut self, p: Point, mods: Mods, view: ViewInfo) -> Option { + if mods.cmd && self.lender.is_none() && !self.tool_editing() && self.lent_tool(self.tool.id(), &mods).is_some() { + return None; + } + self.with_tool_cx(view, |t, cx| t.hover_object(cx, p, mods)) + } + /// General › Use Precise Cursors is on, or Caps Lock is. fn precise_cursors(&self) -> bool { self.prefs.use_precise_cursors || self.caps_lock diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 688f295478..08fba91aa3 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -305,6 +305,12 @@ pub trait Tool: Send { fn wants_rehover(&self) -> bool { false } + /// The object a click at `p` with `mods` would act on, which Smart Guides › Object + /// Highlighting outlines while the pointer rests there (the Eyedropper's source). None when a + /// click there acts on no object, or the tool does not name one. + fn hover_object(&self, _cx: &ToolContext, _p: Point, _mods: Mods) -> Option { + None + } /// What the Info panel shows for the tool as it is now: the drag in progress (a move of the /// selection, a gradient vector, a handle the Pen pulls out, a Scale, Rotate, Reflect or Shear /// tool drag), or the Paintbrush's brush. None for a tool with nothing of its own to show. diff --git a/crates/tools/src/xform/eyedropper.rs b/crates/tools/src/xform/eyedropper.rs index d45dff84ed..3448991367 100644 --- a/crates/tools/src/xform/eyedropper.rs +++ b/crates/tools/src/xform/eyedropper.rs @@ -34,6 +34,9 @@ //! Image Trace's Ignore Color eyedropper passes its bound document point to the panel, which //! samples the original image pixels and ends the pick only when a color is accepted. A miss //! stays armed; this tool changes neither paint nor selection. +//! +//! The object a click at the pointer would act on, with the keys held, is the tool's hover object +//! ([`Tool::hover_object`]), which Smart Guides › Object Highlighting outlines. use std::collections::HashSet; @@ -165,6 +168,12 @@ pub(crate) fn sample_source(cx: &ToolContext, p: Point) -> Option<(vectorcraft_d /// The visible color under `p`, including image pixels, pattern tiles, mesh colors, intermediate /// gradient colors, the steps a blend draws and an envelope's distorted contents. pub(crate) fn sample_color_at(cx: &ToolContext, p: Point) -> Option { + sample_at(cx, p).map(|(c, _)| c) +} + +/// [`sample_color_at`] with the object of the document that gives the color: the object hit, the +/// blend or envelope whose art is sampled, or an object below them that was passed over to. +fn sample_at(cx: &ToolContext, p: Point) -> Option<(Color, NodeId)> { let (doc, opts, raster_sample) = (cx.doc, sample_options(cx), cx.raster_sample); vectorcraft_doc::depth::with_deep_stack(|| { let symbol_nodes = doc.symbols.iter().map(|s| s.art.count()).sum(); @@ -175,13 +184,13 @@ pub(crate) fn sample_color_at(cx: &ToolContext, p: Point) -> Option { }) } -/// The color the front-most object of `doc` hit at `p` with `opts` shows there. Where a stroke +/// The color the front-most object of `doc` hit at `p` with `opts` shows there, and that object. Where a stroke /// gives no color at `p` (a gap between its pattern's tiles), the object's own fill there does; /// an object that gives none at all is passed over for the ones below it. A hit on a blend or an /// envelope, or on an object it holds, samples the art it draws ([`live_color_at`]), and where /// that art leaves `p` empty the whole blend or envelope is passed over. `levels` holds the /// scratch documents for art inside art, one for each level deeper. -fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option], p: Point, opts: HitOptions) -> Option { +fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option], p: Point, opts: HitOptions) -> Option<(Color, NodeId)> { let mut passed: HashSet = HashSet::new(); let mut size = None; loop { @@ -197,7 +206,7 @@ fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option], let h = hit_test_visible_skipping(doc, p, opts, &|id| passed.contains(&id))?; if let Some(live) = drawn_live(doc, &h.ancestry) { if let Some(c) = live_color_at(s, levels, live, p) { - return Some(c); + return Some((c, live.id)); } if !passed.insert(live.id) { return None; @@ -208,13 +217,13 @@ fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option], let n = doc.node(id)?; let on_stroke = h.kind == HitKind::Stroke; if let Some(c) = node_color_at(s, levels, n, on_stroke, p) { - return Some(c); + return Some((c, id)); } if on_stroke && fill_covers(n, p) && let Some(c) = node_color_at(s, levels, n, false, p) { - return Some(c); + return Some((c, id)); } if !passed.insert(id) { return None; @@ -464,7 +473,7 @@ fn art_color_at(s: &mut Sampler, levels: &mut [Option], art: impl Into scratch.insert(Some(layer), usize::MAX, n).ok()?; } let opts = HitOptions { scope: None, tol: 0.0, outline: false, ..s.opts }; - color_under(s, scratch, deeper, p, opts) + color_under(s, scratch, deeper, p, opts).map(|(c, _)| c) } /// Gives `n` and everything in it new ids from `doc` (pattern instances all have id 0). @@ -524,72 +533,50 @@ impl Tool for EyedropperTool { if ev.kind != PointerKind::Down { return vec![]; } - if let Some(binding) = &self.image_trace_ignore_color { - // The panel knows whether this hits an opaque source pixel. It clears the binding - // and restores the previous tool only after accepting a color, not on a miss. - return vec![Action::Dialog("imageTraceIgnoreColor".into(), json!({ "binding": binding, "point": [ev.pos.x, ev.pos.y] }))]; + let Some(click) = self.click(cx, ev.pos, ev.mods) else { return vec![] }; + match click { + Click::ImageTrace(binding) => { + // The panel knows whether this hits an opaque source pixel. It clears the binding + // and restores the previous tool only after accepting a color, not on a miss. + vec![Action::Dialog("imageTraceIgnoreColor".into(), json!({ "binding": binding, "point": [ev.pos.x, ev.pos.y] }))] + } + Click::BrushKeyColor(c, _) => { + let back = self.stop.take().unwrap_or_else(|| "selection".to_string()); + self.brush_key_color = false; + vec![Action::Dialog("brushKeyColor".into(), json!({ "color": color_json(&c) })), Action::SwitchTool(back)] + } + Click::BackToBucket => { + self.stop = None; + vec![Action::SwitchTool("livePaintBucket".into())] + } + Click::MeshPoints(id, points, color) => { + let params = json!({ "id": id.0, "points": points, "color": color_json(&color), "keepModel": true }); + vec![Action::Exec("object.mesh.setPointColor".into(), params)] + } + Click::CopyFrom(src, how) => { + let params = match how { + Some(how) => json!({ "source": src.0, how: true }), + None => json!({ "source": src.0 }), + }; + vec![Action::Exec("appearance.copyFrom".into(), params)] + } + Click::Sample { color, meshes, stop, .. } => { + let color = color_json(&color); + if !meshes.is_empty() { + let ids: Vec = 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 }))] }; + self.stop = None; + vec![Action::Exec("paint.sampleColor".into(), json!({ "color": color, "stop": i })), Action::SwitchTool(back)] + } } - let opts = sample_options(cx); - if self.brush_key_color { - let Some(c) = sample_color_at(cx, ev.pos) else { return vec![] }; - let back = self.stop.clone().unwrap_or_else(|| "selection".to_string()); - self.brush_key_color = false; - self.stop = None; - return vec![Action::Dialog("brushKeyColor".into(), json!({ "color": color_json(&c) })), Action::SwitchTool(back)]; - } - // A pick for a stop of the Live Paint Bucket's gradient (the default paint's) ends without - // sampling once that stop is no longer selected (a Cmd-click selected another object) or no - // longer there (another paint was chosen): the click switches back. - let bucket_paint = if cx.fill_active { &cx.paint.fill } else { &cx.paint.stroke }; - let bucket_stop = cx.gradient_stop.filter(|i| matches!(bucket_paint, Paint::Gradient(g) if *i < g.gradient.stops.len())); - if self.stop.as_deref() == Some("livePaintBucket") && bucket_stop.is_none() { - self.stop = None; - return vec![Action::SwitchTool("livePaintBucket".into())]; - } - let stop = self.stop.as_ref().zip(cx.gradient_stop); - // A plain click on a selected gradient mesh gives the fill color to the point there, else - // to the four points of the patch there. - if stop.is_none() - && !ev.mods.alt - && !ev.mods.shift - && let Paint::Solid { color, .. } = &cx.paint.fill - && let Some((id, points)) = selected_mesh_points(cx, ev.pos) - { - let params = json!({ "id": id.0, "points": points, "color": color_json(color), "keepModel": true }); - return vec![Action::Exec("object.mesh.setPointColor".into(), params)]; - } - // Reading a source is independent of its editability. Only Alt's reverse operation - // writes to the clicked object; Shift+Alt appends its appearance to the selection. - let source = if ev.mods.alt && !ev.mods.shift && stop.is_none() { - hit_test(cx.doc, ev.pos, opts).map(|h| (paint_owner(cx.doc, h.leaf), h.kind)) - } else { - sample_source(cx, ev.pos) - }; - let Some((src, _)) = source else { return vec![] }; - let Some(n) = cx.doc.node(src) else { return vec![] }; - if ev.mods.alt && stop.is_none() { - let how = if ev.mods.shift { "append" } else { "reverse" }; - return vec![Action::Exec("appearance.copyFrom".into(), json!({ "source": src.0, how: true }))]; - } - let image = matches!(n.kind, NodeKind::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 = 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; - out + } + + /// The object a click there samples, recolors or copies attributes to, as [`Self::click`] + /// finds it. + fn hover_object(&self, cx: &ToolContext, p: Point, mods: Mods) -> Option { + self.click(cx, p, mods)?.object() } /// Expose a transient text range alongside gradient-stop and brush-key sampling state. @@ -684,11 +671,92 @@ impl Tool for EyedropperTool { } } +/// What a click with the Eyedropper does, which [`EyedropperTool::pointer`] carries out. +enum Click { + /// Image Trace's Ignore Color pick: the panel samples the image with this binding. + ImageTrace(Value), + /// Brush Options › Key Color: this color, sampled from this object. + BrushKeyColor(Color, NodeId), + /// A pick for a Live Paint Bucket stop that is no longer selected switches back unsampled. + BackToBucket, + /// The fill color goes to these points of this selected gradient mesh. + MeshPoints(NodeId, Vec, Color), + /// `appearance.copyFrom` this source, with `reverse` or `append` or neither. + CopyFrom(NodeId, Option<&'static str>), + /// This color, sampled from `source`, goes to the picked points of `meshes`, else to the + /// gradient stop of `stop` (the tool to switch back to and the stop), else to the active fill + /// or stroke. + Sample { color: Color, source: NodeId, meshes: Vec, stop: Option<(String, usize)> }, +} + +impl Click { + /// The object of the document the click reads from or writes to. + fn object(&self) -> Option { + match self { + Click::ImageTrace(_) | Click::BackToBucket => None, + Click::BrushKeyColor(_, id) | Click::MeshPoints(id, ..) | Click::CopyFrom(id, _) | Click::Sample { source: id, .. } => Some(*id), + } + } +} + impl EyedropperTool { /// Is a gradient stop, Brush Key Color or Image Trace Ignore Color pick armed? fn picking(&self) -> bool { self.stop.is_some() || self.brush_key_color || self.image_trace_ignore_color.is_some() } + + /// What a click at `p` with `mods` does, or None when it does nothing. + fn click(&self, cx: &ToolContext, p: Point, mods: Mods) -> Option { + if let Some(binding) = &self.image_trace_ignore_color { + return Some(Click::ImageTrace(binding.clone())); + } + if self.brush_key_color { + let (c, source) = sample_at(cx, p)?; + return Some(Click::BrushKeyColor(c, source)); + } + // A pick for a stop of the Live Paint Bucket's gradient (the default paint's) ends without + // sampling once that stop is no longer selected (a Cmd-click selected another object) or no + // longer there (another paint was chosen): the click switches back. + let bucket_paint = if cx.fill_active { &cx.paint.fill } else { &cx.paint.stroke }; + let bucket_stop = cx.gradient_stop.filter(|i| matches!(bucket_paint, Paint::Gradient(g) if *i < g.gradient.stops.len())); + if self.stop.as_deref() == Some("livePaintBucket") && bucket_stop.is_none() { + return Some(Click::BackToBucket); + } + let stop = self.stop.clone().zip(cx.gradient_stop); + // A plain click on a selected gradient mesh gives the fill color to the point there, else + // to the four points of the patch there. + if stop.is_none() + && !mods.alt + && !mods.shift + && let Paint::Solid { color, .. } = &cx.paint.fill + && let Some((id, points)) = selected_mesh_points(cx, p) + { + return Some(Click::MeshPoints(id, points, *color)); + } + // Reading a source is independent of its editability. Only Alt's reverse operation + // writes to the clicked object; Shift+Alt appends its appearance to the selection. + let source = if mods.alt && !mods.shift && stop.is_none() { + hit_test(cx.doc, p, sample_options(cx)).map(|h| (paint_owner(cx.doc, h.leaf), h.kind)) + } else { + sample_source(cx, p) + }; + let (src, _) = source?; + let n = cx.doc.node(src)?; + if mods.alt && stop.is_none() { + return Some(Click::CopyFrom(src, Some(if mods.shift { "append" } else { "reverse" }))); + } + let image = matches!(n.kind, NodeKind::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 !(mods.shift || stop.is_some() || image || !meshes.is_empty()) { + return Some(Click::CopyFrom(src, None)); + } + let (color, source) = sample_at(cx, p)?; + Some(Click::Sample { color, source, meshes, stop }) + } } #[cfg(test)] @@ -1824,7 +1892,7 @@ mod tests { let opts = sample_options(&cx); let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: 1_000, exhausted: false, patterns: 0 }; let mut levels: Vec> = (0..MAX_NESTING).map(|_| None).collect(); - assert_eq!(color_under(&mut s, &d, &mut levels, Point::new(150.0, 150.0), opts).map(|c| c.to_hex()), None); + assert_eq!(color_under(&mut s, &d, &mut levels, Point::new(150.0, 150.0), opts).map(|(c, _)| c.to_hex()), None); assert!(s.exhausted); } @@ -1917,6 +1985,52 @@ mod tests { assert_eq!(sampled_hex(&below), "#00ff00"); } + /// The object the hover names for a Shift-click is the one whose color the click samples: the + /// blend where a step is drawn, and the rectangle below it in a gap between the steps. Away + /// from all art it names none. + #[test] + fn shift_hover_names_the_object_the_sample_comes_from() { + use vectorcraft_doc::live::{BlendSpacing, BlendSpec}; + use vectorcraft_geom::Rect; + let d = doc_with_live_over_green(|d| { + let red = solid_rect(d, Rect::new(300.0, 300.0, 320.0, 320.0), Color::rgb(1.0, 0.0, 0.0)); + let blue = solid_rect(d, Rect::new(400.0, 300.0, 420.0, 320.0), Color::rgb(0.0, 0.0, 1.0)); + let spec = BlendSpec { spacing: BlendSpacing::Steps(1), ..Default::default() }; + Node::new(d.alloc_id(), NodeKind::Blend { children: vec![std::sync::Arc::new(red), std::sync::Arc::new(blue)], spec: Box::new(spec) }) + }); + let ids: Vec = d.layers[0].children().unwrap().iter().map(|n| n.id).collect(); + let [.., green, blend] = ids[..] else { panic!("two objects over the rectangle expected") }; + let (s, p) = (Selection::default(), paint()); + let shift = Mods { shift: true, ..Default::default() }; + let t = EyedropperTool::default(); + let names = |x: f64, y: f64| t.hover_object(&cx(&d, &s, &p), Point::new(x, y), shift); + assert_eq!(names(360.0, 310.0), Some(blend), "a blend step"); + assert_eq!(names(335.0, 310.0), Some(green), "a gap between the steps"); + assert_eq!(names(480.0, 480.0), None, "no art"); + } + + /// A plain click on a selected gradient mesh recolors its points, and the hover names that + /// mesh; Image Trace's Ignore Color pick, which the panel samples, names nothing. + #[test] + fn hover_names_the_selected_mesh_a_click_recolors() { + 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 p = paint(); + let mut s = Selection::default(); + s.set([mesh]); + let mut t = EyedropperTool::default(); + let at = Point::new(150.0, 150.0); + let a = t.pointer(&cx(&d, &s, &p), &PointerEvent::new(PointerKind::Down, at.x, at.y)); + assert!(matches!(a.first(), Some(Action::Exec(id, _)) if id == "object.mesh.setPointColor"), "{a:?}"); + assert_eq!(t.hover_object(&cx(&d, &s, &p), at, Mods::default()), Some(mesh)); + t.set_option("imageTraceIgnoreColor", &json!({"binding": 1})); + assert_eq!(t.hover_object(&cx(&d, &s, &p), at, Mods::default()), None); + } + /// A blend of two instances of one symbol draws its steps as instances too: Shift-click on a /// step samples the symbol's art there, and where that art leaves the point empty, what lies /// below. diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index bba6a5d83d..320c5b0f3c 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -98,6 +98,7 @@ impl VectorcraftApp { cursors: Default::default(), view_moved: None, hover_cursor: None, + hover_object: None, presented: None, opening_fit: None, panes: Default::default(), diff --git a/crates/ui-egui/src/caches.rs b/crates/ui-egui/src/caches.rs index 6e1d229023..5c8e1f3a11 100644 --- a/crates/ui-egui/src/caches.rs +++ b/crates/ui-egui/src/caches.rs @@ -87,6 +87,10 @@ pub struct CanvasCache { /// The cursor the active tool last gave over the canvas, with the tool and the modifier keys /// it was for: kept while the view moves. pub hover_cursor: Option<(&'static str, vectorcraft_tools::Mods, vectorcraft_tools::Cursor)>, + /// The object the Eyedropper's click at the pointer would act on, which Object Highlighting + /// outlines, with what it was found for: finding it again, which can sample a color, waits + /// until one of those changes. + pub hover_object: Option<(canvas::HoverObjectKey, Option)>, /// In Presentation Mode, the canvas rect the active artboard was last fitted to: it is fitted /// again when the rect changes (the window going full screen). pub presented: Option, diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 8b366665d4..53a1d373f8 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -61,12 +61,12 @@ use input::handle_input; use outline::KEY_OUTLINE; #[cfg(test)] use outline::{OVERLAY_MAX_ANCHORS, c32, node_outline, walk_drawn}; -pub use overlays::SharedPaths; #[cfg(test)] use overlays::selected_anchor; use overlays::{ HandleLook, blend_widgets_overlay, draw_inside_overlay, draw_overlays, hover_highlight, ime_geometry, overlay_hover_text, selection_overlay, }; +pub use overlays::{HoverObjectKey, SharedPaths}; pub use panes::{Layout as TileLayout, Panes}; pub(crate) use panes::{consolidate, note_drop, noted_cursor, pane, release_on_noted, tile, tiled_area}; pub(crate) use quick_pen_bar::quick_pen_bar_rect; @@ -1670,7 +1670,7 @@ fn selection_visuals( overlays.extend(crate::dialogs::live_paint_gaps::overlays(app)); if app.ui.view.edges && !revolve_edit { if hover_still { - hover_highlight(app, painter, xf); + hover_highlight(app, painter, xf, view_info); } selection_overlay(app, painter, xf, overlays.iter().any(|o| matches!(o, Overlay::CurvePoint { .. })), &mut marks); app.canvas.selection_marks = marks; diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index b4d2d44aac..79d3195eaf 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -10,27 +10,100 @@ use super::outline::{KEY_OUTLINE, c32, node_outline, selection_hit_at, stroke_pa use super::selection_marks::{MarkOptions, SelectionMarks}; use super::{BezPath, Color32, CornerRadius, NodeKind, Overlay, Pos2, Shape, Stroke, StrokeKind, Tokens, VectorcraftApp, Xf, vec2}; -pub(super) fn hover_highlight(app: &VectorcraftApp, p: &egui::Painter, xf: &Xf) { +pub(super) fn hover_highlight(app: &mut VectorcraftApp, p: &egui::Painter, xf: &Xf, view: vectorcraft_engine::ViewInfo) { let Some(h) = app.hover_doc else { return }; // Smart Guides › Object Highlighting: a Smart Guides display option, so it needs them on and Snap to Grid and Pixel Preview off. if !app.ui.view.smart_guides || !app.session.prefs.object_highlighting || app.ui.view.snap_to_grid || app.ui.view.pixel_preview { return; } - if app.session.tool_busy() || !matches!(app.session.tool_id(), "selection" | "directSelection" | "groupSelection") { + if app.session.tool_busy() || !matches!(app.session.tool_id(), "selection" | "directSelection" | "groupSelection" | "eyedropper") { return; } + // With Space lending the view tools, a press pans the view and acts on no object. + let (m, space) = p.ctx().input(|i| (i.modifiers, i.key_down(egui::Key::Space))); + if super::drag::space_lends_view_tools(app, m, space) { + return; + } + let id = if app.session.tool_id() == "eyedropper" { + // The object the Eyedropper's click there samples, recolors or copies to, with the keys + // held now. A selected one is outlined too: a click on it still acts on it. + let mods = super::drag::mods(m, false); + let Some(id) = eyedropper_hover_object(app, h, mods, view) else { return }; + id + } else { + let Some(st) = app.session.active() else { return }; + let Some(hit) = selection_hit_at(app, h, xf.zoom) else { return }; + let id = if app.session.tool_id() == "selection" { hit.top_object(st.isolation) } else { hit.leaf }; + if st.selection.contains(id) { + return; + } + id + }; let Some(st) = app.session.active() else { return }; - let Some(hit) = selection_hit_at(app, h, xf.zoom) else { return }; - let id = if app.session.tool_id() == "selection" { hit.top_object(st.isolation) } else { hit.leaf }; - if st.selection.contains(id) { - return; - } if let Some(n) = st.doc.node(id).filter(|n| !too_many_anchors([*n])) { let color = c32(st.doc.layer_color(id)); stroke_path(p, &node_outline(n, &st.doc.symbol_boxes()), xf, Stroke::new(1.5, color)); } } +/// What the Eyedropper's hover object depends on: the point, the keys held, the document as it is, +/// the selection and isolation, the tool's options (an armed pick), the paint defaults and the +/// selected gradient stop, the selection tolerance, Eyedropper Options (the raster sample size), +/// whether guides show and are locked, and the view's zoom and Outline mode: everything the +/// tool's context gives a click that can change what it acts on. +#[derive(Clone, Debug, PartialEq)] +pub struct HoverObjectKey { + at: vectorcraft_geom::Point, + mods: vectorcraft_tools::Mods, + doc: (u64, u64), + selection: vectorcraft_doc::Selection, + isolation: Option, + options: serde_json::Value, + paint: vectorcraft_tools::PaintDefaults, + fill_active: bool, + stop: Option, + tolerance: f64, + eyedropper: vectorcraft_engine::EyedropperOptions, + guides: (bool, bool), + zoom: f64, + outline: bool, +} + +/// [`vectorcraft_engine::Session::hover_object`] at `at`, found again only when its +/// [`HoverObjectKey`] changes: over an image, or with Shift held, finding it samples a color. +fn eyedropper_hover_object( + app: &mut VectorcraftApp, + at: vectorcraft_geom::Point, + mods: vectorcraft_tools::Mods, + view: vectorcraft_engine::ViewInfo, +) -> Option { + let st = app.session.active()?; + let key = HoverObjectKey { + at, + mods, + doc: (st.uid, st.revision), + selection: st.selection.clone(), + isolation: st.isolation, + options: app.session.tool_options(), + paint: app.session.paint.clone(), + fill_active: app.session.fill_active, + stop: app.session.selected_stop(), + tolerance: app.session.prefs.selection_tolerance, + eyedropper: app.session.prefs.eyedropper, + guides: (view.guides, app.session.guides_locked()), + zoom: view.zoom, + outline: view.outline, + }; + if let Some((k, id)) = &app.canvas.hover_object + && *k == key + { + return *id; + } + let id = app.session.hover_object(at, mods, view); + app.canvas.hover_object = Some((key, id)); + id +} + /// Draw Inside (Shift+D): while the mode lasts, a dotted open rectangle round the corners of the /// object drawn into, selected or not (#4319). pub(super) fn draw_inside_overlay(app: &VectorcraftApp, p: &egui::Painter, xf: &Xf) { diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index d5244aa234..1a714ccfe6 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -6096,6 +6096,142 @@ fn object_highlighting_preference_hides_the_hover_outline() { assert_eq!(outlines(&mut app), 0, "Smart Guides off"); } +/// The screen points of the 1.5 px hover outlines in `color` that one frame with `held` keys down +/// draws, the pointer where the last frame left it. +fn hover_outline_points(app: &mut VectorcraftApp, ctx: &egui::Context, color: Color32, held: egui::Modifiers) -> Vec { + fn flat(s: Shape, out: &mut Vec) { + match s { + Shape::Vec(v) => v.into_iter().for_each(|s| flat(s, out)), + s => out.push(s), + } + } + app.canvas.selection_marks = Default::default(); + let events = vec![egui::Event::ModifiersChanged(held)]; + let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), events, ..Default::default() }; + let mut out = ctx.run_ui(raw, |ui| show(app, ui)); + // The art's raster lands in some frame when the render worker is done with it. + out.textures_delta.clear(); + let mut shapes = vec![]; + out.shapes.into_iter().for_each(|c| flat(c.shape, &mut shapes)); + let solid = egui::epaint::ColorMode::Solid(color); + let mut at = vec![]; + for s in shapes { + if let Shape::Path(ps) = s + && ps.stroke.width == 1.5 + && ps.stroke.color == solid + { + at.extend(ps.points); + } + } + at +} + +/// The screen box around `points`. +fn screen_box(points: &[Pos2]) -> egui::Rect { + points.iter().fold(egui::Rect::NOTHING, |r, p| r.union(egui::Rect::from_min_max(*p, *p))) +} + +/// Whether two screen boxes agree to within a pixel. +fn same_box(a: egui::Rect, b: egui::Rect) -> bool { + (a.min - b.min).length() < 1.0 && (a.max - b.max).length() < 1.0 +} + +/// With the Eyedropper, Smart Guides › Object Highlighting outlines the object under the pointer +/// as the selection tools do (1.5 px in its layer color), and nothing over empty canvas. +#[test] +fn eyedropper_hover_outlines_the_object_under_the_pointer() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.session.execute("select.none", &json!({})).unwrap(); + app.select_tool("eyedropper"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(id))); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(150.0, 150.0)))]); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE); + let rect = egui::Rect::from_two_pos(xf.to_screen(Point::new(100.0, 100.0)), xf.to_screen(Point::new(200.0, 200.0))); + assert!(!at.is_empty() && same_box(screen_box(&at), rect), "the rectangle under the pointer is outlined: {:?}", screen_box(&at)); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(300.0, 50.0)))]); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "nothing over empty canvas"); + // Space lends the view tools: a press pans, so no object is outlined, with any tool. + let space = |pressed| egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::NONE }; + for tool in ["eyedropper", "selection"] { + app.select_tool(tool); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(150.0, 150.0)))]); + assert!(!hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "{tool}: outlined"); + frame(&mut app, &ctx, vec![space(true)]); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "{tool}: Space held"); + frame(&mut app, &ctx, vec![space(false)]); + assert!(!hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "{tool}: Space let go"); + } +} + +/// The Eyedropper's hover outline follows Smart Guides › Object Highlighting. +#[test] +fn eyedropper_hover_outline_follows_object_highlighting() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.session.execute("select.none", &json!({})).unwrap(); + app.select_tool("eyedropper"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(id))); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(150.0, 150.0)))]); + app.session.execute("prefs.set", &json!({"key": "objectHighlighting", "value": false})).unwrap(); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "the option off"); + app.session.execute("prefs.set", &json!({"key": "objectHighlighting", "value": true})).unwrap(); + assert!(!hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "the option on"); +} + +/// The Eyedropper outlines the object its click there then acts on: the front object a plain +/// click copies attributes from, a locked one included (the Eyedropper reads locked art), and with +/// Alt the unlocked object below it that an Alt-click gives the selection's attributes to. +#[test] +fn eyedropper_hover_outline_is_the_object_the_click_acts_on() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let rect = |app: &mut VectorcraftApp, x: f64, y: f64, size: f64, color: &str| { + let id = app.session.execute("shape.rectangle", &json!({"x": x, "y": y, "width": size, "height": size})).unwrap()["id"].as_u64().unwrap(); + app.session.execute("paint.setFill", &json!({"ids": [id], "color": color})).unwrap(); + id + }; + let back = rect(&mut app, 100.0, 100.0, 100.0, "#0000ff"); + let front = rect(&mut app, 150.0, 150.0, 100.0, "#ff0000"); + let target = rect(&mut app, 20.0, 20.0, 40.0, "#00ff00"); + app.session.execute("select.set", &json!({"ids": [target]})).unwrap(); + app.select_tool("eyedropper"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(front))); + let boxed = |x: f64, y: f64, size: f64| egui::Rect::from_two_pos(xf.to_screen(Point::new(x, y)), xf.to_screen(Point::new(x + size, y + size))); + let fill = |app: &VectorcraftApp, id: u64| app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().appearance.fill_paint(); + let over = xf.to_screen(Point::new(175.0, 175.0)); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(over)]); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE); + assert!(same_box(screen_box(&at), boxed(150.0, 150.0, 100.0)), "the front rectangle is outlined: {:?}", screen_box(&at)); + click_at(&mut app, &ctx, over); + assert_eq!(fill(&app, target), fill(&app, front), "the click copied the outlined rectangle's fill"); + + app.session.execute("object.lock", &json!({"ids": [front]})).unwrap(); + app.session.execute("select.set", &json!({"ids": [target]})).unwrap(); + app.session.execute("paint.setFill", &json!({"ids": [target], "color": "#00ff00"})).unwrap(); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(over)]); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE); + assert!(same_box(screen_box(&at), boxed(150.0, 150.0, 100.0)), "the locked front rectangle is still the source: {:?}", screen_box(&at)); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::ALT); + assert!(same_box(screen_box(&at), boxed(100.0, 100.0, 100.0)), "with Alt, the unlocked rectangle below: {:?}", screen_box(&at)); + let button = |pressed| egui::Event::PointerButton { pos: over, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::ALT }; + frame(&mut app, &ctx, vec![egui::Event::ModifiersChanged(egui::Modifiers::ALT), button(true)]); + frame(&mut app, &ctx, vec![button(false), egui::Event::ModifiersChanged(egui::Modifiers::NONE)]); + assert_eq!(fill(&app, back), fill(&app, target), "the Alt-click gave the outlined rectangle the selection's fill"); + assert_ne!(fill(&app, front), fill(&app, target)); +} + /// Hide Corner Widget for angles greater than (#394): a rectangle's 90° corners lose their /// widgets below 90°. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index b1d981428a..143f215fcd 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2015,6 +2015,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Pasting into hex color fields:** in the hex fields of the Color Picker, Swatch Options, Recolor Artwork, the Color panel, Document Setup, Duotone, Color Themes and Perspective Grid, a click or keyboard focus selects the digits. A pasted code of six digits, with or without `#`, replaces them wherever the caret is. A pasted code of three digits also replaces them, unless the paste holds only those digits and exactly three digits stay; those digits then edit the text in place. A press on another field commits the text as Tab and Enter do. As VectorCraft's own rule, a paste that is not a color leaves the field as it was. Tests: `a_hex_code_pasted_into_the_hex_field_replaces_its_digits` in `crates/ui-egui/src/dialogs/tests.rs`, `define_grid_takes_a_three_digit_color` in `crates/ui-egui/src/dialogs/tests_perspective.rs` and `a_paste_into_a_hex_field_replaces_or_edits_its_digits` in `crates/ui-egui/src/tests/numfields.rs`. - **Color Picker layout (#2008):** a centered draggable header, equal-width actions above aligned HSB/RGB/Hex and Lab/CMYK fields, compact field and slider, and warnings below the preview. No horizontal scrolling; narrow windows stack the sections with vertical scrolling. Tests in `dialogs/color_picker.rs` cover actual pointer/key input, typed values before OK/Enter, Cancel/Escape rollback, one Undo step, mode-size stability, warnings and layout at two UI scales. The screen sampler sits above the field and the upstream two-grid Tab order is retained. AccessKit regressions check the action names and each channel slider's displayed value, units and range. German and enlarged English UI renders were reviewed locally; no reference images are shipped. This is a layout improvement, with no change to scores or remaining-hour estimates. - **Eyedropper sources (#1251):** ordinary and Shift clicks, Shift+Alt appearance append, raster pixels and gradient-stop sampling can read visible locked/template art and sources outside isolation. Sampling leaves the source and selection intact; Alt reverse still uses editable hits, and hidden art stays excluded. Engine/tool/hit regressions cover the editing boundary, color models and one-step Undo/Redo. The general object/image workflow is described in [public HelpX](https://helpx.adobe.com/illustrator/using/tool-techniques/eyedropper-tool.html); the lock/isolation expectations come from the user report and these regressions, without a new full-parity measurement. + - **Eyedropper hover outline:** as VectorCraft's own behavior, with Smart Guides › Object Highlighting on, the Eyedropper outlines the object a click at the pointer would act on, in the selection tools' 1.5 px layer-color outline: the source a click copies from (locked and template art included), the selected gradient mesh a click recolors, the object below a locked one that an Alt-click gives the selection's attributes to, and for a Shift-click the object whose color is sampled (a blend or envelope where its art is drawn, the art below where it leaves a gap). A selected object is outlined too. Empty canvas, hidden art and a Cmd-click that borrows a selection tool show no outline, and with the Eyedropper or a selection tool, Space held for the view tools hides the outline. Tests: `crates/ui-egui/src/canvas/tests.rs`, `crates/tools/src/xform/eyedropper.rs`. - **Eyedropper colors in a CMYK document (#2276):** a CMYK image (a four-component JPEG, or an 8- or 16-bit chunky CMYK TIFF) gives its ink amounts as they are, and an RGB image's pixel or an RGB color given to `paint.setFill`, `paint.setStroke`, `paint.sampleColor` or `swatch.new {color}` (hex input and gradient stops included) is separated through the color settings' CMYK working space and intent, as Document Color Mode converts it. With the default Generic CMYK, RGB 83/170/223 separates to C62 M19 Y0 K0, where the profile-free formula gave C63 M24 Y0 K13. - **RGB input to other commands in a CMYK document:** type colors (`text.create`, `text.setStyle`, `text.setRangeStyle`), a Shape Builder hex fill, `paint.editGradient` stops, freeform gradient points, gradient mesh points (the Mesh tool gives a new point the fill's color in its own model), the Symbol Stainer's color and the swatch commands (`swatch.new {colors}`, `swatch.newGroup`, `swatch.editGroup`, `swatch.edit`) separate RGB through the color settings as `paint.setFill` does: with Generic CMYK, `text.setStyle {fill: "#53aadf"}` gives C62 M19 Y0 K0. A color a swatch already has keeps its model, and a swatch color given with `mode` is converted into that mode only. - **Generic CMYK (SWOP-like):** each ink's 40% and 50% tints gain as [CGATS TR 001](https://registry.color.org/cmyk-registry/cgats_tr_001) gives for SWOP printing, and separations stay within SWOP's [300% total ink limit](https://en.wikipedia.org/wiki/Specifications_for_Web_Offset_Publications). The paper, solid and overprint colors, the black-generation curve and the black point are VectorCraft's own values: RGB black separates to 90% black under neutral cyan, magenta and yellow that fill the ink limit (C75 M68 Y67 K90). The ICC profile written for it (embedded in exports) gives the paper as its media white point, and its colorimetric Lab → CMYK table is the inverse of its CMYK → Lab table, without black-point compensation; the perceptual and saturation tables keep compensation. From 05762dba5b17b18118bc61b1d0d8386f4c1f0763 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:45:39 -0800 Subject: [PATCH 2/4] Eyedropper: Cmd hover outlines what the lent selection tool selects With Cmd held, a click with the Eyedropper selects with the selection tool lent to it. The hover outline is now that tool's outline: the object under the pointer, or none when that object is already selected. Before, Cmd hid the outline. While the pointer rests, the canvas compares the state its cached outline was found for with the current state field by field. It copies the selection, the paint defaults and the tool's options into a new key only when some part of that state changed. The progress-doc line states the Alt case as the front editable object (the one below when locked art covers it) and names the tests. New tests cover a selected object, Cmd, hidden art, an armed Ignore Color pick, Shift over a blend on the canvas, and Shift over an envelope. --- crates/tools/src/xform/eyedropper.rs | 25 +++++++++++ crates/ui-egui/src/canvas.rs | 3 +- crates/ui-egui/src/canvas/overlays.rs | 57 +++++++++++++++++++----- crates/ui-egui/src/canvas/tests.rs | 64 +++++++++++++++++++++++++++ docs/target-app-parity.md | 2 +- 5 files changed, 139 insertions(+), 12 deletions(-) diff --git a/crates/tools/src/xform/eyedropper.rs b/crates/tools/src/xform/eyedropper.rs index 3448991367..0eb5008fc8 100644 --- a/crates/tools/src/xform/eyedropper.rs +++ b/crates/tools/src/xform/eyedropper.rs @@ -2009,6 +2009,31 @@ mod tests { assert_eq!(names(480.0, 480.0), None, "no art"); } + /// For a Shift-click on an envelope, the hover names the envelope where its distorted contents + /// are drawn, and the rectangle below where they leave the point empty. + #[test] + fn shift_hover_names_the_envelope_where_its_art_is_drawn() { + use vectorcraft_geom::{Affine, Rect}; + let d = doc_with_live_over_green(|d| { + let red = solid_rect(d, Rect::new(300.0, 300.0, 420.0, 320.0), Color::rgb(1.0, 0.0, 0.0)); + let kind = vectorcraft_doc::EnvelopeKind::Warp { style: "arc".into(), bend: 50.0, h: 0.0, v: 0.0, horizontal: true, version: 0 }; + let content = vec![std::sync::Arc::new(red)]; + let options = Default::default(); + Node::new( + d.alloc_id(), + NodeKind::Envelope { content, kind: Box::new(kind), fidelity: 50.0, editing: false, options, frame: Box::new(Affine::IDENTITY) }, + ) + }); + let ids: Vec = d.layers[0].children().unwrap().iter().map(|n| n.id).collect(); + let [.., green, envelope] = ids[..] else { panic!("two objects over the rectangle expected") }; + let (s, p) = (Selection::default(), paint()); + let shift = Mods { shift: true, ..Default::default() }; + let t = EyedropperTool::default(); + let names = |x: f64, y: f64| t.hover_object(&cx(&d, &s, &p), Point::new(x, y), shift); + assert_eq!(names(360.0, 310.0), Some(envelope), "the distorted contents"); + assert_eq!(names(360.0, 332.0), Some(green), "a point the contents leave empty"); + } + /// A plain click on a selected gradient mesh recolors its points, and the hover names that /// mesh; Image Trace's Ignore Color pick, which the panel samples, names nothing. #[test] diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 53a1d373f8..c1eaf41980 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -61,12 +61,13 @@ use input::handle_input; use outline::KEY_OUTLINE; #[cfg(test)] use outline::{OVERLAY_MAX_ANCHORS, c32, node_outline, walk_drawn}; +pub use overlays::HoverObjectKey; +pub use overlays::SharedPaths; #[cfg(test)] use overlays::selected_anchor; use overlays::{ HandleLook, blend_widgets_overlay, draw_inside_overlay, draw_overlays, hover_highlight, ime_geometry, overlay_hover_text, selection_overlay, }; -pub use overlays::{HoverObjectKey, SharedPaths}; pub use panes::{Layout as TileLayout, Panes}; pub(crate) use panes::{consolidate, note_drop, noted_cursor, pane, release_on_noted, tile, tiled_area}; pub(crate) use quick_pen_bar::quick_pen_bar_rect; diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index 79d3195eaf..736bfb999e 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -19,21 +19,25 @@ pub(super) fn hover_highlight(app: &mut VectorcraftApp, p: &egui::Painter, xf: & if app.session.tool_busy() || !matches!(app.session.tool_id(), "selection" | "directSelection" | "groupSelection" | "eyedropper") { return; } - // With Space lending the view tools, a press pans the view and acts on no object. let (m, space) = p.ctx().input(|i| (i.modifiers, i.key_down(egui::Key::Space))); + let mods = super::drag::mods(m, false); + // With Space lending the view tools, a press pans the view and acts on no object. if super::drag::space_lends_view_tools(app, m, space) { return; } - let id = if app.session.tool_id() == "eyedropper" { + // With the Eyedropper, Cmd lends a selection tool, whose click acts on what that tool outlines. + let eyedropper = app.session.tool_id() == "eyedropper"; + let lent = if eyedropper && !app.session.tool_editing() { app.session.lent_tool_id(&mods) } else { None }; + let id = if eyedropper && lent.is_none() { // The object the Eyedropper's click there samples, recolors or copies to, with the keys // held now. A selected one is outlined too: a click on it still acts on it. - let mods = super::drag::mods(m, false); let Some(id) = eyedropper_hover_object(app, h, mods, view) else { return }; id } else { + let tool = lent.unwrap_or(app.session.tool_id()); let Some(st) = app.session.active() else { return }; let Some(hit) = selection_hit_at(app, h, xf.zoom) else { return }; - let id = if app.session.tool_id() == "selection" { hit.top_object(st.isolation) } else { hit.leaf }; + let id = if tool == "selection" { hit.top_object(st.isolation) } else { hit.leaf }; if st.selection.contains(id) { return; } @@ -70,7 +74,9 @@ pub struct HoverObjectKey { } /// [`vectorcraft_engine::Session::hover_object`] at `at`, found again only when its -/// [`HoverObjectKey`] changes: over an image, or with Shift held, finding it samples a color. +/// [`HoverObjectKey`] changes: over an image, or with Shift held, finding it samples a color. The +/// cached key is compared field by field, the cheap fields first, and the key is copied only +/// when it changed. fn eyedropper_hover_object( app: &mut VectorcraftApp, at: vectorcraft_geom::Point, @@ -78,6 +84,42 @@ fn eyedropper_hover_object( view: vectorcraft_engine::ViewInfo, ) -> Option { let st = app.session.active()?; + let s = &app.session; + let cached = app.canvas.hover_object.as_ref().filter(|(k, _)| { + let HoverObjectKey { + at: k_at, + mods: k_mods, + doc, + selection, + isolation, + options, + paint, + fill_active, + stop, + tolerance, + eyedropper, + guides, + zoom, + outline, + } = k; + *k_at == at + && *k_mods == mods + && *doc == (st.uid, st.revision) + && *isolation == st.isolation + && *fill_active == s.fill_active + && *stop == s.selected_stop() + && *tolerance == s.prefs.selection_tolerance + && *eyedropper == s.prefs.eyedropper + && *guides == (view.guides, s.guides_locked()) + && *zoom == view.zoom + && *outline == view.outline + && *selection == st.selection + && *paint == s.paint + && *options == s.tool_options() + }); + if let Some((_, id)) = cached { + return *id; + } let key = HoverObjectKey { at, mods, @@ -94,11 +136,6 @@ fn eyedropper_hover_object( zoom: view.zoom, outline: view.outline, }; - if let Some((k, id)) = &app.canvas.hover_object - && *k == key - { - return *id; - } let id = app.session.hover_object(at, mods, view); app.canvas.hover_object = Some((key, id)); id diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 1a714ccfe6..c17f11629a 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -6168,6 +6168,70 @@ fn eyedropper_hover_outlines_the_object_under_the_pointer() { } } +/// The Eyedropper outlines a selected object too, since its click still acts on it. With Cmd held, +/// a click selects with the selection tool lent to it, so the outline is that tool's: none on a +/// selected object, and the object under the pointer otherwise. Hiding the object under the +/// pointer, or arming Image Trace's Ignore Color pick (which acts on no object), removes the +/// outline without the pointer moving. +#[test] +fn eyedropper_hover_outline_follows_the_selection_cmd_and_the_document() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.select_tool("eyedropper"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(id))); + let rect = egui::Rect::from_two_pos(xf.to_screen(Point::new(100.0, 100.0)), xf.to_screen(Point::new(200.0, 200.0))); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(150.0, 150.0)))]); + assert!(app.session.active().unwrap().selection.contains(vectorcraft_doc::NodeId(id))); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE); + assert!(!at.is_empty() && same_box(screen_box(&at), rect), "a selected object: {:?}", screen_box(&at)); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::COMMAND).is_empty(), "Cmd over a selected object"); + app.session.execute("select.none", &json!({})).unwrap(); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::COMMAND); + assert!(!at.is_empty() && same_box(screen_box(&at), rect), "Cmd over an unselected object: {:?}", screen_box(&at)); + assert!(!hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "Cmd let go"); + app.session.set_tool_option("imageTraceIgnoreColor", &json!({"binding": 1})); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "an armed Ignore Color pick"); + app.session.set_tool_option("imageTraceIgnoreColor", &serde_json::Value::Null); + assert!(!hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "the pick disarmed"); + app.session.execute("object.hide", &json!({"ids": [id]})).unwrap(); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "hidden art"); +} + +/// For a Shift-click the Eyedropper outlines the object whose color the click samples: the blend +/// where one of its steps is drawn, and the rectangle below it in a gap between the steps. +#[test] +fn eyedropper_shift_hover_outlines_the_object_sampled() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let rect = |app: &mut VectorcraftApp, x: f64, y: f64, w: f64, h: f64, color: &str| { + let id = app.session.execute("shape.rectangle", &json!({"x": x, "y": y, "width": w, "height": h})).unwrap()["id"].as_u64().unwrap(); + app.session.execute("paint.setFill", &json!({"ids": [id], "color": color})).unwrap(); + id + }; + let back = rect(&mut app, 20.0, 50.0, 360.0, 150.0, "#00ff00"); + let a = rect(&mut app, 100.0, 100.0, 20.0, 20.0, "#ff0000"); + let b = rect(&mut app, 200.0, 100.0, 20.0, 20.0, "#0000ff"); + app.session.execute("object.blend.make", &json!({"ids": [a, b], "steps": 1})).unwrap(); + app.session.execute("select.none", &json!({})).unwrap(); + app.select_tool("eyedropper"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(back))); + let boxed = |x0: f64, y0: f64, x1: f64, y1: f64| egui::Rect::from_two_pos(xf.to_screen(Point::new(x0, y0)), xf.to_screen(Point::new(x1, y1))); + // One step, halfway: (150, 100) to (170, 120). + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(160.0, 110.0)))]); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::SHIFT); + assert!(!at.is_empty() && same_box(screen_box(&at), boxed(100.0, 100.0, 220.0, 120.0)), "a blend step: {:?}", screen_box(&at)); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(135.0, 110.0)))]); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::SHIFT); + assert!(!at.is_empty() && same_box(screen_box(&at), boxed(20.0, 50.0, 380.0, 200.0)), "a gap between the steps: {:?}", screen_box(&at)); +} + /// The Eyedropper's hover outline follows Smart Guides › Object Highlighting. #[test] fn eyedropper_hover_outline_follows_object_highlighting() { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 143f215fcd..a061ec8a59 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2015,7 +2015,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Pasting into hex color fields:** in the hex fields of the Color Picker, Swatch Options, Recolor Artwork, the Color panel, Document Setup, Duotone, Color Themes and Perspective Grid, a click or keyboard focus selects the digits. A pasted code of six digits, with or without `#`, replaces them wherever the caret is. A pasted code of three digits also replaces them, unless the paste holds only those digits and exactly three digits stay; those digits then edit the text in place. A press on another field commits the text as Tab and Enter do. As VectorCraft's own rule, a paste that is not a color leaves the field as it was. Tests: `a_hex_code_pasted_into_the_hex_field_replaces_its_digits` in `crates/ui-egui/src/dialogs/tests.rs`, `define_grid_takes_a_three_digit_color` in `crates/ui-egui/src/dialogs/tests_perspective.rs` and `a_paste_into_a_hex_field_replaces_or_edits_its_digits` in `crates/ui-egui/src/tests/numfields.rs`. - **Color Picker layout (#2008):** a centered draggable header, equal-width actions above aligned HSB/RGB/Hex and Lab/CMYK fields, compact field and slider, and warnings below the preview. No horizontal scrolling; narrow windows stack the sections with vertical scrolling. Tests in `dialogs/color_picker.rs` cover actual pointer/key input, typed values before OK/Enter, Cancel/Escape rollback, one Undo step, mode-size stability, warnings and layout at two UI scales. The screen sampler sits above the field and the upstream two-grid Tab order is retained. AccessKit regressions check the action names and each channel slider's displayed value, units and range. German and enlarged English UI renders were reviewed locally; no reference images are shipped. This is a layout improvement, with no change to scores or remaining-hour estimates. - **Eyedropper sources (#1251):** ordinary and Shift clicks, Shift+Alt appearance append, raster pixels and gradient-stop sampling can read visible locked/template art and sources outside isolation. Sampling leaves the source and selection intact; Alt reverse still uses editable hits, and hidden art stays excluded. Engine/tool/hit regressions cover the editing boundary, color models and one-step Undo/Redo. The general object/image workflow is described in [public HelpX](https://helpx.adobe.com/illustrator/using/tool-techniques/eyedropper-tool.html); the lock/isolation expectations come from the user report and these regressions, without a new full-parity measurement. - - **Eyedropper hover outline:** as VectorCraft's own behavior, with Smart Guides › Object Highlighting on, the Eyedropper outlines the object a click at the pointer would act on, in the selection tools' 1.5 px layer-color outline: the source a click copies from (locked and template art included), the selected gradient mesh a click recolors, the object below a locked one that an Alt-click gives the selection's attributes to, and for a Shift-click the object whose color is sampled (a blend or envelope where its art is drawn, the art below where it leaves a gap). A selected object is outlined too. Empty canvas, hidden art and a Cmd-click that borrows a selection tool show no outline, and with the Eyedropper or a selection tool, Space held for the view tools hides the outline. Tests: `crates/ui-egui/src/canvas/tests.rs`, `crates/tools/src/xform/eyedropper.rs`. + - **Eyedropper hover outline:** as VectorCraft's own behavior, with Smart Guides › Object Highlighting on, the Eyedropper outlines the object a click at the pointer would act on, in the selection tools' 1.5 px layer-color outline: the source a click copies from (locked and template art included), the selected gradient mesh a click recolors, the front editable object an Alt-click gives the selection's attributes to (the one below when locked art covers it), and for a Shift-click the object whose color is sampled (a blend or envelope where its art is drawn, the art below where it leaves a gap). A selected object is outlined too. With Cmd held, a click selects with the selection tool lent to the Eyedropper, and the outline is that tool's. Empty canvas and hidden art show no outline, and with the Eyedropper or a selection tool, Space held for the view tools hides the outline. Tests: `eyedropper_hover_outlines_the_object_under_the_pointer`, `eyedropper_hover_outline_follows_object_highlighting`, `eyedropper_hover_outline_is_the_object_the_click_acts_on`, `eyedropper_hover_outline_follows_the_selection_cmd_and_the_document` and `eyedropper_shift_hover_outlines_the_object_sampled` in `crates/ui-egui/src/canvas/tests.rs`, and `shift_hover_names_the_object_the_sample_comes_from`, `shift_hover_names_the_envelope_where_its_art_is_drawn` and `hover_names_the_selected_mesh_a_click_recolors` in `crates/tools/src/xform/eyedropper.rs`. - **Eyedropper colors in a CMYK document (#2276):** a CMYK image (a four-component JPEG, or an 8- or 16-bit chunky CMYK TIFF) gives its ink amounts as they are, and an RGB image's pixel or an RGB color given to `paint.setFill`, `paint.setStroke`, `paint.sampleColor` or `swatch.new {color}` (hex input and gradient stops included) is separated through the color settings' CMYK working space and intent, as Document Color Mode converts it. With the default Generic CMYK, RGB 83/170/223 separates to C62 M19 Y0 K0, where the profile-free formula gave C63 M24 Y0 K13. - **RGB input to other commands in a CMYK document:** type colors (`text.create`, `text.setStyle`, `text.setRangeStyle`), a Shape Builder hex fill, `paint.editGradient` stops, freeform gradient points, gradient mesh points (the Mesh tool gives a new point the fill's color in its own model), the Symbol Stainer's color and the swatch commands (`swatch.new {colors}`, `swatch.newGroup`, `swatch.editGroup`, `swatch.edit`) separate RGB through the color settings as `paint.setFill` does: with Generic CMYK, `text.setStyle {fill: "#53aadf"}` gives C62 M19 Y0 K0. A color a swatch already has keeps its model, and a swatch color given with `mode` is converted into that mode only. - **Generic CMYK (SWOP-like):** each ink's 40% and 50% tints gain as [CGATS TR 001](https://registry.color.org/cmyk-registry/cgats_tr_001) gives for SWOP printing, and separations stay within SWOP's [300% total ink limit](https://en.wikipedia.org/wiki/Specifications_for_Web_Offset_Publications). The paper, solid and overprint colors, the black-generation curve and the black point are VectorCraft's own values: RGB black separates to 90% black under neutral cyan, magenta and yellow that fill the ink limit (C75 M68 Y67 K90). The ICC profile written for it (embedded in exports) gives the paper as its media white point, and its colorimetric Lab → CMYK table is the inverse of its CMYK → Lab table, without black-point compensation; the perceptual and saturation tables keep compensation. From 91bfcc7455a794c1c42da64bd8ffef0535e2b17c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 00:04:25 -0800 Subject: [PATCH 3/4] Eyedropper: count a blend's steps before sampling it; hover skips a selected group member Before the Eyedropper evaluates a blend to sample its color, it now counts the steps of every blend the art holds against the work left. When the steps alone exceed it, the blend is not evaluated and the sample gives no color. Hover runs this lookup on every pointer move with Shift held. The Selection tool's hover outline, and the one it shows when lent to the Eyedropper with Cmd, now outlines nothing over a selected group member, where a press keeps the selection. It uses the same rule as the press (select::selected_under_in). Tests: blend_steps_count_before_the_blend_is_evaluated and selection_hover_outline_skips_a_selected_group_member. --- crates/tools/src/select.rs | 15 ++++++-- crates/tools/src/xform/eyedropper.rs | 54 ++++++++++++++++++++++++++- crates/ui-egui/src/canvas/overlays.rs | 9 ++++- crates/ui-egui/src/canvas/tests.rs | 25 +++++++++++++ docs/target-app-parity.md | 2 +- 5 files changed, 98 insertions(+), 7 deletions(-) diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs index fc18a978e6..0ccb8499ed 100644 --- a/crates/tools/src/select.rs +++ b/crates/tools/src/select.rs @@ -1473,15 +1473,22 @@ fn object_behind(cx: &ToolContext, p: Point) -> Option { /// member with only some anchors or segments selected does not count: the press selects `top`. /// A member with every anchor selected (as `select.anchors` and `select.key` leave a path) counts. fn selected_under(cx: &ToolContext, h: &Hit, top: NodeId) -> Option { - if cx.selection.contains(top) { + selected_under_in(cx.doc, cx.selection, h, top) +} + +/// [`selected_under`] in `doc` with `selection`: the selected object a Selection tool press on +/// `h` lands on, where `top` is the object the press would select. The canvas's hover outline +/// outlines nothing where this finds an object. +pub fn selected_under_in(doc: &vectorcraft_doc::Document, selection: &vectorcraft_doc::Selection, h: &Hit, top: NodeId) -> Option { + if selection.contains(top) { return Some(top); } let every_anchor = |id: NodeId| { - cx.selection + selection .partial(id) - .is_none_or(|picked| cx.doc.node(id).and_then(|n| n.path_data()).is_some_and(|p| p.anchors().all(|(s, i, _)| picked.contains(&(s, i))))) + .is_none_or(|picked| doc.node(id).and_then(|n| n.path_data()).is_some_and(|p| p.anchors().all(|(s, i, _)| picked.contains(&(s, i))))) }; - let whole = |id: NodeId| cx.selection.contains(id) && every_anchor(id) && !cx.selection.segments.contains_key(&id); + let whole = |id: NodeId| selection.contains(id) && every_anchor(id) && !selection.segments.contains_key(&id); let below = h.ancestry.iter().position(|id| *id == top).map_or(&[][..], |i| h.ancestry.get(i..).unwrap_or_default()); below.iter().copied().chain(std::iter::once(h.leaf)).find(|id| whole(*id)) } diff --git a/crates/tools/src/xform/eyedropper.rs b/crates/tools/src/xform/eyedropper.rs index 0eb5008fc8..38a6b8cf58 100644 --- a/crates/tools/src/xform/eyedropper.rs +++ b/crates/tools/src/xform/eyedropper.rs @@ -249,14 +249,31 @@ fn drawn_live<'d>(doc: &'d Document, ancestry: &[NodeId]) -> Option<&'d Node> { /// The color the art blend or envelope `n` draws shows at `p`, sampled as [`art_color_at`] samples /// art: a blend's keys and steps, an envelope's distorted contents, symbol instances in them by /// their symbols' art. Evaluating it counts the objects it holds, and the art made counts its -/// objects. +/// objects. When less work is left than the steps of its blends make, it is not evaluated. fn live_color_at(s: &mut Sampler, levels: &mut [Option], n: &Node, p: Point) -> Option { + let steps = blend_steps_in(n); + if s.work < steps { + // Too little work is left for the steps the blends make. + s.spend(steps)?; + } s.spend(n.count())?; let art = vectorcraft_effects::expand_live_deep(Some(s.doc), n); s.spend(art.count())?; art_color_at(s, levels, [art], p) } +/// The steps the blends in `n` and its subtree make between their keys, at the least: a blend +/// inside another blend's keys is counted once, not once for each step that copies it. +fn blend_steps_in(n: &Node) -> usize { + let mut steps = 0usize; + n.walk(&mut |c| { + if let NodeKind::Blend { children, spec } = &c.kind { + steps = vectorcraft_doc::blend::blend_steps(children, spec).into_iter().fold(steps, usize::saturating_add); + } + }); + steps +} + /// The color `n` shows at `p`: an image's pixels, a mesh's interpolated patch color, a symbol /// instance's art, or the color of its fill (or its stroke, when the stroke was hit or there is no /// fill) there. Images, symbols and patterns are looked up in the sampled document. @@ -2009,6 +2026,41 @@ mod tests { assert_eq!(names(480.0, 480.0), None, "no art"); } + /// A blend's steps count as work before it is evaluated: the steps of every blend it holds + /// are counted, and with less work left than that the sample gives no color. + #[test] + fn blend_steps_count_before_the_blend_is_evaluated() { + use vectorcraft_doc::Document; + use vectorcraft_doc::live::{BlendSpacing, BlendSpec}; + use vectorcraft_geom::Rect; + let blend = |d: &mut Document, steps: u32| { + let red = solid_rect(d, Rect::new(300.0, 300.0, 320.0, 320.0), Color::rgb(1.0, 0.0, 0.0)); + let blue = solid_rect(d, Rect::new(400.0, 300.0, 420.0, 320.0), Color::rgb(0.0, 0.0, 1.0)); + let spec = BlendSpec { spacing: BlendSpacing::Steps(steps), ..Default::default() }; + Node::new(d.alloc_id(), NodeKind::Blend { children: vec![std::sync::Arc::new(red), std::sync::Arc::new(blue)], spec: Box::new(spec) }) + }; + let mut scratch = Document::new(500.0, 500.0); + let (big, small) = (blend(&mut scratch, 1000), blend(&mut scratch, 3)); + let rect = solid_rect(&mut scratch, Rect::new(0.0, 0.0, 10.0, 10.0), Color::rgb(0.0, 1.0, 0.0)); + assert_eq!(blend_steps_in(&big), 1000); + assert_eq!(blend_steps_in(&rect), 0); + let group = + Node::new(scratch.alloc_id(), NodeKind::Group { children: vec![std::sync::Arc::new(big), std::sync::Arc::new(small)], clip: false }); + assert_eq!(blend_steps_in(&group), 1003, "every blend in the group"); + + let d = doc_with_live_over_green(|d| blend(d, 1000)); + let (sel, p) = (Selection::default(), paint()); + let cx = cx(&d, &sel, &p); + let opts = sample_options(&cx); + let mut levels: Vec> = (0..MAX_NESTING).map(|_| None).collect(); + let at = Point::new(360.0, 310.0); + let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: 900, exhausted: false, patterns: 0 }; + assert_eq!(color_under(&mut s, &d, &mut levels, at, opts).map(|(c, _)| c.to_hex()), None); + assert!(s.exhausted, "less work left than the blend's 1,000 steps"); + let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: MAX_WORK, exhausted: false, patterns: 0 }; + assert!(color_under(&mut s, &d, &mut levels, at, opts).is_some(), "a step is drawn at the point"); + } + /// For a Shift-click on an envelope, the hover names the envelope where its distorted contents /// are drawn, and the rectangle below where they leave the point empty. #[test] diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index 736bfb999e..351f3b070e 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -38,7 +38,14 @@ pub(super) fn hover_highlight(app: &mut VectorcraftApp, p: &egui::Painter, xf: & let Some(st) = app.session.active() else { return }; let Some(hit) = selection_hit_at(app, h, xf.zoom) else { return }; let id = if tool == "selection" { hit.top_object(st.isolation) } else { hit.leaf }; - if st.selection.contains(id) { + // A Selection tool press on selected art inside `id`, such as a group member picked with + // Group Selection, keeps the selection and selects nothing new. + let kept = if tool == "selection" { + vectorcraft_tools::select::selected_under_in(&st.doc, &st.selection, &hit, id).is_some() + } else { + st.selection.contains(id) + }; + if kept { return; } id diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index c17f11629a..534dbc5562 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -6201,6 +6201,31 @@ fn eyedropper_hover_outline_follows_the_selection_cmd_and_the_document() { assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "hidden art"); } +/// With a group member selected (as Group Selection leaves it), the Selection tool outlines +/// nothing over that member, where a press keeps the selection, and the group over its other +/// member, where a press selects the group. +#[test] +fn selection_hover_outline_skips_a_selected_group_member() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let a = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + let b = app.session.execute("shape.rectangle", &json!({"x": 200, "y": 100, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + app.session.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + app.session.execute("object.group", &json!({})).unwrap(); + app.session.execute("select.set", &json!({"ids": [a]})).unwrap(); + app.select_tool("selection"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let color = c32(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(a))); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(125.0, 125.0)))]); + assert!(hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE).is_empty(), "the selected member"); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(xf.to_screen(Point::new(225.0, 125.0)))]); + let group = egui::Rect::from_two_pos(xf.to_screen(Point::new(100.0, 100.0)), xf.to_screen(Point::new(250.0, 150.0))); + let at = hover_outline_points(&mut app, &ctx, color, egui::Modifiers::NONE); + assert!(!at.is_empty() && same_box(screen_box(&at), group), "the other member: {:?}", screen_box(&at)); +} + /// For a Shift-click the Eyedropper outlines the object whose color the click samples: the blend /// where one of its steps is drawn, and the rectangle below it in a gap between the steps. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index a061ec8a59..eaa809b5f2 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2015,7 +2015,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Pasting into hex color fields:** in the hex fields of the Color Picker, Swatch Options, Recolor Artwork, the Color panel, Document Setup, Duotone, Color Themes and Perspective Grid, a click or keyboard focus selects the digits. A pasted code of six digits, with or without `#`, replaces them wherever the caret is. A pasted code of three digits also replaces them, unless the paste holds only those digits and exactly three digits stay; those digits then edit the text in place. A press on another field commits the text as Tab and Enter do. As VectorCraft's own rule, a paste that is not a color leaves the field as it was. Tests: `a_hex_code_pasted_into_the_hex_field_replaces_its_digits` in `crates/ui-egui/src/dialogs/tests.rs`, `define_grid_takes_a_three_digit_color` in `crates/ui-egui/src/dialogs/tests_perspective.rs` and `a_paste_into_a_hex_field_replaces_or_edits_its_digits` in `crates/ui-egui/src/tests/numfields.rs`. - **Color Picker layout (#2008):** a centered draggable header, equal-width actions above aligned HSB/RGB/Hex and Lab/CMYK fields, compact field and slider, and warnings below the preview. No horizontal scrolling; narrow windows stack the sections with vertical scrolling. Tests in `dialogs/color_picker.rs` cover actual pointer/key input, typed values before OK/Enter, Cancel/Escape rollback, one Undo step, mode-size stability, warnings and layout at two UI scales. The screen sampler sits above the field and the upstream two-grid Tab order is retained. AccessKit regressions check the action names and each channel slider's displayed value, units and range. German and enlarged English UI renders were reviewed locally; no reference images are shipped. This is a layout improvement, with no change to scores or remaining-hour estimates. - **Eyedropper sources (#1251):** ordinary and Shift clicks, Shift+Alt appearance append, raster pixels and gradient-stop sampling can read visible locked/template art and sources outside isolation. Sampling leaves the source and selection intact; Alt reverse still uses editable hits, and hidden art stays excluded. Engine/tool/hit regressions cover the editing boundary, color models and one-step Undo/Redo. The general object/image workflow is described in [public HelpX](https://helpx.adobe.com/illustrator/using/tool-techniques/eyedropper-tool.html); the lock/isolation expectations come from the user report and these regressions, without a new full-parity measurement. - - **Eyedropper hover outline:** as VectorCraft's own behavior, with Smart Guides › Object Highlighting on, the Eyedropper outlines the object a click at the pointer would act on, in the selection tools' 1.5 px layer-color outline: the source a click copies from (locked and template art included), the selected gradient mesh a click recolors, the front editable object an Alt-click gives the selection's attributes to (the one below when locked art covers it), and for a Shift-click the object whose color is sampled (a blend or envelope where its art is drawn, the art below where it leaves a gap). A selected object is outlined too. With Cmd held, a click selects with the selection tool lent to the Eyedropper, and the outline is that tool's. Empty canvas and hidden art show no outline, and with the Eyedropper or a selection tool, Space held for the view tools hides the outline. Tests: `eyedropper_hover_outlines_the_object_under_the_pointer`, `eyedropper_hover_outline_follows_object_highlighting`, `eyedropper_hover_outline_is_the_object_the_click_acts_on`, `eyedropper_hover_outline_follows_the_selection_cmd_and_the_document` and `eyedropper_shift_hover_outlines_the_object_sampled` in `crates/ui-egui/src/canvas/tests.rs`, and `shift_hover_names_the_object_the_sample_comes_from`, `shift_hover_names_the_envelope_where_its_art_is_drawn` and `hover_names_the_selected_mesh_a_click_recolors` in `crates/tools/src/xform/eyedropper.rs`. + - **Eyedropper hover outline:** as VectorCraft's own behavior, with Smart Guides › Object Highlighting on, the Eyedropper outlines the object a click at the pointer would act on, in the selection tools' 1.5 px layer-color outline: the source a click copies from (locked and template art included), the selected gradient mesh a click recolors, the front editable object an Alt-click gives the selection's attributes to (the one below when locked art covers it), and for a Shift-click the object whose color is sampled (a blend or envelope where its art is drawn, the art below where it leaves a gap). A selected object is outlined too. With Cmd held, a click selects with the selection tool lent to the Eyedropper, and the outline is that tool's. The Selection tool's outline, lent or not, leaves out a group whose selected member is under the pointer, where a press keeps the selection. Finding a Shift-click's sample counts a blend's steps before the blend is evaluated. Empty canvas and hidden art show no outline, and with the Eyedropper or a selection tool, Space held for the view tools hides the outline. Tests: `eyedropper_hover_outlines_the_object_under_the_pointer`, `eyedropper_hover_outline_follows_object_highlighting`, `eyedropper_hover_outline_is_the_object_the_click_acts_on`, `eyedropper_hover_outline_follows_the_selection_cmd_and_the_document`, `selection_hover_outline_skips_a_selected_group_member` and `eyedropper_shift_hover_outlines_the_object_sampled` in `crates/ui-egui/src/canvas/tests.rs`, and `shift_hover_names_the_object_the_sample_comes_from`, `shift_hover_names_the_envelope_where_its_art_is_drawn`, `hover_names_the_selected_mesh_a_click_recolors` and `blend_steps_count_before_the_blend_is_evaluated` in `crates/tools/src/xform/eyedropper.rs`. - **Eyedropper colors in a CMYK document (#2276):** a CMYK image (a four-component JPEG, or an 8- or 16-bit chunky CMYK TIFF) gives its ink amounts as they are, and an RGB image's pixel or an RGB color given to `paint.setFill`, `paint.setStroke`, `paint.sampleColor` or `swatch.new {color}` (hex input and gradient stops included) is separated through the color settings' CMYK working space and intent, as Document Color Mode converts it. With the default Generic CMYK, RGB 83/170/223 separates to C62 M19 Y0 K0, where the profile-free formula gave C63 M24 Y0 K13. - **RGB input to other commands in a CMYK document:** type colors (`text.create`, `text.setStyle`, `text.setRangeStyle`), a Shape Builder hex fill, `paint.editGradient` stops, freeform gradient points, gradient mesh points (the Mesh tool gives a new point the fill's color in its own model), the Symbol Stainer's color and the swatch commands (`swatch.new {colors}`, `swatch.newGroup`, `swatch.editGroup`, `swatch.edit`) separate RGB through the color settings as `paint.setFill` does: with Generic CMYK, `text.setStyle {fill: "#53aadf"}` gives C62 M19 Y0 K0. A color a swatch already has keeps its model, and a swatch color given with `mode` is converted into that mode only. - **Generic CMYK (SWOP-like):** each ink's 40% and 50% tints gain as [CGATS TR 001](https://registry.color.org/cmyk-registry/cgats_tr_001) gives for SWOP printing, and separations stay within SWOP's [300% total ink limit](https://en.wikipedia.org/wiki/Specifications_for_Web_Offset_Publications). The paper, solid and overprint colors, the black-generation curve and the black point are VectorCraft's own values: RGB black separates to 90% black under neutral cyan, magenta and yellow that fill the ink limit (C75 M68 Y67 K90). The ICC profile written for it (embedded in exports) gives the paper as its media white point, and its colorimetric Lab → CMYK table is the inverse of its CMYK → Lab table, without black-point compensation; the perceptual and saturation tables keep compensation. From a935af00151607b160fa477bc6d903aaa5c0c9d6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 00:34:42 -0800 Subject: [PATCH 4/4] Eyedropper: count the steps that copy a nested blend before sampling it Each step of a blend whose keys are blends is a copy of one of them, which makes its own steps when drawn. The work check before a blend is evaluated now counts those steps too, with the same count the blend uses to fit its steps (`vectorcraft_doc::blend::blend_steps_made`), so a nested blend with more steps than the work left is not evaluated. Tests check that the blend is not evaluated when the work left is too little, for a plain blend and for an outer blend of nested blends. --- crates/doc/src/blend.rs | 7 +++ crates/tools/src/xform/eyedropper.rs | 74 ++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/crates/doc/src/blend.rs b/crates/doc/src/blend.rs index 02458af8c5..64545d1bcf 100644 --- a/crates/doc/src/blend.rs +++ b/crates/doc/src/blend.rs @@ -2186,6 +2186,13 @@ pub fn blend_steps(keys: &[Arc], spec: &BlendSpec) -> Vec { StepCount::default().blend(keys, spec, Rail::new(keys, spec).as_ref()).0 } +/// Most steps the blends in `n` and its subtree make in all when drawn: a step that copies a +/// blend counts that blend's steps again, and each instance of a repeat counts its source's +/// steps again. Objects that are not blend steps count 0. +pub fn blend_steps_made(n: &Node) -> usize { + StepCount::default().node(n, false) +} + /// Does each pair of `keys` blended with `spec` ask for the same number of steps /// ([`blend_step_count`]) when each coordinate it counts from moves by up to `length` points and, /// for Smooth Color, the difference between keys of different colors by up to `color` (0 to 1)? diff --git a/crates/tools/src/xform/eyedropper.rs b/crates/tools/src/xform/eyedropper.rs index 38a6b8cf58..0c63f2f21c 100644 --- a/crates/tools/src/xform/eyedropper.rs +++ b/crates/tools/src/xform/eyedropper.rs @@ -249,29 +249,26 @@ fn drawn_live<'d>(doc: &'d Document, ancestry: &[NodeId]) -> Option<&'d Node> { /// The color the art blend or envelope `n` draws shows at `p`, sampled as [`art_color_at`] samples /// art: a blend's keys and steps, an envelope's distorted contents, symbol instances in them by /// their symbols' art. Evaluating it counts the objects it holds, and the art made counts its -/// objects. When less work is left than the steps of its blends make, it is not evaluated. +/// objects. When less work is left than the steps of its blends make in all, the steps that copy +/// a nested blend included ([`vectorcraft_doc::blend::blend_steps_made`]), it is not evaluated. fn live_color_at(s: &mut Sampler, levels: &mut [Option], n: &Node, p: Point) -> Option { - let steps = blend_steps_in(n); + let steps = vectorcraft_doc::blend::blend_steps_made(n); if s.work < steps { // Too little work is left for the steps the blends make. s.spend(steps)?; } s.spend(n.count())?; + #[cfg(test)] + EXPANSIONS.with(|e| e.set(e.get() + 1)); let art = vectorcraft_effects::expand_live_deep(Some(s.doc), n); s.spend(art.count())?; art_color_at(s, levels, [art], p) } -/// The steps the blends in `n` and its subtree make between their keys, at the least: a blend -/// inside another blend's keys is counted once, not once for each step that copies it. -fn blend_steps_in(n: &Node) -> usize { - let mut steps = 0usize; - n.walk(&mut |c| { - if let NodeKind::Blend { children, spec } = &c.kind { - steps = vectorcraft_doc::blend::blend_steps(children, spec).into_iter().fold(steps, usize::saturating_add); - } - }); - steps +#[cfg(test)] +thread_local! { + /// The blends and envelopes [`live_color_at`] has evaluated on this thread. + static EXPANSIONS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// The color `n` shows at `p`: an image's pixels, a mesh's interpolated patch color, a symbol @@ -2027,10 +2024,12 @@ mod tests { } /// A blend's steps count as work before it is evaluated: the steps of every blend it holds - /// are counted, and with less work left than that the sample gives no color. + /// are counted, and with less work left than that the sample gives no color and the blend is + /// not evaluated. #[test] fn blend_steps_count_before_the_blend_is_evaluated() { use vectorcraft_doc::Document; + use vectorcraft_doc::blend::blend_steps_made; use vectorcraft_doc::live::{BlendSpacing, BlendSpec}; use vectorcraft_geom::Rect; let blend = |d: &mut Document, steps: u32| { @@ -2042,11 +2041,11 @@ mod tests { let mut scratch = Document::new(500.0, 500.0); let (big, small) = (blend(&mut scratch, 1000), blend(&mut scratch, 3)); let rect = solid_rect(&mut scratch, Rect::new(0.0, 0.0, 10.0, 10.0), Color::rgb(0.0, 1.0, 0.0)); - assert_eq!(blend_steps_in(&big), 1000); - assert_eq!(blend_steps_in(&rect), 0); + assert_eq!(blend_steps_made(&big), 1000); + assert_eq!(blend_steps_made(&rect), 0); let group = Node::new(scratch.alloc_id(), NodeKind::Group { children: vec![std::sync::Arc::new(big), std::sync::Arc::new(small)], clip: false }); - assert_eq!(blend_steps_in(&group), 1003, "every blend in the group"); + assert_eq!(blend_steps_made(&group), 1003, "every blend in the group"); let d = doc_with_live_over_green(|d| blend(d, 1000)); let (sel, p) = (Selection::default(), paint()); @@ -2054,11 +2053,54 @@ mod tests { let opts = sample_options(&cx); let mut levels: Vec> = (0..MAX_NESTING).map(|_| None).collect(); let at = Point::new(360.0, 310.0); + let evaluated = || EXPANSIONS.with(std::cell::Cell::get); + let before = evaluated(); let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: 900, exhausted: false, patterns: 0 }; assert_eq!(color_under(&mut s, &d, &mut levels, at, opts).map(|(c, _)| c.to_hex()), None); assert!(s.exhausted, "less work left than the blend's 1,000 steps"); + assert_eq!(evaluated(), before, "the blend is not evaluated"); let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: MAX_WORK, exhausted: false, patterns: 0 }; assert!(color_under(&mut s, &d, &mut levels, at, opts).is_some(), "a step is drawn at the point"); + assert!(evaluated() > before, "with enough work the blend is evaluated"); + } + + /// Each step of a blend whose keys are blends is a copy of one of them, so the steps it makes + /// in all count before it is evaluated: an outer blend of 20 steps between two blends of 100 + /// steps makes more than 2,000, though its blends have 220 steps between their own keys. + #[test] + fn steps_that_copy_a_nested_blend_count_before_it_is_evaluated() { + use vectorcraft_doc::Document; + use vectorcraft_doc::live::{BlendSpacing, BlendSpec}; + use vectorcraft_geom::Rect; + let blend = |d: &mut Document, keys: Vec, steps: u32| { + let spec = BlendSpec { spacing: BlendSpacing::Steps(steps), ..Default::default() }; + Node::new(d.alloc_id(), NodeKind::Blend { children: keys.into_iter().map(std::sync::Arc::new).collect(), spec: Box::new(spec) }) + }; + let inner = |d: &mut Document, y: f64| { + let red = solid_rect(d, Rect::new(300.0, y, 320.0, y + 10.0), Color::rgb(1.0, 0.0, 0.0)); + let blue = solid_rect(d, Rect::new(400.0, y, 420.0, y + 10.0), Color::rgb(0.0, 0.0, 1.0)); + blend(d, vec![red, blue], 100) + }; + let d = doc_with_live_over_green(|d| { + let (a, b) = (inner(d, 300.0), inner(d, 330.0)); + blend(d, vec![a, b], 20) + }); + let outer = d.layers[0].children().unwrap().last().unwrap(); + assert!(vectorcraft_doc::blend::blend_steps_made(outer) > 2_000, "the copies' steps count"); + let (sel, p) = (Selection::default(), paint()); + let cx = cx(&d, &sel, &p); + let opts = sample_options(&cx); + let mut levels: Vec> = (0..MAX_NESTING).map(|_| None).collect(); + let at = Point::new(310.0, 305.0); + let evaluated = || EXPANSIONS.with(std::cell::Cell::get); + let before = evaluated(); + let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: 1_000, exhausted: false, patterns: 0 }; + assert_eq!(color_under(&mut s, &d, &mut levels, at, opts).map(|(c, _)| c.to_hex()), None); + assert!(s.exhausted, "less work left than the steps the outer blend makes"); + assert_eq!(evaluated(), before, "the outer blend is not evaluated"); + let mut s = Sampler { doc: &d, opts, raster_sample: cx.raster_sample, symbol_nodes: 0, work: MAX_WORK, exhausted: false, patterns: 0 }; + assert!(color_under(&mut s, &d, &mut levels, at, opts).is_some(), "a key is drawn at the point"); + assert!(evaluated() > before, "with enough work the outer blend is evaluated"); } /// For a Shift-click on an envelope, the hover names the envelope where its distorted contents