diff --git a/crates/ui-egui/src/canvas/cursors.rs b/crates/ui-egui/src/canvas/cursors.rs index 5d1934039c8..5a463668d0e 100644 --- a/crates/ui-egui/src/canvas/cursors.rs +++ b/crates/ui-egui/src/canvas/cursors.rs @@ -34,11 +34,12 @@ pub(crate) fn pencil_tip_is_round(size: f32) -> bool { (h - 0.5) * std::f32::consts::SQRT_2 > h } -/// Whether a brush-tip circle draws its centre mark. -/// Clone Stamp and Healing Brush stay an empty circle until Option is held, the source-point -/// cursor. Other brushes follow Preferences › Cursors › Show Crosshair in Brush Tip, as in -/// Photoshop; the Background Eraser always shows its sampling hotspot, and the Remove tool its -/// centre + (#12550). +/// Whether a brush-tip circle draws its centre mark, for Normal and Full Size Brush Tip cursors +/// alike (both draw through this). Quick Selection never draws one. Clone Stamp and Healing Brush +/// stay an empty circle until Option is held, the source-point cursor. Other brushes follow +/// Preferences › Cursors › Show Crosshair in Brush Tip, as in Photoshop; the Background Eraser +/// and the Color Replacement tool (#11934) always show their sampling hotspot, and the Remove +/// tool its centre + (#12550). pub(super) fn brush_tip_centre(tool: Tool, option: bool, show_crosshair: bool) -> bool { if tool == Tool::QuickSelection { return false; @@ -46,7 +47,7 @@ pub(super) fn brush_tip_centre(tool: Tool, option: bool, show_crosshair: bool) - if matches!(tool, Tool::CloneStamp | Tool::Healing) { return option || show_crosshair; } - show_crosshair || matches!(tool, Tool::BackgroundEraser | Tool::Remove) + show_crosshair || matches!(tool, Tool::BackgroundEraser | Tool::ColorReplacement | Tool::Remove) } /// The display colour of an RGB triple (0..1 per channel) as an egui colour. @@ -413,6 +414,10 @@ pub(crate) fn alt_picks(tool: Tool, mods: egui::Modifiers) -> bool { #[path = "../eyedropper_mask_sample_tests.rs"] mod eyedropper_mask_sample_tests; +#[cfg(test)] +#[path = "../color_replacement_cursor_tests.rs"] +mod color_replacement_cursor_tests; + #[cfg(test)] #[path = "../color_replacement_alt_click_tests.rs"] mod color_replacement_alt_click_tests; diff --git a/crates/ui-egui/src/color_replacement_cursor_tests.rs b/crates/ui-egui/src/color_replacement_cursor_tests.rs new file mode 100644 index 00000000000..e2ed2b1859f --- /dev/null +++ b/crates/ui-egui/src/color_replacement_cursor_tests.rs @@ -0,0 +1,40 @@ +//! #11934: with Normal and Full Size Brush Tip cursors the Color Replacement cursor always draws +//! the centre +, its sampling hotspot, whatever Show Crosshair in Brush Tip says. Other brush +//! tools follow the preference, and Clone Stamp / Healing Brush keep their Alt behaviour. + +use super::*; + +#[test] +fn color_replacement_always_shows_its_centre() { + for show_crosshair in [false, true] { + for option in [false, true] { + assert!(brush_tip_centre(Tool::ColorReplacement, option, show_crosshair), "crosshair pref {show_crosshair}, Alt {option}"); + } + } +} + +#[test] +fn other_brush_tools_follow_the_preference() { + for tool in [Tool::Brush, Tool::Eraser, Tool::PatternStamp, Tool::Dodge, Tool::Pencil, Tool::Smudge] { + for option in [false, true] { + assert!(!brush_tip_centre(tool, option, false), "{tool:?} off, Alt {option}"); + assert!(brush_tip_centre(tool, option, true), "{tool:?} on, Alt {option}"); + } + } + for show_crosshair in [false, true] { + for option in [false, true] { + // The Background Eraser keeps its hotspot, as before; Quick Selection never has one. + assert!(brush_tip_centre(Tool::BackgroundEraser, option, show_crosshair)); + assert!(!brush_tip_centre(Tool::QuickSelection, option, show_crosshair)); + } + } +} + +#[test] +fn clone_stamp_and_healing_keep_their_alt_behaviour() { + for tool in [Tool::CloneStamp, Tool::Healing] { + assert!(!brush_tip_centre(tool, false, false), "{tool:?}"); + assert!(brush_tip_centre(tool, true, false), "{tool:?} with Alt"); + assert!(brush_tip_centre(tool, false, true), "{tool:?} with the preference"); + } +}