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.
This commit is contained in:
dotCooCoo committed 2026-11-19 21:44:13 -08:00
1 parent 54f58fff31
commit d2aede7c6e
9 files changed
+427 -82

No files matched your search

+11 -1
View File
@@ -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<NodeId> {
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
+6
View File
@@ -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<NodeId> {
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.
+186 -72
View File
@@ -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<Color> {
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<Color> {
})
}
/// 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<Document>], p: Point, opts: HitOptions) -> Option<Color> {
fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option<Document>], p: Point, opts: HitOptions) -> Option<(Color, NodeId)> {
let mut passed: HashSet<NodeId> = HashSet::new();
let mut size = None;
loop {
@@ -197,7 +206,7 @@ fn color_under(s: &mut Sampler, doc: &Document, levels: &mut [Option<Document>],
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<Document>],
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<Document>], 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<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 }))] };
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<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;
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<NodeId> {
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<usize>, 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<NodeId>, stop: Option<(String, usize)> },
}
impl Click {
/// The object of the document the click reads from or writes to.
fn object(&self) -> Option<NodeId> {
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<Click> {
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<Option<Document>> = (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<NodeId> = 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.
+1
View File
@@ -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(),
+4
View File
@@ -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<vectorcraft_doc::NodeId>)>,
/// 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<egui::Rect>,
+2 -2
View File
@@ -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;
+80 -7
View File
@@ -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<vectorcraft_doc::NodeId>,
options: serde_json::Value,
paint: vectorcraft_tools::PaintDefaults,
fill_active: bool,
stop: Option<usize>,
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<vectorcraft_doc::NodeId> {
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) {
+136
View File
@@ -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<Pos2> {
fn flat(s: Shape, out: &mut Vec<Shape>) {
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]
+1
View File
@@ -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.