Pencil: Alt key toggles to Smooth Tool starts off, as Pencil Tool Options ships it (#2685)

This commit is contained in:
bflatastic
2026-10-20 01:19:14 +07:00
parent de985a46e6
commit 303c5f8bca
2 changed files with 28 additions and 13 deletions
+13 -9
View File
@@ -79,7 +79,8 @@ impl GestureTool {
size: 10.0,
fill: false,
keep_selected: id != "blobBrush",
alt_smooth: id == "pencil",
// Off, as Pencil Tool Options ships it: Alt keeps drawing a closed path until it is on.
alt_smooth: false,
smoothing: false,
merge_only_selection: false,
edit_within: 12.0,
@@ -190,10 +191,7 @@ impl GestureTool {
let tol = cx.tol(self.edit_within);
if self.smoothing {
if has_sel && pts.len() >= 2 {
return vec![Action::Exec(
"path.smoothRegion".into(),
json!({"points": points_json(pts), "radius": tol, "fidelity": self.fidelity}),
)];
return vec![Action::Exec("path.smoothRegion".into(), json!({"points": points_json(pts), "radius": tol, "fidelity": self.fidelity}))];
}
return vec![];
}
@@ -248,7 +246,11 @@ impl Tool for GestureTool {
self.extend = if self.draws_path() && !self.smoothing { self.find_extend(cx, p) } else { None };
self.redraw = if self.draws_path() && !self.smoothing && self.extend.is_none() { self.find_redraw(cx, p) } else { None };
// A path continued starts at its end, one redrawn on it; a new one where it snaps.
let start = if self.snaps() && !self.smoothing && self.extend.is_none() && self.redraw.is_none() { self.snap.press(cx, p, &[], None) } else { p };
let start = if self.snaps() && !self.smoothing && self.extend.is_none() && self.redraw.is_none() {
self.snap.press(cx, p, &[], None)
} else {
p
};
self.clear();
self.push(start, ev.pressure);
vec![]
@@ -287,7 +289,8 @@ impl Tool for GestureTool {
self.snap.clear();
if self.points.last().is_some_and(|l| l.distance(p) >= cx.tol(1.0)) {
self.push(end, ev.pressure);
} else if self.snaps() && !self.smoothing
} else if self.snaps()
&& !self.smoothing
&& self.points.len() > 1
&& let Some(last) = self.points.last_mut()
{
@@ -595,9 +598,10 @@ mod tests {
let p = paint();
let cx = cx(&d, &s, &p);
// Pencil has alt_smooth on by default.
// Off by default, as Pencil Tool Options ships it; on, Alt lends the Smooth tool.
let mut t = GestureTool::new("pencil");
assert_eq!(t.options()["altSmooth"], json!(true));
assert_eq!(t.options()["altSmooth"], json!(false));
t.set_option("altSmooth", &json!(true));
// When alt is pressed, cursor shows smooth tool.
let alt_mod = Mods { alt: true, ..Default::default() };
+15 -4
View File
@@ -164,8 +164,13 @@ mod tests {
}
assert!(!text.contains("Size:"), "{text}");
let d = app.ui.dialog.as_mut().unwrap();
assert_eq!((d.f64("fidelity", 0.0), d.bool("fill"), d.bool("altSmooth"), d.f64("closeWithin", 0.0), d.f64("editWithin", 0.0)), (1.5, false, true, 15.0, 12.0));
for (k, v) in [("fidelity", json!(6.5)), ("fill", json!(true)), ("altSmooth", json!(false)), ("closeWithin", json!(0)), ("editWithin", json!(20))] {
assert_eq!(
(d.f64("fidelity", 0.0), d.bool("fill"), d.bool("altSmooth"), d.f64("closeWithin", 0.0), d.f64("editWithin", 0.0)),
(1.5, false, false, 15.0, 12.0)
);
for (k, v) in
[("fidelity", json!(6.5)), ("fill", json!(true)), ("altSmooth", json!(true)), ("closeWithin", json!(0)), ("editWithin", json!(20))]
{
d.fields.insert(k.into(), v);
}
super::super::confirm(&mut app).unwrap();
@@ -173,7 +178,7 @@ mod tests {
let o = app.session.tool_options_of("pencil");
assert_eq!(
(o["fidelity"].as_f64(), o["fill"].as_bool(), o["altSmooth"].as_bool(), o["closeWithin"].as_f64(), o["editWithin"].as_f64()),
(Some(6.5), Some(true), Some(false), Some(0.0), Some(20.0))
(Some(6.5), Some(true), Some(true), Some(0.0), Some(20.0))
);
// The Paintbrush keeps its own: the Pencil's change left it alone.
app.run("tool.options", json!({"tool": "paintbrush"})).unwrap();
@@ -186,7 +191,13 @@ mod tests {
app.run("tool.options", json!({"tool": "smooth"})).unwrap();
let text = painted(&mut app);
assert!(text.contains("Smooth Tool Options") && text.contains("Fidelity:"), "{text}");
assert!(!text.contains("Fill new strokes") && !text.contains("Keep selected") && !text.contains("Alt key toggles to Smooth Tool") && !text.contains("Size:"), "{text}");
assert!(
!text.contains("Fill new strokes")
&& !text.contains("Keep selected")
&& !text.contains("Alt key toggles to Smooth Tool")
&& !text.contains("Size:"),
"{text}"
);
for tool in ["blobBrush", "eraser"] {
app.run("tool.options", json!({"tool": tool})).unwrap();
let text = painted(&mut app);