Reset All Tools gives each painting tool its own starting brush (#11810)

Reset All Tools cleared every tool's remembered brush, and a tool
without one takes the live brush when it is picked. With the Brush's
starting tip now differing from the other tools', that leaked: Reset All
from the Brush left the Pencil and Eraser on a 13 px soft tip, and from
another tool it left the Brush on a 20 px hard one. Reset All now gives
each painting tool other than the live one its own starting brush.

Also names the Brush tool's reset tip and updates tool_reset's docs.
This commit is contained in:
RickiNano committed 2026-11-07 08:41:17 +01:00
1 parent 4fa29f657d
commit 9d21d6c640
4 files changed
+52 -9

No files matched your search

+7 -3
View File
@@ -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)
}
+6 -3
View File
@@ -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]
+11 -3
View File
@@ -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, &current)))
.collect();
}
/// The live brush is `app.ui.brush_tool`'s: give it that tool's starting brush.
@@ -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] {