mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #16298 into the merge queue batch
Spot Healing Brush: alerts for a hidden layer, Lock All and a group
This commit is contained in:
commit
b60b4f8981
4 files changed
+88
-1
No files matched your search
@@ -307,6 +307,9 @@ fn press_refused(app: &mut PhotocraftApp, tool: Tool) -> bool {
|
||||
/// case was measured: a layer inside a hidden group, a targeted mask, Sample All Layers and the other layer kinds keep
|
||||
/// the status-bar error. Hidden is checked before the lock, so a hidden layer with Lock All is quiet too.
|
||||
fn quiet_hidden_refusal(app: &PhotocraftApp, tool: Tool) -> bool {
|
||||
if crate::brush_refusal::spot_healing_quiet(app, tool) {
|
||||
return true;
|
||||
}
|
||||
if tool != Tool::Remove || app.ui.tool_options.sample_all.remove || super::paint_target(app) != serde_json::json!("pixels") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! #12581: when the Spot Healing Brush can't heal (a hidden target layer, Lock All, a group's
|
||||
//! pixels), a press opens the reference application's alert with OK and changes nothing. On a hidden
|
||||
//! empty pixel layer with Sample All Layers off the press does nothing and says nothing. Lock
|
||||
//! transparent pixels is no refusal.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_hidden_target_layer() {
|
||||
let mut app = app(Tool::SpotHealing);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the spot healing brush because the target layer is hidden.");
|
||||
assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_all() {
|
||||
let mut app = app(Tool::SpotHealing);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
refused(&mut app, "Could not use the spot healing brush because the layer is locked.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_is_active() {
|
||||
let mut app = app(Tool::SpotHealing);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the spot healing brush because the pixels in a group cannot be edited without merging the group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hidden_empty_layer_with_sample_all_layers_off_does_nothing_quietly() {
|
||||
let mut app = app(Tool::SpotHealing);
|
||||
app.ui.tool_options.sample_all.spot_healing = false;
|
||||
let empty = app.run("layer.new.layer", json!({"name": "Empty"})).unwrap()["layer"].as_u64().unwrap();
|
||||
app.run("layer.setProps", json!({"layer": empty, "visible": false})).unwrap();
|
||||
app.sync_views();
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app));
|
||||
assert_eq!(steps(&app), before, "no History step");
|
||||
assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error: {:?}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_transparent_pixels_still_heals() {
|
||||
let mut app = app(Tool::SpotHealing);
|
||||
app.run("layer.lockLayers", json!({"transparency": true})).unwrap();
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty(), "no refusal: {:?}", alerts(&app));
|
||||
assert_eq!(steps(&app), before + 1, "the stroke was applied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_shared_hidden_text_stays() {
|
||||
assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden.");
|
||||
}
|
||||
@@ -48,6 +48,8 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
Tool::Sharpen => Some(tl!("sharpen tool")),
|
||||
Tool::Sponge => Some(tl!("sponge tool")),
|
||||
Tool::Smudge => Some(tl!("smudge tool")),
|
||||
// The Spot Healing Brush (#12581).
|
||||
Tool::SpotHealing => Some(tl!("spot healing brush")),
|
||||
Tool::ArtHistoryBrush => Some(tl!("art history brush")),
|
||||
Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")),
|
||||
_ => None,
|
||||
@@ -82,6 +84,10 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
|
||||
let pixel_layer = st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| matches!(l.content, photocraft_doc::LayerContent::Raster(_)));
|
||||
return (!hidden && pixel_layer && layer_refusal(app, tool) == Some(LOCKED)).then(|| tl!(REMOVE_LOCKED).to_string());
|
||||
}
|
||||
// A Spot Healing press on a hidden empty pixel layer, Sample All Layers off, is refused quietly (#12581).
|
||||
if hidden && spot_healing_quiet(app, tool) {
|
||||
return None;
|
||||
}
|
||||
let name = tool_name(app, tool)?;
|
||||
// The Art History Brush's hidden alert was measured on a layer's pixels only (#12638): a
|
||||
// hidden mask or channel target keeps the status bar.
|
||||
@@ -126,6 +132,18 @@ fn locked(locks: photocraft_doc::Locks, tool: Tool) -> bool {
|
||||
locks.all || (matches!(tool, Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::ArtHistoryBrush | Tool::MagicEraser) && locks.pixels)
|
||||
}
|
||||
|
||||
/// A Spot Healing press on an empty pixel layer with Sample All Layers off (#12581): when that layer is hidden, the
|
||||
/// press does nothing and says nothing, as in Photoshop; there is nothing to heal from.
|
||||
pub(crate) fn spot_healing_quiet(app: &PhotocraftApp, tool: Tool) -> bool {
|
||||
if tool != Tool::SpotHealing || app.ui.tool_options.sample_all.spot_healing || crate::canvas::paint_target(app) != json!("pixels") {
|
||||
return false;
|
||||
}
|
||||
let Some(st) = app.session.active() else { return false };
|
||||
st.active_layer
|
||||
.and_then(|id| st.doc.layer(id))
|
||||
.is_some_and(|l| matches!(l.content, photocraft_doc::LayerContent::Raster(_)) && l.surface().is_some_and(|s| s.content_bounds().is_empty()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../magic_eraser_refusal_alerts_tests.rs"]
|
||||
mod magic_eraser_refusal_alerts_tests;
|
||||
@@ -134,6 +152,10 @@ mod magic_eraser_refusal_alerts_tests;
|
||||
#[path = "../brush_refusal_alert_tests.rs"]
|
||||
pub(super) mod brush_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../spot_healing_refusal_alert_tests.rs"]
|
||||
mod spot_healing_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../retouch_mode_refusal_alert_tests.rs"]
|
||||
mod retouch_mode_refusal_alert_tests;
|
||||
|
||||
@@ -49,7 +49,8 @@ fn a_hidden_active_layer_is_quiet() {
|
||||
fn the_other_tools_keep_their_message() {
|
||||
refused(&mut hidden(Tool::Brush), "Could not use the brush tool because the target layer is hidden.");
|
||||
refused(&mut hidden(Tool::Smudge), "Could not use the smudge tool because the target layer is hidden.");
|
||||
for tool in [Tool::Pencil, Tool::Eraser, Tool::SpotHealing, Tool::Healing, Tool::CloneStamp] {
|
||||
// The Spot Healing Brush has its own alert since #12581.
|
||||
for tool in [Tool::Pencil, Tool::Eraser, Tool::Healing, Tool::CloneStamp] {
|
||||
let mut app = hidden(tool);
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
|
||||
Reference in new issue
Block a user