From ddf039917a40d87ef26a0c8c1971db5331bd0efe Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:08:25 +0300 Subject: [PATCH 1/2] Clone Stamp: a press without a source point shows the reference's alert The Clone Stamp set a status-bar line when no source point was defined. It now opens the reference application's alert at the press ("Could not use the clone stamp tool because the area to clone has not been defined (Alt-click to define a source point)."), once while it is up, and starts no drag. The Healing Brush keeps its status line. --- crates/ui-egui/src/canvas/tool_input.rs | 7 +++++- crates/ui-egui/src/tools/retouch_ui.rs | 25 +++++++++++++++++--- crates/ui-egui/src/tools/retouch_ui/tests.rs | 18 +++++++------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/canvas/tool_input.rs b/crates/ui-egui/src/canvas/tool_input.rs index 7d4b17e166..ed69d3d909 100644 --- a/crates/ui-egui/src/canvas/tool_input.rs +++ b/crates/ui-egui/src/canvas/tool_input.rs @@ -525,7 +525,12 @@ pub(super) fn tool_event_with_view(app: &mut PhotocraftApp, ev: ToolEvent, mods: if !sets_source && press_refused(app, tool) { return; } - if !sets_source && (crate::rasterize_prompt::intercept(app, tool, x, y, pressure) || refuse_group(app, tool)) { + // The Clone Stamp's no-source alert opens at the press, after any rasterize prompt. + if !sets_source + && (crate::rasterize_prompt::intercept(app, tool, x, y, pressure) + || refuse_group(app, tool) + || crate::retouch_ui::clone_stamp_without_source(app, tool)) + { return; } // ⌘ with a selection tool is the Move tool for the drag: outside the selection (or diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 58aac368db..7576c7dee3 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -198,6 +198,21 @@ pub(crate) fn stroke_seed(points: &[[f64; 3]]) -> u64 { photocraft_engine::paint::rng::seed_from_bytes(first.as_bytes()) } +/// A Clone Stamp press with no source point yet: the reference application's alert, opened at +/// the press (#12609) and once while it is up. Returns whether it refused the stroke. +pub(crate) fn clone_stamp_without_source(app: &mut PhotocraftApp, tool: Tool) -> bool { + if tool != Tool::CloneStamp || clone_params(app).is_some() { + return false; + } + let message = if cfg!(target_os = "macos") { + tl!("Could not use the clone stamp tool because the area to clone has not been defined (Option-click to define a source point).") + } else { + tl!("Could not use the clone stamp tool because the area to clone has not been defined (Alt-click to define a source point).") + }; + open_alert_once(app, message); + true +} + /// Finish a stroke with a retouching tool. Returns false if `tool` isn't one. pub fn finish_stroke(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], mods: egui::Modifiers, line: bool) -> bool { finish_stroke_with(app, tool, points, mods, line, None) @@ -224,6 +239,9 @@ pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[ return true; } let Some(p) = clone_params(app) else { + if clone_stamp_without_source(app, tool) { + return true; + } // Option-click on the Mac, Alt-click on Windows. app.ui.status = if cfg!(target_os = "macos") { tl!("Option-click to define a source point to clone from") @@ -783,7 +801,8 @@ fn cam_amount_slider(ui: &mut egui::Ui, name: &str, value: &mut f32, lo: f32, hi }); } -fn open_cam_range_alert(app: &mut PhotocraftApp, message: &str) { +/// Opens the alert with `message` (English, translated here) unless it is already up. +fn open_alert_once(app: &mut PhotocraftApp, message: &str) { let message = tl!(message).to_owned(); let shown = app.ui.dialogs.iter().any(|d| d.kind == crate::state::DialogKind::Error && d.fields.get("message").and_then(|m| m.as_str()) == Some(message.as_str())); @@ -807,11 +826,11 @@ fn content_aware_move_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } opt(ui, tl!("Structure:")); if cam_integer_popup(ui, "cam-structure", "Structure", &mut app.ui.tool_options.cam_structure, 1.0, 7.0, STRUCTURE_TIP) { - open_cam_range_alert(app, STRUCTURE_RANGE_ALERT); + open_alert_once(app, STRUCTURE_RANGE_ALERT); } opt(ui, tl!("Color:")); if cam_integer_popup(ui, "cam-color", "Color", &mut app.ui.tool_options.cam_color, 0.0, 10.0, COLOR_TIP) { - open_cam_range_alert(app, COLOR_RANGE_ALERT); + open_alert_once(app, COLOR_RANGE_ALERT); } crate::widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.content_aware_move, tl!("Sample All Layers")) .on_hover_text(tl!("Enable to remix all layers")); diff --git a/crates/ui-egui/src/tools/retouch_ui/tests.rs b/crates/ui-egui/src/tools/retouch_ui/tests.rs index a6eba29bd2..545e475ae4 100644 --- a/crates/ui-egui/src/tools/retouch_ui/tests.rs +++ b/crates/ui-egui/src/tools/retouch_ui/tests.rs @@ -225,15 +225,15 @@ fn paint_bucket_mode_reaches_the_fill() { #[test] fn clone_without_a_source_names_the_platform_modifier() { - // Option-click on the Mac, Alt-click elsewhere (#251). - for tool in [Tool::CloneStamp, Tool::Healing] { - let mut app = app(); - app.ui.tool = tool; - assert!(finish_stroke(&mut app, tool, &[[10.0, 30.0, 1.0], [50.0, 30.0, 1.0]], egui::Modifiers::NONE, false)); - assert!(app.ui.status_error, "{tool:?}"); - let want = if cfg!(target_os = "macos") { "Option-click" } else { "Alt-click" }; - assert!(app.ui.status.starts_with(want), "{tool:?}: {}", app.ui.status); - } + // Option-click on the Mac, Alt-click elsewhere (#251). The Clone Stamp says it in an alert + // (#12609, clone_stamp_no_source_alert_tests.rs). + let tool = Tool::Healing; + let mut app = app(); + app.ui.tool = tool; + assert!(finish_stroke(&mut app, tool, &[[10.0, 30.0, 1.0], [50.0, 30.0, 1.0]], egui::Modifiers::NONE, false)); + assert!(app.ui.status_error); + let want = if cfg!(target_os = "macos") { "Option-click" } else { "Alt-click" }; + assert!(app.ui.status.starts_with(want), "{}", app.ui.status); } #[test] From 860f6eb215e927b5b36e30fba72a74d88b72e72d Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:08:25 +0300 Subject: [PATCH 2/2] Test the Clone Stamp's no-source alert --- .../ui-egui/src/brush_refusal_alert_tests.rs | 10 +- .../src/clone_stamp_no_source_alert_tests.rs | 95 +++++++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 2 +- crates/ui-egui/src/tools/retouch_ui.rs | 4 + 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/clone_stamp_no_source_alert_tests.rs diff --git a/crates/ui-egui/src/brush_refusal_alert_tests.rs b/crates/ui-egui/src/brush_refusal_alert_tests.rs index b24872ca6e..8acfae65e9 100644 --- a/crates/ui-egui/src/brush_refusal_alert_tests.rs +++ b/crates/ui-egui/src/brush_refusal_alert_tests.rs @@ -9,7 +9,7 @@ use super::*; use crate::canvas::{ToolEvent, tool_event}; /// A 64 × 64 document with a painted layer active, black foreground, `tool`. -pub(super) fn app(tool: Tool) -> PhotocraftApp { +pub(in crate::tools) fn app(tool: Tool) -> PhotocraftApp { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); app.run("layer.new.layer", json!({})).unwrap(); @@ -24,22 +24,22 @@ pub(super) fn active(app: &PhotocraftApp) -> u64 { app.session.active().unwrap().active_layer.unwrap().0 } -pub(super) fn steps(app: &PhotocraftApp) -> usize { +pub(in crate::tools) fn steps(app: &PhotocraftApp) -> usize { app.session.active().unwrap().history.past_len() } /// A press, a short drag and the release with the active tool. -pub(super) fn stroke(app: &mut PhotocraftApp) { +pub(in crate::tools) fn stroke(app: &mut PhotocraftApp) { tool_event(app, ToolEvent::Down { x: 20.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE); tool_event(app, ToolEvent::Move { x: 44.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE); tool_event(app, ToolEvent::Up { x: 44.0, y: 32.0 }, Modifiers::NONE); } -pub(super) fn alerts(app: &PhotocraftApp) -> Vec { +pub(in crate::tools) fn alerts(app: &PhotocraftApp) -> Vec { app.ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message").and_then(Value::as_str).map(str::to_string)).collect() } -pub(super) fn refused(app: &mut PhotocraftApp, want: &str) { +pub(in crate::tools) fn refused(app: &mut PhotocraftApp, want: &str) { let before = steps(app); stroke(app); assert_eq!(alerts(app), [want], "the alert, once"); diff --git a/crates/ui-egui/src/clone_stamp_no_source_alert_tests.rs b/crates/ui-egui/src/clone_stamp_no_source_alert_tests.rs new file mode 100644 index 0000000000..f4d1bd29d9 --- /dev/null +++ b/crates/ui-egui/src/clone_stamp_no_source_alert_tests.rs @@ -0,0 +1,95 @@ +//! #12609: a Clone Stamp press before any Alt-click opens the reference application's alert with +//! OK at the press, instead of a status-bar line, and paints nothing. The Healing Brush keeps its +//! own behaviour. + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::control::{ControlRequest, Outcome, handle}; +use crate::state::{DialogKind, Tool}; +use crate::tools::brush_refusal::brush_refusal_alert_tests::{alerts, app, refused, steps, stroke}; + +const MESSAGE: &str = if cfg!(target_os = "macos") { + "Could not use the clone stamp tool because the area to clone has not been defined (Option-click to define a source point)." +} else { + "Could not use the clone stamp tool because the area to clone has not been defined (Alt-click to define a source point)." +}; + +/// The active layer's pixels. +fn pixels(app: &PhotocraftApp) -> Vec { + let st = app.session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().read_region(st.doc.bounds()) +} + +#[test] +fn a_stroke_without_a_source_alerts_once_and_paints_nothing() { + let mut app = app(Tool::CloneStamp); + let before = pixels(&app); + refused(&mut app, MESSAGE); + assert!(!app.ui.status_error, "no status-bar error as well: {}", app.ui.status); + assert!(pixels(&app) == before, "after OK the document is unchanged"); +} + +#[test] +fn the_alert_opens_at_the_press_and_the_drag_and_release_add_none() { + let mut app = app(Tool::CloneStamp); + tool_event(&mut app, ToolEvent::Down { x: 20.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE); + assert_eq!(alerts(&app), [MESSAGE], "at the press, before any move"); + assert!(app.drag.is_none() && app.live_stroke.is_none(), "the press starts no stroke"); + // Closed before the drag, so an alert from the move or the release would show. + let id = app.ui.dialogs.iter().find(|d| d.kind == DialogKind::Error).map(|d| d.id).unwrap(); + crate::dialogs::confirm(&mut app, id).unwrap(); + tool_event(&mut app, ToolEvent::Move { x: 44.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Up { x: 44.0, y: 32.0 }, Modifiers::NONE); + assert!(alerts(&app).is_empty(), "neither the drag nor the release alerts"); +} + +#[test] +fn a_second_press_while_the_alert_is_up_adds_none() { + let mut app = app(Tool::CloneStamp); + stroke(&mut app); + stroke(&mut app); + assert_eq!(alerts(&app), [MESSAGE]); +} + +#[test] +fn the_alert_is_listed_and_confirmed_over_the_control_channel() { + let ctx = egui::Context::default(); + let mut app = app(Tool::CloneStamp); + stroke(&mut app); + let (inspect, _rx) = ControlRequest::new("ui.inspect", json!({})); + let Outcome::Done(inspect) = handle(&mut app, &ctx, &inspect) else { panic!("ui.inspect replies at once") }; + let dialog = &inspect["result"]["dialogs"][0]; + assert_eq!(dialog["fields"]["message"], MESSAGE, "{inspect}"); + let (confirm, _rx) = ControlRequest::new("ui.dialog.confirm", json!({"dialog": dialog["id"]})); + assert!(matches!(handle(&mut app, &ctx, &confirm), Outcome::Done(v) if v["ok"] == true)); + assert!(alerts(&app).is_empty()); +} + +#[test] +fn after_an_alt_click_the_clone_stamp_paints_without_an_alert() { + let mut app = app(Tool::CloneStamp); + // A white band around the source on the red layer, so the clone has something to copy. + app.run("select.rect", json!({"x": 0, "y": 0, "width": 64, "height": 20})).unwrap(); + app.run("edit.fill", json!({"color": "#ffffff"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + tool_event(&mut app, ToolEvent::Down { x: 10.0, y: 10.0, pressure: 1.0 }, Modifiers::ALT); + tool_event(&mut app, ToolEvent::Up { x: 10.0, y: 10.0 }, Modifiers::ALT); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty()); + assert_eq!(steps(&app), before + 1, "one Clone Stamp state"); + let st = app.session.active().unwrap(); + let on_stroke = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().rgba(32, 32); + assert!(on_stroke[1] > 0.5, "the stroke copies the white source onto the red: {on_stroke:?}"); +} + +#[test] +fn the_healing_brush_keeps_its_status_line() { + let mut app = app(Tool::Healing); + stroke(&mut app); + assert!(alerts(&app).is_empty()); + assert!(app.ui.status_error && app.ui.status.contains("source point to clone from"), "{}", app.ui.status); +} diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index e58eba61ff..1baa0de82b 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -90,7 +90,7 @@ pub fn prompt(app: &mut PhotocraftApp, message: &str) { #[cfg(test)] #[path = "../brush_refusal_alert_tests.rs"] -mod brush_refusal_alert_tests; +pub(super) mod brush_refusal_alert_tests; #[cfg(test)] #[path = "../sharpen_refusal_alert_tests.rs"] diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 7576c7dee3..68abe3dfae 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -1226,3 +1226,7 @@ mod sponge_flow_field_tests; #[cfg(test)] #[path = "../healing_indexed_alert_tests.rs"] mod healing_indexed_alert_tests; + +#[cfg(test)] +#[path = "../clone_stamp_no_source_alert_tests.rs"] +mod clone_stamp_no_source_alert_tests;