diff --git a/crates/ui-egui/src/canvas/cursor_policy.rs b/crates/ui-egui/src/canvas/cursor_policy.rs index f5e6180877..5aac0cc5f0 100644 --- a/crates/ui-egui/src/canvas/cursor_policy.rs +++ b/crates/ui-egui/src/canvas/cursor_policy.rs @@ -50,17 +50,22 @@ pub(crate) fn sample_target() -> Cursor { /// The pointer of a painting tool that acts on a click and has no brush tip: the Paint Bucket's /// arrow with the bucket below right of it, the hotspot on the arrow's tip, so a click fills the -/// pixel under the tip (#12539), and the Magic Eraser's crosshair. Precise Other Cursors (or Caps -/// Lock, `precise`) gives the Paint Bucket the crosshair too (#3968). `None` for a tool that -/// strokes with the brush. +/// pixel under the tip (#12539), and the Magic Eraser's own icon with the hotspot on the eraser's +/// end at the lower left (#12001). Precise Other Cursors (or Caps Lock, `precise`) gives both the +/// crosshair (#3968). `None` for a tool that strokes with the brush. pub(crate) fn click_tool_cursor(tool: Tool, precise: bool) -> Option { match tool { Tool::PaintBucket if !precise => Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(tool)))), + Tool::MagicEraser if !precise => Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(tool), MAGIC_ERASER_HOTSPOT, None))), Tool::PaintBucket | Tool::MagicEraser => Some(Cursor::Painted(PaintedCursor::Crosshair)), _ => None, } } +/// The Magic Eraser icon's point that sits on the pointer, in its 24-unit box: the middle of the eraser's end, which +/// lies at the lower left of the `eraser_magic` glyph (#12001). +pub(crate) const MAGIC_ERASER_HOTSPOT: egui::Vec2 = egui::vec2(4.6, 18.4); + /// Path Selection's own pointer (#13295): the light arrow, and the solid one with ⌥ (without ⌘) /// where a press would land on a component (`path_components::over_component`). ⌘ keeps the light /// one; Precise Other Cursors (or Caps Lock, `precise`) the crosshair. `mods` and `at` are the @@ -161,3 +166,7 @@ mod triangle_alt_eyedropper_tests; #[cfg(test)] #[path = "custom_shape_alt_eyedropper_tests.rs"] mod custom_shape_alt_eyedropper_tests; + +#[cfg(test)] +#[path = "magic_eraser_cursor_tests.rs"] +mod magic_eraser_cursor_tests; diff --git a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs new file mode 100644 index 0000000000..aed908d1fe --- /dev/null +++ b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs @@ -0,0 +1,46 @@ +//! #12001: the Magic Eraser's cursor is its own toolbar icon with the hotspot on the eraser's end at the lower left, +//! also with Shift held; Precise Other Cursors and Caps Lock give the crosshair. Driven through real egui input on +//! the real canvas; the assertions read the cursor the tool asked the tool host for. + +use craft::behavior::{Cursor, PaintedCursor}; +use craft::ui::runtime::windows::WindowHost; +use egui::Modifiers; +use egui_kittest::Harness; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::guide_cursor_tests::{harness, hover}; +use crate::state::Tool; + +/// A point away from the harness's guide at x = 200. +const AT: [f32; 2] = [100.0, 150.0]; + +fn cursor_with(h: &mut Harness<'static, Box>, mods: Modifiers) -> Option { + hover(h, AT[0], AT[1], mods); + h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone()) +} + +#[test] +fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() { + let mut h = harness(Tool::MagicEraser); + let Some(Cursor::Painted(PaintedCursor::Tool { icon, hotspot, badge, .. })) = cursor_with(&mut h, Modifiers::NONE) else { + panic!("an icon cursor, not the crosshair"); + }; + assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon"); + // The eraser end of the glyph, at the lower left of its 24-unit box: pinned by value so a moved constant fails. + assert_eq!(hotspot, egui::vec2(4.6, 18.4), "the eraser tip"); + assert!(badge.is_none()); + assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it"); +} + +#[test] +fn precise_other_cursors_and_caps_lock_give_the_crosshair() { + let mut h = harness(Tool::MagicEraser); + let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair)); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap(); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Precise: the crosshair"); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "standard"})).unwrap(); + assert_ne!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Standard again: the icon"); + WindowHost::of(&h.ctx).set_caps_lock(Some(true)); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Caps Lock: the crosshair"); +}