From f3eec351297b51b814cc53cd26ce88eb82eba455 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:13:43 -0500 Subject: [PATCH 1/3] Brush HUD: hardness at Photoshop's rate and a Diameter / Hardness / Opacity readout Fixes #11891. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/brush_hud_rate_tests.rs | 76 +++++++++++++++++++ crates/ui-egui/src/dialogs/liquify_ui.rs | 4 +- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/tools/brush_resize.rs | 24 ++++-- .../ui-egui/src/tools/brush_resize/tests.rs | 20 ++--- 5 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 crates/ui-egui/src/brush_hud_rate_tests.rs diff --git a/crates/ui-egui/src/brush_hud_rate_tests.rs b/crates/ui-egui/src/brush_hud_rate_tests.rs new file mode 100644 index 0000000000..2008891185 --- /dev/null +++ b/crates/ui-egui/src/brush_hud_rate_tests.rs @@ -0,0 +1,76 @@ +//! #11891: the Alt+right-drag brush HUD changes hardness at Photoshop's rate (50 screen points +//! down from 0 % give 13 %), and its readout has three lines: "Diameter :", "Hardness :" and +//! "Opacity :". The horizontal size change is unchanged. + +use egui::{Modifiers, PointerButton, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::brush_resize::{readout_label, resized}; +use crate::state::Tool; + +#[test] +fn fifty_points_down_from_zero_give_thirteen_percent() { + for zoom in [0.5, 1.0, 2.0] { + // The drag is in document pixels; 50 screen points is 50 / zoom of them. + let (_, hardness) = resized((13.0, 0.0), 0.0, f64::from(50.0 / zoom), zoom); + assert!((hardness - 0.13).abs() <= 0.02, "zoom {zoom}: {hardness}"); + } + assert_eq!(resized((13.0, 0.0), 0.0, -50.0, 1.0).1, 0.0, "up from 0 % stays 0 %"); +} + +#[test] +fn the_size_change_is_unchanged() { + assert_eq!(resized((13.0, 0.0), 50.0, 0.0, 1.0).0, 113.0); + assert_eq!(resized((13.0, 0.0), -278.0, 0.0, 1.0).0, 1.0); +} + +#[test] +fn labels_get_a_space_before_the_colon() { + assert_eq!(readout_label("Diameter:"), "Diameter :"); + assert_eq!(readout_label("Diamètre :"), "Diamètre :", "a translation's own spacing stays"); + assert_eq!(readout_label("Size"), "Size"); +} + +#[test] +fn the_readout_shows_diameter_hardness_and_opacity() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("tools.setBrush", json!({"brush": {"size": 13, "hardness": 0.0, "opacity": 1.0}})).unwrap(); + app.ui.tool = Tool::Brush; + app.sync_views(); + let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_step_dt(1.0 / 60.0).build_ui_state( + |ui, app: &mut PhotocraftApp| { + let ctx = ui.ctx().clone(); + if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); + }, + app, + ); + crate::PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.run_steps(4); + let c = h.state().last_canvas_rect.center(); + let alt = Modifiers::ALT; + h.event(egui::Event::ModifiersChanged(alt)); + h.event(egui::Event::PointerMoved(c)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: c, button: PointerButton::Secondary, pressed: true, modifiers: alt }); + h.run_steps(1); + for i in 1..=5 { + h.event(egui::Event::PointerMoved(c + vec2(0.0, 10.0 * i as f32))); + h.run_steps(1); + } + let hardness = h.state().session.tools.brush.hardness; + assert!((hardness - 0.13).abs() <= 0.02, "{hardness}"); + for label in ["Diameter :", "Hardness :", "Opacity :"] { + assert!(h.query_by_label(label).is_some(), "{label}"); + } + assert!(h.query_by_label("13%").is_some() && h.query_by_label("100%").is_some()); + h.event(egui::Event::PointerButton { pos: c + vec2(0.0, 50.0), button: PointerButton::Secondary, pressed: false, modifiers: alt }); + h.run_steps(2); +} diff --git a/crates/ui-egui/src/dialogs/liquify_ui.rs b/crates/ui-egui/src/dialogs/liquify_ui.rs index f5263b1e81..006cff16a1 100644 --- a/crates/ui-egui/src/dialogs/liquify_ui.rs +++ b/crates/ui-egui/src/dialogs/liquify_ui.rs @@ -800,11 +800,13 @@ fn brush_resize_gesture(mods: egui::Modifiers, secondary: bool) -> bool { } /// Horizontal motion sets the diameter (the circle's edge follows the pointer). Vertical motion -/// sets density, Liquify's edge falloff, over the same 200 px travel the canvas uses for hardness. +/// sets density, Liquify's edge falloff, over 200 px of travel. fn resized_brush(start_size: f32, start_density: f32, dx: f32, dy: f32, zoom: f32) -> (f32, f32) { // Liquify stores density as 0–100; the shared brush gesture works on normalized hardness. // Use the same zoom-corrected screen movement and size limits as the main canvas. let zoom = if zoom.is_finite() && zoom > 0.0 { zoom } else { 1.0 }; + // Density keeps its 200 px travel; the canvas hardness took Photoshop's slower rate (#11891). + let dy = dy * crate::brush_resize::HARDNESS_TRAVEL / 200.0; let (size, density) = crate::brush_resize::resized((start_size, start_density / 100.0), f64::from(dx / zoom), f64::from(dy / zoom), zoom); (size, (density * 100.0).round()) } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 1ba53441ad..c647726cac 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -989,6 +989,8 @@ mod menu_item_labels_tests; #[cfg(test)] mod pen_path_ownership_tests; +#[cfg(test)] +mod brush_hud_rate_tests; #[cfg(test)] mod doc_tab_menu_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/tools/brush_resize.rs b/crates/ui-egui/src/tools/brush_resize.rs index e22faf2347..24596b34d6 100644 --- a/crates/ui-egui/src/tools/brush_resize.rs +++ b/crates/ui-egui/src/tools/brush_resize.rs @@ -19,8 +19,9 @@ use crate::PhotocraftApp; use crate::canvas::{ToolEvent, ViewXform}; use crate::state::Tool; -/// Screen points of vertical drag that take the hardness from 0 % to 100 %. -pub const HARDNESS_TRAVEL: f32 = 200.0; +/// Screen points of vertical drag that take the hardness from 0 % to 100 %: Photoshop's rate, +/// where 50 points down from 0 % give 13 % (#11891). +pub const HARDNESS_TRAVEL: f32 = 385.0; /// The brush size range (`tools.setBrush` accepts the same). const SIZE: std::ops::RangeInclusive = 1.0..=MAX_BRUSH_SIZE; @@ -151,15 +152,22 @@ pub fn draw(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform) -> boo // Photoshop hides the pointer while the circle stays put. painter.ctx().set_cursor_icon(egui::CursorIcon::None); let at = painter.ctx().pointer_latest_pos().unwrap_or(c); - let (label, value) = if app.session.prefs().tools.vary_round_brush_hardness_on_hud { - (tl!("Hardness:"), format!("{}%", (b.hardness * 100.0).round() as i64)) - } else { - (tl!("Opacity:"), format!("{}%", (b.opacity * 100.0).round() as i64)) - }; - crate::canvas::draw_readout(painter.ctx(), "brush-resize-readout", at, [tl!("Diameter:"), label], [format!("{} px", b.size.round() as i64), value]); + let percent = |v: f32| format!("{}%", (v * 100.0).round() as i64); + let labels = [readout_label(tl!("Diameter:")), readout_label(tl!("Hardness:")), readout_label(tl!("Opacity:"))]; + let values = [format!("{} px", b.size.round() as i64), percent(b.hardness), percent(b.opacity)]; + crate::canvas::draw_readout(painter.ctx(), "brush-resize-readout", at, labels.each_ref().map(String::as_str), values); true } +/// A readout label as Photoshop's HUD shows it, with a space before the colon ("Diameter :", +/// #11891). A translation that already has one keeps it. +pub(crate) fn readout_label(label: &str) -> String { + match label.strip_suffix(':') { + Some(head) if !head.ends_with(char::is_whitespace) => format!("{head} :"), + _ => label.to_owned(), + } +} + /// The tip preview's tint: Preferences ▸ Cursors ▸ Brush Preview colour (red by default, as in /// Photoshop), at the overlay's alpha. Unreadable values keep the red. fn preview_tint(app: &PhotocraftApp) -> Color32 { diff --git a/crates/ui-egui/src/tools/brush_resize/tests.rs b/crates/ui-egui/src/tools/brush_resize/tests.rs index 3cba8bef99..89cc875cf9 100644 --- a/crates/ui-egui/src/tools/brush_resize/tests.rs +++ b/crates/ui-egui/src/tools/brush_resize/tests.rs @@ -22,7 +22,7 @@ fn history(app: &PhotocraftApp) -> usize { #[test] fn mapping_is_bounded() { assert_eq!(resized((40.0, 0.5), 10.0, 0.0, 1.0), (60.0, 0.5), "the edge follows the pointer"); - assert_eq!(resized((40.0, 0.5), 0.0, 50.0, 2.0), (40.0, 1.0), "down is harder, in screen points"); + assert_eq!(resized((40.0, 0.5), 0.0, f64::from(HARDNESS_TRAVEL / 4.0), 2.0), (40.0, 1.0), "down is harder, in screen points"); assert_eq!(resized((40.0, 0.5), -1e9, -1e9, 1.0), (1.0, 0.0)); assert_eq!(resized((40.0, 0.5), 1e9, 1e9, 1.0), (MAX_BRUSH_SIZE, 1.0)); assert_eq!(resized((40.0, 0.5), f64::NAN, f64::INFINITY, f32::NAN), (40.0, 0.5)); @@ -41,11 +41,11 @@ fn ctrl_alt_drag_resizes_every_brush_tool_without_painting_or_history() { // Right grows the size. tool_event(&mut app, ToolEvent::Move { x: 130.0, y: 100.0, pressure: 1.0 }, CTRL_ALT); assert_eq!(app.session.tools.brush.size, 100.0, "{tool:?}"); - // Down raises the hardness (at 100 %, 200 points take it from 0 to 100 %). - tool_event(&mut app, ToolEvent::Move { x: 130.0, y: 160.0, pressure: 1.0 }, CTRL_ALT); + // Down raises the hardness (at 100 %, 385 points take it from 0 to 100 %, #11891). + tool_event(&mut app, ToolEvent::Move { x: 130.0, y: 215.5, pressure: 1.0 }, CTRL_ALT); assert_eq!(app.session.tools.brush.hardness, 0.5, "{tool:?}"); // Letting go of the keys mid-drag keeps resizing until the button is released. - tool_event(&mut app, ToolEvent::Up { x: 120.0, y: 180.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Up { x: 120.0, y: 254.0 }, Modifiers::NONE); let b = &app.session.tools.brush; assert_eq!((b.size, b.hardness), (80.0, 0.6), "{tool:?}"); assert!(app.brush_resize.is_none() && app.drag.is_none()); @@ -298,8 +298,8 @@ fn vary_round_brush_hardness_on_hud_switches_the_vertical_target() { } let (h0, o0) = (app.session.tools.brush.hardness, app.session.tools.brush.opacity); tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 100.0, pressure: 1.0 }, CTRL_ALT); - tool_event(&mut app, ToolEvent::Move { x: 100.0, y: 140.0, pressure: 1.0 }, CTRL_ALT); - tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 140.0 }, CTRL_ALT); + tool_event(&mut app, ToolEvent::Move { x: 100.0, y: 177.0, pressure: 1.0 }, CTRL_ALT); + tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 177.0 }, CTRL_ALT); let b = &app.session.tools.brush; if vary { assert_eq!((b.hardness, b.opacity), (h0 + 0.2, o0), "hardness moves with the drag"); @@ -330,16 +330,16 @@ fn drag_in_view(rotation: f32, flip: bool, dx: f64, dy: f64) -> (f32, f32) { fn a_rotated_view_keeps_horizontal_for_size_and_vertical_for_hardness() { // Unrotated, with and without View › Flip Horizontal: unchanged. assert_eq!(drag_in_view(0.0, false, 30.0, 0.0), (100.0, 0.2), "right grows"); - assert_eq!(drag_in_view(0.0, false, 0.0, 40.0), (40.0, 0.4), "down hardens"); + assert_eq!(drag_in_view(0.0, false, 0.0, 77.0), (40.0, 0.4), "down hardens"); assert_eq!(drag_in_view(0.0, true, -30.0, 0.0), (100.0, 0.2), "flipped: screen right grows"); - assert_eq!(drag_in_view(0.0, true, 0.0, 40.0), (40.0, 0.4), "flipped: down hardens"); + assert_eq!(drag_in_view(0.0, true, 0.0, 77.0), (40.0, 0.4), "flipped: down hardens"); // 90° clockwise: document +y points screen-left and document +x screen-down. assert_eq!(drag_in_view(90.0, false, 0.0, 10.0), (20.0, 0.2), "screen-left shrinks, the hardness stays"); assert_eq!(drag_in_view(90.0, false, 0.0, -30.0), (100.0, 0.2), "screen-right grows"); - assert_eq!(drag_in_view(90.0, false, 40.0, 0.0), (40.0, 0.4), "screen-down hardens, the size stays"); + assert_eq!(drag_in_view(90.0, false, 77.0, 0.0), (40.0, 0.4), "screen-down hardens, the size stays"); // 180°: document -x is screen right. assert_eq!(drag_in_view(180.0, false, -30.0, 0.0), (100.0, 0.2), "screen right still grows"); - assert_eq!(drag_in_view(180.0, false, 0.0, -40.0), (40.0, 0.4), "screen down still hardens"); + assert_eq!(drag_in_view(180.0, false, 0.0, -77.0), (40.0, 0.4), "screen down still hardens"); // 90° and flipped: document +y points screen-right. assert_eq!(drag_in_view(90.0, true, 0.0, 30.0), (100.0, 0.2), "rotated and flipped: screen right grows"); } From 4c11894d0a2c7b4b506d836ad7e1a75bd0cf2a07 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 11 Nov 2026 13:38:46 +0100 Subject: [PATCH 2/3] PR #12056: cargo fmt after merging main (lib.rs test modules) --- crates/ui-egui/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0aa01cdae5..077585d2f6 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1055,8 +1055,6 @@ mod menu_item_labels_tests; #[cfg(test)] mod pen_path_ownership_tests; -#[cfg(test)] -mod brush_hud_rate_tests; #[cfg(test)] mod artboard_options_bar_tests; #[cfg(test)] @@ -1064,6 +1062,8 @@ mod background_eraser_bar_angle_tests; #[cfg(test)] mod brush_alt_digit_smoothing_tests; #[cfg(test)] +mod brush_hud_rate_tests; +#[cfg(test)] mod brush_opacity_minimum_tests; #[cfg(test)] mod burn_default_tip_tests; From 7236bb88a66ea93b0ecd6c52a5e7272e696a3888 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 11 Nov 2026 13:49:57 +0100 Subject: [PATCH 3/3] PR #12056: opacity keeps its 200-point HUD rate; Select and Mask test follows the hardness rate With Vary Round Brush Hardness on HUD off, the vertical drag sets the opacity, which now keeps main's rate (200 points for 100 %) while the hardness takes the measured 385. The Select and Mask resize test computes its expected hardness from HARDNESS_TRAVEL. Co-Authored-By: DuBearte Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/select_mask_ui/tests.rs | 5 +++-- crates/ui-egui/src/tools/brush_resize.rs | 8 ++++++-- crates/ui-egui/src/tools/brush_resize/tests.rs | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index e1d320322c..e6e321985a 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -888,7 +888,8 @@ fn alt_right_drag_resizes_the_workspace_brush() { let w = h.state().distort.select_mask.as_ref().unwrap(); let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); assert_eq!(w.brush_size, want, "horizontal motion sets the diameter (zoom {zoom})"); - assert_eq!(w.hardness, 70.0, "upward motion softens the brush, 200 points for 100 %"); + let soft = (100.0 - 60.0 * 100.0 / crate::brush_resize::HARDNESS_TRAVEL).round(); + assert_eq!(w.hardness, soft, "upward motion softens the brush, at the canvas HUD's rate"); assert_eq!((w.quick_size, w.refine_size), (30.0, 30.0), "the other tools keep their sizes"); assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "resizing selected nothing"); assert!(w.resize.is_none(), "the gesture ends with the button"); @@ -904,7 +905,7 @@ fn alt_right_drag_resizes_the_workspace_brush() { pointer_drag(&mut h, over, PointerButton::Primary, Modifiers::CTRL | Modifiers::ALT, vec2(-10.0, 0.0)); let w = h.state().distort.select_mask.as_ref().unwrap(); assert_eq!(w.quick_size, (30.0 - 2.0 * f64::from(10.0 / zoom)).round().max(1.0)); - assert_eq!((w.brush_size, w.hardness), (want, 70.0), "the Brush keeps its size and hardness"); + assert_eq!((w.brush_size, w.hardness), (want, soft), "the Brush keeps its size and hardness"); assert!(w.strokes.is_empty() && w.edits.len() == 1, "resizing Quick Selection selected nothing"); } diff --git a/crates/ui-egui/src/tools/brush_resize.rs b/crates/ui-egui/src/tools/brush_resize.rs index 24596b34d6..075c06b579 100644 --- a/crates/ui-egui/src/tools/brush_resize.rs +++ b/crates/ui-egui/src/tools/brush_resize.rs @@ -22,6 +22,9 @@ use crate::state::Tool; /// Screen points of vertical drag that take the hardness from 0 % to 100 %: Photoshop's rate, /// where 50 points down from 0 % give 13 % (#11891). pub const HARDNESS_TRAVEL: f32 = 385.0; +/// Screen points of vertical drag that take the opacity from 0 % to 100 % when "Vary Round Brush +/// Hardness on HUD" is off: the rate it had before the hardness rate was measured (#11891). +pub const OPACITY_TRAVEL: f32 = 200.0; /// The brush size range (`tools.setBrush` accepts the same). const SIZE: std::ops::RangeInclusive = 1.0..=MAX_BRUSH_SIZE; @@ -123,10 +126,11 @@ fn update(app: &mut PhotocraftApp, r: Resize, x: f64, y: f64) { // No view: document axes, mirrored by View › Flip Horizontal. _ => ((x - r.anchor[0]) * if app.ui.view.flip_horizontal { -1.0 } else { 1.0 }, y - r.anchor[1], app.point_zoom()), }; - let (size, v) = resized(r.start, dx, dy, zoom); // "Vary Round Brush Hardness on HUD" (Preferences ▸ Tools, on by default): off, the vertical - // movement takes the opacity instead of the hardness, as in Photoshop. + // movement takes the opacity instead of the hardness, as in Photoshop, at its own rate. let vary = app.session.prefs().tools.vary_round_brush_hardness_on_hud; + let dy = if vary { dy } else { dy * f64::from(HARDNESS_TRAVEL / OPACITY_TRAVEL) }; + let (size, v) = resized(r.start, dx, dy, zoom); let b = &app.session.tools.brush; if b.size == size && if vary { b.hardness == v } else { b.opacity == v } { return; diff --git a/crates/ui-egui/src/tools/brush_resize/tests.rs b/crates/ui-egui/src/tools/brush_resize/tests.rs index 89cc875cf9..b2e5790b68 100644 --- a/crates/ui-egui/src/tools/brush_resize/tests.rs +++ b/crates/ui-egui/src/tools/brush_resize/tests.rs @@ -297,9 +297,11 @@ fn vary_round_brush_hardness_on_hud_switches_the_vertical_target() { app.run("prefs.set", json!({"path": "tools.varyRoundBrushHardnessOnHud", "value": false})).unwrap(); } let (h0, o0) = (app.session.tools.brush.hardness, app.session.tools.brush.opacity); + // 20 % of each travel: 77 points for the hardness, 40 for the opacity, which keeps its rate. + let y = if vary { 177.0 } else { 140.0 }; tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 100.0, pressure: 1.0 }, CTRL_ALT); - tool_event(&mut app, ToolEvent::Move { x: 100.0, y: 177.0, pressure: 1.0 }, CTRL_ALT); - tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 177.0 }, CTRL_ALT); + tool_event(&mut app, ToolEvent::Move { x: 100.0, y, pressure: 1.0 }, CTRL_ALT); + tool_event(&mut app, ToolEvent::Up { x: 100.0, y }, CTRL_ALT); let b = &app.session.tools.brush; if vary { assert_eq!((b.hardness, b.opacity), (h0 + 0.2, o0), "hardness moves with the drag");