Merge pull request #12295 from hectorviov/fix/mixer-load-solid-colors

Mixer Brush: Load Solid Colors Only in the load menu (#11952)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-10 14:20:02 +01:00
commit 60fef64a7a
6 files changed
+146 -5

No files matched your search

@@ -169,6 +169,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) {
+5 -1
View File
@@ -31,11 +31,15 @@ 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, `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,
}
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 }
}
}
+7 -2
View File
@@ -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;
}
@@ -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<f32> = ["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");
}
+19 -2
View File
@@ -132,8 +132,13 @@ pub(super) fn mixer_combination_dropdown(
#[path = "../mixer_blend_combination_tests.rs"]
mod mixer_blend_combination_tests;
#[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.
/// 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());
@@ -156,7 +161,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");
@@ -164,6 +169,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!({}))
@@ -171,6 +182,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,
@@ -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 => {