Symbols: Shift with the Symbol Stainer and Styler keeps the instance's other fills

The paint of the topmost fill changes in place, so its blend mode,
effects and the instance's other appearance items stay as they are.
This commit is contained in:
dotCooCoo committed 2026-11-14 18:48:17 -08:00
1 parent f1c08689bf
commit dba9c8066d
2 files changed
+17 -9

No files matched your search

+7 -9
View File
@@ -1260,20 +1260,18 @@ pub(super) fn symbol_adjust(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "count": count }))
}
/// Move the paint of instance `id`'s stain or style (`fill`, with its amount) toward `to` by `t`,
/// keeping the amount. An instance without a stain or style, or one whose paint does not change, is
/// left as it is. Returns whether it changed.
/// Move the paint of instance `id`'s stain or style (`fill`, its topmost fill with the amount)
/// toward `to` by `t`. The fill keeps its amount and everything else it has, and the instance's
/// other appearance items stay as they are. An instance without a stain or style, or one whose
/// paint does not change, is left as it is. Returns whether it changed.
fn recolor_keeping_amount(d: &mut Document, id: NodeId, fill: Option<(Paint, f64)>, to: &Paint, t: f64) -> bool {
let Some((own, amount)) = fill.filter(|(_, o)| *o > 0.0) else { return false };
let Some((own, _)) = fill.filter(|(_, o)| *o > 0.0) else { return false };
let paint = vectorcraft_doc::blend::lerp_paint(&own, to, t.clamp(0.0, 1.0) as f32);
if paint == own {
return false;
}
let Some(n) = d.node_mut(id) else { return false };
n.appearance.items.retain(|i| !matches!(i, AppearanceItem::Fill(_)));
let mut f = FillLayer::new(paint);
f.opacity = (amount as f32).min(1.0);
n.appearance.items.insert(0, AppearanceItem::Fill(f));
let Some(f) = d.node_mut(id).and_then(|n| n.appearance.fill_mut()) else { return false };
f.paint = paint;
true
}
@@ -140,6 +140,15 @@ fn shift_with_the_stainer_keeps_the_amount_and_changes_the_color() {
adjust(&mut s, json!({"tool": "stain", "points": [[100, 150], [100, 150]], "radius": 5, "intensity": 10, "color": "#ff0000"}));
let (red, amount) = fill(&s, a).unwrap();
assert!(amount > 0.2 && red[0] > 0.99 && red[2] < 0.01, "{red:?} {amount}");
// A second fill below the stain, which Shift leaves as it is.
s.edit("Add fill", |d, _| {
let n = d.node_mut(a).unwrap();
let lower = n.appearance.fill().unwrap().clone();
n.appearance.items.insert(0, vectorcraft_doc::AppearanceItem::Fill(vectorcraft_doc::FillLayer { opacity: 0.5, ..lower }));
Ok(())
})
.unwrap();
let lower = node(&s, a).appearance.items[0].clone();
let stain = |s: &mut Session, x: f64| {
adjust(s, json!({"tool": "stain", "points": [[x, 150], [x, 150]], "radius": 5, "intensity": 10, "color": "#0000ff", "shift": true}))
};
@@ -147,6 +156,7 @@ fn shift_with_the_stainer_keeps_the_amount_and_changes_the_color() {
let (color, kept) = fill(&s, a).unwrap();
assert_eq!(kept, amount, "the amount stays");
assert!(color[0] < red[0] && color[2] > 0.01, "toward blue: {color:?}");
assert_eq!((node(&s, a).appearance.items.len(), &node(&s, a).appearance.items[0]), (2, &lower), "the other fill stays");
// More strokes go on toward blue, with the amount still the same.
for _ in 0..30 {
stain(&mut s, 100.0);