mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 18:56:55 -06:00
Part of #394: Preferences that act on selection, the wheel, tool tips and the grid
Fifteen Preferences options were stored but read by nothing. They now act, through the existing plumbing (ToolContext for the tools, the prefs read by the canvas for the view), and reach agents through prefs.set: - General: Show Tool Tips (off: no widget's tool tip comes due), Double Click To Isolate, Zoom with Mouse Wheel (the wheel zooms about the pointer, Shift-wheel scrolls up and down, Cmd/Ctrl-wheel sideways), Use Precise Cursors (Pen, Eyedropper, Slice and Blend pointers become a crosshair). - Selection & Anchor Display: Tolerance (objects, anchors and handles, in place of the fixed 3 and 4 px), Object Selection by Path Only (compound paths too), Command Click to Select Objects Behind (cycles down the objects under the pointer; not when Cmd only borrows the selection tool), Zoom to Selection (Zoom In/Out centre the selection), anchor Size, Highlight anchors on mouse over (Direct Selection). - Type: Number of Recent Fonts (up to 15 Recent Fonts slots). - Guides & Grid: guide and grid Color and Style (lines or dots), Grids In Back. The canvas's context menu, panel drops and hover highlight pick objects like the selection tools. The control channel gets ui.wheel (with modifiers held like ui.click) so agents can turn the wheel. The rest of #394 stays open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f7a03160d6
commit
47bed05ff4
@@ -95,11 +95,13 @@ pub struct DirectSelectionTool {
|
||||
mesh: MeshEdit,
|
||||
/// Smart guides of the handle being dragged.
|
||||
guides: Vec<Overlay>,
|
||||
/// The anchor under the pointer (Highlight anchors on mouse over): its path, where it is.
|
||||
hover: Option<(NodeId, Point)>,
|
||||
}
|
||||
|
||||
impl DirectSelectionTool {
|
||||
pub fn new(group: bool) -> Self {
|
||||
Self { group, state: State::Idle, spine: None, mesh: MeshEdit::default(), guides: vec![] }
|
||||
Self { group, state: State::Idle, spine: None, mesh: MeshEdit::default(), guides: vec![], hover: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +238,7 @@ impl Tool for DirectSelectionTool {
|
||||
}
|
||||
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
|
||||
let p = ev.pos;
|
||||
let tol = cx.tol(4.0);
|
||||
let tol = cx.pick_tol();
|
||||
match (ev.kind, self.state.clone()) {
|
||||
(PointerKind::Down, _) if self.group => {
|
||||
let Some(h) = hit_test(cx.doc, p, cx.hit_options()) else {
|
||||
@@ -260,6 +262,10 @@ impl Tool for DirectSelectionTool {
|
||||
}
|
||||
}
|
||||
(PointerKind::DoubleClick, _) if !self.group => corners::double_click(cx, p).into_iter().collect(),
|
||||
(PointerKind::Move, State::Idle) => {
|
||||
self.hover = if self.group || !cx.highlight_anchors { None } else { hovered_anchor(cx, p) };
|
||||
vec![]
|
||||
}
|
||||
(PointerKind::Down, _) => {
|
||||
if let Some(c) = CornerDrag::hit(cx, ev) {
|
||||
self.state = State::Corner(c);
|
||||
@@ -492,6 +498,9 @@ impl Tool for DirectSelectionTool {
|
||||
if matches!(self.state, State::Handle { .. }) {
|
||||
out.extend(self.guides.iter().cloned());
|
||||
}
|
||||
if let Some((id, p)) = self.hover.filter(|_| matches!(self.state, State::Idle)) {
|
||||
out.push(Overlay::Anchor { p, color: cx.doc.layer_color(id), filled: false, size: 8.0 });
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
@@ -504,6 +513,17 @@ impl Tool for DirectSelectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The anchor within the selection tolerance of `p`, of a selected path or the path under `p`:
|
||||
/// what Highlight anchors on mouse over marks (a press there picks it).
|
||||
fn hovered_anchor(cx: &ToolContext, p: Point) -> Option<(NodeId, Point)> {
|
||||
let under = hit_test(cx.doc, p, cx.hit_options()).map(|h| h.leaf);
|
||||
let tol = cx.pick_tol();
|
||||
cx.selection.objects.iter().copied().chain(under).find_map(|id| {
|
||||
let path = cx.doc.node(id).and_then(editable_path)?;
|
||||
path.anchors().find(|(_, _, a)| a.p.distance(p) <= tol).map(|(_, _, a)| (id, a.p))
|
||||
})
|
||||
}
|
||||
|
||||
/// The frame anchors of the selected area type, which Direct Selection drags.
|
||||
fn frame_overlays(cx: &ToolContext) -> Vec<Overlay> {
|
||||
let mut out = vec![];
|
||||
@@ -564,6 +584,30 @@ mod tests {
|
||||
(d, g, k1)
|
||||
}
|
||||
|
||||
/// Highlight anchors on mouse over (#394): the anchor under the pointer, within the selection
|
||||
/// tolerance, shows enlarged; none with the preference off or away from anchors.
|
||||
#[test]
|
||||
fn the_anchor_under_the_pointer_is_highlighted() {
|
||||
let (d, id) = doc_with_rect();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let big = |t: &DirectSelectionTool, cx: &ToolContext| {
|
||||
t.overlays(cx).into_iter().find_map(|o| match o {
|
||||
Overlay::Anchor { p, size, .. } if size > 5.0 => Some(p),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
let mut t = DirectSelectionTool::new(false);
|
||||
let on = cx(&d, &s, &p);
|
||||
t.pointer(&on, &PointerEvent::new(PointerKind::Move, 102.0, 101.0));
|
||||
assert_eq!(big(&t, &on), Some(Point::new(100.0, 100.0)), "the corner of {id:?}");
|
||||
t.pointer(&on, &PointerEvent::new(PointerKind::Move, 150.0, 100.0));
|
||||
assert_eq!(big(&t, &on), None, "mid-segment: no anchor");
|
||||
let off = ToolContext { highlight_anchors: false, ..cx(&d, &s, &p) };
|
||||
t.pointer(&off, &PointerEvent::new(PointerKind::Move, 102.0, 101.0));
|
||||
assert_eq!(big(&t, &off), None, "off");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_a_spine_point_moves_it() {
|
||||
let (d, g, _) = blend_doc();
|
||||
|
||||
+47
-1
@@ -253,6 +253,22 @@ pub struct ToolContext<'a> {
|
||||
/// General → Disable Auto Add/Delete is off: the Pen adds an anchor on a selected path's
|
||||
/// segment and deletes one of its anchors.
|
||||
pub auto_add_delete: bool,
|
||||
/// Selection & Anchor Display → Tolerance: how near (screen pixels) a click must be to a path
|
||||
/// or an anchor to pick it.
|
||||
pub selection_tolerance: f64,
|
||||
/// Selection & Anchor Display → Object Selection by Path Only: a click inside a filled path
|
||||
/// doesn't pick it, only one on its path does.
|
||||
pub path_only: bool,
|
||||
/// General → Double Click To Isolate: a double-click on a group with the Selection tool
|
||||
/// isolates it.
|
||||
pub double_click_isolate: bool,
|
||||
/// Selection & Anchor Display → Command Click to Select Objects Behind: Cmd/Ctrl-click with the
|
||||
/// Selection tool selects the object under the selected one, the next click the one under
|
||||
/// that.
|
||||
pub select_behind: bool,
|
||||
/// Selection & Anchor Display → Highlight anchors on mouse over: Direct Selection marks the
|
||||
/// anchor under the pointer.
|
||||
pub highlight_anchors: bool,
|
||||
/// The document window (none headless): screen-fixed widgets sit in it.
|
||||
pub screen: Option<ScreenFrame>,
|
||||
/// Where the Plane Switching Widget sits (Perspective Grid Options); None while it's hidden.
|
||||
@@ -276,8 +292,12 @@ impl ToolContext<'_> {
|
||||
pub fn offset_label(&self, dx: f64, dy: f64) -> String {
|
||||
format!("dX: {}\ndY: {}", self.len(dx), self.len(dy))
|
||||
}
|
||||
/// The selection tolerance in document units ([`Self::selection_tolerance`]).
|
||||
pub fn pick_tol(&self) -> f64 {
|
||||
self.tol(self.selection_tolerance)
|
||||
}
|
||||
pub fn hit_options(&self) -> vectorcraft_doc::hit::HitOptions {
|
||||
vectorcraft_doc::hit::HitOptions { tol: self.tol(3.0), outline: self.outline, path_only: false }
|
||||
vectorcraft_doc::hit::HitOptions { tol: self.pick_tol(), outline: self.outline, path_only: self.path_only }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,6 +376,27 @@ pub enum Cursor {
|
||||
BlendAnchor,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
/// General › Use Precise Cursors: the drawing tools' pointers (the Pen's in every state, the
|
||||
/// Eyedropper's, the Slice and Blend tools') become a plain crosshair at the hotspot.
|
||||
pub fn precise(self) -> Self {
|
||||
match self {
|
||||
Cursor::Pen
|
||||
| Cursor::PenAdd
|
||||
| Cursor::PenDelete
|
||||
| Cursor::PenClose
|
||||
| Cursor::PenContinue
|
||||
| Cursor::PenConvert
|
||||
| Cursor::Eyedropper
|
||||
| Cursor::Slice
|
||||
| Cursor::Blend
|
||||
| Cursor::BlendObject
|
||||
| Cursor::BlendAnchor => Cursor::Crosshair,
|
||||
c => c,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A tool state machine.
|
||||
pub trait Tool: Send {
|
||||
fn id(&self) -> &'static str;
|
||||
@@ -524,6 +565,11 @@ pub(crate) mod testutil {
|
||||
slices_hidden: false,
|
||||
slices_locked: false,
|
||||
auto_add_delete: true,
|
||||
selection_tolerance: 3.0,
|
||||
path_only: false,
|
||||
double_click_isolate: true,
|
||||
select_behind: true,
|
||||
highlight_anchors: true,
|
||||
screen: None,
|
||||
plane_widget: Some(Default::default()),
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//! The Selection tool (V): click/shift-click, marquee, move (Alt copies, Shift constrains),
|
||||
//! bounding-box scale (Shift proportional, Alt from centre) and rotate (outside corners, Shift 45°),
|
||||
//! drag a live rectangle's corner widget to round its corners (Alt-click cycles their kind,
|
||||
//! double-click opens the Corners dialog), double-click to enter isolation mode.
|
||||
//! double-click opens the Corners dialog), double-click to enter isolation mode (Double Click To
|
||||
//! Isolate), Cmd/Ctrl-click to select the object behind (Command Click to Select Objects Behind).
|
||||
//! The bounding box stands at the selection's own angle after a rotation, so its handles scale
|
||||
//! along the objects' axes. A handle drag resizes area type's frame (the type area) instead of
|
||||
//! scaling its type: the text reflows at its size.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::hit::{hit_test, marquee};
|
||||
use vectorcraft_doc::hit::{hit_test, marquee, objects_at};
|
||||
use vectorcraft_doc::{NodeId, OrientedBox};
|
||||
use vectorcraft_geom::{Affine, Point, Rect};
|
||||
|
||||
@@ -114,7 +115,7 @@ impl Tool for SelectionTool {
|
||||
}
|
||||
if let Some(h) = hit_test(cx.doc, p, cx.hit_options()) {
|
||||
let top = h.top_object(cx.isolation);
|
||||
if cx.doc.node(top).is_some_and(|n| matches!(n.kind, vectorcraft_doc::NodeKind::Group { .. })) {
|
||||
if cx.double_click_isolate && cx.doc.node(top).is_some_and(|n| matches!(n.kind, vectorcraft_doc::NodeKind::Group { .. })) {
|
||||
return vec![Action::Exec("object.isolate".into(), json!({ "id": top.0 }))];
|
||||
}
|
||||
if cx.doc.node(top).is_some_and(|n| matches!(n.kind, vectorcraft_doc::NodeKind::Text(_))) {
|
||||
@@ -152,7 +153,14 @@ impl Tool for SelectionTool {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
// 2. Objects.
|
||||
// 2. Objects: Cmd/Ctrl-click selects the one under the selected one (cycling).
|
||||
if m.cmd
|
||||
&& cx.select_behind
|
||||
&& let Some(behind) = object_behind(cx, p)
|
||||
{
|
||||
self.state = State::Moving { start: p, began: false, deselect: None };
|
||||
return vec![Action::Exec("select.set".into(), json!({ "ids": [behind.0] }))];
|
||||
}
|
||||
match hit_test(cx.doc, p, cx.hit_options()) {
|
||||
Some(h) => {
|
||||
let top = h.top_object(cx.isolation);
|
||||
@@ -321,6 +329,14 @@ impl Tool for SelectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Select Behind: of the objects under `p` (topmost first), the one below the lowest selected
|
||||
/// one, back to the topmost after the bottom one; the topmost when none is selected.
|
||||
fn object_behind(cx: &ToolContext, p: Point) -> Option<NodeId> {
|
||||
let stack = objects_at(cx.doc, p, cx.hit_options(), cx.isolation);
|
||||
let next = stack.iter().rposition(|id| cx.selection.contains(*id)).map_or(0, |i| i + 1);
|
||||
stack.get(next).or(stack.first()).copied()
|
||||
}
|
||||
|
||||
/// Is `n` area type (text in a frame) whose frame the tools reshape? Type in perspective isn't:
|
||||
/// it transforms whole.
|
||||
pub(crate) fn is_area_type(n: &vectorcraft_doc::Node) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user