feat(ui): the Healing Brush Mode menus gain Replace and the reference's rules (#12101)

Both measured menus, options bar dropdown and Shift+right-click, now list
Normal, Replace, a rule, Multiply, Screen, Darken, Lighten, a rule, Color,
Luminosity. Replace is a Healing Brush tool option, like the painting tools'
Clear flags: picking it runs no command and adds no History step, and the
stroke params carry mode:"replace" to the engine commit this branch adds. The
seven blend modes, their keyboard letters, the step cycle and Reset Tool keep
their meanings; the new option resets with the Healing Brush.
This commit is contained in:
hnoerenberg committed 2026-11-26 22:55:35 +01:00
1 parent de75f47644
commit 5cb23ca42a
10 files changed
+224 -21

No files matched your search

+35 -4
View File
@@ -20,6 +20,9 @@ pub(crate) enum Item {
Separator,
/// The tool's blend mode.
Blend(BlendMode),
/// The Healing Brush's Replace row (#12101): copy the source without healing. It is not a
/// blend mode: the stroke sends it as a mode word, and the keys and the ⇧+ / ⇧− cycle skip it.
HealingReplace,
/// Painting-only: paint behind the layer's pixels (Brush, Pencil and Pattern Stamp).
Behind,
/// Painting-only: paint transparency (Brush, Pencil, Paint Bucket).
@@ -39,6 +42,7 @@ impl Item {
Item::EditBrush => "Edit Brush…",
Item::Separator => return None,
Item::Blend(m) => m.label(),
Item::HealingReplace => "Replace",
Item::Behind => "Behind",
Item::Clear => "Clear",
Item::Eraser(m) => match m {
@@ -98,8 +102,8 @@ fn blend_items(behind: bool, clear: bool) -> Vec<Item> {
/// `tool`'s menu, top to bottom. Empty for a tool without one (its Shift+right-click keeps its
/// other route). Only what the tool's options bar offers is listed: the reference application's
/// Behind for the Clone Stamp, History Brush, Gradient and Paint Bucket, the Blur, Sharpen and Smudge
/// modes, the Spot Healing modes and the Healing Brush's source and Replace have no setting here.
/// Behind for the Clone Stamp, History Brush, Gradient and Paint Bucket, the Blur, Sharpen and
/// Smudge modes, the Spot Healing modes and the Healing Brush's source have no setting here.
pub(crate) fn items(tool: Tool) -> Vec<Item> {
let with_brush = |rest: Vec<Item>| std::iter::once(Item::EditBrush).chain(std::iter::once(Item::Separator)).chain(rest).collect::<Vec<_>>();
match tool {
@@ -110,7 +114,22 @@ pub(crate) fn items(tool: Tool) -> Vec<Item> {
Tool::Eraser => ["brush", "pencil", "block"].into_iter().map(Item::Eraser).collect(),
Tool::Dodge | Tool::Burn => with_brush(["shadows", "midtones", "highlights"].into_iter().map(Item::Range).collect()),
Tool::Sponge => with_brush(["desaturate", "saturate"].into_iter().map(Item::Sponge).collect()),
Tool::Healing => crate::blend_keys::HEALING_MODES.into_iter().map(Item::Blend).collect(),
// The measured list (#12101): Replace after Normal, rules before Multiply and before Color.
Tool::Healing => {
use BlendMode::*;
vec![
Item::Blend(Normal),
Item::HealingReplace,
Item::Separator,
Item::Blend(Multiply),
Item::Blend(Screen),
Item::Blend(Darken),
Item::Blend(Lighten),
Item::Separator,
Item::Blend(Color),
Item::Blend(Luminosity),
]
}
Tool::Gradient => blend_items(false, false),
Tool::PaintBucket => blend_items(false, true),
_ => Vec::new(),
@@ -151,7 +170,15 @@ pub(crate) fn current(app: &PhotocraftApp, tool: Tool) -> Option<Item> {
Tool::Brush => painting(o.brush_clear),
Tool::Pencil => painting(o.pencil_clear),
Tool::PatternStamp => painting(false),
Tool::CloneStamp | Tool::HistoryBrush | Tool::Healing => Item::Blend(crate::blend_keys::brush_tool_mode(tool, brush.mode)),
Tool::CloneStamp | Tool::HistoryBrush => Item::Blend(crate::blend_keys::brush_tool_mode(tool, brush.mode)),
// Replace wins over the brush's blend mode: it is the row the tool option selects (#12101).
Tool::Healing => {
if o.healing_replace {
Item::HealingReplace
} else {
Item::Blend(crate::blend_keys::brush_tool_mode(tool, brush.mode))
}
}
Tool::Gradient => Item::Blend(o.gradient_blend_mode),
Tool::PaintBucket if o.bucket_clear => Item::Clear,
Tool::PaintBucket => Item::Blend(o.bucket_blend_mode),
@@ -231,6 +258,8 @@ pub(crate) fn choose(app: &mut PhotocraftApp, item: Item) {
Ok(_) => match tool {
Tool::Brush => app.ui.tool_options.brush_clear = item == Item::Clear,
Tool::Pencil => app.ui.tool_options.pencil_clear = item == Item::Clear,
// Any of the seven blend modes leaves Replace (#12101).
Tool::Healing => app.ui.tool_options.healing_replace = false,
_ => {}
},
Err(e) => app.ui.status = e,
@@ -246,6 +275,8 @@ pub(crate) fn choose(app: &mut PhotocraftApp, item: Item) {
Item::Eraser(m) => app.ui.tool_options.eraser_mode = m.into(),
Item::Range(r) => app.ui.tool_options.tone_range = r.into(),
Item::Sponge(m) => app.ui.tool_options.sponge_mode = m.into(),
// Replace is a tool option: it runs no command and adds no History step (#12101).
Item::HealingReplace if tool == Tool::Healing => app.ui.tool_options.healing_replace = true,
Item::Blend(m) if tool == Tool::Gradient => crate::blend_keys::set_gradient_mode(app, m),
Item::Blend(m) if tool == Tool::PaintBucket => {
app.ui.tool_options.bucket_clear = false;
@@ -509,7 +509,7 @@ fn shift_right_menu_lists_each_tools_own_rows_in_order() {
(Tool::Sponge, edit(vec!["Desaturate", "Saturate"])),
(Tool::PaintBucket, with(&["Clear"])),
(Tool::MixerBrush, vec!["Edit Brush…"]),
(Tool::Healing, vec!["Normal", "Multiply", "Screen", "Darken", "Lighten", "Color", "Luminosity"]),
(Tool::Healing, vec!["Normal", "Replace", "Multiply", "Screen", "Darken", "Lighten", "Color", "Luminosity"]),
(Tool::SpotHealing, vec![]),
(Tool::MagicEraser, vec![]),
] {
@@ -0,0 +1,110 @@
//! #12101: the Healing Brush's Mode menus gain Replace and the reference's two separators, in the
//! measured order Normal, Replace, separator, Multiply, Screen, Darken, Lighten, separator, Color,
//! Luminosity. Picking Replace is a tool option only: it adds no History step, sends
//! `mode:"replace"` on the next stroke, and any other mode pick leaves it. The keyboard cycle
//! stays inside the seven blend modes.
use craft::ui::patterns::blend_keys::{BlendShortcut, BlendStep};
use photocraft_color::BlendMode;
use serde_json::json;
use super::PaintMode;
use super::fill::mode_entries;
use crate::blend_keys::{fired, test_fired};
use crate::brush_mode_menu::{Item, current, items, labels};
use crate::state::Tool;
use crate::{PhotocraftApp, brush_mode_menu};
/// The measured row order of the canvas Shift+right-click menu, separators in place.
const MENU_ROWS: [Item; 10] = [
Item::Blend(BlendMode::Normal),
Item::HealingReplace,
Item::Separator,
Item::Blend(BlendMode::Multiply),
Item::Blend(BlendMode::Screen),
Item::Blend(BlendMode::Darken),
Item::Blend(BlendMode::Lighten),
Item::Separator,
Item::Blend(BlendMode::Color),
Item::Blend(BlendMode::Luminosity),
];
/// The same list as the options bar dropdown's entry values (`None` is a rule).
const BAR_ROWS: [Option<PaintMode>; 10] = [
Some(PaintMode::Blend(BlendMode::Normal)),
Some(PaintMode::HealingReplace),
None,
Some(PaintMode::Blend(BlendMode::Multiply)),
Some(PaintMode::Blend(BlendMode::Screen)),
Some(PaintMode::Blend(BlendMode::Darken)),
Some(PaintMode::Blend(BlendMode::Lighten)),
None,
Some(PaintMode::Blend(BlendMode::Color)),
Some(PaintMode::Blend(BlendMode::Luminosity)),
];
#[test]
fn both_healing_mode_lists_show_replace_and_the_two_separators() {
assert_eq!(items(Tool::Healing), MENU_ROWS, "the Shift+right-click menu rows");
assert_eq!(labels(Tool::Healing), ["Normal", "Replace", "Multiply", "Screen", "Darken", "Lighten", "Color", "Luminosity"], "the labels, separators left out");
let entries = mode_entries(Tool::Healing, true, false);
let values: Vec<Option<PaintMode>> = entries.iter().map(|e| e.value().cloned()).collect();
assert_eq!(values, BAR_ROWS, "the options bar dropdown");
// Another tool's list is untouched by this: the Clone Stamp keeps the layer modes.
assert!(!mode_entries(Tool::CloneStamp, true, false).iter().any(|e| e.value() == Some(&PaintMode::HealingReplace)), "no Replace on the Clone Stamp");
assert!(items(Tool::CloneStamp).iter().all(|i| *i != Item::HealingReplace), "no Replace row on the Clone Stamp menu");
}
/// A Healing Brush app with a document, a set clone source and the tool active.
fn app() -> Box<PhotocraftApp> {
let mut a = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
a.run("file.new", json!({"width": 32, "height": 32})).unwrap();
a.ui.tool = Tool::Healing;
crate::retouch_ui::set_source(&mut a, 8.0, 8.0);
a
}
/// The mode the next stroke would carry in its params.
fn stroke_mode(a: &PhotocraftApp) -> String {
crate::retouch_ui::clone_params(a).expect("a source is set")["mode"].as_str().unwrap_or_default().to_owned()
}
fn steps(a: &PhotocraftApp) -> usize {
a.session.active().unwrap().history.past_len()
}
#[test]
fn the_canvas_menu_replace_row_switches_the_stroke_without_a_history_step() {
let mut a = app();
let before = steps(&a);
brush_mode_menu::choose(&mut a, Item::HealingReplace);
assert!(a.ui.tool_options.healing_replace, "the row sets the tool option");
assert_eq!(stroke_mode(&a), "replace", "the next stroke sends mode:\"replace\"");
assert_eq!(current(&a, Tool::Healing), Some(Item::HealingReplace), "the menu checks Replace");
assert_eq!(steps(&a), before, "picking the Mode adds no History step");
// An existing row leaves Replace and paints its blend mode.
brush_mode_menu::choose(&mut a, Item::Blend(BlendMode::Multiply));
assert!(!a.ui.tool_options.healing_replace, "Multiply leaves Replace");
assert_eq!(a.session.tools.brush.mode, BlendMode::Multiply);
assert_eq!(stroke_mode(&a), "Multiply");
assert_eq!(steps(&a), before, "picking a Mode never adds a History step");
// Replace is not offered to the other tools' choose route: their rows and options stay.
let mut b = app();
b.ui.tool = Tool::CloneStamp;
brush_mode_menu::choose(&mut b, Item::HealingReplace);
assert!(!b.ui.tool_options.healing_replace, "the Clone Stamp never takes Replace");
}
#[test]
fn the_mode_keys_keep_the_seven_modes_and_clear_replace() {
// Replace stays out of the letter keys and the ⇧+ / ⇧− cycle: the seven modes and their order.
let mut a = app();
a.ui.tool_options.healing_replace = true;
assert!(fired(&mut a, &test_fired(BlendShortcut::Multiply.into())), "⇧⌥M is taken");
assert_eq!(a.session.tools.brush.mode, BlendMode::Multiply);
assert!(!a.ui.tool_options.healing_replace, "a letter pick leaves Replace");
let mut b = app();
assert!(fired(&mut b, &test_fired(BlendStep::Next.into())), "⇧+ is taken");
assert_eq!(b.session.tools.brush.mode, BlendMode::Multiply, "the cycle still runs Normal to Multiply");
assert!(!b.ui.tool_options.healing_replace, "the cycle never picks Replace");
}
+6 -2
View File
@@ -21,7 +21,8 @@ use crate::brush_mode_menu::Item;
use crate::state::Tool;
use crate::{PhotocraftApp, brush_mode_menu};
/// Photoshop's Healing Brush modes, less Replace (not implemented yet).
/// Photoshop's Healing Brush modes. Replace is the tool's own option, not a blend mode: the menus
/// add it as a row of its own (#12101), and the letters and steps below keep this list.
pub const HEALING_MODES: [BlendMode; 7] =
[BlendMode::Normal, BlendMode::Multiply, BlendMode::Screen, BlendMode::Darken, BlendMode::Lighten, BlendMode::Color, BlendMode::Luminosity];
@@ -129,7 +130,10 @@ fn set_tool_mode(app: &mut PhotocraftApp, mode: Option<BlendMode>) {
brush.insert("behind".into(), json!(false));
}
if !brush.is_empty() {
let _ = app.run("tools.setBrush", json!({ "brush": brush }));
// Replace (#12101): a key-picked blend mode leaves it, in the same pick.
if app.run("tools.setBrush", json!({ "brush": brush })).is_ok() && app.ui.tool == Tool::Healing {
app.ui.tool_options.healing_replace = false;
}
}
}
+33 -13
View File
@@ -262,27 +262,43 @@ fn stamp_members(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) {
// Pattern Stamp's list has Behind, greyed on the Background.
let entries = fill::mode_entries(tool, crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind), threshold);
if !entries.is_empty() {
let current =
if tool == Tool::PatternStamp && brush.behind { PaintMode::Behind } else { PaintMode::Blend(crate::blend_keys::brush_tool_mode(tool, brush.mode)) };
let current = if tool == Tool::Healing && app.ui.tool_options.healing_replace {
PaintMode::HealingReplace
} else if tool == Tool::PatternStamp && brush.behind {
PaintMode::Behind
} else {
PaintMode::Blend(crate::blend_keys::brush_tool_mode(tool, brush.mode))
};
let picked = labelled(ui, tl!("Mode"), |ui| {
let select = fill::mode_select(Bind::given(current), &entries);
let select = if tool == Tool::CloneStamp { select.tooltip(tl!("Painting Mode")) } else { select };
select.show(ui)
});
if let Some(mode) = picked.and_then(|shown| shown.events.value().cloned()) {
let mut after = brush.clone();
match mode {
PaintMode::Blend(blend) => {
after.mode = blend;
if tool == Tool::PatternStamp {
after.behind = false;
}
if mode == PaintMode::HealingReplace {
// Replace (#12101): a tool option like the painting tools' Clear, with no brush
// value to write: the next stroke carries mode:"replace", and picking a Mode adds
// no History step.
app.ui.tool_options.healing_replace = true;
} else {
if tool == Tool::Healing {
// Any of the seven blend modes leaves Replace (#12101).
app.ui.tool_options.healing_replace = false;
}
PaintMode::Behind => after.behind = true,
PaintMode::Clear => {}
let mut after = brush.clone();
match mode {
PaintMode::Blend(blend) => {
after.mode = blend;
if tool == Tool::PatternStamp {
after.behind = false;
}
}
PaintMode::Behind => after.behind = true,
PaintMode::Clear | PaintMode::HealingReplace => {}
}
// A pick is one step of its own.
crate::brush_panel::commit_keyed(app, &brush, &after, None);
}
// A pick is one step of its own.
crate::brush_panel::commit_keyed(app, &brush, &after, None);
}
}
// Both stamps use whole percents. Only Clone Stamp alerts on an out-of-range commit (#12607).
@@ -417,3 +433,7 @@ mod clone_stamp_fields_tests;
#[cfg(test)]
#[path = "art_history_bar_controls_tests.rs"]
mod art_history_bar_controls_tests;
#[cfg(test)]
#[path = "../healing_mode_menu_tests.rs"]
mod healing_mode_menu_tests;
@@ -16,6 +16,7 @@ fn label_of(mode: PaintMode) -> String {
PaintMode::Blend(blend) => tl!(blend.label()).to_owned(),
PaintMode::Behind => tl!("Behind").to_owned(),
PaintMode::Clear => tl!("Clear").to_owned(),
PaintMode::HealingReplace => tl!("Replace").to_owned(),
}
}
@@ -26,6 +27,25 @@ fn label_of(mode: PaintMode) -> String {
pub(crate) fn mode_entries(tool: Tool, behind_enabled: bool, threshold: bool) -> Vec<Entry<PaintMode>> {
static CACHE: crate::i18n::LangCache<(Tool, bool, bool), Vec<Entry<PaintMode>>> = crate::i18n::LangCache::new();
CACHE.get_or_build((tool, behind_enabled, threshold), || {
if tool == Tool::Healing {
// The Healing Brush's measured list (#12101): Normal, Replace, a rule, Multiply,
// Screen, Darken, Lighten, a rule, Color, Luminosity. Not the blend-group rules: the
// reference starts its groups elsewhere in this short list. Replace has no letter: the
// ⇧⌥ keys and the ⇧+ / ⇧− cycle keep the seven blend modes.
let blend = |b: BlendMode| Entry::new(PaintMode::Blend(b), label_of(PaintMode::Blend(b)));
return vec![
blend(BlendMode::Normal),
Entry::new(PaintMode::HealingReplace, label_of(PaintMode::HealingReplace)),
Entry::separator(),
blend(BlendMode::Multiply),
blend(BlendMode::Screen),
blend(BlendMode::Darken),
blend(BlendMode::Lighten),
Entry::separator(),
blend(BlendMode::Color),
blend(BlendMode::Luminosity),
];
}
let keyed: Vec<BlendKeyEntry<PaintMode>> = if tool == Tool::PatternStamp {
crate::brush_mode_menu::pattern_stamp_choices()
.into_iter()
@@ -78,6 +98,8 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
o.bucket_blend_mode = blend;
}
PaintMode::Behind => {}
// Replace belongs to the Healing Brush's list, never the Paint Bucket's.
PaintMode::HealingReplace => {}
}
if let Some(opacity) = number_field(ui, tl!("Opacity"), o.fill_opacity, 1.0..=100.0, "%").landed() {
o.fill_opacity = *opacity;
@@ -28,6 +28,9 @@ pub(crate) enum PaintMode {
Behind,
/// Paint transparency.
Clear,
/// The Healing Brush's Replace (#12101): copy the source without healing. A tool option, not a
/// brush value; only the Healing Brush's Mode list offers it.
HealingReplace,
}
impl PaintMode {
@@ -37,6 +40,7 @@ impl PaintMode {
PaintMode::Blend(m) => m.label(),
PaintMode::Behind => "Behind",
PaintMode::Clear => "Clear",
PaintMode::HealingReplace => "Replace",
}
}
}
@@ -209,6 +213,9 @@ fn apply_values(app: &mut PhotocraftApp, tool: Tool, brush: &mut BrushSettings,
brush.mode = BlendMode::Normal;
}
PaintMode::Clear => brush.behind = false,
// Replace is the Healing Brush's row; a paint-bar tool's list never shows it, so
// `after.mode` is never this here.
PaintMode::HealingReplace => {}
}
}
}
+4
View File
@@ -93,6 +93,9 @@ pub struct ToolOptions {
pub pattern_stamp_angle: f32,
/// current | currentAndBelow | all
pub clone_sample: String,
/// Healing Brush › Mode: Replace, which copies the source without healing (#12101). Like the
/// painting tools' Clear flags it is tool-only: the stroke params carry it, not the brush.
pub healing_replace: bool,
/// Spot Healing: contentAware | createTexture | proximityMatch
pub spot_type: String,
/// Patch: source (repair the selection) | destination (repair where it is dragged).
@@ -479,6 +482,7 @@ impl Default for ToolOptions {
pattern_stamp_scale: 100.0,
pattern_stamp_angle: 0.0,
clone_sample: "current".into(),
healing_replace: false,
spot_type: "contentAware".into(),
patch_mode: "source".into(),
patch_content_aware: false,
+5
View File
@@ -48,6 +48,11 @@ pub(crate) fn clone_params(app: &PhotocraftApp) -> Option<Value> {
// View › Pattern Preview: both tools carry a stroke on across the canvas edges (#8883).
let sample = if clone_stamp_indexed(app) { "current" } else { o.clone_sample.as_str() };
let mut p = json!({"aligned": o.clone_aligned, "sampleLayer": sample, "mode": mode.label(), "wrap": app.ui.view.pattern_preview});
// The Healing Brush's Replace row (#12101): the stroke copies the source; the word rides the
// params in place of the brush's blend mode. The Clone Stamp never sends it.
if app.ui.tool == Tool::Healing && o.healing_replace {
p["mode"] = json!("replace");
}
if app.ui.tool == Tool::CloneStamp {
p["opacity"] = json!(app.session.tools.brush.opacity * 100.0);
p["flow"] = json!(app.session.tools.brush.flow * 100.0);
+1 -1
View File
@@ -234,7 +234,7 @@ pub fn option_keys(tool: Tool) -> &'static [&'static str] {
Tool::Zoom => reset!(zoom_scrubby, zoom_in),
Tool::Hand => reset!(hand_scroll_all),
Tool::SpotHealing => reset!(spot_type),
Tool::Healing => reset!(clone_aligned, clone_sample),
Tool::Healing => reset!(clone_aligned, clone_sample, healing_replace),
Tool::Patch => reset!(patch_mode, patch_content_aware, patch_structure, patch_color),
Tool::ContentAwareMove => reset!(cam_mode, cam_structure, cam_color, cam_transform_on_drop),
Tool::RedEye => reset!(red_eye_pupil_size, red_eye_darken),