mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
On a layer mask, an alpha channel or Quick Mask the Mode list now greys Behind, and a stored Behind drags in Normal there instead of sending a combination `paint.gradient` refuses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e406ce39cd
commit
3f5e245d9c
3 files changed
+31
-4
No files matched your search
@@ -58,3 +58,26 @@ fn a_classic_drag_in_behind_keeps_the_layers_pixels() {
|
||||
assert_eq!(s.rgba(40, 60), [1.0, 0.0, 0.0, 1.0], "the red under the gradient's dark end stays");
|
||||
assert!(s.rgba(150, 60)[3] > 0.99, "the transparent half takes the gradient");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stored_behind_drags_normal_on_quick_mask_and_is_greyed_there() {
|
||||
// Behind is pixels-only: on Quick Mask the bar greys it and a stored Behind paints the mask in Normal.
|
||||
let mut h = harness(Tool::Gradient);
|
||||
h.state_mut().ui.tool_options.gradient_classic = true;
|
||||
h.state_mut().ui.tool_options.gradient_behind = true;
|
||||
h.state_mut().run("layer.new.layer", json!({})).unwrap();
|
||||
h.state_mut().run("select.editInQuickMaskMode", json!({"on": true})).unwrap();
|
||||
h.run_steps(4);
|
||||
let at = mode_dropdown(&h).center();
|
||||
wheel(&mut h, at, -1.0);
|
||||
wheel(&mut h, at, -1.0);
|
||||
assert!(!h.state().ui.tool_options.gradient_behind, "the wheel steps past the greyed Behind");
|
||||
let app = h.state_mut();
|
||||
app.ui.tool_options.gradient_behind = true;
|
||||
let steps = app.session.active().unwrap().history.past_len();
|
||||
let m = egui::Modifiers::NONE;
|
||||
crate::canvas::tool_event(app, ToolEvent::Down { x: 5.0, y: 5.0, pressure: 1.0 }, m);
|
||||
crate::canvas::tool_event(app, ToolEvent::Move { x: 40.0, y: 5.0, pressure: 1.0 }, m);
|
||||
crate::canvas::tool_event(app, ToolEvent::Up { x: 80.0, y: 5.0 }, m);
|
||||
assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1, "the drag painted the Quick Mask");
|
||||
}
|
||||
@@ -59,7 +59,9 @@ pub(crate) fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let words = Env::of(ui).words::<GradientFillWords>();
|
||||
let styles: Vec<Entry<GradientStyle>> = GradientStyle::ALL.iter().map(|style| Entry::new(*style, style.label(&words)).icon(style.icon())).collect();
|
||||
let modes = [Entry::new(false, tl!("Gradient").to_owned()), Entry::new(true, tl!("Classic gradient").to_owned())];
|
||||
let blends = blend_modes(crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind));
|
||||
// Behind paints under a layer's pixels: greyed on a mask, a channel or Quick Mask, as the engine refuses it there.
|
||||
let pixels = crate::canvas::paint_target(app) == serde_json::json!("pixels");
|
||||
let blends = blend_modes(pixels && crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind));
|
||||
let open_editor;
|
||||
let presets;
|
||||
{
|
||||
@@ -82,7 +84,7 @@ pub(crate) fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let fill_opacity = app.ui.tool_options.fill_opacity;
|
||||
{
|
||||
let o = &app.ui.tool_options;
|
||||
let shown = if o.gradient_behind { None } else { Some(o.gradient_blend_mode) };
|
||||
let shown = if o.gradient_behind && pixels { None } else { Some(o.gradient_blend_mode) };
|
||||
let mut mode = shown;
|
||||
labelled(ui, tl!("Mode"), |ui| {
|
||||
Select::new(tl!("Blend Mode").to_owned(), Bind::bound(&mut mode), &blends).show(ui);
|
||||
|
||||
@@ -87,10 +87,12 @@ fn commit(app: &mut PhotocraftApp, from: [f32; 2], to: [f32; 2], redraw: Option<
|
||||
return;
|
||||
}
|
||||
let o = app.ui.tool_options.clone();
|
||||
let mode = if o.gradient_behind { "behind" } else { o.gradient_blend_mode.label() };
|
||||
let target = crate::canvas::paint_target(app);
|
||||
// A stored Behind paints Normal on a mask, a channel or Quick Mask, where the bar greys it.
|
||||
let mode = if o.gradient_behind && target == json!("pixels") { "behind" } else { o.gradient_blend_mode.label() };
|
||||
let params = json!({
|
||||
"from": from, "to": to, "style": o.gradient_style, "reverse": o.gradient_reverse, "dither": o.gradient_dither,
|
||||
"opacity": o.fill_opacity, "mode": mode, "target": crate::canvas::paint_target(app),
|
||||
"opacity": o.fill_opacity, "mode": mode, "target": target,
|
||||
});
|
||||
let result = app.run("paint.gradient", params);
|
||||
report(app, result);
|
||||
|
||||
Reference in new issue
Block a user