diff --git a/crates/ui-egui/src/canvas/drag.rs b/crates/ui-egui/src/canvas/drag.rs index fdc718be0f..11bbf564bb 100644 --- a/crates/ui-egui/src/canvas/drag.rs +++ b/crates/ui-egui/src/canvas/drag.rs @@ -16,6 +16,9 @@ pub struct Drag { pub clear: bool, /// ⇧ constraint of a painting stroke (stroke_constraint.rs). pub constrain: Option, + /// A ⇧-click line from the previous stroke's end. Smoothing doesn't apply to it, so it ends + /// at the click whatever Catch-up on Stroke End is set to, as in Photoshop (#11887). + pub line: bool, /// Modifiers held now (updated on every pointer event of the gesture). pub live: egui::Modifiers, /// Which of the modifiers held at the press have been released since. @@ -55,6 +58,7 @@ impl Drag { erase, clear: false, constrain: None, + line: false, live: modifiers, released: egui::Modifiers::NONE, reposition: false, diff --git a/crates/ui-egui/src/canvas/strokes.rs b/crates/ui-egui/src/canvas/strokes.rs index c7c6d4b643..9f23076bf2 100644 --- a/crates/ui-egui/src/canvas/strokes.rs +++ b/crates/ui-egui/src/canvas/strokes.rs @@ -293,10 +293,14 @@ pub(super) fn live_stroke(app: &PhotocraftApp, idx: usize) -> Option<&LiveStroke } /// `paint.stroke` params for a Brush/Eraser drag (shared by the live preview and the commit). The -/// stroke smoothing is the session brush's (the options bar's Smoothing %). +/// stroke smoothing is the session brush's (the options bar's Smoothing %), except on a ⇧-click +/// line, which isn't smoothed (#11887). pub(super) fn stroke_params(app: &PhotocraftApp, d: &Drag, points: &[Vec]) -> serde_json::Value { let tool = d.tool; let mut p = json!({ "points": points, "erase": d.erase, "zoom": app.point_zoom(), "target": paint_target(app) }); + if d.line { + p["smoothing"] = json!(0.0); + } if d.clear { p["mode"] = json!("clear"); } diff --git a/crates/ui-egui/src/canvas/tool_input.rs b/crates/ui-egui/src/canvas/tool_input.rs index 0f8a04f770..eaf9ed596a 100644 --- a/crates/ui-egui/src/canvas/tool_input.rs +++ b/crates/ui-egui/src/canvas/tool_input.rs @@ -578,7 +578,7 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) } // ⌥ flips Dodge/Burn and Blur/Sharpen for this stroke. let tool = crate::retouch_ui::alt_flipped(tool, mods.alt); - let mut drag = Drag { clear, ..Drag::new(tool, from.map_or([x, y], |p| [p[0], p[1]]), points, mods, erase) }; + let mut drag = Drag { clear, line: from.is_some(), ..Drag::new(tool, from.map_or([x, y], |p| [p[0], p[1]]), points, mods, erase) }; drag.capture_vector_owners(app); drag.capture_selection_at_press(app); drag.document = super::drag::DragDocument::capture(app); diff --git a/crates/ui-egui/src/tools/stroke_constraint.rs b/crates/ui-egui/src/tools/stroke_constraint.rs index 51760cc6cb..77f1edc707 100644 --- a/crates/ui-egui/src/tools/stroke_constraint.rs +++ b/crates/ui-egui/src/tools/stroke_constraint.rs @@ -243,6 +243,30 @@ mod tests { assert!(alpha(&app, 20, 100) > 0.9 && alpha(&app, 40, 80) > 0.9 && alpha(&app, 90, 30) > 0.9); } + #[test] + fn shift_click_line_ends_at_the_click_with_catch_up_on_stroke_end_off() { + // Measured in Photoshop (#11887): smoothing doesn't apply to a ⇧-click line, whatever + // Smoothing and Catch-up on Stroke End are set to. + let mut app = app(); + app.ui.tool = Tool::Brush; + app.session.tools.brush.smoothing.amount = 0.6; + app.session.tools.brush.smoothing.catch_up_on_end = false; + let none = egui::Modifiers::NONE; + // A plain two-point drag at this smoothing ends short of the release point. + tool_event(&mut app, ToolEvent::Down { x: 10.0, y: 60.0, pressure: 1.0 }, none); + tool_event(&mut app, ToolEvent::Move { x: 100.0, y: 60.0, pressure: 1.0 }, none); + tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 60.0 }, none); + assert!(alpha(&app, 100, 60) == 0.0, "a smoothed drag lags"); + // ⇧-click: the line runs from the drag's release point all the way to the click. + let shift = egui::Modifiers::SHIFT; + tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 110.0, pressure: 1.0 }, shift); + tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 110.0 }, shift); + assert_eq!(last_stroke_points(&app), vec![[100.0, 60.0], [100.0, 110.0]]); + assert!(alpha(&app, 100, 62) > 0.9 && alpha(&app, 100, 85) > 0.9 && alpha(&app, 100, 110) > 0.9); + // The options bar's Smoothing is unchanged. + assert_eq!(app.session.tools.brush.smoothing.amount, 0.6); + } + #[test] fn shift_click_interpolates_from_previous_strokes_endpoint_pressure() { let mut app = app();