diff --git a/crates/ui-egui/src/burn_default_tip_tests.rs b/crates/ui-egui/src/burn_default_tip_tests.rs index 78b92efb25..b1a087a114 100644 --- a/crates/ui-egui/src/burn_default_tip_tests.rs +++ b/crates/ui-egui/src/burn_default_tip_tests.rs @@ -8,7 +8,7 @@ use crate::PhotocraftApp; use crate::control::{ControlRequest, handle}; use crate::state::Tool; -fn app() -> PhotocraftApp { +pub(super) fn app() -> PhotocraftApp { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); app.sync_views(); @@ -16,7 +16,7 @@ fn app() -> PhotocraftApp { } /// Run a menu command as the control channel does, then the frame's sync. -fn invoke(app: &mut PhotocraftApp, id: &str, params: serde_json::Value) { +pub(super) fn invoke(app: &mut PhotocraftApp, id: &str, params: serde_json::Value) { let ctx = egui::Context::default(); let (req, _rx) = ControlRequest::new("ui.menu.invoke", json!({"id": id, "params": params})); handle(app, &ctx, &req); @@ -24,7 +24,7 @@ fn invoke(app: &mut PhotocraftApp, id: &str, params: serde_json::Value) { } /// Pick `tool`, and swap its brush in as a frame does. -fn pick(app: &mut PhotocraftApp, tool: Tool) { +pub(super) fn pick(app: &mut PhotocraftApp, tool: Tool) { app.ui.tool = tool; crate::paint_mouse::sync_tool_brush(app); app.sync_views(); diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index 6842d3a675..0bcec596d3 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -39,11 +39,12 @@ pub fn sync_tool_brush(app: &mut PhotocraftApp) { } // A tool seen for the first time takes what the brush has, at Photoshop's smoothing, but // in Normal mode: each tool's Mode starts at Normal, so a Multiply Brush doesn't make the - // first Clone Stamp stroke multiply (or give Healing a mode its menu doesn't have). + // first Pattern Stamp stroke multiply (or give Healing a mode its menu doesn't have). // The Art History Brush also starts at full opacity (#10263): its Opacity is its own. - // The Background Eraser, the Healing Brush and the Burn tool start with their own measured - // tips instead, as the whole brush Reset Tool gives them (#11911, #12099, #12671). - None if matches!(tool, Tool::BackgroundEraser | Tool::Healing | Tool::Burn) => fresh_brush(tool, ¤t), + // The Background Eraser, the Healing Brush, the Burn tool and the Clone Stamp start with + // their own measured tips instead, as the whole brush Reset Tool gives them (#11911, + // #12099, #12671, #12601). + None if matches!(tool, Tool::BackgroundEraser | Tool::Healing | Tool::Burn | Tool::CloneStamp) => fresh_brush(tool, ¤t), None => { let opacity = if tool == Tool::ArtHistoryBrush { BrushSettings::default().opacity } else { current.opacity }; BrushSettings { smoothing: first_smoothing(), mode: photocraft_color::BlendMode::Normal, opacity, ..current } @@ -79,12 +80,14 @@ const BACKGROUND_ERASER_TIP: (f32, f32, f32) = (13.0, 1.0, 0.25); const HEALING_BRUSH_TIP: (f32, f32, f32) = (19.0, 1.0, 0.25); /// The Burn tool's tip after Reset Tool (#12671): a 65 px soft round at 25 % spacing. const BURN_TOOL_TIP: (f32, f32, f32) = (65.0, 0.0, 0.25); +/// The Clone Stamp's tip after Reset Tool (#12601): a 21 px soft round at 25 % spacing. +const CLONE_STAMP_TIP: (f32, f32, f32) = (21.0, 0.0, 0.25); /// `tool`'s brush as it starts out (Reset Tool, #2825): the default brush at Photoshop's /// smoothing, with the session's own fields of `current`. The Brush tool's tip is /// [`BRUSH_TOOL_TIP`], the Background Eraser's [`BACKGROUND_ERASER_TIP`], the Healing Brush's -/// [`HEALING_BRUSH_TIP`], the Burn tool's [`BURN_TOOL_TIP`]; the other tools keep the default -/// tip. +/// [`HEALING_BRUSH_TIP`], the Burn tool's [`BURN_TOOL_TIP`], the Clone Stamp's +/// [`CLONE_STAMP_TIP`] with no smoothing; the other tools keep the default tip. pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings { let mut brush = BrushSettings { smoothing: first_smoothing(), ..BrushSettings::default() }; match tool { @@ -92,6 +95,10 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings Tool::BackgroundEraser => (brush.size, brush.hardness, brush.spacing) = BACKGROUND_ERASER_TIP, Tool::Healing => (brush.size, brush.hardness, brush.spacing) = HEALING_BRUSH_TIP, Tool::Burn => (brush.size, brush.hardness, brush.spacing) = BURN_TOOL_TIP, + Tool::CloneStamp => { + (brush.size, brush.hardness, brush.spacing) = CLONE_STAMP_TIP; + brush.smoothing.amount = 0.0; + } _ => {} } session_fields(current, &brush) diff --git a/crates/ui-egui/src/canvas/paint_mouse/tests.rs b/crates/ui-egui/src/canvas/paint_mouse/tests.rs index 8880183d29..c0b20d1bdf 100644 --- a/crates/ui-egui/src/canvas/paint_mouse/tests.rs +++ b/crates/ui-egui/src/canvas/paint_mouse/tests.rs @@ -582,9 +582,9 @@ fn art_history_brush_starts_at_full_opacity() { sync_tool_brush(&mut app); assert_eq!(app.session.tools.brush.opacity, 1.0, "Art History starts at 100%"); assert_eq!(app.session.tools.brush.size, 40.0, "and inherits the size"); - app.ui.tool = Tool::CloneStamp; + app.ui.tool = Tool::HistoryBrush; sync_tool_brush(&mut app); - assert_eq!(app.session.tools.brush.opacity, 1.0, "the Clone Stamp takes the Art History brush's opacity"); + assert_eq!(app.session.tools.brush.opacity, 1.0, "the History Brush takes the Art History brush's opacity"); app.ui.tool = Tool::Brush; sync_tool_brush(&mut app); app.ui.tool = Tool::Eraser; diff --git a/crates/ui-egui/src/clone_stamp_reset_tip_tests.rs b/crates/ui-egui/src/clone_stamp_reset_tip_tests.rs new file mode 100644 index 0000000000..6691811f2e --- /dev/null +++ b/crates/ui-egui/src/clone_stamp_reset_tip_tests.rs @@ -0,0 +1,93 @@ +//! #12601: the Clone Stamp starts, and comes back after Reset Tool, with the reference +//! application's tip: a 21 px soft round (hardness 0 %, angle 0°, roundness 100 %) at 25 % +//! spacing, with no smoothing. Other tools' starting tips are unchanged. + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::burn_default_tip_tests::{app, invoke, pick}; +use crate::state::Tool; + +/// Size, hardness, spacing, angle, roundness and smoothing of the live brush, as `brush.get` +/// reports the tip. +fn tip(app: &mut PhotocraftApp) -> [f64; 6] { + let b = app.run("brush.get", json!({})).unwrap(); + let [size, hardness, spacing, angle, roundness] = ["size", "hardness", "spacing", "angle", "roundness"].map(|k| b[k].as_f64().unwrap()); + let smoothing = f64::from(app.session.tools.brush.smoothing.amount); + [size, hardness, spacing, angle, roundness, smoothing].map(|v| (v * 1e4).round() / 1e4) +} + +/// A tip that is no tool's starting tip, so a reset has something to undo. +fn scramble(app: &mut PhotocraftApp) { + let b = &mut app.session.tools.brush; + (b.size, b.hardness, b.spacing, b.angle, b.roundness, b.smoothing.amount) = (57.0, 0.4, 0.6, 30.0, 0.5, 0.3); +} + +const CLONE_STAMP_TIP: [f64; 6] = [21.0, 0.0, 0.25, 0.0, 1.0, 0.0]; + +#[test] +fn reset_tool_gives_the_clone_stamp_a_21_px_soft_tip() { + let mut app = app(); + pick(&mut app, Tool::CloneStamp); + scramble(&mut app); + invoke(&mut app, "tool.reset", json!({})); + assert_eq!(tip(&mut app), CLONE_STAMP_TIP); + // The options-bar brush chip reads the live brush's rounded size. + assert_eq!(app.session.tools.brush.size.round(), 21.0); +} + +#[test] +fn a_first_use_starts_with_the_tip() { + // No stored tool brushes, as on a fresh install: the Clone Stamp's first pick, after another + // tool's tip. + let mut app = app(); + pick(&mut app, Tool::Pencil); + scramble(&mut app); + pick(&mut app, Tool::CloneStamp); + assert_eq!(tip(&mut app), CLONE_STAMP_TIP); + // Its own tip is then kept across tool switches. + app.session.tools.brush.size = 42.0; + pick(&mut app, Tool::Pencil); + pick(&mut app, Tool::CloneStamp); + assert_eq!(tip(&mut app)[0], 42.0); +} + +#[test] +fn reset_all_tools_gives_it_the_tip_active_or_picked_later() { + let mut app = app(); + pick(&mut app, Tool::CloneStamp); + scramble(&mut app); + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + assert_eq!(tip(&mut app), CLONE_STAMP_TIP, "active"); + let mut app = self::app(); + pick(&mut app, Tool::CloneStamp); + scramble(&mut app); + pick(&mut app, Tool::Pencil); + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + pick(&mut app, Tool::CloneStamp); + assert_eq!(tip(&mut app), CLONE_STAMP_TIP, "picked after the reset"); +} + +#[test] +fn other_tools_keep_their_reset_tips() { + for (tool, want) in [ + (Tool::Brush, [13.0, 0.0, 0.25, 0.0, 1.0, 0.1]), + (Tool::BackgroundEraser, [13.0, 1.0, 0.25, 0.0, 1.0, 0.1]), + (Tool::Healing, [19.0, 1.0, 0.25, 0.0, 1.0, 0.1]), + (Tool::Burn, [65.0, 0.0, 0.25, 0.0, 1.0, 0.1]), + (Tool::HistoryBrush, [20.0, 1.0, 0.1, 0.0, 1.0, 0.1]), + (Tool::PatternStamp, [20.0, 1.0, 0.1, 0.0, 1.0, 0.1]), + ] { + let mut a = app(); + pick(&mut a, tool); + scramble(&mut a); + invoke(&mut a, "tool.reset", json!({})); + assert_eq!(tip(&mut a), want, "{tool:?}"); + } + // The Pattern Stamp's first use still takes the current tip, as before. + let mut a = app(); + pick(&mut a, Tool::Pencil); + scramble(&mut a); + pick(&mut a, Tool::PatternStamp); + assert_eq!(tip(&mut a)[0], 57.0, "Pattern Stamp, first use"); +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 3edadc59cb..904e6fb075 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1066,3 +1066,6 @@ mod view_guides_submenu_tests; #[cfg(test)] mod background_eraser_digit_keys_tests; + +#[cfg(test)] +mod clone_stamp_reset_tip_tests; diff --git a/crates/ui-egui/src/panels/brush_panel/tests.rs b/crates/ui-egui/src/panels/brush_panel/tests.rs index 3744ce40a2..24f12b89d9 100644 --- a/crates/ui-egui/src/panels/brush_panel/tests.rs +++ b/crates/ui-egui/src/panels/brush_panel/tests.rs @@ -431,6 +431,8 @@ fn options_bar_harness(tool: crate::state::Tool) -> Harness<'static, PhotocraftA #[test] fn clone_stamp_opacity_and_flow_are_journaled_per_gesture() { let mut h = options_bar_harness(crate::state::Tool::CloneStamp); + // The Clone Stamp's own starting brush: a tool swap is not a journaled command. + let start = h.state().session.tools.brush.clone(); for (label, field) in [("Opacity", "opacity"), ("Flow", "flow")] { let n = h.state().session.journal.len(); let rect = caption_rect(&h, label); @@ -459,6 +461,7 @@ fn clone_stamp_opacity_and_flow_are_journaled_per_gesture() { assert_eq!(params["opacity"], json!(h.state().session.tools.brush.opacity * 100.0)); assert_eq!(params["flow"], json!(h.state().session.tools.brush.flow * 100.0)); let mut replay = photocraft_engine::Session::new(); + replay.tools.brush = start; for (id, params) in &h.state().session.journal { replay.execute(id, params.clone()).unwrap(); } diff --git a/crates/ui-egui/src/stroke_timing_tests.rs b/crates/ui-egui/src/stroke_timing_tests.rs index c015ecb409..ecaf1c5b8d 100644 --- a/crates/ui-egui/src/stroke_timing_tests.rs +++ b/crates/ui-egui/src/stroke_timing_tests.rs @@ -417,16 +417,18 @@ fn the_stroke_trace_times_each_frame_of_a_stroke_and_ends_on_release() { #[test] fn releasing_a_clone_stamp_stroke_commits_what_a_replay_paints() { let setup = |run: &mut dyn FnMut(&str, Value)| { - run("tools.setBrush", json!({"brush": {"size": 16, "hardness": 0.4}})); + // The whole tip that differs from the default brush, as a replay starts from that. + run("tools.setBrush", json!({"brush": {"size": 16, "hardness": 0.4, "spacing": 0.25, "smoothing": {"amount": 0.0}}})); run("paint.stroke", json!({"points": [[10, 20], [190, 80]], "size": 30, "hardness": 0.5, "color": "#2060c0"})); run("cloneSource.set", json!({"source": [40, 30]})); }; let mut h = harness(); + // Picked first, so the brush set above is the Clone Stamp's own. + h.state_mut().ui.tool = Tool::CloneStamp; + h.run_steps(1); setup(&mut |id, p| { h.state_mut().run(id, p).unwrap(); }); - h.state_mut().ui.tool = Tool::CloneStamp; - h.run_steps(1); move_to(&mut h, 60.0, 50.0); button(&mut h, 60.0, 50.0, true); for (x, y) in [(80.0, 40.0), (110.0, 60.0), (140.0, 45.0), (170.0, 65.0)] { diff --git a/crates/ui-egui/src/tools/retouch_ui/tests.rs b/crates/ui-egui/src/tools/retouch_ui/tests.rs index a4001339e5..cae060ba6e 100644 --- a/crates/ui-egui/src/tools/retouch_ui/tests.rs +++ b/crates/ui-egui/src/tools/retouch_ui/tests.rs @@ -72,6 +72,9 @@ fn clone_stamp_in_pattern_preview_wraps_a_dab_across_the_right_edge() { let mut app = app(); app.run("paint.pencil", json!({"points": [[10, 10]], "size": 24, "color": "#ff0000"})).unwrap(); app.ui.tool = Tool::CloneStamp; + crate::paint_mouse::sync_tool_brush(&mut app); + // A hard tip, so the wrapped part of the dab is fully painted. + app.run("tools.setBrush", json!({"brush": {"size": 20, "hardness": 1}})).unwrap(); app.ui.clone_source = Some([10.0, 10.0]); app.ui.view.pattern_preview = pattern_preview; let modifiers = egui::Modifiers::NONE; @@ -96,6 +99,8 @@ fn clone_stamp_in_pattern_preview_wraps_a_dab_across_the_right_edge() { fn clone_stamp_paints_with_the_brush_hardness() { let rim = |hardness: f32| { let mut app = app(); + app.ui.tool = Tool::CloneStamp; + crate::paint_mouse::sync_tool_brush(&mut app); app.run("tools.setBrush", json!({"brush": {"size": 24, "hardness": hardness}})).unwrap(); app.run("paint.pencil", json!({"points": [[15, 30]], "size": 40, "color": "#ff0000"})).unwrap(); app.ui.tool = Tool::CloneStamp; diff --git a/crates/ui-egui/tests/it/healing_reset_tip.rs b/crates/ui-egui/tests/it/healing_reset_tip.rs index c783b0fa28..77aa0f32b3 100644 --- a/crates/ui-egui/tests/it/healing_reset_tip.rs +++ b/crates/ui-egui/tests/it/healing_reset_tip.rs @@ -1,6 +1,6 @@ //! #12099: Reset Tool gives the Healing Brush the reference application's tip, a 19 px hard round //! at 25 % spacing, not the 20 px default at 10 %; Reset All Tools and a first use do too. The -//! Clone Stamp, the Spot Healing Brush and commands without brush params keep theirs. +//! Pattern Stamp, the Spot Healing Brush and commands without brush params keep theirs. use photocraft_ui_egui::control::{ControlRequest, handle}; use photocraft_ui_egui::{PhotocraftApp, Tool}; @@ -90,7 +90,7 @@ fn a_first_use_starts_with_the_tip() { #[test] fn other_retouch_tools_and_session_strokes_keep_their_tips() { - for tool in [Tool::CloneStamp, Tool::SpotHealing] { + for tool in [Tool::PatternStamp, Tool::SpotHealing] { let mut a = app(); pick(&mut a, tool); scramble(&mut a);