diff --git a/crates/engine/src/cmd/retouch_cmds/dab.rs b/crates/engine/src/cmd/retouch_cmds/dab.rs index a950ad5992..f7289b2a21 100644 --- a/crates/engine/src/cmd/retouch_cmds/dab.rs +++ b/crates/engine/src/cmd/retouch_cmds/dab.rs @@ -265,9 +265,26 @@ impl DabTool { } } +/// The reference application refuses a Dodge stroke in Indexed Color and Bitmap documents, with +/// its alert's words (#12686); other modes (Multichannel and Duotone were not measured) tone as +/// before. The live stroke checks this too, so it previews nothing there. +fn mode_refusal(s: &Session, cmd: &str) -> Result<()> { + let tool = match cmd { + "paint.dodge" => "dodge tool", + _ => return Ok(()), + }; + let why = match s.active().map(|st| st.doc.mode) { + Some(photocraft_color::ColorMode::Indexed) => "it does not work with Indexed Color images (convert image to RGB Color mode to edit).", + Some(photocraft_color::ColorMode::Bitmap) => "it does not work with Bitmap images (convert image to Grayscale mode to edit).", + _ => return Ok(()), + }; + Err(EngineError::Other(format!("Could not use the {tool} because {why}"))) +} + /// Dodge, Burn, Sponge, Blur, Sharpen and Smudge: each dab edits a working copy in order /// (`apply_dab_stroke`). Blur, Sharpen and Smudge can sample all layers. pub(super) fn dab_cmd(s: &mut Session, p: &Value, cmd: &str) -> Result { + mode_refusal(s, cmd)?; let (stroke, id) = parse_brush(s, p, cmd)?; let (tool, label) = DabTool::parse(s, cmd, p, &stroke)?; let all = matches!(tool, DabTool::Focus { .. } | DabTool::Smudge { .. }) && sample_all_layers(p); @@ -418,6 +435,7 @@ pub struct LiveDab { impl LiveDab { /// Start a live stroke of `cmd` from its params; their `points` are rendered. pub fn begin(s: &Session, cmd: &str, p: &Value) -> Result { + mode_refusal(s, cmd)?; has_pixel_layer(s).map_err(EngineError::Other)?; if sample_all_layers(p) { return Err(bad(cmd, "Sample All Layers strokes aren't previewed live")); diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index c1919c8639..f1e202635d 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -13,6 +13,20 @@ pub const HIDDEN: &str = "Could not use the {tool} because the target layer is h pub const LOCKED: &str = "Could not use the {tool} because the layer is locked."; pub const GROUP: &str = "Could not use the {tool} because the pixels in a group cannot be edited without merging the group."; +/// The colour-mode alerts (#12686); `{tool}` is [`mode_tool_name`]. The engine refuses the +/// command with the same words. +pub const INDEXED: &str = "Could not use the {tool} because it does not work with Indexed Color images (convert image to RGB Color mode to edit)."; +pub const BITMAP: &str = "Could not use the {tool} because it does not work with Bitmap images (convert image to Grayscale mode to edit)."; + +/// The tool's name in the colour-mode alerts, for the tools whose wording was measured: the Dodge +/// tool. Kept apart from [`tool_name`]: the layer alerts weren't measured for these tools (#12685). +fn mode_tool_name(tool: Tool) -> Option<&'static str> { + match tool { + Tool::Dodge => Some(tl!("dodge tool")), + _ => None, + } +} + /// The tool's name in the alerts, for the tools whose wording was measured: the Brush. pub fn tool_name(tool: Tool) -> Option<&'static str> { match tool { @@ -23,8 +37,17 @@ pub fn tool_name(tool: Tool) -> Option<&'static str> { /// The alert a press with `tool` gets, if any. `hidden` is the press-time hidden-target refusal /// (`canvas::tool_input`), which this only words; the lock and the group are checked here. Lock -/// transparent pixels is no refusal, and a group's targeted mask paints. +/// transparent pixels is no refusal, and a group's targeted mask paints. A tool with a +/// [`mode_tool_name`] gets only its colour-mode alert, in an Indexed Color or Bitmap document. pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { + if let Some(name) = mode_tool_name(tool) { + let template = match app.session.active()?.doc.mode { + photocraft_doc::ColorMode::Indexed => INDEXED, + photocraft_doc::ColorMode::Bitmap => BITMAP, + _ => return None, + }; + return Some(crate::i18n::fmt(tl!(template), &[("tool", name)])); + } let name = tool_name(tool)?; let template = if hidden { HIDDEN