mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Merge pull request #12293 from hectorviov/fix/mixer-blend-combinations
Mixer Brush: Useful mixer brush combinations dropdown (#11946)
This commit is contained in:
5 files changed
+232
-2
No files matched your search
@@ -0,0 +1,171 @@
|
||||
//! The Mixer Brush's Useful mixer brush combinations dropdown (#11946): between the Clean after
|
||||
//! each stroke toggle and Wet, Custom then the reference's twelve entries in four groups; each
|
||||
//! sets Wet, Load and Mix in one `tools.setBrush` change and leaves Flow. Reset Tool shows Custom.
|
||||
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use super::{MIXER_COMBINATION_GROUPS, MIXER_COMBINATIONS};
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
const TIP: &str = "Useful mixer brush combinations";
|
||||
|
||||
fn harness() -> Harness<'static, PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.ui.tool = Tool::MixerBrush;
|
||||
crate::paint_mouse::sync_tool_brush(&mut app);
|
||||
app.run("tools.setBrush", json!({"brush": {"mixer": {"flow": 0.42}}})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1800.0, 700.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);
|
||||
h
|
||||
}
|
||||
|
||||
fn has_fonts(h: &Harness<'static, PhotocraftApp>) -> bool {
|
||||
h.ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into())))
|
||||
}
|
||||
|
||||
/// The combinations dropdown, by the entry it shows.
|
||||
fn dropdown_rect(h: &Harness<'static, PhotocraftApp>, shows: &str) -> egui::Rect {
|
||||
h.get_all_by_role(egui::accesskit::Role::ComboBox)
|
||||
.find(|n| n.accesskit_node().value().as_deref() == Some(shows))
|
||||
.unwrap_or_else(|| panic!("no dropdown showing {shows}"))
|
||||
.rect()
|
||||
}
|
||||
|
||||
fn open_and_pick(h: &mut Harness<'static, PhotocraftApp>, shows: &str, entry: &str) {
|
||||
h.get_all_by_role(egui::accesskit::Role::ComboBox).find(|n| n.accesskit_node().value().as_deref() == Some(shows)).unwrap().click();
|
||||
h.run_steps(3);
|
||||
entry_node(h, entry).click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// An entry of the open list (not the Wet field, which shares the "Wet" label).
|
||||
fn entry_node<'a>(h: &'a Harness<'static, PhotocraftApp>, entry: &'a str) -> egui_kittest::Node<'a> {
|
||||
h.get_all_by_label(entry).rfind(|n| n.accesskit_node().role() != egui::accesskit::Role::SpinButton).unwrap_or_else(|| panic!("no entry {entry}"))
|
||||
}
|
||||
|
||||
fn mixer(h: &Harness<'static, PhotocraftApp>) -> (f32, f32, f32, f32) {
|
||||
let m = &h.state().session.tools.brush.mixer;
|
||||
(m.wet, m.load, m.mix, m.flow)
|
||||
}
|
||||
|
||||
fn set_brush_count(h: &Harness<'static, PhotocraftApp>) -> usize {
|
||||
h.state().session.journal.iter().filter(|(id, _)| id == "tools.setBrush").count()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_dropdown_sits_before_wet_with_the_reference_entries_in_order() {
|
||||
let mut h = harness();
|
||||
if !has_fonts(&h) {
|
||||
return;
|
||||
}
|
||||
let combo = dropdown_rect(&h, "Custom");
|
||||
let clean = h.get_by_label("Clean the brush after each stroke").rect();
|
||||
let wet = h.get_all_by_role(egui::accesskit::Role::SpinButton).find(|n| n.accesskit_node().label().as_deref() == Some("Wet")).unwrap().rect();
|
||||
assert!(clean.right() <= combo.left() && combo.right() <= wet.left(), "clean {clean:?}, dropdown {combo:?}, wet {wet:?}");
|
||||
assert_eq!(
|
||||
h.get_all_by_role(egui::accesskit::Role::ComboBox)
|
||||
.find(|n| n.accesskit_node().value().as_deref() == Some("Custom"))
|
||||
.unwrap()
|
||||
.accesskit_node()
|
||||
.label()
|
||||
.as_deref(),
|
||||
Some(TIP)
|
||||
);
|
||||
let labels: Vec<&str> = MIXER_COMBINATIONS.iter().map(|(l, _)| *l).collect();
|
||||
assert_eq!(
|
||||
labels,
|
||||
[
|
||||
"Custom",
|
||||
"Dry",
|
||||
"Dry, Light Load",
|
||||
"Dry, Heavy Load",
|
||||
"Moist",
|
||||
"Moist, Light Mix",
|
||||
"Moist, Heavy Mix",
|
||||
"Wet",
|
||||
"Wet, Light Mix",
|
||||
"Wet, Heavy Mix",
|
||||
"Very Wet",
|
||||
"Very Wet, Light Mix",
|
||||
"Very Wet, Heavy Mix"
|
||||
]
|
||||
);
|
||||
// Separators above Dry, Moist, Wet and Very Wet.
|
||||
let groups: Vec<&str> = MIXER_COMBINATION_GROUPS.iter().map(|&i| MIXER_COMBINATIONS[i].0).collect();
|
||||
assert_eq!(groups, ["Dry", "Moist", "Wet", "Very Wet"]);
|
||||
// The open list shows the entries top to bottom in that order.
|
||||
h.get_all_by_role(egui::accesskit::Role::ComboBox).find(|n| n.accesskit_node().value().as_deref() == Some("Custom")).unwrap().click();
|
||||
h.run_steps(3);
|
||||
let tops: Vec<f32> = labels[1..].iter().map(|l| entry_node(&h, l).rect().top()).collect();
|
||||
assert!(tops.windows(2).all(|w| w[0] < w[1]), "entries out of order: {tops:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_entry_sets_wet_load_and_mix_in_one_change_and_keeps_flow() {
|
||||
let mut h = harness();
|
||||
if !has_fonts(&h) {
|
||||
return;
|
||||
}
|
||||
let expected = [
|
||||
("Dry", (0.0, 0.5, 0.0)),
|
||||
("Dry, Light Load", (0.0, 0.05, 0.0)),
|
||||
("Dry, Heavy Load", (0.0, 1.0, 0.0)),
|
||||
("Moist", (0.1, 0.05, 0.5)),
|
||||
("Moist, Light Mix", (0.1, 0.05, 0.0)),
|
||||
("Moist, Heavy Mix", (0.1, 0.05, 1.0)),
|
||||
("Wet", (0.5, 0.5, 0.5)),
|
||||
("Wet, Light Mix", (0.5, 0.5, 0.0)),
|
||||
("Wet, Heavy Mix", (0.5, 0.5, 1.0)),
|
||||
("Very Wet", (1.0, 0.5, 0.5)),
|
||||
("Very Wet, Light Mix", (1.0, 0.5, 0.0)),
|
||||
("Very Wet, Heavy Mix", (1.0, 0.5, 1.0)),
|
||||
];
|
||||
let mut shows = "Custom";
|
||||
for (entry, (wet, load, mix)) in expected {
|
||||
let before = set_brush_count(&h);
|
||||
open_and_pick(&mut h, shows, entry);
|
||||
assert_eq!(mixer(&h), (wet, load, mix, 0.42), "{entry}");
|
||||
assert_eq!(set_brush_count(&h), before + 1, "{entry}: one tools.setBrush change");
|
||||
assert_eq!(h.state().ui.tool_options.mixer_combination, MIXER_COMBINATIONS.iter().position(|(l, _)| *l == entry).unwrap());
|
||||
dropdown_rect(&h, entry);
|
||||
shows = entry;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_tool_shows_custom_and_a_typed_value_keeps_the_pick() {
|
||||
let mut h = harness();
|
||||
if !has_fonts(&h) {
|
||||
return;
|
||||
}
|
||||
open_and_pick(&mut h, "Custom", "Wet, Heavy Mix");
|
||||
// A typed Wet keeps showing the picked entry (not measured; today's behaviour).
|
||||
h.get_all_by_role(egui::accesskit::Role::SpinButton).find(|n| n.accesskit_node().numeric_value() == Some(50.0)).expect("Wet field").click();
|
||||
h.run_steps(1);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Text("30".into()));
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
assert_eq!(mixer(&h).0, 0.3);
|
||||
dropdown_rect(&h, "Wet, Heavy Mix");
|
||||
// Reset Tool: Custom again.
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "tool.reset", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().ui.tool_options.mixer_combination, 0);
|
||||
dropdown_rect(&h, "Custom");
|
||||
}
|
||||
@@ -64,6 +64,56 @@ pub(super) fn smoothing_options(ui: &mut egui::Ui, b: &mut photocraft_engine::Br
|
||||
});
|
||||
}
|
||||
|
||||
/// A Useful mixer brush combinations entry: its label and the Wet, Load and Mix it sets.
|
||||
type MixerCombination = (&'static str, Option<(f32, f32, f32)>);
|
||||
|
||||
/// The Mixer Brush's Useful mixer brush combinations, in the reference's order: each entry's label
|
||||
/// and the Wet, Load and Mix (0..1) it sets. Custom, the first, sets nothing.
|
||||
pub(crate) const MIXER_COMBINATIONS: [MixerCombination; 13] = [
|
||||
("Custom", None),
|
||||
("Dry", Some((0.0, 0.5, 0.0))),
|
||||
("Dry, Light Load", Some((0.0, 0.05, 0.0))),
|
||||
("Dry, Heavy Load", Some((0.0, 1.0, 0.0))),
|
||||
("Moist", Some((0.1, 0.05, 0.5))),
|
||||
("Moist, Light Mix", Some((0.1, 0.05, 0.0))),
|
||||
("Moist, Heavy Mix", Some((0.1, 0.05, 1.0))),
|
||||
("Wet", Some((0.5, 0.5, 0.5))),
|
||||
("Wet, Light Mix", Some((0.5, 0.5, 0.0))),
|
||||
("Wet, Heavy Mix", Some((0.5, 0.5, 1.0))),
|
||||
("Very Wet", Some((1.0, 0.5, 0.5))),
|
||||
("Very Wet, Light Mix", Some((1.0, 0.5, 0.0))),
|
||||
("Very Wet, Heavy Mix", Some((1.0, 0.5, 1.0))),
|
||||
];
|
||||
|
||||
/// The entries of [`MIXER_COMBINATIONS`] a separator line goes above: Dry, Moist, Wet, Very Wet.
|
||||
const MIXER_COMBINATION_GROUPS: [usize; 4] = [1, 4, 7, 10];
|
||||
|
||||
/// Mixer Brush: the Useful mixer brush combinations dropdown (#11946). Picking an entry sets Wet,
|
||||
/// Load and Mix together (Flow stays) and keeps showing it, also after a value is typed; Custom
|
||||
/// sets nothing. `picked` is the entry shown.
|
||||
pub(super) fn mixer_combination_dropdown(
|
||||
ui: &mut egui::Ui,
|
||||
picked: &mut usize,
|
||||
m: &mut photocraft_engine::paint::mixer::MixerSettings,
|
||||
) -> Option<egui::Response> {
|
||||
const ID: &str = "mixer-combination";
|
||||
let opts: Vec<(usize, &str)> = MIXER_COMBINATIONS.iter().enumerate().map(|(i, (label, _))| (i, *label)).collect();
|
||||
let mut shown = (*picked).min(MIXER_COMBINATIONS.len() - 1);
|
||||
let chosen =
|
||||
widgets::dropdown_wheel_grouped(ui, ID, tl!("Useful mixer brush combinations"), &mut shown, &opts, 132.0, |i| MIXER_COMBINATION_GROUPS.contains(i)).0;
|
||||
if let Some(&i) = chosen.last() {
|
||||
*picked = i;
|
||||
if let Some((wet, load, mix)) = MIXER_COMBINATIONS[i].1 {
|
||||
(m.wet, m.load, m.mix) = (wet, load, mix);
|
||||
}
|
||||
}
|
||||
ui.ctx().read_response(ui.make_persistent_id(egui::IdSalt::new(ID)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../mixer_blend_combination_tests.rs"]
|
||||
mod mixer_blend_combination_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) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use super::brush_controls::{brush_preset_chip, mixer_load_swatch, paint_mode_dropdown, smoothing_field, smoothing_options, tool_mode_dropdown};
|
||||
use super::brush_controls::{
|
||||
brush_preset_chip, mixer_combination_dropdown, mixer_load_swatch, paint_mode_dropdown, smoothing_field, smoothing_options, tool_mode_dropdown,
|
||||
};
|
||||
use super::properties::{select_and_mask_button, selection_mode_buttons};
|
||||
use super::{BlendMode, Color32, PhotocraftApp, RichText, Sense, Tokens, Tool, Value, icons, json, starts_blend_group, vec2, widgets};
|
||||
use photocraft_paint::BrushSettings;
|
||||
@@ -279,6 +281,9 @@ fn brush_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: Tokens,
|
||||
*on = !*on;
|
||||
}
|
||||
}
|
||||
if let Some(r) = mixer_combination_dropdown(ui, &mut app.ui.tool_options.mixer_combination, &mut b.mixer) {
|
||||
r.on_hover_text(tl!("Useful mixer brush combinations"));
|
||||
}
|
||||
widgets::vline(ui, 22.0);
|
||||
for (label, value) in
|
||||
[(tl!("Wet"), &mut b.mixer.wet), (tl!("Load"), &mut b.mixer.load), (tl!("Mix"), &mut b.mixer.mix), (tl!("Flow"), &mut b.mixer.flow)]
|
||||
|
||||
@@ -254,6 +254,9 @@ pub struct ToolOptions {
|
||||
/// `paint.pencil`), as in Photoshop's options bar (#2662).
|
||||
#[serde(default = "default_eraser_mode")]
|
||||
pub eraser_mode: String,
|
||||
/// Mixer Brush › Useful mixer brush combinations: the entry last picked, an index into
|
||||
/// `brush_controls::MIXER_COMBINATIONS` (0 = Custom, #11946).
|
||||
pub mixer_combination: usize,
|
||||
/// Magnetic Lasso: detection width (px, 1..256), edge contrast (%, 1..100), how often it
|
||||
/// fastens points by itself (0..100), and whether pen pressure narrows the width.
|
||||
pub magnetic_width: f32,
|
||||
@@ -536,6 +539,7 @@ impl Default for ToolOptions {
|
||||
brush_clear: false,
|
||||
pencil_clear: false,
|
||||
eraser_mode: default_eraser_mode(),
|
||||
mixer_combination: 0,
|
||||
magnetic_width: 10.0,
|
||||
magnetic_contrast: 10.0,
|
||||
magnetic_frequency: 57.0,
|
||||
|
||||
@@ -262,11 +262,11 @@ pub fn option_keys(tool: Tool) -> &'static [&'static str] {
|
||||
Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Star | Tool::CustomShape => {
|
||||
reset!(shape_mode, shape_fill, stroke_width, shape_stroke, shape_fill_gradient, shape_stroke_gradient, corner_radius, polygon_sides, line_weight)
|
||||
}
|
||||
Tool::MixerBrush => reset!(mixer_combination),
|
||||
Tool::ColorSampler
|
||||
| Tool::Ruler
|
||||
| Tool::Note
|
||||
| Tool::Count
|
||||
| Tool::MixerBrush
|
||||
| Tool::Hand
|
||||
| Tool::RotateView
|
||||
| Tool::HistoryBrush
|
||||
|
||||
Reference in new issue
Block a user