Pencil and Blob Brush: Alt smooths with the Smooth tool's Fidelity

When Alt switches the Pencil (with Alt key toggles to Smooth Tool on)
or the Blob Brush to the Smooth tool, the drag sent the drawing tool's
own Fidelity (1.5 by default) to path.smoothRegion. The Smooth tool
sends its own Fidelity (2.5 by default, set in Smooth Tool Options).

Both tools now smooth with the Smooth tool's Fidelity. The engine gives
them the stored Smooth Fidelity when it makes the tool, and again when
Smooth Tool Options changes while one of them is active. Each tool's
own Fidelity still sets how its strokes are fitted.
This commit is contained in:
dotCooCoo
2026-10-30 23:52:26 +07:00
committed by bflatastic
parent 71f566c6aa
commit 7d97c633b7
4 changed files with 86 additions and 4 deletions
+35
View File
@@ -96,3 +96,38 @@ fn options_are_saved_with_the_preferences() {
t.execute("prefs.reset", &json!({})).unwrap();
assert_eq!(t.prefs.tool_settings["polygon"]["sides"], json!(9));
}
/// The Fidelity an Alt smoothing drag uses on a selected path.
fn alt_smooth_fidelity(s: &mut Session) -> Option<f64> {
use vectorcraft_tools::{Action, Mods, PointerEvent, PointerKind};
let mods = Mods { alt: true, ..Default::default() };
let mut last = vec![];
for (kind, x, y) in [(PointerKind::Down, 50.0, 150.0), (PointerKind::Drag, 150.0, 150.0), (PointerKind::Up, 250.0, 160.0)] {
let ev = PointerEvent { mods, ..PointerEvent::new(kind, x, y) };
last = s.with_tool_cx(ViewInfo::default(), |t, cx| t.pointer(cx, &ev));
}
last.iter().find_map(|a| match a {
Action::Exec(c, v) if c == "path.smoothRegion" => v["fidelity"].as_f64(),
_ => None,
})
}
/// Alt switches Pencil and Blob Brush to Smooth, using Smooth Tool Options' stored Fidelity.
#[test]
fn alt_smoothing_takes_the_smooth_tools_fidelity() {
for id in ["pencil", "blobBrush"] {
let mut s = session();
s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap();
select(&mut s, "smooth");
s.set_tool_option("fidelity", &json!(6));
select(&mut s, id);
if id == "pencil" {
s.set_tool_option("altSmooth", &json!(true));
}
s.set_tool_option("fidelity", &json!(3));
assert_eq!(alt_smooth_fidelity(&mut s), Some(6.0), "{id}");
s.set_tool_option_cmd(&json!({"tool": "smooth", "key": "fidelity", "value": 9})).unwrap();
assert_eq!(alt_smooth_fidelity(&mut s), Some(9.0), "{id}");
assert_eq!(s.tool_options()["fidelity"], json!(3.0), "{id}");
}
}
+8 -1
View File
@@ -216,6 +216,12 @@ impl Session {
}
}
}
// Alt switches the Pencil or Blob Brush to Smooth, using Smooth Tool Options' Fidelity.
if matches!(t.id(), "pencil" | "blobBrush")
&& let Some(v) = prefs.tool_settings.get("smooth").and_then(|s| s.get("fidelity"))
{
t.set_option("smoothFidelity", v);
}
}
/// Store the persistent options of `t` in `prefs` (so they are saved with them too).
@@ -623,7 +629,8 @@ impl Session {
/// Set options of tool `id` (default: the active tool). Another tool's persistent options are
/// stored for when it is chosen, and the active tool takes those it shares with it (the
/// Liquify tools' Global Brush Dimensions). Returns the tool's options.
/// Liquify tools' Global Brush Dimensions, the Smooth tool's Fidelity for the Pencil's and
/// Blob Brush's Alt smoothing). Returns the tool's options.
pub fn set_tool_options(&mut self, id: Option<&str>, values: &Map<String, Value>) -> Value {
let active = id.is_none_or(|id| id == self.tool.id());
self.tool_set_since_reset |= active;