From ea3afd57a6104e3a453a659a7f38f9843fe390fe Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 22:56:23 -0600 Subject: [PATCH 1/2] Mixer Brush: Load Solid Colors Only in the load menu (#11952) The Current Brush Load menu gets a separator and the checkable entry Load Solid Colors Only, off by default and kept with the Mixer Brush's own brush (MixerSettings.solid_colors_only). With it on, Alt+click loads the one colour under the hotspot (paint.mixerLoad) instead of the sampled tip image; off, it loads the tip image as before. --- .../engine/src/cmd/brush_cmds/mixer_live.rs | 1 + crates/paint/src/mixer.rs | 5 +- crates/ui-egui/src/canvas/tool_input.rs | 9 +- .../src/mixer_load_solid_colors_tests.rs | 113 ++++++++++++++++++ crates/ui-egui/src/panels/brush_controls.rs | 18 ++- .../ui-egui/src/panels/brush_panel/tests.rs | 1 + 6 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/mixer_load_solid_colors_tests.rs diff --git a/crates/engine/src/cmd/brush_cmds/mixer_live.rs b/crates/engine/src/cmd/brush_cmds/mixer_live.rs index bfe409c471..e6b7adcd6d 100644 --- a/crates/engine/src/cmd/brush_cmds/mixer_live.rs +++ b/crates/engine/src/cmd/brush_cmds/mixer_live.rs @@ -168,6 +168,7 @@ impl LiveMixer { sample_all_layers: flag(p, "sampleAllLayers", bm.sample_all_layers) && crate::channel_cmds::target_of(p) == crate::channel_cmds::Target::Pixels, clean_after_stroke: flag(p, "cleanAfterStroke", bm.clean_after_stroke), load_after_stroke: flag(p, "loadAfterStroke", bm.load_after_stroke), + solid_colors_only: bm.solid_colors_only, }; let initial_state = if let Some(value) = p.get("mixerState") { if value.get("spatial").and_then(Value::as_array).is_some_and(|v| v.len() != 4096) { diff --git a/crates/paint/src/mixer.rs b/crates/paint/src/mixer.rs index bb34749065..b5ee739731 100644 --- a/crates/paint/src/mixer.rs +++ b/crates/paint/src/mixer.rs @@ -31,11 +31,14 @@ pub struct MixerSettings { pub load_after_stroke: bool, /// Empty the brush after each stroke (the automatic Clean option). pub clean_after_stroke: bool, + /// Load Solid Colors Only (the load menu's checkable entry): ⌥-click loads the one colour + /// under the hotspot instead of the sampled tip image (#11952). Off by default. + pub solid_colors_only: bool, } impl Default for MixerSettings { fn default() -> Self { - Self { wet: 0.5, load: 0.5, mix: 0.5, flow: 1.0, sample_all_layers: false, clean_after_stroke: true, load_after_stroke: true } + Self { wet: 0.5, load: 0.5, mix: 0.5, flow: 1.0, sample_all_layers: false, clean_after_stroke: true, load_after_stroke: true, solid_colors_only: false } } } diff --git a/crates/ui-egui/src/canvas/tool_input.rs b/crates/ui-egui/src/canvas/tool_input.rs index f148b8dfa5..a5008d740c 100644 --- a/crates/ui-egui/src/canvas/tool_input.rs +++ b/crates/ui-egui/src/canvas/tool_input.rs @@ -98,8 +98,13 @@ fn preflight_tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modi if let ToolEvent::Down { x, y, pressure } = ev { app.mixer_sampling = true; let pen = app.stylus.sample().unwrap_or_default(); - let p = json!({"points":[[x,y,pressure,pen.tilt_x,pen.tilt_y,pen.rotation]],"target":paint_target(app)}); - if let Err(e) = app.run("brush.mixer.sample", p) { + // Load Solid Colors Only loads the one colour under the hotspot (#11952). + let (id, p) = if app.session.tools.brush.mixer.solid_colors_only { + ("paint.mixerLoad", json!({"x": x, "y": y})) + } else { + ("brush.mixer.sample", json!({"points":[[x,y,pressure,pen.tilt_x,pen.tilt_y,pen.rotation]],"target":paint_target(app)})) + }; + if let Err(e) = app.run(id, p) { app.ui.status = e; app.ui.status_error = true; } diff --git a/crates/ui-egui/src/mixer_load_solid_colors_tests.rs b/crates/ui-egui/src/mixer_load_solid_colors_tests.rs new file mode 100644 index 0000000000..e5d75e9385 --- /dev/null +++ b/crates/ui-egui/src/mixer_load_solid_colors_tests.rs @@ -0,0 +1,113 @@ +//! The Mixer Brush load menu's Load Solid Colors Only (#11952): Load Brush, Clean Brush, a +//! separator, then the checkable entry, off by default and kept with the Mixer Brush's own brush. +//! On, ⌥-click loads the one colour under the hotspot (red/green edge at 200,300 → 30,180,60), the +//! swatch shows it and the next stroke paints it; off, ⌥-click loads the tip image as before. + +use egui::{Modifiers, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +const RED: [f32; 4] = [220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0, 1.0]; +const GREEN: [f32; 4] = [30.0 / 255.0, 180.0 / 255.0, 60.0 / 255.0, 1.0]; + +/// An 800 × 600 document whose pixel layer is red left of x 200 and green from there on, with the +/// Mixer Brush active. +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); + app.run("layer.new.layer", json!({"name": "Split"})).unwrap(); + app.run("select.rect", json!({"x": 0, "y": 0, "width": 200, "height": 600})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": RED})).unwrap(); + app.run("select.rect", json!({"x": 200, "y": 0, "width": 600, "height": 600})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": GREEN})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + app.run("tools.setColors", json!({"foreground": "#000000", "background": "#ffffff"})).unwrap(); + app.ui.tool = Tool::MixerBrush; + crate::paint_mouse::sync_tool_brush(&mut app); + app +} + +fn alt_click(app: &mut PhotocraftApp, x: f64, y: f64) { + tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, Modifiers::ALT); + tool_event(app, ToolEvent::Up { x, y }, Modifiers::ALT); +} + +fn level(c: [f32; 4]) -> [i32; 4] { + c.map(|v| (v * 255.0).round() as i32) +} + +#[test] +fn the_load_menu_lists_load_solid_colors_only_after_a_separator() { + let mut h = Harness::builder().with_size(vec2(1600.0, 400.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::panels::options_bar(app, ui); + }, + app(), + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio); + h.run_steps(4); + if !h.ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + assert!(!h.state().session.tools.brush.mixer.solid_colors_only, "off by default"); + let open = |h: &mut Harness<'static, PhotocraftApp>| { + h.get_by_label("Current Brush Load").click(); + h.run_steps(3); + }; + open(&mut h); + let tops: Vec = ["Load Brush", "Clean Brush", "Load Solid Colors Only"].iter().map(|l| h.get_by_label(l).rect().top()).collect(); + assert!(tops.windows(2).all(|w| w[0] < w[1]), "menu order {tops:?}"); + // The separator: a larger gap above the entry than between Load Brush and Clean Brush. + assert!(tops[2] - tops[1] > tops[1] - tops[0], "no separator before Load Solid Colors Only: {tops:?}"); + let entry = h.get_by_label("Load Solid Colors Only"); + assert_eq!(entry.accesskit_node().role(), egui::accesskit::Role::CheckBox); + assert_eq!(entry.accesskit_node().toggled(), Some(egui::accesskit::Toggled::False)); + entry.click(); + h.run_steps(3); + assert!(h.state().session.tools.brush.mixer.solid_colors_only, "the entry turns it on"); + assert_eq!(h.state().session.journal.last().map(|(id, _)| id.as_str()), Some("tools.setBrush")); + // It is the Mixer Brush's own setting: the Brush tool's brush doesn't have it on. + let app = h.state_mut(); + app.ui.tool = Tool::Brush; + crate::paint_mouse::sync_tool_brush(app); + assert!(!app.session.tools.brush.mixer.solid_colors_only, "the Brush tool's brush is its own"); + app.ui.tool = Tool::MixerBrush; + crate::paint_mouse::sync_tool_brush(app); + assert!(app.session.tools.brush.mixer.solid_colors_only, "the Mixer Brush keeps it"); +} + +#[test] +fn with_it_on_alt_click_loads_the_colour_under_the_hotspot_and_the_next_stroke_paints_it() { + let mut app = app(); + app.run("tools.setBrush", json!({"brush": {"mixer": {"solidColorsOnly": true, "wet": 0.0}, "size": 20, "hardness": 1.0}})).unwrap(); + alt_click(&mut app, 200.0, 300.0); + let mixer = &app.session.tools.mixer; + assert_eq!(mixer.reservoir.map(level), Some(level(GREEN)), "{mixer:?}"); + assert!(mixer.spatial.is_none(), "a plain colour, not the tip image"); + // The Current Brush Load swatch shows it. + assert_eq!(mixer.next_load(app.session.tools.foreground).map(level), Some(level(GREEN))); + // The next stroke, on an empty layer above, paints it. + app.run("layer.new.layer", json!({"name": "Paint"})).unwrap(); + tool_event(&mut app, ToolEvent::Down { x: 400.0, y: 100.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Move { x: 500.0, y: 100.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Up { x: 500.0, y: 100.0 }, Modifiers::NONE); + let st = app.session.active().unwrap(); + let px = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().rgba(450, 100); + let [r, g, b, a] = level(px); + assert!((r - 30).abs() <= 2 && (g - 180).abs() <= 2 && (b - 60).abs() <= 2 && a >= 250, "stroke painted {:?}", level(px)); +} + +#[test] +fn with_it_off_alt_click_loads_the_tip_image_as_before() { + let mut app = app(); + alt_click(&mut app, 200.0, 300.0); + assert!(app.session.tools.mixer.spatial.is_some(), "the sampled tip image"); +} diff --git a/crates/ui-egui/src/panels/brush_controls.rs b/crates/ui-egui/src/panels/brush_controls.rs index ddd45f38ba..6619698fe2 100644 --- a/crates/ui-egui/src/panels/brush_controls.rs +++ b/crates/ui-egui/src/panels/brush_controls.rs @@ -64,6 +64,10 @@ pub(super) fn smoothing_options(ui: &mut egui::Ui, b: &mut photocraft_engine::Br }); } +#[cfg(test)] +#[path = "../mixer_load_solid_colors_tests.rs"] +mod mixer_load_solid_colors_tests; + /// Mixer Brush: the Current Brush Load swatch shows the paint the next stroke starts with (an /// empty swatch when the brush is clean). Its menu holds Load Brush and Clean Brush. pub(super) fn mixer_load_swatch(app: &mut PhotocraftApp, ui: &mut egui::Ui) { @@ -88,7 +92,7 @@ pub(super) fn mixer_load_swatch(app: &mut PhotocraftApp, ui: &mut egui::Ui) { icons::paint(ui, Rect::from_center_size(pos2(r.right() - 9.0, r.center().y), vec2(10.0, 10.0)), "chevron-down", 9.0, t.text_faint); resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tl!("Current Brush Load"))); let resp = resp.on_hover_text(tl!("Current Brush Load")); - let mut run = None; + let (mut run, mut solid_colors) = (None, None); egui::Popup::menu(&resp).show(|ui| { if ui.button(tl!("Load Brush")).clicked() { run = Some("brush.mixer.load"); @@ -96,6 +100,12 @@ pub(super) fn mixer_load_swatch(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if ui.button(tl!("Clean Brush")).clicked() { run = Some("brush.mixer.clean"); } + ui.separator(); + // Load Solid Colors Only: ⌥-click loads one colour, not the tip image (#11952). + let mut solid = app.session.tools.brush.mixer.solid_colors_only; + if ui.checkbox(&mut solid, tl!("Load Solid Colors Only")).changed() { + solid_colors = Some(solid); + } }); if let Some(id) = run && let Err(e) = app.run(id, json!({})) @@ -103,6 +113,12 @@ pub(super) fn mixer_load_swatch(app: &mut PhotocraftApp, ui: &mut egui::Ui) { app.ui.status = e; app.ui.status_error = true; } + if let Some(on) = solid_colors + && let Err(e) = app.run("tools.setBrush", json!({"brush": {"mixer": {"solidColorsOnly": on}}})) + { + app.ui.status = e; + app.ui.status_error = true; + } } /// Options-bar brush chip: a click shows or hides Photoshop's Brush Preset picker below it (size, diff --git a/crates/ui-egui/src/panels/brush_panel/tests.rs b/crates/ui-egui/src/panels/brush_panel/tests.rs index 164443600c..4777f429c7 100644 --- a/crates/ui-egui/src/panels/brush_panel/tests.rs +++ b/crates/ui-egui/src/panels/brush_panel/tests.rs @@ -114,6 +114,7 @@ fn edit_section(i: usize, b: &mut BrushSettings) { sample_all_layers: true, load_after_stroke: false, clean_after_stroke: false, + solid_colors_only: true, }; } 7 => { From 9390637f824061b0666c658772306e4b8a92b6ca Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 8 Nov 2026 10:09:15 -0600 Subject: [PATCH 2/2] Mixer Brush: the load menu's and the setting's comments list Load Solid Colors Only and its key (eliets2 review on #12295) --- crates/paint/src/mixer.rs | 5 +++-- crates/ui-egui/src/panels/brush_controls.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/paint/src/mixer.rs b/crates/paint/src/mixer.rs index b5ee739731..1b381f2a0f 100644 --- a/crates/paint/src/mixer.rs +++ b/crates/paint/src/mixer.rs @@ -31,8 +31,9 @@ pub struct MixerSettings { pub load_after_stroke: bool, /// Empty the brush after each stroke (the automatic Clean option). pub clean_after_stroke: bool, - /// Load Solid Colors Only (the load menu's checkable entry): ⌥-click loads the one colour - /// under the hotspot instead of the sampled tip image (#11952). Off by default. + /// Load Solid Colors Only (the load menu's checkable entry, `solidColorsOnly` in + /// `tools.setBrush`): ⌥-click loads the one colour under the hotspot instead of the sampled tip + /// image (#11952). Off by default. Load Brush and the load after each stroke ignore it. pub solid_colors_only: bool, } diff --git a/crates/ui-egui/src/panels/brush_controls.rs b/crates/ui-egui/src/panels/brush_controls.rs index 6619698fe2..7fcdb45309 100644 --- a/crates/ui-egui/src/panels/brush_controls.rs +++ b/crates/ui-egui/src/panels/brush_controls.rs @@ -69,7 +69,8 @@ pub(super) fn smoothing_options(ui: &mut egui::Ui, b: &mut photocraft_engine::Br mod mixer_load_solid_colors_tests; /// Mixer Brush: the Current Brush Load swatch shows the paint the next stroke starts with (an -/// empty swatch when the brush is clean). Its menu holds Load Brush and Clean Brush. +/// empty swatch when the brush is clean). Its menu holds Load Brush, Clean Brush, a separator and +/// the checkable Load Solid Colors Only. pub(super) fn mixer_load_swatch(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let t = Tokens::get(ui.ctx()); let (r, _) = ui.allocate_exact_size(vec2(40.0, 26.0), Sense::hover());