mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge branch 'bb-epic-color-replacement-mx3tl41i' of github.com:davidmann4/photocraft into bb-11931
This commit is contained in:
commit
a7e30f1122
7 files changed
+414
-22
No files matched your search
@@ -78,6 +78,10 @@ impl Default for ReplaceSettings {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "replace_tolerance_falloff_tests.rs"]
|
||||
mod replace_tolerance_falloff_tests;
|
||||
|
||||
fn dist(a: &[f32; 4], b: [f32; 3]) -> f32 {
|
||||
(a[0] - b[0]).abs().max((a[1] - b[1]).abs()).max((a[2] - b[2]).abs())
|
||||
}
|
||||
@@ -138,8 +142,10 @@ pub fn color_replacement_effect(pre: Surface, rs: ReplaceSettings) -> impl FnMut
|
||||
if d > tol {
|
||||
0.0
|
||||
} else if soft && tol > 0.0 {
|
||||
// Soft falloff over the last quarter of the tolerance.
|
||||
((tol - d) / (tol * 0.25)).clamp(0.0, 1.0)
|
||||
// Soft across the whole tolerance, as the reference measures (#11916): each dab
|
||||
// replaces less the further a colour is from the sample. The exponent is fitted to
|
||||
// its eight-block table (within 6 levels at Tolerance 10, 30, 50 and 100).
|
||||
(1.0 - (d / tol).powf(1.15)).clamp(0.0, 1.0)
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
//! #11916: colours near the Tolerance limit are only partly replaced, fading over the whole
|
||||
//! range, as the reference application measures.
|
||||
|
||||
use super::*;
|
||||
use crate::{BrushSettings, StrokePoint};
|
||||
use photocraft_color::PixelFormat;
|
||||
|
||||
/// Eight 100 px blocks at y 300..600, block i = (200, 40 + 20 i, 40); a 40 px hard round tip
|
||||
/// swept from x 50 to `end_x` at y 450 in Color mode with blue, Sampling Once, Discontiguous.
|
||||
fn blocks_after(tolerance: f32, end_x: f64) -> Vec<[f32; 3]> {
|
||||
let fmt = PixelFormat::RGBA8;
|
||||
let mut s = Surface::new(fmt);
|
||||
for i in 0..8 {
|
||||
let c = [200.0 / 255.0, (40.0 + 20.0 * i as f32) / 255.0, 40.0 / 255.0, 1.0];
|
||||
s.fill_rect(Rect::new(100 * i, 300, 100 * i + 100, 600), &photocraft_raster::from_rgba(&fmt, c));
|
||||
}
|
||||
let stroke = Stroke {
|
||||
brush: BrushSettings { size: 40.0, hardness: 1.0, spacing: 0.25, pressure_size: false, ..Default::default() },
|
||||
points: vec![StrokePoint::new(50.0, 450.0, 1.0), StrokePoint::new(end_x, 450.0, 1.0)],
|
||||
};
|
||||
let rs = ReplaceSettings {
|
||||
mode: ReplaceMode::Color,
|
||||
sampling: Sampling::Once,
|
||||
limits: Limits::Discontiguous,
|
||||
tolerance: tolerance / 100.0,
|
||||
anti_alias: true,
|
||||
color: [0.0, 0.0, 1.0, 1.0],
|
||||
..Default::default()
|
||||
};
|
||||
apply_color_replacement(&mut s, &stroke, &rs, None, false).expect("the stroke fits");
|
||||
(0..8).map(|i| s.rgba(100 * i + 50, 450)).map(|c| [c[0] * 255.0, c[1] * 255.0, c[2] * 255.0]).collect()
|
||||
}
|
||||
|
||||
fn untouched(i: usize) -> [f32; 3] {
|
||||
[200.0, 40.0 + 20.0 * i as f32, 40.0]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tolerance_fades_over_its_whole_range() {
|
||||
// The reference's table for a stroke from x 50 to 750; None = untouched. Block 7's centre is
|
||||
// the stroke's end, where the reference's value depends on where its last dabs land, so
|
||||
// block 7 is checked below with a stroke that runs past it.
|
||||
let table: [(f32, [Option<[f32; 3]>; 7]); 4] = [
|
||||
(10.0, [Some([71.0, 71.0, 255.0]), Some([122.0, 74.0, 183.0]), None, None, None, None, None]),
|
||||
(30.0, [Some([71.0, 71.0, 255.0]), Some([85.0, 85.0, 254.0]), Some([102.0, 95.0, 242.0]), Some([141.0, 106.0, 181.0]), None, None, None]),
|
||||
(
|
||||
50.0,
|
||||
[
|
||||
Some([71.0, 71.0, 255.0]),
|
||||
Some([85.0, 85.0, 255.0]),
|
||||
Some([97.0, 96.0, 254.0]),
|
||||
Some([114.0, 110.0, 247.0]),
|
||||
Some([132.0, 120.0, 226.0]),
|
||||
Some([157.0, 137.0, 180.0]),
|
||||
Some([188.0, 156.0, 92.0]),
|
||||
],
|
||||
),
|
||||
(
|
||||
100.0,
|
||||
[
|
||||
Some([71.0, 71.0, 255.0]),
|
||||
Some([85.0, 85.0, 255.0]),
|
||||
Some([99.0, 99.0, 255.0]),
|
||||
Some([111.0, 111.0, 255.0]),
|
||||
Some([123.0, 123.0, 254.0]),
|
||||
Some([138.0, 137.0, 251.0]),
|
||||
Some([151.0, 149.0, 246.0]),
|
||||
],
|
||||
),
|
||||
];
|
||||
for (tol, row) in table {
|
||||
let got = blocks_after(tol, 750.0);
|
||||
for (i, want) in row.iter().enumerate() {
|
||||
let want = want.unwrap_or_else(|| untouched(i));
|
||||
let within = if row[i].is_some() { 6.0 } else { 0.5 };
|
||||
for k in 0..3 {
|
||||
assert!((got[i][k] - want[k]).abs() <= within, "tolerance {tol}, block {i}: {:?}, expected {want:?}", got[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Block 7 lies outside Tolerance 50 and below. At 100 a stroke on to x 790 leaves its centre
|
||||
// only partly replaced: the reference measures 166,165,238 there.
|
||||
assert_eq!(blocks_after(50.0, 750.0)[7].map(f32::round), untouched(7));
|
||||
let b7 = blocks_after(100.0, 790.0)[7];
|
||||
for (k, want) in [166.0, 165.0, 238.0].into_iter().enumerate() {
|
||||
assert!((b7[k] - want).abs() <= 6.0, "tolerance 100, block 7: {b7:?}, expected 166,165,238");
|
||||
}
|
||||
}
|
||||
|
||||
/// A click on the border between red above and block 1 below samples red: the red is replaced
|
||||
/// fully, block 1 only partly (the reference: 67,67,255 and 157,68,119).
|
||||
#[test]
|
||||
fn a_border_click_partly_replaces_the_neighbouring_colour() {
|
||||
let fmt = PixelFormat::RGBA8;
|
||||
let mut s = Surface::new(fmt);
|
||||
s.fill_rect(Rect::new(0, 0, 200, 450), &photocraft_raster::from_rgba(&fmt, [220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0, 1.0]));
|
||||
s.fill_rect(Rect::new(0, 450, 200, 600), &photocraft_raster::from_rgba(&fmt, [200.0 / 255.0, 60.0 / 255.0, 40.0 / 255.0, 1.0]));
|
||||
let stroke = Stroke {
|
||||
brush: BrushSettings { size: 40.0, hardness: 1.0, spacing: 0.25, pressure_size: false, ..Default::default() },
|
||||
points: vec![StrokePoint::new(100.0, 449.5, 1.0)],
|
||||
};
|
||||
let rs = ReplaceSettings {
|
||||
mode: ReplaceMode::Color,
|
||||
sampling: Sampling::Continuous,
|
||||
limits: Limits::Contiguous,
|
||||
tolerance: 0.3,
|
||||
color: [0.0, 0.0, 1.0, 1.0],
|
||||
..Default::default()
|
||||
};
|
||||
apply_color_replacement(&mut s, &stroke, &rs, None, false).expect("the stroke fits");
|
||||
let (red, below) = (s.rgba(100, 440).map(|v| v * 255.0), s.rgba(100, 455).map(|v| v * 255.0));
|
||||
assert!(red[0] < 75.0 && red[2] > 250.0, "red replaced fully: {red:?}");
|
||||
assert!(below[0] > 120.0 && below[0] < 199.0 && below[2] > 41.0, "block 1 partly replaced: {below:?}");
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
//! #11929: the Color Replacement options bar ends with the brush Angle field and the Pressure for Size
|
||||
//! toggle, after Anti-alias. Both edit the tool's own brush, the one the Brush Settings panel shows;
|
||||
//! typed angles are whole degrees -180..180 with the reference application's alerts.
|
||||
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
use egui::{Key, Modifiers, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{PhotocraftApp, Tool};
|
||||
|
||||
type H = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
const PRESSURE: &str = "Always use pressure for size";
|
||||
const RANGE_ALERT: &str = "An integer between -180 ° and 180 ° is required. Closest value inserted.";
|
||||
const INVALID_ALERT: &str = "Invalid numeric entry. An integer between -180 ° and 180 ° is required. Restored last valid value.";
|
||||
|
||||
fn bar() -> H {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 80, "height": 80})).unwrap();
|
||||
crate::theme::install_fonts(app.ctx());
|
||||
crate::theme::apply(app.ctx(), &crate::theme::AppTheme::pro());
|
||||
let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(vec2(1800.0, 300.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut Box<PhotocraftApp>| {
|
||||
crate::panels::options_bar(app, ui);
|
||||
crate::dialogs::run(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn select(h: &mut H, tool: Tool) {
|
||||
h.state_mut().ui.tool = tool;
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn angle_field<'a>(h: &'a H) -> egui_kittest::Node<'a> {
|
||||
h.query_all_by_role(Role::SpinButton).find(|n| n.accesskit_node().label().is_some_and(|l| l.trim_end_matches(':') == "Angle")).expect("the Angle field")
|
||||
}
|
||||
|
||||
fn shown_angle(h: &H) -> Option<f64> {
|
||||
angle_field(h).accesskit_node().numeric_value()
|
||||
}
|
||||
|
||||
fn pressure_on(h: &H) -> bool {
|
||||
h.get_by_role_and_label(Role::Button, PRESSURE).accesskit_node().toggled() == Some(Toggled::True)
|
||||
}
|
||||
|
||||
fn type_angle(h: &mut H, text: &str) {
|
||||
angle_field(h).click();
|
||||
h.run_steps(1);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
|
||||
h.event(egui::Event::Text(text.into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(Key::Enter);
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// `number` with the system's decimal mark, which the field reads.
|
||||
fn local(number: &str) -> String {
|
||||
let mark = craft::i18n::Region::system().decimal.filter(|c| *c == ',').unwrap_or('.');
|
||||
number.replace('.', &mark.to_string())
|
||||
}
|
||||
|
||||
/// The messages of the open alerts.
|
||||
fn alerts(h: &H) -> Vec<String> {
|
||||
h.state().framework.dialogs.open_dialogs().iter().filter_map(|d| d.fields.as_ref()?.get("message")?.as_str().map(str::to_owned)).collect()
|
||||
}
|
||||
|
||||
fn dismiss(h: &mut H) {
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(4);
|
||||
assert!(alerts(h).is_empty(), "OK closes the alert");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn angle_and_pressure_for_size_follow_anti_alias_with_the_reference_defaults_and_tooltips() {
|
||||
let mut h = bar();
|
||||
select(&mut h, Tool::ColorReplacement);
|
||||
let anti_alias = h.get_by_label("Anti-alias").rect();
|
||||
let angle = angle_field(&h);
|
||||
let pressure = h.get_by_role_and_label(Role::Button, PRESSURE);
|
||||
assert!(anti_alias.right() <= angle.rect().left(), "Anti-alias, then Angle");
|
||||
assert!(angle.rect().right() <= pressure.rect().left(), "Angle, then Pressure for Size");
|
||||
assert_eq!(angle.accesskit_node().description().as_deref(), Some("Set the brush angle"));
|
||||
assert_eq!(pressure.accesskit_node().description().as_deref(), Some("Always use Pressure for Size. When off, Brush Preset controls pressure"));
|
||||
assert_eq!(shown_angle(&h), Some(0.0), "0° by default");
|
||||
assert!(!pressure_on(&h), "Pressure for Size is off by default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_angles_are_clamped_and_truncated_with_the_reference_alerts() {
|
||||
let mut h = bar();
|
||||
select(&mut h, Tool::ColorReplacement);
|
||||
for (typed, kept) in [("400", 180.0), ("-200", -180.0)] {
|
||||
type_angle(&mut h, typed);
|
||||
assert_eq!(h.state().session.tools.brush.angle, kept, "{typed}: the closest value is kept");
|
||||
assert_eq!(alerts(&h), [RANGE_ALERT], "{typed}");
|
||||
dismiss(&mut h);
|
||||
assert_eq!(h.state().session.tools.brush.angle, kept, "{typed}: the value stays after OK");
|
||||
}
|
||||
type_angle(&mut h, &local("45.5"));
|
||||
assert_eq!(h.state().session.tools.brush.angle, 45.0, "a fraction is truncated");
|
||||
assert!(alerts(&h).is_empty(), "45.5 is in range: no alert");
|
||||
|
||||
type_angle(&mut h, "abc");
|
||||
assert_eq!(alerts(&h), [INVALID_ALERT], "a non-number");
|
||||
dismiss(&mut h);
|
||||
assert_eq!(h.state().session.tools.brush.angle, 45.0, "a non-number keeps the last value");
|
||||
assert_eq!(shown_angle(&h), Some(45.0), "the field shows the last valid value again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_controls_write_the_color_replacement_brush_only_and_share_it_with_brush_settings() {
|
||||
let mut h = bar();
|
||||
// Color Replacement's brush exists from its first use on (that use takes the live tip); only
|
||||
// then does the Brush get values of its own.
|
||||
select(&mut h, Tool::ColorReplacement);
|
||||
select(&mut h, Tool::Brush);
|
||||
h.state_mut().run("tools.setBrush", json!({"brush": {"angle": -30.0, "pressureSize": true}})).unwrap();
|
||||
select(&mut h, Tool::ColorReplacement);
|
||||
assert_eq!(shown_angle(&h), Some(0.0), "Color Replacement shows its own brush, not the Brush's");
|
||||
assert!(!pressure_on(&h));
|
||||
|
||||
// The Brush Settings panel edits the active tool's brush through this command.
|
||||
h.state_mut().run("tools.setBrush", json!({"brush": {"angle": 60.0}})).unwrap();
|
||||
h.run_steps(2);
|
||||
assert_eq!(shown_angle(&h), Some(60.0), "the field shows the panel's angle");
|
||||
type_angle(&mut h, "25");
|
||||
h.get_by_role_and_label(Role::Button, PRESSURE).click();
|
||||
h.run_steps(2);
|
||||
let brush = &h.state().session.tools.brush;
|
||||
assert_eq!((brush.angle, brush.pressure_size), (25.0, true), "the panel reads the same brush");
|
||||
|
||||
select(&mut h, Tool::Brush);
|
||||
let brush = &h.state().session.tools.brush;
|
||||
assert_eq!((brush.angle, brush.pressure_size), (-30.0, true), "the Brush keeps its own values");
|
||||
select(&mut h, Tool::ColorReplacement);
|
||||
assert_eq!(shown_angle(&h), Some(25.0));
|
||||
assert!(pressure_on(&h), "Color Replacement keeps its own values");
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//! #11924: when the Color Replacement tool can't paint (a hidden target layer, Lock All, a group),
|
||||
//! a press opens the reference application's alert with OK and changes nothing. Lock transparent
|
||||
//! pixels still recolours. Other tools keep their alerts.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke};
|
||||
use super::*;
|
||||
use crate::control::{ControlRequest, Reply, handle};
|
||||
|
||||
#[test]
|
||||
fn a_hidden_target_layer() {
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the Color Replacement tool 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);
|
||||
assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden.", "the shared text is unchanged");
|
||||
}
|
||||
|
||||
/// A targeted layer mask on a hidden layer keeps the status-bar refusal: only a pixel target gets the alert (CodeRabbit
|
||||
/// on #16279).
|
||||
#[test]
|
||||
fn a_hidden_layer_with_a_mask_target_keeps_the_status_bar_message() {
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
app.run("layer.layerMask.revealAll", json!({})).unwrap();
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
app.ui.mask_target = true;
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app));
|
||||
assert!(app.ui.status_error, "the status bar says it: {:?}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_all() {
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
refused(&mut app, "Could not use the Color Replacement tool because the layer is locked.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_is_active() {
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the Color Replacement tool because the target is a group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_transparent_pixels_still_recolours() {
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
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_alert_is_listed_and_confirmed_over_the_control_channel() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app(Tool::ColorReplacement);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
stroke(&mut app);
|
||||
let mut call = |method: &str, params: serde_json::Value| {
|
||||
let (req, _rx) = ControlRequest::new(method, params);
|
||||
match handle(&mut app, &ctx, &req) {
|
||||
Reply::Done(v) => v,
|
||||
_ => panic!("{method}: expected an immediate reply"),
|
||||
}
|
||||
};
|
||||
let inspect = call("ui.inspect", json!({}));
|
||||
let dialog = &inspect["result"]["dialogs"][0];
|
||||
assert_eq!(dialog["fields"]["message"], "Could not use the Color Replacement tool because the layer is locked.", "{inspect}");
|
||||
assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true);
|
||||
assert!(alerts(&app).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_brush_keeps_its_group_text() {
|
||||
let mut app = app(Tool::Brush);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the brush tool because the pixels in a group cannot be edited without merging the group.");
|
||||
}
|
||||
@@ -82,11 +82,11 @@ fn painting_a_hidden_layer_is_refused_at_the_press() {
|
||||
let n = steps(&app);
|
||||
tool_event(&mut app, ToolEvent::Down { x: 30.0, y: 30.0, pressure: 1.0 }, egui::Modifiers::NONE);
|
||||
assert!(!crate::canvas::testing::in_gesture(&app) && app.live_stroke.is_none(), "{tool:?}: no stroke started");
|
||||
// The Brush (#11898), the Classic gradient (#12017), the Paint Bucket (#12537) and the Clone
|
||||
// Stamp (#12608) say so in an alert, the other tools in the status bar.
|
||||
// The Brush (#11898), the Classic gradient (#12017), the Paint Bucket (#12537), the Clone
|
||||
// Stamp (#12608) and Color Replacement (#11924) say so in an alert, the other tools in the status bar.
|
||||
let alerts = alerts(&app);
|
||||
let alert = alerts.iter().any(|m| m.contains("target layer is hidden"));
|
||||
if matches!(tool, Tool::Brush | Tool::Gradient | Tool::PaintBucket | Tool::CloneStamp) {
|
||||
if matches!(tool, Tool::Brush | Tool::Gradient | Tool::PaintBucket | Tool::CloneStamp | Tool::ColorReplacement) {
|
||||
assert!(alert, "{tool:?}: {alerts:?}");
|
||||
} else {
|
||||
assert!(app.ui.status.contains("target layer is hidden") && alerts.is_empty(), "{tool:?}: {}", app.ui.status);
|
||||
|
||||
@@ -18,6 +18,8 @@ pub const GROUP: &str = "Could not use the {tool} because the pixels in a group
|
||||
pub const CLONE_STAMP_GROUP: &str = "Could not use the {tool} because the source is a group.";
|
||||
/// The Brush's alert when an adjustment layer's own content, not its mask, is targeted (#17640).
|
||||
pub const CONTENT: &str = "Could not use the {tool} because the content of the layer is not directly editable.";
|
||||
/// The Color Replacement tool's group alert (#11924): its own wording, not the Brush's [`GROUP`].
|
||||
pub const TARGET_GROUP: &str = "Could not use the {tool} because the target is a group.";
|
||||
/// The Remove tool's one measured alert, Lock All (#12552): it doesn't name the tool.
|
||||
pub const REMOVE_LOCKED: &str = "Can't use the tool because the layer is locked.";
|
||||
|
||||
@@ -43,7 +45,7 @@ fn mode_tool_name(tool: Tool) -> Option<&'static str> {
|
||||
|
||||
/// The tool's name in the alerts, for the tools whose wording was measured: the Brush, the
|
||||
/// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Burn tool (#12672), the Healing Brush (#12111), the Art History Brush
|
||||
/// (#12638), the Clone Stamp (#12608), the Paint Bucket (#12537) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017).
|
||||
/// (#12638), the Clone Stamp (#12608), the Paint Bucket (#12537), the Color Replacement tool (#11924) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017).
|
||||
pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
match tool {
|
||||
Tool::Brush => Some(tl!("brush tool")),
|
||||
@@ -60,6 +62,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
Tool::CloneStamp => Some(tl!("clone stamp tool")),
|
||||
// The Paint Bucket's click (#12537).
|
||||
Tool::PaintBucket => Some(tl!("paint bucket")),
|
||||
Tool::ColorReplacement => Some(tl!("Color Replacement tool")),
|
||||
Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")),
|
||||
_ => None,
|
||||
}
|
||||
@@ -98,9 +101,9 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
|
||||
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.
|
||||
if hidden && tool == Tool::ArtHistoryBrush && !pixels_target(&crate::canvas::paint_target(app)) {
|
||||
// The Art History Brush's (#12638) and the Color Replacement tool's (#11924) hidden alerts were measured on a
|
||||
// layer's pixels only: a hidden mask or channel target keeps the status bar.
|
||||
if hidden && matches!(tool, Tool::ArtHistoryBrush | Tool::ColorReplacement) && !pixels_target(&crate::canvas::paint_target(app)) {
|
||||
return None;
|
||||
}
|
||||
// A group is the Healing Brush's no-source alert (#12109), hidden or not: it keeps today's
|
||||
@@ -123,6 +126,8 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
|
||||
return Some(crate::i18n::fmt(tl!(CONTENT), &[("tool", name)]));
|
||||
}
|
||||
let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? };
|
||||
// The Color Replacement tool says a group differently (#11924).
|
||||
let template = if tool == Tool::ColorReplacement && template == GROUP { TARGET_GROUP } else { template };
|
||||
Some(crate::i18n::fmt(tl!(template), &[("tool", name)]))
|
||||
}
|
||||
|
||||
@@ -213,6 +218,10 @@ mod retouch_mode_refusal_alert_tests;
|
||||
#[path = "../smudge_refusal_alert_tests.rs"]
|
||||
mod smudge_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../color_replacement_refusal_alert_tests.rs"]
|
||||
mod color_replacement_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "remove_hidden_layer_tests.rs"]
|
||||
mod remove_hidden_layer_tests;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
use craft::behavior::{IconId, NumberCodec};
|
||||
use craft::ui::buttons::ToggleButton;
|
||||
use craft::ui::choice::{Checkbox, Segmented};
|
||||
use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, bind_tracked};
|
||||
use craft::ui::contract::{Bind, EditResponse, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, bind_tracked};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::primitives::IconSpec;
|
||||
use craft::ui::runtime::env::Env;
|
||||
use craft::ui::text::{NumberField, NumberValue, RangeAlert};
|
||||
use craft::ui::text::{NumberField, NumberValue, RangeAlert, TextWords};
|
||||
use photocraft_color::BlendMode;
|
||||
|
||||
use super::heal::{check, choose, string_entries};
|
||||
@@ -75,12 +75,12 @@ pub(super) fn sponge(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<Range
|
||||
flow
|
||||
}
|
||||
|
||||
/// Smudge keeps the original Angle field's truncation of typed fractions.
|
||||
/// Smudge and Color Replacement keep the original Angle field's truncation of typed fractions.
|
||||
/// The shared field still owns parsing, range alerts, stepping and scrubbing.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct SmudgeAngle(f32);
|
||||
struct TruncatedAngle(f32);
|
||||
|
||||
impl NumberValue for SmudgeAngle {
|
||||
impl NumberValue for TruncatedAngle {
|
||||
fn number(&self) -> Option<f64> {
|
||||
Some(f64::from(self.0))
|
||||
}
|
||||
@@ -98,10 +98,13 @@ impl NumberValue for SmudgeAngle {
|
||||
}
|
||||
}
|
||||
|
||||
fn smudge_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
|
||||
/// The truncating Angle field over the active tool's own brush. `invalid_alert`: text that does not
|
||||
/// parse shows the reference's "Invalid numeric entry" alert when the edit ends (Color Replacement,
|
||||
/// #11929); without it the field keeps the last value silently, as Smudge's always did.
|
||||
fn truncated_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp, invalid_alert: bool) -> Option<RangeAlert> {
|
||||
let before = (*app.session.tools.brush).clone();
|
||||
let mut brush = before.clone();
|
||||
let mut angle = SmudgeAngle(brush.angle);
|
||||
let mut angle = TruncatedAngle(brush.angle);
|
||||
let shown = Field::new(tl!("Angle"))
|
||||
.side(SideLabel::new().scrub(true).icon(IconSpec::svg(IconId::new("rotate_cw"))).layout(FieldLayout::Inside))
|
||||
.sizing(Sizing::Content)
|
||||
@@ -122,14 +125,39 @@ fn smudge_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert
|
||||
brush.angle = angle.0;
|
||||
key = shown.edit.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e));
|
||||
alert = shown.out_of_range.filter(|alert| !alert.range.contains(&alert.typed.trunc()));
|
||||
if invalid_alert {
|
||||
invalid_angle_entry(ui, app, &shown.edit);
|
||||
}
|
||||
}
|
||||
crate::brush_panel::commit_keyed(app, &before, &brush, key);
|
||||
alert
|
||||
}
|
||||
|
||||
/// Smudge's pressure-for-size switch edits the active tool's own brush through
|
||||
/// the same command and gesture path as the current Background Eraser controls.
|
||||
fn smudge_pressure_size(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
|
||||
/// Ends an Angle edit whose text does not parse: Enter lets the field go (it then restores the last
|
||||
/// valid value, as leaving it does), and the end shows the reference's alert, once.
|
||||
fn invalid_angle_entry<T>(ui: &egui::Ui, app: &mut PhotocraftApp, edit: &EditResponse<T>) {
|
||||
let id = edit.response.id.with("invalid_angle_entry");
|
||||
let was_unparsed = ui.data(|d| d.get_temp::<bool>(id)).unwrap_or(false);
|
||||
ui.data_mut(|d| d.insert_temp(id, edit.unparsed));
|
||||
let entered = edit.unparsed && ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
if entered {
|
||||
ui.memory_mut(|m| m.surrender_focus(edit.response.id));
|
||||
}
|
||||
if !entered && !(was_unparsed && edit.text_lost_focus) {
|
||||
return;
|
||||
}
|
||||
let env = Env::of(ui);
|
||||
let end = |n: f64| env.words::<TextWords>().range_end.fill(&[("n", env.units().number(n, 0..=0).as_str()), ("unit", "°")]);
|
||||
let message = crate::i18n::fmt(
|
||||
tl!("Invalid numeric entry. An integer between {low} and {high} is required. Restored last valid value."),
|
||||
&[("low", end(-180.0).as_str()), ("high", end(180.0).as_str())],
|
||||
);
|
||||
crate::dialogs::alerts::alert(app, message);
|
||||
}
|
||||
|
||||
/// The pressure-for-size switch of Smudge and Color Replacement edits the active tool's own brush
|
||||
/// through the same command and gesture path as the current Background Eraser controls.
|
||||
fn brush_pressure_size(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
|
||||
let before = (*app.session.tools.brush).clone();
|
||||
let mut brush = before.clone();
|
||||
let pressure = ToggleButton::new(tl!("Always use pressure for size"), Bind::given(brush.pressure_size))
|
||||
@@ -152,7 +180,7 @@ pub(super) fn blur_sharpen_smudge(ui: &mut egui::Ui, app: &mut PhotocraftApp, to
|
||||
// The cell writes only on a commit, so a shared fraction is not rounded (#12650).
|
||||
let strength = number(tl!("Strength"), bind_tracked!(app.ui.tool_options => strength), 1.0..=100.0).whole().unit("%").show(ui).out_of_range;
|
||||
let angle = match tool {
|
||||
Tool::Smudge => smudge_angle(ui, app),
|
||||
Tool::Smudge => truncated_angle(ui, app, false),
|
||||
Tool::Sharpen => brush_angle(ui, app),
|
||||
_ => None,
|
||||
};
|
||||
@@ -167,7 +195,7 @@ pub(super) fn blur_sharpen_smudge(ui: &mut egui::Ui, app: &mut PhotocraftApp, to
|
||||
}
|
||||
if tool == Tool::Smudge {
|
||||
check(ui, tl!("Finger Painting"), bind_tracked!(app.ui.tool_options => finger_painting), true, None);
|
||||
smudge_pressure_size(ui, app);
|
||||
brush_pressure_size(ui, app);
|
||||
}
|
||||
strength.or(angle)
|
||||
}
|
||||
@@ -212,9 +240,16 @@ pub(super) fn color_replacement(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> O
|
||||
.show(ui)
|
||||
.out_of_range;
|
||||
check(ui, tl!("Anti-alias"), bind_tracked!(app.ui.tool_options => cr_anti_alias), true, Some(tl!("Anti-alias brush application")));
|
||||
tolerance
|
||||
// The tool's own brush tip, as the Brush Settings panel shows it (#11929).
|
||||
let angle = truncated_angle(ui, app, true);
|
||||
brush_pressure_size(ui, app);
|
||||
tolerance.or(angle)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../../../sharpen_bar_angle_tests.rs"]
|
||||
mod sharpen_bar_angle_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../../../color_replacement_bar_angle_tests.rs"]
|
||||
mod color_replacement_bar_angle_tests;
|
||||
Reference in new issue
Block a user