mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge #18579 into the merge queue batch
Background Eraser: not-allowed cursor over a layer mask and a 32-bit document
This commit is contained in:
commit
61b73c8b50
2 files changed
+130
No files matched your search
@@ -0,0 +1,116 @@
|
||||
//! #18097: with the Background Eraser active the canvas cursor is the not-allowed one over a layer
|
||||
//! mask and over the composite of a 32-bit document, as the reference application shows, and the
|
||||
//! tip cursor everywhere the issue left unmeasured.
|
||||
|
||||
use craft::behavior::{Cursor, CursorIcon};
|
||||
use egui::{Modifiers, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::hover;
|
||||
use crate::state::Tool;
|
||||
|
||||
const IN_IMAGE: f32 = 100.0;
|
||||
const ON_LAYER: f32 = 150.0;
|
||||
const BLOCKED: Option<Cursor> = Some(Cursor::System(CursorIcon::NotAllowed));
|
||||
|
||||
/// The canvas at 100 % on a 400 × 300 `depth`-bit document with the Background Eraser active.
|
||||
fn harness(depth: u32) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300, "depth": depth})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.extras.rulers = false;
|
||||
app.ui.tool = Tool::BackgroundEraser;
|
||||
let ctx = app.ctx().clone();
|
||||
let mut h = Harness::builder().with_context(ctx).with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |_cc| app);
|
||||
h.run_steps(4);
|
||||
let v = &mut h.state_mut().ui.views[0];
|
||||
v.zoom = 1.0;
|
||||
v.center = [200.0, 150.0];
|
||||
v.clear_pending();
|
||||
h.run_steps(2);
|
||||
h
|
||||
}
|
||||
|
||||
/// A pixel layer filled red, so the tool has pixels to erase.
|
||||
fn pixel_layer(h: &mut Harness<'static, Box<PhotocraftApp>>) {
|
||||
h.state_mut().run("layer.new.layer", json!({})).unwrap();
|
||||
h.state_mut().run("edit.fill", json!({"color": "#ff0000"})).unwrap();
|
||||
}
|
||||
|
||||
/// A layer mask revealing everything, on the active layer.
|
||||
fn layer_mask(h: &mut Harness<'static, Box<PhotocraftApp>>) {
|
||||
h.state_mut().run("select.all", json!({})).unwrap();
|
||||
// The selection becomes the mask.
|
||||
h.state_mut().run("layer.layerMask.revealSelection", json!({})).unwrap();
|
||||
}
|
||||
|
||||
fn cursor(h: &mut Harness<'static, Box<PhotocraftApp>>) -> Option<Cursor> {
|
||||
hover(h, IN_IMAGE, ON_LAYER, Modifiers::NONE);
|
||||
h.state().canvas_tools.last_response.as_ref().and_then(|response| response.cursor.clone())
|
||||
}
|
||||
|
||||
/// Done when 1 and 2: a layer mask (enabled or disabled, of a pixel layer or a group) blocks the
|
||||
/// cursor, the layer's own pixels do not.
|
||||
#[test]
|
||||
fn a_layer_mask_blocks_the_background_eraser_cursor() {
|
||||
let mut h = harness(8);
|
||||
pixel_layer(&mut h);
|
||||
let normal = cursor(&mut h);
|
||||
assert!(normal.is_some() && normal != BLOCKED, "the pixel layer has the tip cursor");
|
||||
|
||||
layer_mask(&mut h);
|
||||
h.state_mut().ui.mask_target = true;
|
||||
assert_eq!(cursor(&mut h), BLOCKED, "the targeted mask");
|
||||
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::NotAllowed);
|
||||
|
||||
h.state_mut().run("layer.layerMask.enabled", json!({"enabled": false})).unwrap();
|
||||
assert_eq!(cursor(&mut h), BLOCKED, "a disabled mask is targeted too");
|
||||
|
||||
h.state_mut().run("layer.layerMask.enabled", json!({"enabled": true})).unwrap();
|
||||
h.state_mut().ui.mask_target = false;
|
||||
assert_eq!(cursor(&mut h), normal, "the layer's own pixels keep the tip cursor");
|
||||
|
||||
// A group's mask, targeted from the Layers panel.
|
||||
h.state_mut().run("layer.new.group", json!({})).unwrap();
|
||||
layer_mask(&mut h);
|
||||
h.state_mut().ui.mask_target = true;
|
||||
assert_eq!(cursor(&mut h), BLOCKED, "a group mask");
|
||||
}
|
||||
|
||||
/// Done when 1 and 2: the composite of a 32-bit document blocks the cursor, an 8- or 16-bit one
|
||||
/// does not.
|
||||
#[test]
|
||||
fn a_thirty_two_bit_composite_blocks_the_background_eraser_cursor() {
|
||||
for (depth, blocked) in [(8, false), (16, false), (32, true)] {
|
||||
let mut h = harness(depth);
|
||||
pixel_layer(&mut h);
|
||||
let got = cursor(&mut h);
|
||||
assert_eq!(got == BLOCKED, blocked, "{depth}-bit: {got:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Done when 3: the targets the issue left unmeasured keep today's cursor: the Quick Mask, an
|
||||
/// adjustment layer's mask, and a vector mask.
|
||||
#[test]
|
||||
fn the_unmeasured_targets_keep_the_tip_cursor() {
|
||||
let mut h = harness(8);
|
||||
pixel_layer(&mut h);
|
||||
let normal = cursor(&mut h);
|
||||
|
||||
h.state_mut().run("select.editInQuickMaskMode", json!({"on": true})).unwrap();
|
||||
assert_eq!(cursor(&mut h), normal, "Quick Mask");
|
||||
h.state_mut().run("select.editInQuickMaskMode", json!({"on": false})).unwrap();
|
||||
|
||||
h.state_mut().run("layer.newAdjustmentLayer.curves", json!({})).unwrap();
|
||||
layer_mask(&mut h);
|
||||
h.state_mut().ui.mask_target = true;
|
||||
assert_eq!(cursor(&mut h), normal, "an adjustment layer's mask");
|
||||
|
||||
let mut h = harness(8);
|
||||
pixel_layer(&mut h);
|
||||
let normal = cursor(&mut h);
|
||||
h.state_mut().run("layer.vectorMask.add", json!({})).unwrap();
|
||||
assert_eq!(cursor(&mut h), normal, "a vector mask");
|
||||
}
|
||||
@@ -167,6 +167,16 @@ pub(super) fn paint_cursor_blocked(app: &PhotocraftApp) -> bool {
|
||||
if tool == Tool::ArtHistoryBrush {
|
||||
return app.session.active().is_some_and(|state| matches!(state.doc.mode, photocraft_color::ColorMode::Indexed | photocraft_color::ColorMode::Bitmap));
|
||||
}
|
||||
// The Background Eraser refuses a layer mask and the composite of a 32-bit document, and shows
|
||||
// the not-allowed cursor over both (#18097). The targets the issue left unmeasured (an alpha
|
||||
// channel, Quick Mask, an adjustment layer, colour channels) keep the tip cursor.
|
||||
if tool == Tool::BackgroundEraser {
|
||||
let Some(state) = app.session.active() else { return false };
|
||||
let target = super::paint_target(app);
|
||||
let mask = target.as_str() == Some("mask") && !crate::adjustment_layer_active(state);
|
||||
let wide = target.as_str() == Some("pixels") && state.doc.depth == photocraft_color::SampleType::F32;
|
||||
return mask || wide;
|
||||
}
|
||||
if !matches!(tool, Tool::Brush | Tool::Eraser | Tool::PaintBucket | Tool::MixerBrush) {
|
||||
return false;
|
||||
}
|
||||
@@ -264,3 +274,7 @@ mod locked_layer_cursor_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "art_history_mode_cursor_tests.rs"]
|
||||
mod art_history_mode_cursor_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "background_eraser_target_cursor_tests.rs"]
|
||||
mod background_eraser_target_cursor_tests;
|
||||
Reference in new issue
Block a user