From 1e927e61a568732b121861d69ba0ed48e4252ed4 Mon Sep 17 00:00:00 2001 From: Terra854 Date: Wed, 2 Dec 2026 21:00:15 +0800 Subject: [PATCH 1/3] Enable Pencil preset size pressure on first use and reset --- crates/ui-egui/src/canvas/paint_mouse.rs | 6 +- .../tools/pencil_default_pressure_tests.rs | 118 ++++++++++++++++++ crates/ui-egui/src/tools/tool_reset.rs | 4 + 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/tools/pencil_default_pressure_tests.rs diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index 59fbc29aac..6a380183b8 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -173,7 +173,11 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings } Tool::BackgroundEraser => (brush.size, brush.hardness, brush.spacing) = BACKGROUND_ERASER_TIP, Tool::Healing => (brush.size, brush.hardness, brush.spacing) = HEALING_BRUSH_TIP, - Tool::Pencil => (brush.size, brush.hardness, brush.spacing) = PENCIL_TOOL_TIP, + Tool::Pencil => { + (brush.size, brush.hardness, brush.spacing) = PENCIL_TOOL_TIP; + // Its preset follows pen pressure even with both options-bar overrides off (#17764). + crate::bg_eraser_popup::set_size_control(&mut brush, crate::bg_eraser_popup::PEN_PRESSURE); + } Tool::Burn | Tool::Dodge | Tool::Sponge => (brush.size, brush.hardness, brush.spacing) = TONING_TOOL_TIP, Tool::Smudge => (brush.size, brush.hardness, brush.spacing) = SMUDGE_TOOL_TIP, Tool::ColorReplacement => { diff --git a/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs b/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs new file mode 100644 index 0000000000..3760e4f9d8 --- /dev/null +++ b/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs @@ -0,0 +1,118 @@ +//! #17764: Pencil's starting preset controls size, independently of the bar overrides. +//! The very-low-pressure minimum footprint belongs to #17765, not this default change. + +use egui::Modifiers; +use photocraft_engine::paint::{BrushSettings, Control, Dynamic, ShapeDynamics}; +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.sync_views(); + app +} + +fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) { + let ctx = app.ctx().clone(); + crate::menus::invoke(app, &ctx, id, params).unwrap(); +} + +fn assert_defaults(brush: &BrushSettings) { + assert!(brush.shape_dynamics.enabled); + assert_eq!(brush.shape_dynamics.size, Dynamic::controlled(Control::PenPressure)); + assert!(!brush.transfer.enabled); + assert_eq!(brush.transfer.opacity.control, Control::Off); + assert!(!brush.pressure_size && !brush.pressure_opacity); + assert_eq!((brush.size, brush.hardness, brush.spacing), (1.0, 1.0, 0.25)); +} + +#[test] +fn first_use_and_reset_tool_restore_the_pressure_preset_without_bar_overrides() { + let mut app = app(); + // The outgoing tool cannot supply the Pencil's dynamics or toggles. + app.session.tools.brush.pressure_size = true; + app.session.tools.brush.pressure_opacity = true; + app.session.tools.brush.transfer.enabled = true; + app.session.tools.brush.shape_dynamics.size.jitter = 0.8; + invoke(&mut app, "tools.select.pencil", json!({})); + assert_defaults(&app.session.tools.brush); + app.run( + "tools.setBrush", + json!({"brush": { + "shapeDynamics": {"enabled": false, "size": {"control": "off", "jitter": 0.9, "minimum": 0.8}}, + "transfer": {"enabled": true, "opacity": {"control": "penPressure"}}, + "pressureSize": true, "pressureOpacity": true + }}), + ) + .unwrap(); + invoke(&mut app, "tool.reset", json!({})); + assert_defaults(&app.session.tools.brush); +} + +#[test] +fn reset_all_restores_the_saved_pencil_without_changing_other_tools() { + let mut app = app(); + invoke(&mut app, "tools.select.pencil", json!({})); + app.session.tools.brush.shape_dynamics.enabled = false; + invoke(&mut app, "tools.select.brush", json!({})); + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + assert!(!app.session.tools.brush.shape_dynamics.enabled); + invoke(&mut app, "tools.select.pencil", json!({})); + assert_defaults(&app.session.tools.brush); + + let current = BrushSettings::default(); + for tool in Tool::ALL.iter().copied().filter(|tool| !matches!(tool, Tool::Pencil | Tool::ColorReplacement)) { + let brush = crate::paint_mouse::fresh_brush(tool, ¤t); + assert_eq!(brush.shape_dynamics, ShapeDynamics::default(), "{tool:?}"); + assert_eq!(brush.transfer, current.transfer, "{tool:?}"); + assert!(!brush.pressure_size && !brush.pressure_opacity, "{tool:?}"); + } +} + +fn prepare_stroke(app: &mut PhotocraftApp) { + invoke(app, "tools.select.pencil", json!({})); + invoke(app, "tool.reset", json!({})); + app.run("tools.setBrush", json!({"brush": {"size": 41, "smoothing": {"amount": 0.0}}})).unwrap(); +} + +fn opaque_width(app: &PhotocraftApp) -> usize { + let state = app.session.active().unwrap(); + let surface = state.doc.layer(state.active_layer.unwrap()).unwrap().surface().unwrap(); + (0..100) + .filter(|&y| { + let alpha = surface.rgba(100, y)[3]; + assert!(alpha == 0.0 || alpha == 1.0, "Pencil stays opaque: {alpha}"); + alpha > 0.0 + }) + .count() +} + +#[test] +fn reset_pencil_draws_half_and_full_pressure_widths_through_the_actual_tool_path() { + for (pressure, allowed) in [(0.5, 20..=22), (1.0, 41..=41)] { + let mut app = app(); + prepare_stroke(&mut app); + tool_event(&mut app, ToolEvent::Down { x: 30.0, y: 50.0, pressure }, Modifiers::NONE); + for x in (40..=170).step_by(10) { + tool_event(&mut app, ToolEvent::Move { x: f64::from(x), y: 50.0, pressure }, Modifiers::NONE); + } + tool_event(&mut app, ToolEvent::Up { x: 170.0, y: 50.0 }, Modifiers::NONE); + assert!(!app.ui.status_error, "{}", app.ui.status); + let width = opaque_width(&app); + assert!(allowed.contains(&width), "pressure={pressure}, width={width}"); + } +} + +#[test] +fn no_pressure_mouse_points_keep_the_full_nominal_width() { + let mut app = app(); + prepare_stroke(&mut app); + // Omitted pressure is the command's real no-pen path, not a fake zero-pressure pen. + app.run("paint.pencil", json!({"points": [[30, 50], [170, 50]]})).unwrap(); + assert_eq!(opaque_width(&app), 41); +} diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 497315af60..705579a9e8 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -499,3 +499,7 @@ mod bg_eraser_reset_pressure_tests; #[cfg(test)] #[path = "zoom_reset_all_keeps_mode_tests.rs"] mod zoom_reset_all_keeps_mode_tests; + +#[cfg(test)] +#[path = "pencil_default_pressure_tests.rs"] +mod pencil_default_pressure_tests; From ced0778a2246b1592db7df17751661844417d495 Mon Sep 17 00:00:00 2001 From: Terra854 Date: Wed, 2 Dec 2026 21:38:50 +0800 Subject: [PATCH 2/3] Isolate Pencil toolbar pressure regression from preset control --- crates/ui-egui/src/pencil_pressure_toggles_tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/pencil_pressure_toggles_tests.rs b/crates/ui-egui/src/pencil_pressure_toggles_tests.rs index b2b0c55b1e..e2e0a04db1 100644 --- a/crates/ui-egui/src/pencil_pressure_toggles_tests.rs +++ b/crates/ui-egui/src/pencil_pressure_toggles_tests.rs @@ -119,7 +119,12 @@ fn pressure_for_size_narrows_a_low_pressure_pencil_stroke() { let mut h = bar(AppTheme::pro_medium()); let app = h.state_mut(); app.run("layer.new.layer", json!({})).unwrap(); - app.run("tools.setBrush", json!({"brush": {"size": 13.0, "pressureSize": true, "smoothing": {"amount": 0.0}}})).unwrap(); + // Isolate the bar override: the Pencil preset also controls size by pressure after #17764. + app.run( + "tools.setBrush", + json!({"brush": {"size": 13.0, "pressureSize": true, "shapeDynamics": {"size": {"control": "off"}}, "smoothing": {"amount": 0.0}}}), + ) + .unwrap(); app.run("paint.pencil", json!({"points": [[20.0, 50.0, 0.2], [30.0, 50.0, 0.2], [60.0, 50.0, 1.0]]})).unwrap(); let (low, high) = (width(app, 22, 50), width(app, 58, 50)); assert!(low < high, "pressure for size on: low-pressure {low} px, high-pressure {high} px"); From facfd0ace5091f6da39a7d4dfd3f83933ba5df53 Mon Sep 17 00:00:00 2001 From: Terra854 Date: Wed, 2 Dec 2026 22:22:35 +0800 Subject: [PATCH 3/3] Keep Pencil default guard independent of sibling presets --- crates/ui-egui/src/tools/pencil_default_pressure_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs b/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs index 3760e4f9d8..64f854a649 100644 --- a/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs +++ b/crates/ui-egui/src/tools/pencil_default_pressure_tests.rs @@ -66,7 +66,7 @@ fn reset_all_restores_the_saved_pencil_without_changing_other_tools() { assert_defaults(&app.session.tools.brush); let current = BrushSettings::default(); - for tool in Tool::ALL.iter().copied().filter(|tool| !matches!(tool, Tool::Pencil | Tool::ColorReplacement)) { + for tool in [Tool::BackgroundEraser, Tool::Healing, Tool::CloneStamp] { let brush = crate::paint_mouse::fresh_brush(tool, ¤t); assert_eq!(brush.shape_dynamics, ShapeDynamics::default(), "{tool:?}"); assert_eq!(brush.transfer, current.transfer, "{tool:?}");