diff --git a/crates/ui-egui/src/tools/lasso_ui.rs b/crates/ui-egui/src/tools/lasso_ui.rs index 72f486378e0..fac20a39edc 100644 --- a/crates/ui-egui/src/tools/lasso_ui.rs +++ b/crates/ui-egui/src/tools/lasso_ui.rs @@ -155,6 +155,11 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool if !p.iter().all(|n| n.is_finite()) { return true; } + if tool == Tool::FreeformPen && matches!(ev, ToolEvent::Down { .. }) && !active(app) && crate::vector_ui::freeform_locked_shape(app) { + app.ui.status = tl!("Locked").into(); + app.ui.status_error = true; + return true; + } modifiers(app, mods); match ev { ToolEvent::Down { .. } => { diff --git a/crates/ui-egui/src/tools/vector_ui.rs b/crates/ui-egui/src/tools/vector_ui.rs index 65f2248addb..b3ee2f47e60 100644 --- a/crates/ui-egui/src/tools/vector_ui.rs +++ b/crates/ui-egui/src/tools/vector_ui.rs @@ -125,3 +125,5 @@ mod pen_path_ops_tests; #[cfg(test)] mod paint_tests; + +pub(crate) use pen::freeform_locked_shape; diff --git a/crates/ui-egui/src/tools/vector_ui/pen.rs b/crates/ui-egui/src/tools/vector_ui/pen.rs index 3a1dd03f317..43d27105e8a 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen.rs @@ -651,6 +651,18 @@ fn path_op_button(ui: &mut egui::Ui, glyph: &str, label: &str, checked: bool) -> // --------------------------------------------------------------------------------------------- // Freeform Pen and Curvature Pen +/// Refuse a Freeform stroke before drawing when its selected shape cannot be edited. +pub(crate) fn freeform_locked_shape(app: &PhotocraftApp) -> bool { + if app.ui.tool_options.vector_mode != "shape" || pen_path_op(&app.ui.tool_options).is_none() { + return false; + } + let Some(id) = selected_shape(&app.session) else { return false }; + app.session.active().is_some_and(|st| { + let locks = st.doc.effective_locks(id); + locks.all || locks.pixels + }) +} + /// Freeform Pen release: fit the drag's trace within the options bar's Curve Fit and commit it /// as the Pen does. Releasing on the start point closes the path; a click draws nothing. The /// points at indices `straight` were ⌥-clicked: the segment into each one stays straight. diff --git a/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs index 8bb6ee72dc4..48bdbc97766 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs @@ -321,3 +321,26 @@ fn an_unknown_operation_falls_back_to_new_layer() { square(&mut app, 30.0, 30.0, 50.0); assert_eq!(layers(&app), count + 2); } + +#[test] +fn freeform_refuses_a_locked_shape_before_starting_a_stroke() { + use crate::canvas::{ToolEvent, tool_event}; + for lock in ["all", "pixels"] { + let mut app = app(); + app.ui.tool_options.vector_mode = "shape".into(); + square(&mut app, 20.0, 20.0, 100.0); + let (id, body) = shape_path(&app); + app.run("layer.lockLayers", json!({lock: true})).unwrap(); + let steps = app.session.active().unwrap().history.past_len(); + app.ui.tool = Tool::FreeformPen; + app.ui.tool_options.pen_path_op = "subtract".into(); + tool_event(&mut app, ToolEvent::Down { x: 50.0, y: 50.0, pressure: 1.0 }, egui::Modifiers::NONE); + assert!(app.drag.is_none(), "{lock}: stroke was not started"); + assert!(app.ui.status_error, "{lock}"); + assert_eq!(shape_path(&app), (id, body), "{lock}"); + assert_eq!(app.session.active().unwrap().history.past_len(), steps, "{lock}"); + app.session.undo(); + tool_event(&mut app, ToolEvent::Down { x: 50.0, y: 50.0, pressure: 1.0 }, egui::Modifiers::NONE); + assert!(app.drag.is_some(), "{lock}: unlocked stroke can start"); + } +}