Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Curvature Pen: edit finished paths (drag, add, smooth/corner) with an adaptive cursor (#5197)

baz21c7cf637aa9
diff --git a/crates/engine/src/path_edit_cmds.rs b/crates/engine/src/path_edit_cmds.rs
index 6db84c270..503ac8efa 100644
--- a/crates/engine/src/path_edit_cmds.rs
+++ b/crates/engine/src/path_edit_cmds.rs
@@ -80,6 +80,9 @@ fn move_anchors(s: &mut Session, p: &Value) -> Result<Value> {
})
.collect::<Result<_>>()?;
let d = offset(CMD, p)?;
+ if p.get("curvature").and_then(Value::as_bool).unwrap_or(false) {
+ return edit_path(s, CMD, p, "Drag Anchor Points", |path| edit::move_anchors_curvature(path, &anchors, d));
+ }
edit_path(s, CMD, p, "Drag Anchor Points", |path| edit::move_anchors(path, &anchors, d))
}
@@ -106,6 +109,9 @@ fn bend_segment(s: &mut Session, p: &Value) -> Result<Value> {
fn convert_point(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "path.convertPoint";
let k = knot(CMD, p)?;
+ if p.get("curvature").and_then(Value::as_bool).unwrap_or(false) {
+ return edit_path(s, CMD, p, "Convert Point", |path| edit::toggle_curvature_point(path, k));
+ }
let out = point(CMD, p, "out")?;
edit_path(s, CMD, p, "Convert Point", |path| edit::convert_point(path, k, out))
}
@@ -155,7 +161,7 @@ pub fn specs() -> Vec<CommandSpec> {
journal: true,
};
vec![
- spec("path.moveAnchors", "Drag Anchor Points", r#""anchors":[[subpath,knot],…],"move":[dx,dy] (anchors move with their handles; Direct Selection drag)"#.into(), move_anchors),
+ spec("path.moveAnchors", "Drag Anchor Points", r#""anchors":[[subpath,knot],…],"move":[dx,dy],"curvature":bool=false (anchors move with their handles; Direct Selection drag. curvature = the Curvature Pen's drag: every smooth knot of the touched subpaths gets its handles recomputed so the curve flows through the anchors)"#.into(), move_anchors),
spec(
"path.moveHandle",
"Drag Direction Point",
@@ -171,7 +177,7 @@ pub fn specs() -> Vec<CommandSpec> {
spec(
"path.convertPoint",
"Convert Point",
- r#""subpath":i,"knot":j,"out":[x,y]? (none: corner with retracted handles; given: smooth with this out handle and its mirror)"#.into(),
+ r#""subpath":i,"knot":j,"out":[x,y]? (none: corner with retracted handles; given: smooth with this out handle and its mirror),"curvature":bool=false (the Curvature Pen's double-click: toggles smooth/corner and reflows the smooth knots of the subpath; out ignored)"#.into(),
convert_point,
),
spec(
@@ -226,6 +232,36 @@ mod tests {
assert_eq!(work(&s), before);
}
+ #[test]
+ fn a_curvature_anchor_drag_reflows_the_smooth_knots() {
+ let mut s = session();
+ let smooth = |a: [f64; 2]| json!({"anchor": a, "in": a, "out": a, "smooth": true});
+ let path = json!({"subpaths": [{"closed": true, "knots": [smooth([0.0, 50.0]), smooth([100.0, 0.0]), smooth([200.0, 50.0]), smooth([100.0, 100.0])]}]});
+ s.execute("path.set", json!({"path": path})).unwrap();
+ s.execute("path.moveAnchors", json!({"anchors": [[0, 1]], "move": [0, 60], "curvature": true})).unwrap();
+ let p = work(&s);
+ let pts = [[0.0, 50.0], [100.0, 60.0], [200.0, 50.0], [100.0, 100.0]];
+ let want = photocraft_vector::edit::curvature_knots(&pts, &[false; 4], true);
+ for (k, w) in p.subpaths[0].knots.iter().zip(want) {
+ assert_eq!([[k.anchor.x, k.anchor.y], [k.in_ctrl.x, k.in_ctrl.y], [k.out_ctrl.x, k.out_ctrl.y]], w);
+ }
+ assert_eq!(s.active().unwrap().history.undo_label(), Some("Drag Anchor Points"));
+ assert!(s.execute("path.moveAnchors", json!({"anchors": [[0, 9]], "move": [1, 0], "curvature": true})).is_err());
+ }
+
+ #[test]
+ fn a_curvature_convert_toggles_the_point_and_reflows() {
+ let mut s = session();
+ s.execute("path.set", json!({"path": square()})).unwrap();
+ let before = work(&s);
+ s.execute("path.convertPoint", json!({"subpath": 0, "knot": 1, "curvature": true})).unwrap();
+ let k = work(&s).subpaths[0].knots[1];
+ assert!(k.smooth && k.in_ctrl != k.anchor && k.out_ctrl != k.anchor, "{k:?}");
+ s.execute("path.convertPoint", json!({"subpath": 0, "knot": 1, "curvature": true})).unwrap();
+ assert_eq!(work(&s), before);
+ assert!(s.execute("path.convertPoint", json!({"subpath": 0, "knot": 9, "curvature": true})).is_err());
+ }
+
#[test]
fn a_coalesced_drag_is_one_history_step() {
let mut s = session();
diff --git a/crates/ui-egui/src/direct_select.rs b/crates/ui-egui/src/direct_select.rs
index addd5fd0d..26fba5dad 100644
--- a/crates/ui-egui/src/direct_select.rs
+++ b/crates/ui-egui/src/direct_select.rs
@@ -67,6 +67,10 @@ pub struct DirectSelection {
pub segment: Option<[usize; 2]>,
#[serde(skip)]
pub drag: Option<Drag>,
+ /// The history step the drag's commit joins (`coalesce`): a Curvature Pen click on a segment
+ /// adds the anchor it then drags, and both are one step.
+ #[serde(skip)]
+ pub coalesce: Option<String>,
}
#[derive(Clone, Debug, PartialEq)]
@@ -80,6 +84,8 @@ pub enum Drag {
#[derive(Clone, Debug, PartialEq)]
pub enum Edit {
Anchors(Vec<[usize; 2]>),
+ /// The Curvature Pen dragging anchors: the smooth knots around them reflow.
+ Curvature(Vec<[usize; 2]>),
/// A handle, where it was at the press, and whether it moves alone (⌥).
Handle([usize; 2], Handle, Point, bool),
Segment([usize; 2], f64),
@@ -93,6 +99,7 @@ impl Edit {
let d = [end[0] - start[0], end[1] - start[1]];
match self {
Edit::Anchors(a) => ("path.moveAnchors", json!({"anchors": a, "move": d})),
+ Edit::Curvature(a) => ("path.moveAnchors", json!({"anchors": a, "move": d, "curvature": true})),
Edit::Handle([s, k], h, from, independent) => {
("path.moveHandle", json!({"subpath": s, "knot": k, "handle": h.name(), "to": [from.x + d[0], from.y + d[1]], "independent": independent}))
}
@@ -107,6 +114,7 @@ impl Edit {
let mut p = base.clone();
match self {
Edit::Anchors(a) => edit::move_anchors(&mut p, a, d),
+ Edit::Curvature(a) => edit::move_anchors_curvature(&mut p, a, d),
Edit::Handle(k, h, from, independent) => edit::move_handle(&mut p, *k, *h, Point::new(from.x + d[0], from.y + d[1]), *independent),
Edit::Segment(k, t) => edit::bend_segment(&mut p, *k, *t, d),
Edit::Convert(k) => edit::convert_point(&mut p, *k, Some(Point::new(end[0], end[1]))),
@@ -130,6 +138,12 @@ fn converting(tool: Tool, mods: Modifiers, pen_idle: bool) -> bool {
!mods.command && (tool == Tool::ConvertPoint || (tool == Tool::Pen && mods.alt && pen_idle))
}
+/// Is the Curvature Pen idle (no path being drawn, no ⌘/Ctrl)? Then it edits the active path in
+/// place, as in Photoshop: a press on one of its anchors drags it, with no modifier.
+fn curvature_idle(app: &PhotocraftApp, mods: Modifiers) -> bool {
+ app.ui.tool == Tool::CurvaturePen && !mods.command && app.ui.pen.as_ref().is_none_or(|p| p.knots.is_empty())
+}
+
/// The tools that take every pointer event on the canvas, not just a press that hits a path.
fn owns(tool: Tool) -> bool {
matches!(tool, Tool::DirectSelection | Tool::ConvertPoint)
@@ -139,6 +153,7 @@ fn owns(tool: Tool) -> bool {
/// Delete Anchor Point tools show it too: they edit the same paths.
pub fn shows(app: &PhotocraftApp, mods: Modifiers) -> bool {
direct(app.ui.tool, mods)
+ || curvature_idle(app, mods)
|| app.ui.direct_selection.drag.is_some()
|| matches!(app.ui.tool, Tool::AddAnchorPoint | Tool::DeleteAnchorPoint | Tool::ConvertPoint)
}
@@ -199,6 +214,9 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
let tool = app.ui.tool;
match ev {
ToolEvent::Down { x, y, .. } => {
+ if curvature_idle(app, mods) {
+ return curvature_press(app, [x, y]);
+ }
let pen_idle = app.ui.pen.is_none();
// Pen + ⌥ is Convert Point only while no path is being drawn.
let convert = converting(tool, mods, pen_idle);
@@ -231,6 +249,7 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
ToolEvent::Up { x, y } => match app.ui.direct_selection.drag.take() {
Some(Drag::Edit { target, base, edit, start, .. }) => {
release(app, target, &base, &edit, start, [x, y]);
+ app.ui.direct_selection.coalesce = None;
true
}
Some(Drag::Marquee { start, add, .. }) => {
@@ -326,6 +345,83 @@ fn press(app: &mut PhotocraftApp, p: [f64; 2], mods: Modifiers, convert: bool) -
true
}
+/// What the idle Curvature Pen has under document point `p` on the active paths: an anchor or a
+/// segment, with the path it is on. Handles don't count.
+fn curvature_target(app: &PhotocraftApp, p: [f64; 2]) -> Option<(PathRef, Path, Hit)> {
+ let tol = 6.0 / f64::from(app.point_zoom().max(0.01));
+ active_paths(app).into_iter().find_map(|(r, path)| match edit::hit(&path, Point::new(p[0], p[1]), tol, &[]) {
+ Some(h @ (Hit::Anchor(_) | Hit::Segment(..))) => Some((r, path, h)),
+ _ => None,
+ })
+}
+
+/// What a Curvature Pen press at `p` would do to an existing point, for its cursor: the anchor
+/// under it (idle: one of the active path's; drawing: one of the path being drawn), or the active
+/// path's segment it would add an anchor to.
+pub fn curvature_hover(app: &PhotocraftApp, p: [f64; 2], mods: Modifiers) -> Option<Hit> {
+ if app.ui.tool != Tool::CurvaturePen || mods.command {
+ return None;
+ }
+ if !curvature_idle(app, mods) {
+ return crate::vector_ui::curvature_anchor_at(app, p[0], p[1]).map(|i| Hit::Anchor([0, i]));
+ }
+ curvature_target(app, p).map(|(.., h)| h)
+}
+
+/// The idle Curvature Pen's double-click on an anchor of the active path: smooth ↔ corner, and
+/// the subpath reflows (one `path.convertPoint` with `curvature`).
+pub(crate) fn curvature_toggle_active(app: &mut PhotocraftApp, p: [f64; 2]) {
+ let Some((target, _, Hit::Anchor([s, k]))) = curvature_target(app, p) else { return };
+ let mut params = json!({"subpath": s, "knot": k, "curvature": true});
+ if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params().as_object()) {
+ o.extend(tp.clone());
+ }
+ if let Err(e) = app.run("path.convertPoint", params) {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ }
+ app.ui.direct_selection = DirectSelection { target: Some(target), anchors: vec![[s, k]], ..Default::default() };
+}
+
+/// Curvature Pen press with no path being drawn, on the active path: an anchor is grabbed and
+/// dragged; a segment gets a new anchor there (`path.addAnchor`), dragged the same way. Either
+/// way the curve reflows smoothly through the moved anchor, as in Photoshop (`path.moveAnchors`
+/// with `curvature` on release), and an added anchor and its drag are one history step. False
+/// when the press hits neither, so it starts a new path.
+fn curvature_press(app: &mut PhotocraftApp, p: [f64; 2]) -> bool {
+ let Some((target, mut base, hit)) = curvature_target(app, p) else { return false };
+ let mut coalesce = None;
+ let k = match hit {
+ Hit::Anchor(k) => k,
+ Hit::Segment([s, k], t) => {
+ let key = format!("curvature-add-{}", app.ui.alloc_id());
+ let mut params = json!({"subpath": s, "knot": k, "t": t.clamp(0.01, 0.99), "coalesce": key});
+ if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params().as_object()) {
+ o.extend(tp.clone());
+ }
+ let added = match app.run("path.addAnchor", params) {
+ Ok(v) => v,
+ Err(e) => {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ return true;
+ }
+ };
+ let n = |f: &str| added["anchor"][f].as_u64().and_then(|v| usize::try_from(v).ok());
+ let (Some(s), Some(k), Some(path)) = (n("subpath"), n("knot"), active_paths(app).into_iter().find(|(r, _)| *r == target).map(|(_, p)| p)) else {
+ return true;
+ };
+ base = path;
+ coalesce = Some(key);
+ [s, k]
+ }
+ Hit::Handle(..) => return false,
+ };
+ app.ui.direct_selection = DirectSelection { target: Some(target), anchors: vec![k], coalesce, ..Default::default() };
+ app.ui.direct_selection.drag = Some(Drag::Edit { target, base, edit: Edit::Curvature(vec![k]), start: p, end: p, preview: None });
+ true
+}
+
/// End of an edit drag: commit it as one command. A click (no movement) commits nothing, except
/// Pen + ⌥ on an anchor, which makes it a corner. The Pen path being drawn takes the edit directly.
fn release(app: &mut PhotocraftApp, target: PathRef, base: &Path, edit: &Edit, start: [f64; 2], end: [f64; 2]) {
@@ -352,6 +448,9 @@ fn release(app: &mut PhotocraftApp, target: PathRef, base: &Path, edit: &Edit, s
if let (Some(p), Some(t)) = (params.as_object_mut(), target.params().as_object()) {
p.extend(t.clone());
}
+ if let (Some(p), Some(key)) = (params.as_object_mut(), app.ui.direct_selection.coalesce.take()) {
+ p.insert("coalesce".into(), json!(key));
+ }
if let Err(e) = app.run(id, params) {
app.ui.status = e;
app.ui.status_error = true;
@@ -418,7 +517,15 @@ pub fn arrow_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
/// the marquee.
pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32, paths: bool) {
let ds = &app.ui.direct_selection;
- for (r, path) in if paths { candidates(app) } else { Vec::new() } {
+ // The idle Curvature Pen shows the anchors of the path it edits, not every shape's.
+ let shown = if !paths {
+ Vec::new()
+ } else if curvature_idle(app, painter.ctx().input(|i| i.modifiers)) {
+ active_paths(app)
+ } else {
+ candidates(app)
+ };
+ for (r, path) in shown {
let path = match &ds.drag {
Some(Drag::Edit { target, preview: Some(p), .. }) if *target == r => p.clone(),
_ => path,
diff --git a/crates/ui-egui/src/direct_select_tests.rs b/crates/ui-egui/src/direct_select_tests.rs
index c6b02c79b..0f3a5ba99 100644
--- a/crates/ui-egui/src/direct_select_tests.rs
+++ b/crates/ui-egui/src/direct_select_tests.rs
@@ -325,3 +325,173 @@ fn arrow_keys_nudge_the_selected_anchors() {
assert!(app.session.undo() && app.session.undo());
assert_eq!(work(&app), before);
}
+
+#[test]
+fn the_curvature_pen_drags_an_anchor_of_the_active_path_without_a_modifier() {
+ // As in Photoshop: with no path being drawn, pressing an anchor and dragging moves it.
+ let mut app = app(Tool::CurvaturePen);
+ with_path(&mut app);
+ assert!(super::shows(&app, Modifiers::NONE), "the Curvature Pen shows the active path's anchors");
+ let (before, n) = (work(&app), steps(&app));
+ drag(&mut app, [40.5, 120.5], [50.5, 130.5], Modifiers::NONE);
+ assert_eq!(anchor(&app, 3), Point::new(50.0, 130.0));
+ assert_eq!(anchor(&app, 0), Point::new(40.0, 40.0), "only the dragged anchor moved");
+ assert_eq!(work(&app).subpaths.len(), 1, "no new path was started");
+ assert!(app.ui.pen.is_none(), "nor is one being drawn");
+ assert_eq!(steps(&app), n + 1, "one history step for the whole drag");
+ assert!(app.session.undo());
+ assert_eq!(work(&app), before);
+}
+
+#[test]
+fn the_curvature_pen_off_an_anchor_still_draws_and_edits_its_own_path() {
+ let mut app = app(Tool::CurvaturePen);
+ with_path(&mut app);
+ let before = work(&app);
+ // A press on empty canvas starts a new path, as before (a segment would get an anchor).
+ click(&mut app, [80.0, 170.0], Modifiers::NONE);
+ click(&mut app, [170.0, 170.0], Modifiers::NONE);
+ assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(2));
+ assert!(!super::shows(&app, Modifiers::NONE), "while drawing, the Curvature Pen shows its own path");
+ // While drawing, a press on an anchor of the path being drawn moves that one, not the work path's.
+ drag(&mut app, [170.0, 170.0], [180.0, 160.0], Modifiers::NONE);
+ assert_eq!(app.ui.pen.as_ref().and_then(|p| p.knots.get(1)).map(|k| k[0]), Some([180.0, 160.0]));
+ assert_eq!(work(&app), before);
+}
+
+#[test]
+fn a_closed_curvature_pen_path_stays_editable_with_the_curvature_pen() {
+ let mut app = app(Tool::CurvaturePen);
+ app.ui.tool_options.vector_mode = "path".into();
+ for p in [[40.0, 40.0], [160.0, 40.0], [100.0, 160.0], [40.0, 40.0]] {
+ click(&mut app, p, Modifiers::NONE);
+ }
+ assert!(app.ui.pen.is_none(), "clicking the first anchor closed the path");
+ assert!(work(&app).subpaths[0].closed);
+ let n = steps(&app);
+ tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 160.0, pressure: 1.0 }, Modifiers::NONE);
+ tool_event(&mut app, ToolEvent::Move { x: 100.0, y: 180.0, pressure: 1.0 }, Modifiers::NONE);
+ let Some(Drag::Edit { preview: Some(shown), .. }) = app.ui.direct_selection.drag.clone() else { panic!("an anchor drag with a preview") };
+ tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 180.0 }, Modifiers::NONE);
+ assert_eq!(work(&app), shown, "the preview is what the drag commits");
+ assert_eq!((work(&app).subpaths.len(), steps(&app)), (1, n + 1));
+ // The whole loop reflows through the moved anchor, as the Curvature Pen drew it.
+ let pts = [[40.0, 40.0], [160.0, 40.0], [100.0, 180.0]];
+ let want = photocraft_vector::edit::curvature_knots(&pts, &[false; 3], true);
+ for (k, w) in work(&app).subpaths[0].knots.iter().zip(want) {
+ assert_eq!([[k.anchor.x, k.anchor.y], [k.in_ctrl.x, k.in_ctrl.y], [k.out_ctrl.x, k.out_ctrl.y]], w);
+ }
+}
+
+/// A Pen-drawn work path: a closed square of corners (40, 40)–(160, 160).
+fn with_corner_square(app: &mut PhotocraftApp) {
+ let path = json!({"subpaths": [{"closed": true, "knots": [[40, 40], [160, 40], [160, 160], [40, 160]]}]});
+ app.run("path.set", json!({"name": "work", "path": path})).unwrap();
+}
+
+#[test]
+fn the_curvature_pen_adds_an_anchor_on_a_segment_and_drags_it_in_one_step() {
+ let mut app = app(Tool::CurvaturePen);
+ with_corner_square(&mut app);
+ let n = steps(&app);
+ // A press on the top edge adds an anchor there; the drag pulls it up.
+ drag(&mut app, [100.0, 40.0], [100.0, 10.0], Modifiers::NONE);
+ let sp = &work(&app).subpaths[0];
+ assert_eq!(sp.knots.len(), 5, "one anchor added");
+ assert_eq!(sp.knots[1].anchor, Point::new(100.0, 10.0));
+ assert!(app.ui.pen.is_none(), "no new path was started");
+ assert_eq!(steps(&app), n + 1, "adding and dragging the anchor is one history step");
+ assert!(app.session.undo());
+ assert_eq!(work(&app).subpaths[0].knots.len(), 4);
+ // A click on a segment just adds the anchor.
+ click(&mut app, [160.0, 100.0], Modifiers::NONE);
+ assert_eq!(work(&app).subpaths[0].knots.len(), 5);
+}
+
+#[test]
+fn a_curvature_pen_double_click_rounds_a_pen_corner_and_back() {
+ let mut app = app(Tool::CurvaturePen);
+ with_corner_square(&mut app);
+ let before = work(&app);
+ crate::vector_ui::curvature_toggle(&mut app, 160.0, 40.0);
+ let k = work(&app).subpaths[0].knots[1];
+ assert!(k.smooth && k.in_ctrl != k.anchor && k.out_ctrl != k.anchor, "the corner turned smooth: {k:?}");
+ crate::vector_ui::curvature_toggle(&mut app, 160.0, 40.0);
+ assert_eq!(work(&app), before);
+ // Off the path it does nothing (and starts nothing).
+ crate::vector_ui::curvature_toggle(&mut app, 100.0, 100.0);
+ assert_eq!((work(&app), app.ui.pen.is_none()), (before, true));
+}
+
+#[test]
+fn the_curvature_pen_cursor_shows_what_a_press_does() {
+ use crate::tool_feedback::{Badge, badge};
+ let mut app = app(Tool::CurvaturePen);
+ with_corner_square(&mut app);
+ for (at, want) in [([100.0, 40.0], Some(Badge::Add)), ([160.0, 40.0], Some(Badge::Move)), ([100.0, 100.0], None)] {
+ app.hover_doc = Some(at);
+ assert_eq!(badge(&app, Tool::CurvaturePen, Modifiers::NONE), want, "at {at:?}");
+ }
+ // ⌘/Ctrl is Direct Selection: no Curvature Pen badge.
+ app.hover_doc = Some([160.0, 40.0]);
+ assert_eq!(badge(&app, Tool::CurvaturePen, Modifiers::COMMAND), None);
+ // While drawing, its own anchors take the move badge and the active path's segments none.
+ click(&mut app, [20.0, 180.0], Modifiers::NONE);
+ click(&mut app, [60.0, 190.0], Modifiers::NONE);
+ app.hover_doc = Some([60.0, 190.0]);
+ assert_eq!(badge(&app, Tool::CurvaturePen, Modifiers::NONE), Some(Badge::Move));
+ app.hover_doc = Some([100.0, 40.0]);
+ assert_eq!(badge(&app, Tool::CurvaturePen, Modifiers::NONE), None);
+}
+
+/// The real canvas: a Curvature Pen double-click on a Pen corner of the active path rounds it.
+#[test]
+fn a_curvature_pen_double_click_through_the_canvas_rounds_a_corner() {
+ use egui::{PointerButton, vec2};
+ use egui_kittest::Harness;
+ let mut app = app(Tool::CurvaturePen);
+ with_corner_square(&mut app);
+ app.ui.extras.rulers = false;
+ let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(1.0 / 60.0).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ let ctx = ui.ctx().clone();
+ if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ return;
+ }
+ egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run_steps(4);
+ let v = &mut h.state_mut().ui.views[0];
+ v.zoom = 1.0;
+ v.center = [100.0, 100.0];
+ v.fit_pending = false;
+ h.run_steps(2);
+ let p = {
+ let app = h.state();
+ let v = &app.ui.views[0];
+ let xf = crate::canvas::ViewXform {
+ rect: crate::rulers::content_rect(app, app.last_canvas_rect),
+ zoom: v.zoom,
+ center: v.center,
+ flip: false,
+ rotation: v.rotation,
+ aspect: app.ui.view.display_aspect(),
+ };
+ xf.to_screen(160.0, 40.0)
+ };
+ for _ in 0..2 {
+ h.event(egui::Event::PointerMoved(p));
+ h.run_steps(1);
+ for down in [true, false] {
+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: down, modifiers: Modifiers::NONE });
+ h.run_steps(1);
+ }
+ }
+ h.run_steps(1);
+ let k = work(h.state()).subpaths[0].knots[1];
+ assert!(k.smooth && k.in_ctrl != k.anchor, "the double-clicked corner is smooth: {k:?}");
+ assert!(h.state().ui.pen.is_none(), "and no path was started");
+}
diff --git a/crates/ui-egui/src/tool_feedback.rs b/crates/ui-egui/src/tool_feedback.rs
index eda03b305..2e66ae07c 100644
--- a/crates/ui-egui/src/tool_feedback.rs
+++ b/crates/ui-egui/src/tool_feedback.rs
@@ -17,6 +17,8 @@ pub enum Badge {
Add,
Subtract,
Intersect,
+ /// Four arrows: a press drags the point under the pointer (the Curvature Pen over an anchor).
+ Move,
}
impl Badge {
@@ -105,6 +107,12 @@ pub fn badge(app: &PhotocraftApp, tool: Tool, m: egui::Modifiers) -> Option<Badg
if let Some(t) = crate::anchor_tools::effective(tool, m) {
return (!m.command).then_some(if t == Tool::AddAnchorPoint { Badge::Add } else { Badge::Subtract });
}
+ // The Curvature Pen over a point: + on the active path's segments (a click adds an anchor
+ // there), four arrows on an anchor (a press drags it).
+ if let Some(p) = app.hover_doc.filter(|_| tool == Tool::CurvaturePen) {
+ return crate::direct_select::curvature_hover(app, p, m)
+ .map(|h| if matches!(h, photocraft_vector::edit::Hit::Segment(..)) { Badge::Add } else { Badge::Move });
+ }
// The Pen over the active path with Auto Add/Delete on: what a click would do (#4144).
if let Some(p) = app.hover_doc.filter(|_| tool == Tool::Pen) {
return crate::anchor_tools::pen_auto(app, tool, m, p).map(|(t, ..)| if t == Tool::AddAnchorPoint { Badge::Add } else { Badge::Subtract });
@@ -129,6 +137,17 @@ pub fn badge_glyph(b: Badge, c: Pos2, h: f32) -> Vec<[Pos2; 2]> {
match b {
Badge::Add => vec![[c - vec2(h, 0.0), c + vec2(h, 0.0)], [c - vec2(0.0, h), c + vec2(0.0, h)]],
Badge::Subtract => vec![[c - vec2(h, 0.0), c + vec2(h, 0.0)]],
+ Badge::Move => {
+ let a = h * 0.45;
+ let mut v = vec![[c - vec2(h, 0.0), c + vec2(h, 0.0)], [c - vec2(0.0, h), c + vec2(0.0, h)]];
+ for d in [vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0)] {
+ let tip = c + d * h;
+ let side = vec2(-d.y, d.x) * a;
+ v.push([tip, tip - d * a + side]);
+ v.push([tip, tip - d * a - side]);
+ }
+ v
+ }
Badge::Intersect => {
let d = h * 0.8;
vec![[c + vec2(-d, -d), c + vec2(d, d)], [c + vec2(-d, d), c + vec2(d, -d)]]
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index 99dcdbab2..d4df992fe 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -558,6 +558,11 @@ fn curvature_refresh(pen: &mut PenPath, closed: bool) {
pen.knots = photocraft_vector::edit::curvature_knots(&anchors, &corners, closed);
}
+/// The anchor of the Curvature Pen path being drawn under (x, y), for the cursor.
+pub(crate) fn curvature_anchor_at(app: &PhotocraftApp, x: f64, y: f64) -> Option<usize> {
+ curvature_hit(app, x, y)
+}
+
/// The Curvature Pen's anchor within a few screen pixels of (x, y).
fn curvature_hit(app: &PhotocraftApp, x: f64, y: f64) -> Option<usize> {
let tol = 6.0 / app.point_zoom().max(0.01) as f64;
@@ -606,8 +611,14 @@ pub fn curvature_up(app: &mut PhotocraftApp) {
}
/// Curvature Pen double-click: toggle the anchor under the pointer between smooth and corner
-/// (double-clicking empty canvas therefore places a corner point, as in Photoshop).
+/// (double-clicking empty canvas therefore places a corner point, as in Photoshop). With no path
+/// being drawn, an anchor of the active path toggles the same way and its subpath reflows
+/// (`path.convertPoint` with `curvature`), so a Pen-drawn corner rounds off.
pub fn curvature_toggle(app: &mut PhotocraftApp, x: f64, y: f64) {
+ if app.ui.pen.as_ref().is_none_or(|p| p.knots.is_empty()) {
+ crate::direct_select::curvature_toggle_active(app, [x, y]);
+ return;
+ }
let Some(i) = curvature_hit(app, x, y) else { return };
let Some(pen) = app.ui.pen.as_mut() else { return };
if let Some(at) = pen.unlinked.iter().position(|&c| c == i) {
diff --git a/crates/vector/src/edit.rs b/crates/vector/src/edit.rs
index ea99cff25..d08d76212 100644
--- a/crates/vector/src/edit.rs
+++ b/crates/vector/src/edit.rs
@@ -116,6 +116,39 @@ pub fn move_anchors(path: &mut Path, anchors: &[[usize; 2]], d: [f64; 2]) -> Res
Ok(())
}
+/// The Curvature Pen's anchor drag: moves the anchors like [`move_anchors`], then recomputes the
+/// handles of every smooth knot in the subpaths it touched with [`curvature_knots`], so the curve
+/// keeps flowing smoothly through all its anchors, as Photoshop does. Corner knots keep their own
+/// handles (moved with them).
+pub fn move_anchors_curvature(path: &mut Path, anchors: &[[usize; 2]], d: [f64; 2]) -> Result<(), String> {
+ move_anchors(path, anchors, d)?;
+ let mut subs: Vec<usize> = anchors.iter().map(|a| a[0]).collect();
+ subs.sort_unstable();
+ subs.dedup();
+ for s in subs {
+ let sp = path.subpaths.get_mut(s).ok_or_else(|| format!("no subpath {s}"))?;
+ let pts: Vec<[f64; 2]> = sp.knots.iter().map(|k| [k.anchor.x, k.anchor.y]).collect();
+ let corners: Vec<bool> = sp.knots.iter().map(|k| !k.smooth).collect();
+ let fresh = curvature_knots(&pts, &corners, sp.closed);
+ for (k, f) in sp.knots.iter_mut().zip(fresh) {
+ if k.smooth {
+ k.in_ctrl = Point::new(f[1][0], f[1][1]);
+ k.out_ctrl = Point::new(f[2][0], f[2][1]);
+ }
+ }
+ }
+ Ok(())
+}
+
+/// The Curvature Pen's double-click on an anchor: a corner becomes smooth and a smooth knot a
+/// corner (handles retracted), then the subpath reflows as [`move_anchors_curvature`] does, so the
+/// segments around a new smooth point curve through it.
+pub fn toggle_curvature_point(path: &mut Path, knot: [usize; 2]) -> Result<(), String> {
+ let k = knot_mut(path, knot)?;
+ *k = if k.smooth { Knot::corner(k.anchor.x, k.anchor.y) } else { Knot { smooth: true, ..*k } };
+ move_anchors_curvature(path, &[knot], [0.0, 0.0])
+}
+
/// Puts handle `h` of a knot at `to`. A smooth knot turns its other handle to stay collinear,
/// unless `independent` (Convert Point / ⌥), which makes it a corner whose handles move apart.
pub fn move_handle(path: &mut Path, knot: [usize; 2], h: Handle, to: Point, independent: bool) -> Result<(), String> {
@@ -348,6 +381,60 @@ mod tests {
path.subpaths[s].knots[k]
}
+ /// A closed four-anchor curvature loop (all smooth), as the Curvature Pen draws it.
+ fn loop4() -> Path {
+ let pts = [[0.0, 50.0], [100.0, 0.0], [200.0, 50.0], [100.0, 100.0]];
+ let knots = curvature_knots(&pts, &[false; 4], true)
+ .into_iter()
+ .map(|k| Knot::smooth(Point::new(k[0][0], k[0][1]), Point::new(k[1][0], k[1][1]), Point::new(k[2][0], k[2][1])))
+ .collect();
+ Path::new(vec![Subpath { closed: true, knots, op: Default::default() }])
+ }
+
+ #[test]
+ fn a_curvature_drag_reflows_every_smooth_knot_through_the_moved_anchor() {
+ let mut p = loop4();
+ move_anchors_curvature(&mut p, &[[0, 1]], [0.0, 60.0]).unwrap();
+ let pts = [[0.0, 50.0], [100.0, 60.0], [200.0, 50.0], [100.0, 100.0]];
+ let want = curvature_knots(&pts, &[false; 4], true);
+ for (k, w) in p.subpaths[0].knots.iter().zip(want) {
+ assert_eq!([[k.anchor.x, k.anchor.y], [k.in_ctrl.x, k.in_ctrl.y], [k.out_ctrl.x, k.out_ctrl.y]], w);
+ }
+ // The neighbours turned: not a plain move.
+ assert_ne!(at(&p, 0, 0).out_ctrl, at(&loop4(), 0, 0).out_ctrl);
+ }
+
+ #[test]
+ fn a_curvature_drag_keeps_corner_handles_and_rejects_bad_indices() {
+ let mut p = curve();
+ move_anchors_curvature(&mut p, &[[0, 1]], [0.0, 10.0]).unwrap();
+ assert_eq!((at(&p, 0, 0), at(&p, 0, 2)), (at(&curve(), 0, 0), at(&curve(), 0, 2)), "the corners kept their handles");
+ assert_eq!(at(&p, 0, 1).anchor, Point::new(50.0, 10.0));
+ let before = curve();
+ let mut q = curve();
+ assert!(move_anchors_curvature(&mut q, &[[0, 9]], [1.0, 1.0]).is_err());
+ assert!(move_anchors_curvature(&mut q, &[[4, 0]], [1.0, 1.0]).is_err());
+ assert_eq!(q, before, "a refused edit changes nothing");
+ }
+
+ #[test]
+ fn a_curvature_double_click_turns_a_corner_smooth_and_back() {
+ // A closed square of corners, as the Pen draws it.
+ let square = || Path::new(vec![Subpath::polygon(&[(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)])]);
+ let mut p = square();
+ toggle_curvature_point(&mut p, [0, 1]).unwrap();
+ let k = at(&p, 0, 1);
+ assert!(k.smooth);
+ let want = curvature_knots(&[[0.0, 0.0], [100.0, 0.0], [100.0, 100.0], [0.0, 100.0]], &[true, false, true, true], true)[1];
+ assert_eq!([[k.in_ctrl.x, k.in_ctrl.y], [k.out_ctrl.x, k.out_ctrl.y]], [want[1], want[2]], "its handles follow its neighbours");
+ assert_eq!((at(&p, 0, 0), at(&p, 0, 2)), (at(&square(), 0, 0), at(&square(), 0, 2)), "the corners around keep theirs");
+ toggle_curvature_point(&mut p, [0, 1]).unwrap();
+ assert_eq!(p, square(), "a second double-click makes it a corner again");
+ assert!(toggle_curvature_point(&mut p, [0, 7]).is_err());
+ assert!(toggle_curvature_point(&mut p, [3, 0]).is_err());
+ assert_eq!(p, square());
+ }
+
#[test]
fn anchors_move_with_their_handles_once_each() {
let mut p = curve();
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index b71a199d8..d723d86f3 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -121,6 +121,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| Click corner, drag smooth, ⌥ breaks a handle, ⌘ direct-selects, ⇧ 45° | done | TOOL-214-10; `vector_ui.rs` (#3751) |
| Handle on the last point, close-drag handle | partial | #1482 |
| Pen Auto Add/Delete: click a segment of the active path to add, an anchor to delete; ⇧ suspends it | done | #4144 |
+| Curvature Pen edits the active path with no modifier: drag an anchor (the curve reflows), click a segment to add an anchor, double-click smooth ↔ corner; cursor badge + on segments, four arrows on anchors | done: `direct_select.rs` (`curvature_press`, `curvature_hover`), `path.moveAnchors`/`path.convertPoint` with `curvature`, `direct_select_tests.rs` | |
| Path operations in the options bar (combine, subtract, intersect, exclude) | partial | `layer.combineShapes.*`; Pen options #1397 |
| On-canvas corner-radius handles on live shapes | missing | TOOL-214-12 |
| Shape stroke controls (dash, caps, joins, align) | done | TOOL-1053-1, [`shape-strokes.md`](shape-strokes.md) |
@@ -241,6 +242,7 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-12 | minor | Free Transform options bar: H and V skew fields; a sheared box reads as skew instead of a taller H |
| 2026-10-12 | minor | Layers panel: Clip Thumbnails to Layer Bounds frames each layer's pixels instead of the canvas (#4281) |
| 2026-10-13 | minor | Smart filter rows can be dragged up or down their stack to reorder the filters |
+| 2026-10-13 | minor | Curvature Pen edits the active path: drag anchors, click a segment to add, double-click smooth/corner, cursor badges |
| 2026-10-11 | minor | Pen ⇧ 45° done: ⇧-click puts the next anchor on the nearest 45° ray, ⇧-drag turns its handles in 45° steps (TOOL-214-10 done, #3751) |
| 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit |
| 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) |