mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Refuse freeform pen strokes on locked shapes
This commit is contained in:
1 parent
b18274f6d7
commit
d24669d412
4 files changed
+42
No files matched your search
@@ -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 { .. } => {
|
||||
|
||||
@@ -125,3 +125,5 @@ mod pen_path_ops_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod paint_tests;
|
||||
|
||||
pub(crate) use pen::freeform_locked_shape;
|
||||
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user