From 0adab7407dcb24b096a50288b6d3d745e8cb084e Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 14 Nov 2026 17:31:55 -0600 Subject: [PATCH] Eraser: Reset Tool and a first use give a 13 px hard tip at 25 % spacing with Smoothing 0 % (#11936) --- crates/ui-egui/src/canvas/paint_mouse.rs | 12 +- .../ui-egui/src/canvas/paint_mouse/tests.rs | 12 +- crates/ui-egui/src/options_hit_area_tests.rs | 4 +- .../src/pencil_reset_defaults_tests.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/tests.rs | 11 +- .../src/tools/remove_default_size_tests.rs | 4 +- .../tests/it/background_eraser_reset_tip.rs | 15 +- .../ui-egui/tests/it/brush_reset_defaults.rs | 9 +- .../ui-egui/tests/it/eraser_reset_defaults.rs | 134 ++++++++++++++++++ crates/ui-egui/tests/it/main.rs | 1 + 10 files changed, 176 insertions(+), 28 deletions(-) create mode 100644 crates/ui-egui/tests/it/eraser_reset_defaults.rs diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index be57e18fb71..cb103047235 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -51,6 +51,9 @@ pub fn sync_tool_brush(app: &mut PhotocraftApp) { // The Pencil starts with its own 1 px hard round (#12200) regardless of the Brush, keeping // the outgoing opacity. None if tool == Tool::Pencil => BrushSettings { opacity: current.opacity, ..fresh_brush(tool, ¤t) }, + // The Eraser starts with its Reset Tool tip and no smoothing (#11936), keeping the outgoing + // opacity and flow as before (a first use's are not measured). + None if tool == Tool::Eraser => BrushSettings { opacity: current.opacity, flow: current.flow, ..fresh_brush(tool, ¤t) }, None => { let fresh = BrushSettings::default(); let (opacity, flow) = match tool { @@ -87,6 +90,9 @@ fn session_fields(current: &BrushSettings, brush: &BrushSettings) -> BrushSettin /// The Brush tool's tip after Reset Tool, as the reference measures it (#11810): size, hardness /// and spacing of a 13 px soft round at 25 % spacing. const BRUSH_TOOL_TIP: (f32, f32, f32) = (13.0, 0.0, 0.25); +/// The Eraser's tip after Reset Tool (#11936): a 13 px hard round at 25 % spacing, with no +/// smoothing. +const ERASER_TOOL_TIP: (f32, f32, f32) = (13.0, 1.0, 0.25); /// The Background Eraser's tip after Reset Tool (#11911): a 13 px hard round at 25 % spacing. const BACKGROUND_ERASER_TIP: (f32, f32, f32) = (13.0, 1.0, 0.25); /// The Healing Brush's tip after Reset Tool (#12099): a 19 px hard round at 25 % spacing. @@ -107,7 +113,7 @@ const SMUDGE_TOOL_TIP: (f32, f32, f32) = (13.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 +/// [`BRUSH_TOOL_TIP`], the Eraser's [`ERASER_TOOL_TIP`] with no smoothing, the Background Eraser's [`BACKGROUND_ERASER_TIP`], the Healing Brush's /// [`HEALING_BRUSH_TIP`], the Burn, Dodge and Sponge tools' [`TONING_TOOL_TIP`], the Clone Stamp's /// [`CLONE_STAMP_TIP`] with no smoothing, the Remove tool's size [`REMOVE_TOOL_SIZE`], the Smudge /// tool's [`SMUDGE_TOOL_TIP`] and the Pencil's [`PENCIL_TOOL_TIP`]; the other tools keep the @@ -116,6 +122,10 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings let mut brush = BrushSettings { smoothing: first_smoothing(), ..BrushSettings::default() }; match tool { Tool::Brush => (brush.size, brush.hardness, brush.spacing) = BRUSH_TOOL_TIP, + Tool::Eraser => { + (brush.size, brush.hardness, brush.spacing) = ERASER_TOOL_TIP; + brush.smoothing.amount = 0.0; + } Tool::BackgroundEraser => (brush.size, brush.hardness, brush.spacing) = BACKGROUND_ERASER_TIP, Tool::Healing => (brush.size, brush.hardness, brush.spacing) = HEALING_BRUSH_TIP, Tool::Pencil => (brush.size, brush.hardness, brush.spacing) = PENCIL_TOOL_TIP, diff --git a/crates/ui-egui/src/canvas/paint_mouse/tests.rs b/crates/ui-egui/src/canvas/paint_mouse/tests.rs index b20920dae98..a434a388c93 100644 --- a/crates/ui-egui/src/canvas/paint_mouse/tests.rs +++ b/crates/ui-egui/src/canvas/paint_mouse/tests.rs @@ -550,10 +550,10 @@ fn the_brush_is_a_per_tool_option_that_presets_keep() { app.session.tools.brush.smoothing.pulled_string = true; app.run("tools.setBrush", json!({"preset": preset})).unwrap(); assert_eq!((amount(&app), app.session.tools.brush.smoothing.pulled_string), (0.42, true)); - // The Eraser has its own (10 % at first); switching back restores the Brush's. + // The Eraser has its own (0 % at first, #11936); switching back restores the Brush's. app.ui.tool = Tool::Eraser; sync_tool_brush(&mut app); - assert_eq!(amount(&app), 0.1); + assert_eq!(amount(&app), 0.0); app.session.tools.brush.smoothing.amount = 0.0; app.ui.tool = Tool::Brush; sync_tool_brush(&mut app); @@ -611,19 +611,19 @@ fn each_tool_keeps_its_own_brush() { // A tool seen for the first time starts from the brush the old tool left (Photoshop's // 10 % smoothing), so nothing is lost by switching. - app.ui.tool = Tool::Eraser; + app.ui.tool = Tool::Blur; sync_tool_brush(&mut app); assert_eq!(size(&brush(&app)), 40.0, "a new tool inherits the current brush"); - // The Eraser edits its own size; the Brush keeps 40 px. + // The Blur tool edits its own size; the Brush keeps 40 px. app.run("tools.setBrush", json!({"brush": {"size": 8, "hardness": 1.0}})).unwrap(); app.ui.tool = Tool::Brush; sync_tool_brush(&mut app); assert_eq!(size(&brush(&app)), 40.0, "the Brush keeps its own size"); assert_eq!(hardness(&brush(&app)), 0.2, "and its hardness"); - app.ui.tool = Tool::Eraser; + app.ui.tool = Tool::Blur; sync_tool_brush(&mut app); - assert_eq!(size(&brush(&app)), 8.0, "the Eraser keeps its own size"); + assert_eq!(size(&brush(&app)), 8.0, "the Blur tool keeps its own size"); assert_eq!(hardness(&brush(&app)), 1.0, "and its hardness"); // Mode, opacity, flow and the dynamics sections are per tool too. diff --git a/crates/ui-egui/src/options_hit_area_tests.rs b/crates/ui-egui/src/options_hit_area_tests.rs index 0503a3db9da..85fdc2ef6be 100644 --- a/crates/ui-egui/src/options_hit_area_tests.rs +++ b/crates/ui-egui/src/options_hit_area_tests.rs @@ -165,10 +165,12 @@ fn options_disabled_eraser_caption_and_added_regions_do_nothing() { h.state_mut().ui.tool = crate::state::Tool::Eraser; h.state_mut().ui.tool_options.eraser_mode = "block".into(); h.run_steps(3); + // The Eraser's own brush (its first use gives it its reset tip, #11936): nothing changes it. + let hardness = h.state().session.tools.brush.hardness; let (l, f) = geometry(&h); for at in [l.center(), pos2(f.right() + 8.0, l.center().y), l.center() + vec2(0.0, 10.0)] { drag(&mut h, at, 12.0, Modifiers::NONE); - assert_eq!(h.state().session.tools.brush.hardness, 0.5); + assert_eq!(h.state().session.tools.brush.hardness, hardness); assert!(h.state().session.journal.is_empty()); } } diff --git a/crates/ui-egui/src/pencil_reset_defaults_tests.rs b/crates/ui-egui/src/pencil_reset_defaults_tests.rs index 37ebd78b4e5..861b7ffeb21 100644 --- a/crates/ui-egui/src/pencil_reset_defaults_tests.rs +++ b/crates/ui-egui/src/pencil_reset_defaults_tests.rs @@ -150,5 +150,5 @@ fn brush_and_other_painting_tools_keep_their_reset_tips() { pick(&mut a, Tool::Eraser); let e = a.run("brush.get", json!({})).unwrap(); let eraser_tip = ["size", "hardness", "spacing"].map(|k| (e[k].as_f64().unwrap() * 1e4).round() / 1e4); - assert_eq!(eraser_tip, [20.0, 1.0, 0.1]); + assert_eq!(eraser_tip, [13.0, 1.0, 0.25], "the Eraser's own reset tip (#11936)"); } diff --git a/crates/ui-egui/src/prefs/prefs_ui/tests.rs b/crates/ui-egui/src/prefs/prefs_ui/tests.rs index 4f0d1f1584c..f40991b5591 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/tests.rs @@ -1375,23 +1375,24 @@ fn the_saved_brush_owner_follows_the_saved_last_brush() { app.session.tools.brush_changed(); crate::last_brush::persist(&mut app, &ctx); crate::tool_memory::persist(&mut app, &ctx); - // The Brush's tip becomes a big sampled one, then the Eraser takes over that brush. + // The Brush's tip becomes a big sampled one, then the Blur tool takes over that brush (the Eraser has its own + // starting tip since #11936). app.session.tools.brush.tip = TipShape::Sampled(GrayTile::from_fn(400, 300, |x, y| ((x * y) % 7) as f32 / 7.0)); app.session.tools.brush_changed(); - app.ui.tool = Tool::Eraser; + app.ui.tool = Tool::Blur; crate::paint_mouse::sync_tool_brush(&mut app); crate::last_brush::persist(&mut app, &ctx); crate::tool_memory::persist(&mut app, &ctx); tick(&mut app, &ctx); let saved = stored(&store); assert_eq!(saved["lastBrush"]["brush"]["size"], json!(77.0), "the big tip is not remembered yet"); - assert_ne!(saved["toolBrushes"]["owner"], json!("Eraser"), "{saved}"); + assert_ne!(saved["toolBrushes"]["owner"], json!("Blur"), "{saved}"); let (mut app2, _) = app_with_saved(store.lock().unwrap().clone()); tick(&mut app2, &ctx); assert_eq!(app2.ui.brush_tool, Tool::Brush, "the 77 px brush is the Brush's"); assert_eq!(app2.session.tools.brush.size, 77.0); - // Once the Eraser's brush is saved, the Eraser owns it in the preferences too. + // Once the Blur tool's brush is saved, the Blur tool owns it in the preferences too. app.session.tools.brush.tip = TipShape::Round; app.session.tools.brush.size = 33.0; app.session.tools.brush_changed(); @@ -1399,7 +1400,7 @@ fn the_saved_brush_owner_follows_the_saved_last_brush() { crate::tool_memory::persist(&mut app, &ctx); tick(&mut app, &ctx); let saved = stored(&store); - assert_eq!(saved["toolBrushes"]["owner"], json!("Eraser"), "{saved}"); + assert_eq!(saved["toolBrushes"]["owner"], json!("Blur"), "{saved}"); assert_eq!(saved["lastBrush"]["brush"]["size"], json!(33.0)); } diff --git a/crates/ui-egui/src/tools/remove_default_size_tests.rs b/crates/ui-egui/src/tools/remove_default_size_tests.rs index 5bcd0b5dc08..d52661e7b1c 100644 --- a/crates/ui-egui/src/tools/remove_default_size_tests.rs +++ b/crates/ui-egui/src/tools/remove_default_size_tests.rs @@ -66,11 +66,11 @@ fn reset_all_tools_gives_it_19_px_active_or_picked_later() { assert_eq!(tip(&mut app), REMOVE_TIP, "picked after the reset"); } -/// The Pencil resets to its 1 px hard round (#12200). +/// The Pencil resets to its 1 px hard round (#12200), the Eraser to its 13 px tip (#11936). #[test] fn other_tools_keep_their_reset_sizes() { for (tool, want) in - [(Tool::Brush, 13.0), (Tool::Pencil, 1.0), (Tool::Eraser, 20.0), (Tool::SpotHealing, 20.0), (Tool::Healing, 19.0), (Tool::CloneStamp, 21.0)] + [(Tool::Brush, 13.0), (Tool::Pencil, 1.0), (Tool::Eraser, 13.0), (Tool::SpotHealing, 20.0), (Tool::Healing, 19.0), (Tool::CloneStamp, 21.0)] { let mut a = app(); pick(&mut a, tool); diff --git a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs index c47e7ce0535..6194fc60bfc 100644 --- a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs +++ b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs @@ -96,18 +96,17 @@ fn a_first_use_starts_with_the_tip() { #[test] fn other_tools_and_session_strokes_keep_their_tips() { - for tool in [Tool::Eraser, Tool::Blur] { - let mut a = app(); - pick(&mut a, tool); - scramble(&mut a); - control(&mut a, "ui.menu.invoke", json!({"id": "tool.reset"})); - assert_eq!(tip(&mut a), DEFAULT_TIP, "{tool:?}"); - } + // The Eraser has its own reset tip since #11936 (`eraser_reset_defaults`); the Blur tool hasn't. + let mut a = app(); + pick(&mut a, Tool::Blur); + scramble(&mut a); + control(&mut a, "ui.menu.invoke", json!({"id": "tool.reset"})); + assert_eq!(tip(&mut a), DEFAULT_TIP, "Blur"); let mut app = app(); assert_eq!(tip(&mut app), DEFAULT_TIP, "what `paint.stroke` / `paint.backgroundEraser` paint with when no `brush` is given"); // A first use of another tool still takes the current tip, as before. pick(&mut app, Tool::Pencil); scramble(&mut app); - pick(&mut app, Tool::Eraser); + pick(&mut app, Tool::Blur); assert_eq!(tip(&mut app)[0], 57.0); } diff --git a/crates/ui-egui/tests/it/brush_reset_defaults.rs b/crates/ui-egui/tests/it/brush_reset_defaults.rs index 745de079506..4d644d7c964 100644 --- a/crates/ui-egui/tests/it/brush_reset_defaults.rs +++ b/crates/ui-egui/tests/it/brush_reset_defaults.rs @@ -70,10 +70,11 @@ fn reset_all_tools_from_another_tool_gives_the_brush_its_tip() { let mut app = app(); pick(&mut app, Tool::Brush); scramble(&mut app); - pick(&mut app, Tool::Eraser); + // The Sharpen tool, which has no reset tip of its own (the Eraser has since #11936). + pick(&mut app, Tool::Sharpen); scramble(&mut app); control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); - assert_eq!(tip(&mut app), DEFAULT_TIP, "the Eraser"); + assert_eq!(tip(&mut app), DEFAULT_TIP, "the Sharpen tool"); pick(&mut app, Tool::Brush); assert_eq!(tip(&mut app), BRUSH_TIP, "the Brush"); } @@ -85,7 +86,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { let mut app = app(); pick(&mut app, Tool::Brush); control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); - for tool in [Tool::Eraser, Tool::Blur] { + for tool in [Tool::Sharpen, Tool::Blur] { pick(&mut app, tool); assert_eq!(tip(&mut app), DEFAULT_TIP, "{tool:?}"); } @@ -93,7 +94,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { #[test] fn other_painting_tools_keep_the_default_reset_tip() { - for tool in [Tool::Eraser, Tool::Blur] { + for tool in [Tool::Sharpen, Tool::Blur] { let mut a = app(); pick(&mut a, tool); scramble(&mut a); diff --git a/crates/ui-egui/tests/it/eraser_reset_defaults.rs b/crates/ui-egui/tests/it/eraser_reset_defaults.rs new file mode 100644 index 00000000000..a6f91ed5292 --- /dev/null +++ b/crates/ui-egui/tests/it/eraser_reset_defaults.rs @@ -0,0 +1,134 @@ +//! #11936: Reset Tool gives the Eraser the reference application's tip, a 13 px hard round at +//! 25 % spacing, with Smoothing 0 % and both pressure controls off; Reset All Tools and a first +//! use do too. The Brush and Pencil keep their 10 % smoothing, and `paint.stroke` without a +//! `brush` keeps today's defaults. + +use photocraft_ui_egui::control::{ControlRequest, handle}; +use photocraft_ui_egui::{PhotocraftApp, Tool}; +use serde_json::{Value, json}; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.sync_views(); + app +} + +/// A control request as the control channel sends it, then the frame's sync. +fn control(app: &mut PhotocraftApp, method: &str, params: Value) -> Value { + let ctx = egui::Context::default(); + let (req, rx) = ControlRequest::new(method, params); + handle(app, &ctx, &req); + app.sync_views(); + rx.try_recv().unwrap_or(Value::Null) +} + +/// Pick `tool`, and swap its brush in as a frame does. +fn pick(app: &mut PhotocraftApp, tool: Tool) { + app.ui.tool = tool; + photocraft_ui_egui::paint_mouse::sync_tool_brush(app); + app.sync_views(); +} + +fn brush(app: &mut PhotocraftApp) -> Value { + app.run("brush.get", json!({})).unwrap() +} + +/// Size, hardness, spacing, angle, roundness and smoothing, as `brush.get` reports them. +fn tip(app: &mut PhotocraftApp) -> [f64; 6] { + let b = brush(app); + let smoothing = b["smoothing"].as_f64().or_else(|| b["smoothing"]["amount"].as_f64()).unwrap(); + let [size, hardness, spacing, angle, roundness] = ["size", "hardness", "spacing", "angle", "roundness"].map(|k| b[k].as_f64().unwrap()); + [size, hardness, spacing, angle, roundness, smoothing].map(|v| (v * 1e4).round() / 1e4) +} + +fn pressures(app: &mut PhotocraftApp) -> (bool, bool) { + let b = brush(app); + (b["pressureSize"].as_bool().unwrap(), b["pressureOpacity"].as_bool().unwrap()) +} + +/// A tip, smoothing and pressure that are neither default, 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.pressure_size, b.pressure_opacity) = (57.0, 0.4, 0.6, 30.0, 0.5, true, true); + b.smoothing.amount = 0.6; +} + +const ERASER: [f64; 6] = [13.0, 1.0, 0.25, 0.0, 1.0, 0.0]; + +#[test] +fn reset_tool_gives_the_eraser_a_13_px_hard_tip_without_smoothing() { + let mut app = app(); + pick(&mut app, Tool::Eraser); + scramble(&mut app); + control(&mut app, "ui.menu.invoke", json!({"id": "tool.reset"})); + assert_eq!(tip(&mut app), ERASER); + assert_eq!(pressures(&mut app), (false, false), "pressure for size and opacity off"); + // The options-bar brush chip and Smoothing field show the brush's size and smoothing. + assert_eq!(app.session.tools.brush.size.round(), 13.0); + assert_eq!(app.session.tools.brush.smoothing.amount, 0.0); +} + +#[test] +fn reset_all_tools_gives_it_the_tip_active_or_picked_later() { + let mut app = app(); + pick(&mut app, Tool::Eraser); + scramble(&mut app); + control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); + assert_eq!(tip(&mut app), ERASER, "active"); + let mut app = self::app(); + pick(&mut app, Tool::Eraser); + scramble(&mut app); + pick(&mut app, Tool::Brush); + control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); + pick(&mut app, Tool::Eraser); + assert_eq!(tip(&mut app), ERASER, "picked after the reset"); + assert_eq!(pressures(&mut app), (false, false)); +} + +#[test] +fn a_first_use_starts_with_the_tip() { + // No stored tool brushes: the Eraser's first pick, after another tool's tip. + let mut app = app(); + pick(&mut app, Tool::Blur); + scramble(&mut app); + pick(&mut app, Tool::Eraser); + assert_eq!(tip(&mut app), ERASER); + // Its own tip is then kept across tool switches. + app.session.tools.brush.size = 42.0; + pick(&mut app, Tool::Blur); + pick(&mut app, Tool::Eraser); + assert_eq!(tip(&mut app)[0], 42.0); +} + +#[test] +fn a_flow_50_stroke_after_reset_leaves_alpha_12_to_22() { + let mut app = app(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("edit.fill", json!({"color": "#2050c8"})).unwrap(); + pick(&mut app, Tool::Eraser); + control(&mut app, "ui.menu.invoke", json!({"id": "tool.reset"})); + app.session.tools.brush.flow = 0.5; + let points: Vec<[f64; 3]> = (0..=120).map(|i| [40.0 + i as f64, 100.5, 1.0]).collect(); + app.run("paint.stroke", json!({"points": points, "erase": true})).unwrap(); + let st = app.session.active().unwrap(); + let surf = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap(); + for x in [70, 100, 130] { + let a = (surf.pixel(x, 100)[3] * 255.0).round(); + assert!((12.0..=22.0).contains(&a), "alpha {a} at {x},100"); + } + assert_eq!((surf.pixel(100, 80)[3] * 255.0).round(), 255.0, "outside the stroke"); +} + +#[test] +fn the_brush_and_pencil_keep_their_smoothing_and_session_strokes_their_defaults() { + for tool in [Tool::Brush, Tool::Pencil] { + let mut a = app(); + pick(&mut a, tool); + scramble(&mut a); + control(&mut a, "ui.menu.invoke", json!({"id": "tool.reset"})); + assert_eq!(tip(&mut a)[5], 0.1, "{tool:?} at 10 %"); + } + let mut app = app(); + assert_eq!(tip(&mut app)[..3], [20.0, 1.0, 0.1], "what `paint.stroke` paints with when no `brush` is given"); +} diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 8004bf5b73f..ea4a5208714 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -31,6 +31,7 @@ mod crop_turn_keeps_frame_inside; mod custom_print_paper; mod display_shadows; mod drag_preview_canvas; +mod eraser_reset_defaults; mod export_as_scaling; mod eyedropper_ring; mod full_res_preview;