Refuse Dodge in Indexed Color and Bitmap documents

paint.dodge and its live stroke return the reference application's
message in Indexed Color and Bitmap documents and tone nothing; a press
with the Dodge tool shows it as a modal alert. Other modes keep dodging.
This commit is contained in:
rmsff committed 2026-11-10 13:14:36 +03:00
1 parent 71a5c58585
commit 7188facf57
2 files changed
+42 -1

No files matched your search

+18
View File
@@ -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<Value> {
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<Self> {
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"));
+24 -1
View File
@@ -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<String> {
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