diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index e3fe876e16c..ab145ff2b30 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -67,13 +67,17 @@ fn session_fields(current: &BrushSettings, brush: &BrushSettings) -> BrushSettin BrushSettings { color: current.color, background: current.background, erase: current.erase, seed: current.seed, ..brush.clone() } } +/// 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); + /// `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 the reference's -/// 13 px soft round at 25 % spacing (#11810); the other tools keep the default tip. +/// smoothing, with the session's own fields of `current`. The Brush tool's tip is +/// [`BRUSH_TOOL_TIP`]; 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() }; if tool == Tool::Brush { - (brush.size, brush.hardness, brush.spacing) = (13.0, 0.0, 0.25); + (brush.size, brush.hardness, brush.spacing) = BRUSH_TOOL_TIP; } session_fields(current, &brush) } diff --git a/crates/ui-egui/src/prefs/prefs_ui/tests.rs b/crates/ui-egui/src/prefs/prefs_ui/tests.rs index dabde320b8e..e38c82d661e 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/tests.rs @@ -1313,7 +1313,7 @@ fn remembered_tool_brushes_survive_damage() { } /// #6212: Reset Tool forgets that tool's remembered options and brush; Reset All Tools -/// forgets every tool's. +/// forgets every tool's: each painting tool keeps only its own starting brush (#11810). #[test] fn reset_tools_clear_the_remembered_options_and_brushes() { use crate::state::Tool; @@ -1352,10 +1352,13 @@ fn reset_tools_clear_the_remembered_options_and_brushes() { tick(&mut app, &ctx); let saved = stored(&store); assert!(saved["toolOptions"].is_null(), "{saved}"); - assert!(saved["toolBrushes"]["brushes"].as_object().is_none_or(|m| m.is_empty()), "{saved}"); + let starting = |brushes: &[(Tool, photocraft_engine::BrushSettings)]| { + brushes.iter().all(|(t, b)| *b == crate::paint_mouse::fresh_brush(*t, b) && b.size != 77.0) + }; + assert!(starting(&app.ui.tool_brushes), "{saved}"); let (app2, _) = app_with_saved(store.lock().unwrap().clone()); assert_eq!(app2.ui.tool_options, crate::state::ToolOptions::default()); - assert!(app2.ui.tool_brushes.is_empty()); + assert!(!app2.ui.tool_brushes.is_empty() && starting(&app2.ui.tool_brushes), "remembered across a restart"); } #[test] diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 29e5270cf46..b2f7b00877e 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -13,8 +13,9 @@ //! Smudge). Resetting one of those tools resets the shared field too. Sample All Layers is kept per //! tool, as in Photoshop, so resetting a tool resets only its own. //! [`reset_options`] lists the fields of each tool. The selection tools also go back to New -//! Selection, and the painting tools (the ones with a brush in the options bar) get the default -//! brush, keeping the colours. Tools without options (Hand, Rotate View, Ruler, Note, …) have +//! Selection, and the painting tools (the ones with a brush in the options bar) get their starting +//! brush (`paint_mouse::fresh_brush`: the Brush tool's 13 px soft round, the default brush for the +//! others), keeping the colours. Tools without options (Hand, Rotate View, Ruler, Note, …) have //! nothing to reset. use serde_json::{Map, Value, json}; @@ -91,8 +92,15 @@ fn reset_all(app: &mut PhotocraftApp) { app.ui.frame_tool = Default::default(); app.ui.tool_options = ToolOptions::default(); app.ui.selection_mode = 0; - app.ui.tool_brushes.clear(); reset_session_brush(app); + // Every other painting tool gets its own starting brush. Left without one, it would take the + // live brush when picked (`sync_tool_brush`), and the tools' starting tips differ (#11810). + let (live, current) = (app.ui.brush_tool, app.session.tools.brush.clone()); + app.ui.tool_brushes = Tool::ALL + .iter() + .filter(|t| **t != live && crate::paint_mouse::has_brush_picker(**t)) + .map(|t| (*t, crate::paint_mouse::fresh_brush(*t, ¤t))) + .collect(); } /// The live brush is `app.ui.brush_tool`'s: give it that tool's starting brush. diff --git a/crates/ui-egui/tests/it/brush_reset_defaults.rs b/crates/ui-egui/tests/it/brush_reset_defaults.rs index 1bdd1b79791..0c596a21025 100644 --- a/crates/ui-egui/tests/it/brush_reset_defaults.rs +++ b/crates/ui-egui/tests/it/brush_reset_defaults.rs @@ -63,6 +63,34 @@ fn reset_all_tools_gives_the_brush_its_tip() { assert_eq!(tip(&mut app), BRUSH_TIP); } +/// Reset All Tools from another painting tool: the Brush gets its own tip when picked, not the +/// live brush. +#[test] +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); + 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"); + pick(&mut app, Tool::Brush); + assert_eq!(tip(&mut app), BRUSH_TIP, "the Brush"); +} + +/// Reset All Tools from the Brush: the other painting tools get the default tip when picked, not +/// the Brush's. +#[test] +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::Pencil, Tool::Eraser] { + pick(&mut app, tool); + assert_eq!(tip(&mut app), DEFAULT_TIP, "{tool:?}"); + } +} + #[test] fn other_painting_tools_keep_the_default_reset_tip() { for tool in [Tool::Pencil, Tool::Eraser] {