Merge pull request #19152

Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
davidmann4andautocraft-bot[bot] authored and autocraft-bot[bot] committed 2026-12-02 22:19:56 +00:00
commit 1e2eabbe33
4 files changed
+133 -2

No files matched your search

+5 -1
View File
@@ -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 => {
@@ -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");
@@ -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<PhotocraftApp> {
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::BackgroundEraser, Tool::Healing, Tool::CloneStamp] {
let brush = crate::paint_mouse::fresh_brush(tool, &current);
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);
}
+4
View File
@@ -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;