diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index 56f955106b..74a10d337f 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -855,7 +855,7 @@ pub(crate) use object::bounds_rewrite; pub(crate) use object::{keep_aligned_in, refresh_pixel_aligned}; /// The rules `object.scale`, `object.reflect` and `object.shear` check their params with. pub use object::{reflect_axis, scale_factors, shear_tangent}; -pub(crate) use paint::{LIVE_PAINT_BUCKET, asks_defaults_only}; +pub(crate) use paint::{asks_defaults_only, painting_tool_of}; pub use plugin_call::{Location, ParamsPlace, key_location, location_in, location_keys}; pub use select::SIMILAR; pub(crate) use vectorcraft_doc::range::parse_range; diff --git a/crates/engine/src/cmd/freeform.rs b/crates/engine/src/cmd/freeform.rs index 548e5fade2..e31c21dd00 100644 --- a/crates/engine/src/cmd/freeform.rs +++ b/crates/engine/src/cmd/freeform.rs @@ -19,7 +19,7 @@ pub fn specs() -> Vec { "Add Freeform Point", [], None, - "{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its points); the points on a label's characters are not stored; an error while the proxies show the Live Paint Bucket's colors and no ids, id or item are given → {index}", + "{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its points); the points on a label's characters are not stored; an error while the proxy shows the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) and no ids, id or item are given → {index}", has_doc, add_point ), @@ -28,7 +28,7 @@ pub fn specs() -> Vec { "Edit Freeform Point", [], None, - "{index? (default: the selected point), at?: [x,y] (document coordinates), color? (#rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} move or recolour a point of the freeform gradient; an error while the proxies show the Live Paint Bucket's colors and no ids, id or item are given → {index}", + "{index? (default: the selected point), at?: [x,y] (document coordinates), color? (#rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} move or recolour a point of the freeform gradient; an error while the proxy shows the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) and no ids, id or item are given → {index}", has_doc, set_point ), @@ -37,7 +37,7 @@ pub fn specs() -> Vec { "Delete Freeform Point", [], None, - "{index? (default: the selected point), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} remove a point (never the last one); lines through it close up around it and lines left with one point go; an error while the proxies show the Live Paint Bucket's colors and no ids, id or item are given → {index}", + "{index? (default: the selected point), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} remove a point (never the last one); lines through it close up around it and lines left with one point go; an error while the proxy shows the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) and no ids, id or item are given → {index}", has_doc, delete_point ), @@ -46,7 +46,7 @@ pub fn specs() -> Vec { "Add Freeform Line", [], None, - "{points: [index, …] (at least two), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} join points with a smooth line through them, in order; an error while the proxies show the Live Paint Bucket's colors and no ids, id or item are given → {line}", + "{points: [index, …] (at least two), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} join points with a smooth line through them, in order; an error while the proxy shows the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) and no ids, id or item are given → {line}", has_doc, add_line ), @@ -55,7 +55,7 @@ pub fn specs() -> Vec { "Split Freeform Line", [], None, - "{line: line index, segment: the segment from the line's point `segment` to the next, t?: 0..1 along it (default 0.5), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point on a line there (colour, opacity and spread between the segment's ends) and select it; an error while the proxies show the Live Paint Bucket's colors and no ids, id or item are given → {index}", + "{line: line index, segment: the segment from the line's point `segment` to the next, t?: 0..1 along it (default 0.5), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind; without one, a Live Paint group's faces take a fill edit and its edges take a stroke edit), aligned?: bool (as paint.editGradient), target?: \"object\"|\"contents\"} add a point on a line there (colour, opacity and spread between the segment's ends) and select it; an error while the proxy shows the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) and no ids, id or item are given → {index}", has_doc, split_line ), @@ -64,7 +64,7 @@ pub fn specs() -> Vec { "Select Freeform Point", [], None, - "{index: point index | null to clear} select a point of the freeform gradient behind the active proxy (the first selected object's; an index is an error while the proxies show the Live Paint Bucket's colors): the point the Gradient tool, the Gradient and Color panels and Delete act on → {index}", + "{index: point index | null to clear} select a point of the freeform gradient behind the active proxy (the first selected object's; an index is an error while the proxy shows the colors the active tool paints with: the Live Paint Bucket's, the Shape Builder's fill): the point the Gradient tool, the Gradient and Color panels and Delete act on → {index}", has_doc, select_point ), @@ -73,7 +73,7 @@ pub fn specs() -> Vec { "Freeform Gradient", [], None, - "{stroke?: bool (default: the active proxy)} the freeform gradient behind the proxy of the first selected object (an error while the proxies show the Live Paint Bucket's colors) → {mode: points|lines, points: [{at: [x,y] (document coordinates), color, opacity, spread}], lines: [[index, …]], selected: index|null}", + "{stroke?: bool (default: the active proxy)} the freeform gradient behind the proxy of the first selected object (an error while the proxy shows the colors the active tool paints with: the Live Paint Bucket's, the Shape Builder's fill) → {mode: points|lines, points: [{at: [x,y] (document coordinates), color, opacity, spread}], lines: [[index, …]], selected: index|null}", has_doc, get ), @@ -81,13 +81,21 @@ pub fn specs() -> Vec { } const NOT_FREEFORM: &str = "the paint is not a freeform gradient (apply one with paint.editGradient {kind: \"freeform\"})"; -const BUCKET_NOT_FREEFORM: &str = "the Live Paint Bucket's colors have no freeform points (give ids, id or item to edit an object's)"; -const BUCKET_NO_POINTS: &str = "the Live Paint Bucket's colors have no freeform points"; + +/// " have no freeform points" for the tool whose colors the fill (or stroke, `stroke`) +/// proxy shows ([`Session::painting_tool`]): the Live Paint Bucket's colors, the Shape Builder's +/// fill. None when the proxy shows the selection's paint. +fn tool_no_points(s: &Session, stroke: bool) -> Option<&'static str> { + s.painting_tool(stroke).map(|id| match id { + "shapeBuilder" => "the Shape Builder's fill has no freeform points", + _ => "the Live Paint Bucket's colors have no freeform points", + }) +} /// The error of `paint.freeform.get` and `paint.freeform.selectPoint` when the active proxy shows no freeform gradient: -/// while the Live Paint Bucket paints, the proxies show its colors, which have none. -fn no_proxy_freeform(s: &Session) -> &'static str { - if s.bucket_paints() { BUCKET_NO_POINTS } else { NOT_FREEFORM } +/// while the active tool paints with the chosen colors of that kind, the proxy shows them, which have none. +fn no_proxy_freeform(s: &Session, stroke: bool) -> &'static str { + tool_no_points(s, stroke).unwrap_or(NOT_FREEFORM) } impl Session { @@ -187,13 +195,16 @@ pub(crate) fn parse_mode(m: &str) -> std::result::Result { /// as one undo step; returns what it returned for the first. An unplaced gradient gets the /// automatic points it shows first, and the stops follow the points' colours. fn edit(s: &mut Session, p: &Value, cmd: &str, mut f: impl FnMut(&mut Freeform, Space) -> std::result::Result) -> Result { - // While the Live Paint Bucket paints, the proxies show its colors, which have no freeform points - // (paint.freeform.get finds none): an edit that names no target is refused. A bad `aligned` or - // `target` is refused first, as it is without the bucket. - if super::paint::for_bucket(s, p) { + // While the active tool paints with the chosen colors (the Live Paint Bucket's, the Shape + // Builder's fill), the proxy shows them, and they have no freeform points (paint.freeform.get + // finds none): an edit that names no target is refused. A bad `aligned`, `target` or `stroke` + // is refused first, as it is otherwise. + let kind = super::paint::tool_gradient_kind(s, p, cmd)?; + if super::paint::for_tool(s, p, kind) { super::appearance::aligned(p, cmd)?; super::appearance::targets_contents(p)?; - return Err(bad(cmd, BUCKET_NOT_FREEFORM)); + let none = tool_no_points(s, kind).unwrap_or(NOT_FREEFORM); + return Err(bad(cmd, format!("{none} (give ids, id or item to edit an object's)"))); } let item = item_target(s, p, cmd)?; let stroke = edits_stroke(s, p, item, !s.fill_active, cmd)?; @@ -347,7 +358,7 @@ fn select_point(s: &mut Session, p: &Value) -> Result { Some(Value::Null) => None, Some(v) => { let i = v.as_u64().map(index).ok_or_else(|| bad(C, "`index` must be a whole number or null"))?; - let (f, _) = s.proxy_freeform(!s.fill_active).ok_or_else(|| bad(C, no_proxy_freeform(s)))?; + let (f, _) = s.proxy_freeform(!s.fill_active).ok_or_else(|| bad(C, no_proxy_freeform(s, !s.fill_active)))?; check_index(&f, i).map_err(|e| bad(C, e))?; Some(i) } @@ -359,7 +370,7 @@ fn select_point(s: &mut Session, p: &Value) -> Result { fn get(s: &mut Session, p: &Value) -> Result { const C: &str = "paint.freeform.get"; let stroke = switch_or(p, "stroke", !s.fill_active, C)?; - let (f, _) = s.proxy_freeform(stroke).ok_or_else(|| bad(C, no_proxy_freeform(s)))?; + let (f, _) = s.proxy_freeform(stroke).ok_or_else(|| bad(C, no_proxy_freeform(s, stroke)))?; let selected = if stroke != s.fill_active { s.selected_freeform_point().filter(|i| *i < f.points.len()) } else { None }; let mut v = vectorcraft_tools::params::freeform_json(&f); v["selected"] = json!(selected); diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 2b14fdba2d..1178906459 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -24,7 +24,7 @@ pub fn specs() -> Vec { "Gradient", ["Window", "Gradient"], None, - "{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds; an error when no object is edited, as with nothing selected, the Live Paint Bucket's gradient, or a fill edit of a Live Paint group without faces: the default gradient fits each new object and keeps no aspect), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, defaultsOnly?: bool (as paint.setFill), strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. Without `item`, a Live Paint group's faces take a fill edit and its edges take a stroke edit. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes (the paint the bucket paints with)", + "{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds; an error when no object is edited, as with nothing selected, the Live Paint Bucket's gradient, the Shape Builder's fill, or a fill edit of a Live Paint group without faces: the default gradient fits each new object and keeps no aspect), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, defaultsOnly?: bool (as paint.setFill), strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. Without `item`, a Live Paint group's faces take a fill edit and its edges take a stroke edit. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes (the paint the tool paints with)", has_doc, edit_gradient ), @@ -42,7 +42,7 @@ pub fn specs() -> Vec { "Select Gradient Stop", [], None, - "{index: stop index (0 = the start) | null to clear} select a stop of the gradient behind the active proxy (the first selected object's, else the default paint; the default paint's while the Live Paint Bucket is the active tool): the stop the Gradient tool's annotator, the Gradient and Color panels and Delete/arrow keys act on; refused while an object of a symbol instance's art is selected, except while the Live Paint Bucket is the active tool → {index}", + "{index: stop index (0 = the start) | null to clear} select a stop of the gradient behind the active proxy (the first selected object's, else the default paint; the default paint's while the Live Paint Bucket, or with the Fill proxy in front the Shape Builder, is the active tool): the stop the Gradient tool's annotator, the Gradient and Color panels and Delete/arrow keys act on; refused while an object of a symbol instance's art is selected, except while the proxy in front shows the default paint that way → {index}", always, select_stop ), @@ -61,9 +61,9 @@ pub(crate) fn active_gradient(s: &Session) -> Option { fn select_stop(s: &mut Session, p: &Value) -> Result { const C: &str = "gradient.selectStop"; // No document is needed for the default paint's gradient, so this does not use `refuse_symbol_part`. - // While the Live Paint Bucket is active the proxies show the default paint, whose stops can be - // selected with a part picked. - if !s.bucket_paints() && s.active().is_some_and(|st| st.selection.symbol_part.is_some()) { + // While the Live Paint Bucket is active the proxies show the default paint (the Shape Builder's + // Fill proxy does too), whose stops can be selected with a part picked. + if !s.tool_paints(!s.fill_active) && s.active().is_some_and(|st| st.selection.symbol_part.is_some()) { return Err(super::brushsym::part_only()); } let index = match p.get("index") { @@ -84,10 +84,10 @@ fn select_stop(s: &mut Session, p: &Value) -> Result { /// Whose gradient a selected stop belongs to: the active document, its first selected object /// (None: the default paint), whether a part of a symbol instance's art is picked, the proxy in -/// front, the Appearance panel's active item and whether the Live Paint Bucket is the active tool -/// (its proxies show the default paint). Selecting other art, picking a part of the instance, -/// toggling the proxy, picking another item or choosing the bucket or leaving it leaves no stop -/// selected. +/// front, the Appearance panel's active item and the tool the proxy in front shows the default +/// paint for (the Live Paint Bucket, or the Shape Builder's Fill proxy). Selecting other art, +/// picking a part of the instance, toggling the proxy, picking another item or choosing such a +/// tool or leaving it leaves no stop selected. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct StopOwner { doc: Option, @@ -98,7 +98,8 @@ pub(crate) struct StopOwner { part: bool, fill: bool, item: Option, - bucket: bool, + /// The tool whose color the proxy in front stood for ([`Session::painting_tool`]). + painter: Option<&'static str>, } impl StopOwner { @@ -111,19 +112,24 @@ impl StopOwner { part: st.is_some_and(|d| d.selection.symbol_part.is_some()), fill: s.fill_active, item: s.appearance_item(), - bucket: s.bucket_paints(), + painter: s.painting_tool(!s.fill_active), } } + + /// The tool whose gradient the stop is on; None for the selection's paint. + pub(crate) fn painter(&self) -> Option<&'static str> { + self.painter + } } impl Session { /// Does `paint.editGradient` without `ids` edit objects on the fill (or the stroke, `stroke`)? It does not - /// while the Live Paint Bucket is active or when nothing it can paint is selected (a Live Paint group stands - /// only for its faces in a fill edit and its edges in a stroke edit): it then edits no object and takes no - /// `aspect`. + /// while the active tool paints with the chosen fill (or stroke: [`Session::tool_paints`]) or when nothing it + /// can paint is selected (a Live Paint group stands only for its faces in a fill edit and its edges in a stroke + /// edit): it then edits no object and takes no `aspect`. pub fn gradient_edit_has_objects(&self, stroke: bool) -> bool { let p = json!({ "stroke": stroke }); - !super::paint::for_bucket(self, &p) + !super::paint::for_tool(self, &p, stroke) && item_target(self, &p, "paint.editGradient") .is_ok_and(|item| item.of_kind(self, !stroke).targets_for(self, &p, !stroke).is_ok_and(|ids| !ids.is_empty())) } @@ -526,9 +532,10 @@ fn apply_gradient_edit_in_model( if let Some(b) = bounds { gp.seed_freeform(b, if switched { inside } else { &|_| true }); } + // Without points (the default gradient's, placed on no object yet) the stops are the colors. if recolor && !switched - && let Some(f) = &mut gp.freeform + && let Some(f) = gp.freeform.as_mut().filter(|f| !f.points.is_empty()) { f.recolor(&gp.gradient); gp.gradient.stops = f.stops(); @@ -546,9 +553,10 @@ fn apply_gradient_edit_in_model( fn edit_gradient(s: &mut Session, p: &Value) -> Result { const C: &str = "paint.editGradient"; - // While the Live Paint Bucket is active, the gradient it paints with changes; the selection keeps its own. - let bucket = super::paint::bucket_color_params(s, p, C)?; - let p = bucket.as_ref().unwrap_or(p); + // While the active tool paints with the chosen fill or stroke, the gradient it paints with changes; the + // selection keeps its own. + let for_tool = super::paint::tool_gradient_params(s, p, C)?; + let p = for_tool.as_ref().unwrap_or(p); let item = item_target(s, p, C)?; let stroke = edits_stroke(s, p, item, !s.fill_active, C)?; check_switches(p, &["reverse", "dither"], C)?; @@ -649,7 +657,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { })?; if let Some(m) = mode && !selected - && (bucket.is_some() || p.get("ids").is_none()) + && (for_tool.is_some() || p.get("ids").is_none()) && let Some(st) = s.new_art_stroke_mut() { st.gradient_mode = m; diff --git a/crates/engine/src/cmd/gradpresets.rs b/crates/engine/src/cmd/gradpresets.rs index 89deda43ad..9b429beaa2 100644 --- a/crates/engine/src/cmd/gradpresets.rs +++ b/crates/engine/src/cmd/gradpresets.rs @@ -33,7 +33,7 @@ pub fn specs() -> Vec { "Apply Gradient Preset", [], None, - "{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, defaultsOnly?, target? (as paint.editGradient)} give the gradient behind the active proxy (or the targeted fill or stroke) the preset's type, stops, method, spread and repeats (a freeform preset's: the first three), and a fill its dither, keeping its placement; a solid or no paint becomes the gradient. One undo step, as paint.editGradient (while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes, by the active proxy) → {name, ids: the objects painted (none: only the default changed)}", + "{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, defaultsOnly?, target? (as paint.editGradient)} give the gradient behind the active proxy (or the targeted fill or stroke) the preset's type, stops, method, spread and repeats (a freeform preset's: the first three), and a fill its dither, keeping its placement; a solid or no paint becomes the gradient. One undo step, as paint.editGradient (while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes, by the active proxy) → {name, ids: the objects painted (none: only the default changed)}", has_doc, apply ), @@ -207,10 +207,10 @@ fn apply(s: &mut Session, p: &Value) -> Result { const C: &str = "gradient.presets.apply"; let name = name_param(p, C)?; let preset = s.gradient_preset(name).ok_or_else(|| bad(C, format!("no gradient preset `{name}` (see gradient.presets.list)")))?; - // While the Live Paint Bucket is active, the gradient it paints with changes, chosen by the - // active proxy rather than the selection's Appearance row (as paint.editGradient chooses). - let bucket = super::paint::bucket_color_params(s, p, C)?; - let p = bucket.as_ref().unwrap_or(p); + // While the active tool paints with the chosen fill or stroke, the gradient it paints with + // changes (as paint.editGradient chooses). + let for_tool = super::paint::tool_gradient_params(s, p, C)?; + let p = for_tool.as_ref().unwrap_or(p); let stroke = edits_stroke(s, p, item_target(s, p, C)?, !s.fill_active, C)?; let g = &preset.gradient; let mut edit = p.clone(); diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rs index 80c4cbefb9..4f92220324 100644 --- a/crates/engine/src/cmd/library.rs +++ b/crates/engine/src/cmd/library.rs @@ -1247,7 +1247,7 @@ fn use_item(s: &mut Session, p: &Value) -> Result { } Kind::FillColor | Kind::StrokeColor => { let stroke = to_stroke(p, kind)?; - let only = super::paint::defaults_only(s, p, C)?; + let only = super::paint::defaults_only(s, p, C, stroke)?; let color = data.get("color").cloned().ok_or_else(|| bad(C, "no colour"))?; let set = if stroke { "paint.setStroke" } else { "paint.setFill" }; match str_param(&data, "spot").map(str::trim).filter(|n| !n.is_empty()) { @@ -1260,7 +1260,7 @@ fn use_item(s: &mut Session, p: &Value) -> Result { } Kind::FillGradient | Kind::StrokeGradient => { let stroke = to_stroke(p, kind)?; - let only = super::paint::defaults_only(s, p, C)?; + let only = super::paint::defaults_only(s, p, C, stroke)?; let damaged = || bad(C, "the library item is damaged"); let mut g: GradientPaint = data.get("gradient").cloned().and_then(|v| serde_json::from_value(v).ok()).ok_or_else(damaged)?; if !clean_gradient(&mut g) { @@ -1275,7 +1275,7 @@ fn use_item(s: &mut Session, p: &Value) -> Result { } Kind::FillPattern | Kind::StrokePattern => { let stroke = to_stroke(p, kind)?; - let only = super::paint::defaults_only(s, p, C)?; + let only = super::paint::defaults_only(s, p, C, stroke)?; let pattern = use_pattern(s, &data, stroke, only)?; Ok(json!({ "kind": if stroke { "strokePattern" } else { "fillPattern" }, "pattern": pattern })) } diff --git a/crates/engine/src/cmd/newart.rs b/crates/engine/src/cmd/newart.rs index b95134aa59..ffea03187d 100644 --- a/crates/engine/src/cmd/newart.rs +++ b/crates/engine/src/cmd/newart.rs @@ -224,9 +224,11 @@ impl Session { /// the first selected object (so the last selection's once nothing is selected). Not while the /// Live Paint Bucket is the active tool: the fill and stroke are the colors it paints with. Nor /// after a command that changed only them (`defaultsOnly`), unless a later step of a batch - /// changed what new art would take ([`Session::new_art_source`]). + /// changed what new art would take ([`Session::new_art_source`]). While the Shape Builder is + /// active, the fill it paints with stays ([`Session::tool_paints`]). pub(crate) fn inherit_new_art(&mut self) { - if self.prefs.new_art_basic || self.bucket_paints() { + let (fill, stroke) = (self.tool_paints(false), self.tool_paints(true)); + if self.prefs.new_art_basic || (fill && stroke) { return; } let Some(source) = self.new_art_source() else { return }; @@ -234,7 +236,20 @@ impl Session { return; } let NewArtSource { appearance, opacity, blend, style, .. } = source; + let kept_fill = fill.then(|| self.paint.fill.clone()); + let kept_stroke = stroke.then(|| (self.paint.stroke.clone(), self.paint.stroke_width)); self.take_new_art(appearance, opacity, blend, style, true); + let p = &mut self.paint; + // New art whose kept paint differs from the selection's is not linked to its graphic style. + if kept_fill.as_ref().is_some_and(|f| *f != p.fill) || kept_stroke.as_ref().is_some_and(|(s, w)| *s != p.stroke || *w != p.stroke_width) { + p.style = None; + } + if let Some(f) = kept_fill { + p.fill = f; + } + if let Some((s, w)) = kept_stroke { + (p.stroke, p.stroke_width) = (s, w); + } } /// What [`Session::inherit_new_art`] gives new art: the appearance of the active document's @@ -275,13 +290,14 @@ impl Session { let (fill, stroke) = self.proxy_paints(); let weight_mixed = read.as_ref().map_or_else(|| self.active().is_some_and(|st| st.stroke_mixed().weight), |p| p.weight_mixed); let weight = self.shown_stroke().filter(|st| st.paint != Paint::None && !weight_mixed).map(|st| st.width); - if !fill_mixed { + // A proxy that shows the color the active tool paints with (the Shape Builder's fill) keeps it. + if !fill_mixed && !self.tool_paints(false) { self.paint.fill = unplaced(&fill); } - if !stroke_mixed { + if !stroke_mixed && !self.tool_paints(true) { self.paint.stroke = unplaced(&stroke); } - if let Some(width) = weight { + if let Some(width) = weight.filter(|_| !self.tool_paints(true)) { self.paint.stroke_width = width; } } diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index b09bc04d4b..25ca3a60ca 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -20,6 +20,21 @@ use crate::{DocState, EngineError}; /// object in particular is the color it paints with ([`apply_paint`]). pub(crate) const LIVE_PAINT_BUCKET: &str = "livePaintBucket"; +/// The Shape Builder's tool id. While it is active, a fill chosen for no object in particular is +/// the current fill only, which merges fill with when Pick Color From is Color Swatches; a stroke +/// chosen then still paints the selection. +const SHAPE_BUILDER: &str = "shapeBuilder"; + +/// Tool `id`'s id when it paints with the fill (or the stroke, `stroke`) chosen while it is +/// active: the Live Paint Bucket with both, the Shape Builder with the fill. +pub(crate) fn painting_tool_of(id: &str, stroke: bool) -> Option<&'static str> { + match id { + LIVE_PAINT_BUCKET => Some(LIVE_PAINT_BUCKET), + SHAPE_BUILDER if !stroke => Some(SHAPE_BUILDER), + _ => None, + } +} + pub fn specs() -> Vec { vec![ cmd!( @@ -27,7 +42,7 @@ pub fn specs() -> Vec { "Fill", [], None, - "{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), opacity?: 0..100 (a percentage, as transparency.set's; the opacity of that fill item on each target, in the undo step of the paint, or alone without color, none, swatch or gradient, when it changes neither the defaults nor the recent colors (with New Art Has Basic Appearance off, the next shape copies the first selected object's appearance after any command, its opacity included); with no paint or a solid color, the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso take it themselves, and with another paint the fill item takes it; with no paint, a target without that fill item is left as it is (a paint given with the opacity creates the item, which then takes it, except for the color a grayscale or 1-bit image is drawn in, which creates none), and an opacity that no target takes is an error that also leaves the paint undone; type characters have no opacity of their own, so an opacity that only characters would take is an error, and so are one with nothing selected and no ids and one for an object selected in a symbol instance), ids?|id?, defaultsOnly?: bool, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no ids, id or item are given), the paint goes to those characters only; without `item`, a Live Paint group among the targets (or inside one) takes the fill on its faces only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes (the color the bucket paints with) and the selection keeps its paint; `defaultsOnly` with ids, id or item is refused, and the journal records a change the bucket made this way with `defaultsOnly: true`, so a replay with another tool active changes the default too → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}", + "{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), opacity?: 0..100 (a percentage, as transparency.set's; the opacity of that fill item on each target, in the undo step of the paint, or alone without color, none, swatch or gradient, when it changes neither the defaults nor the recent colors (with New Art Has Basic Appearance off, the next shape copies the first selected object's appearance after any command, its opacity included); with no paint or a solid color, the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso take it themselves, and with another paint the fill item takes it; with no paint, a target without that fill item is left as it is (a paint given with the opacity creates the item, which then takes it, except for the color a grayscale or 1-bit image is drawn in, which creates none), and an opacity that no target takes is an error that also leaves the paint undone; type characters have no opacity of their own, so an opacity that only characters would take is an error, and so are one with nothing selected and no ids and one for an object selected in a symbol instance), ids?|id?, defaultsOnly?: bool, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no ids, id or item are given), the paint goes to those characters only; without `item`, a Live Paint group among the targets (or inside one) takes the fill on its faces only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind. While the Live Paint Bucket or the Shape Builder is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, only the default changes (the color the bucket paints with, and the fill the Shape Builder's merges take with Pick Color From Color Swatches) and the selection keeps its paint; `defaultsOnly` with ids, id or item is refused, and the journal records a change either tool made this way with `defaultsOnly: true`, so a replay with another tool active changes the default too → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}", has_doc, |s, p| set_paint(s, p, true) ), @@ -36,7 +51,7 @@ pub fn specs() -> Vec { "Stroke", [], None, - "{…as paint.setFill, item?: the stroke item to set, aligned?: bool (as paint.setFill), opacity?: 0..100 (the opacity of that stroke item, as paint.setFill's for the fill item)} same as paint.setFill, for the stroke; without `item`, a Live Paint group among the targets (or inside one) takes the stroke on its edges only; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's stroke changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, as paint.setFill", + "{…as paint.setFill, item?: the stroke item to set, aligned?: bool (as paint.setFill), opacity?: 0..100 (the opacity of that stroke item, as paint.setFill's for the fill item)} same as paint.setFill, for the stroke (while the Shape Builder is the active tool, the selection still takes the stroke); without `item`, a Live Paint group among the targets (or inside one) takes the stroke on its edges only; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's stroke changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, as paint.setFill", has_doc, |s, p| { set_paint(s, p, false) } ), @@ -45,7 +60,7 @@ pub fn specs() -> Vec { "Swap Fill and Stroke", [], Some("Shift+X"), - "{ids?|id?, defaultsOnly?: bool} swap the fill and stroke of the selection (type too) and of the defaults. A Live Paint group's faces take the stroke its edges share and its edges take the fill its faces share, a gradient fitted to each face or edge; a group whose faces' fills or edges' strokes differ (a freeform gradient counts as differing), or that has no face or no edge, keeps its paint. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring what the swap changes on its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), or `defaultsOnly: true` is given, only the defaults change", + "{ids?|id?, defaultsOnly?: bool} swap the fill and stroke of the selection (type too) and of the defaults. A Live Paint group's faces take the stroke its edges share and its edges take the fill its faces share, a gradient fitted to each face or edge; a group whose faces' fills or edges' strokes differ (a freeform gradient counts as differing), or that has no face or no edge, keeps its paint. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring what the swap changes on its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket or the Shape Builder is the active tool and no ids or id are given (a null one counts as none), or `defaultsOnly: true` is given, only the defaults change (with the Shape Builder, the default fill takes the stroke the Stroke proxy shows, the selection's)", has_doc, swap ), @@ -54,7 +69,7 @@ pub fn specs() -> Vec { "Default Fill and Stroke", [], Some("D"), - "{ids?|id?, defaultsOnly?: bool} white fill and 1 pt black stroke for the selection and the defaults (in a document whose Default Graphic Style differs from the shipped one, as a New Document profile can redefine it: that style's fills, strokes and effects, without its opacity or a link to it); type gets black fill and no stroke. A Live Paint group's faces get no fill and its edges get a 0.5 pt black stroke, in place of their whole appearance and also when the Default Graphic Style is redefined, and with only Live Paint groups selected (or in ids) the defaults become no fill and a 0.5 pt black stroke (with New Art Has Basic Appearance off, new art then takes the selection's appearance, as after any command). On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke, and on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none), or `defaultsOnly: true` is given, only the defaults change", + "{ids?|id?, defaultsOnly?: bool} white fill and 1 pt black stroke for the selection and the defaults (in a document whose Default Graphic Style differs from the shipped one, as a New Document profile can redefine it: that style's fills, strokes and effects, without its opacity or a link to it); type gets black fill and no stroke. A Live Paint group's faces get no fill and its edges get a 0.5 pt black stroke, in place of their whole appearance and also when the Default Graphic Style is redefined, and with only Live Paint groups selected (or in ids) the defaults become no fill and a 0.5 pt black stroke (with New Art Has Basic Appearance off, new art then takes the selection's appearance, as after any command). On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke, and on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md). While the Live Paint Bucket or the Shape Builder is the active tool and no ids or id are given (a null one counts as none), or `defaultsOnly: true` is given, only the defaults change", has_doc, default_paint ), @@ -75,7 +90,7 @@ pub fn specs() -> Vec { "None", [], Some("/"), - "{defaultsOnly?: bool} set the active proxy (fill or stroke) to None, as paint.setFill or paint.setStroke with none does (while the Live Paint Bucket is the active tool, or with `defaultsOnly: true`, only the default changes) → {objects}", + "{defaultsOnly?: bool} set the active proxy (fill or stroke) to None, as paint.setFill or paint.setStroke with none does (while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool, or with `defaultsOnly: true`, only the default changes) → {objects}", has_doc, |s, p| { let f = s.fill_active; @@ -103,7 +118,7 @@ pub fn proxy_specs() -> Vec { "Invert", [], None, - "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path; a Live Paint group recolors its faces' fills or its edges' strokes) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md); no undo step when no color changes → {changed}", + "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path; a Live Paint group recolors its faces' fills or its edges' strokes) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, or while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (docs/mcp.md); no undo step when no color changes → {changed}", has_doc, |s, p| proxy_recolor(s, p, "paint.invert", "Invert", &super::colorcmds::invert) ), @@ -112,7 +127,7 @@ pub fn proxy_specs() -> Vec { "Complement", [], None, - "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} replace the active proxy's colours by their complements ((highest + lowest) − each component, over RGB or CMY; grey unchanged) keeping each colour's model; a Live Paint group recolors its faces' fills or its edges' strokes as with paint.invert; honours the Appearance panel's active item and a selected object of a dynamic symbol instance as paint.invert does; with nothing selected, or while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, the default; no undo step when no color changes → {changed}", + "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} replace the active proxy's colours by their complements ((highest + lowest) − each component, over RGB or CMY; grey unchanged) keeping each colour's model; a Live Paint group recolors its faces' fills or its edges' strokes as with paint.invert; honours the Appearance panel's active item and a selected object of a dynamic symbol instance as paint.invert does; with nothing selected, or while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, the default; no undo step when no color changes → {changed}", has_doc, |s, p| proxy_recolor(s, p, "paint.complement", "Complement", &|c: Color| c.complement_keep_model()) ), @@ -121,7 +136,7 @@ pub fn proxy_specs() -> Vec { "Apply Last Color", [], Some(","), - "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} apply the last solid colour used (paint.recent lastColor) to the active proxy of the selection and the default (while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, to the default only) → {objects} (as paint.setFill)", + "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} apply the last solid colour used (paint.recent lastColor) to the active proxy of the selection and the default (while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, to the default only) → {objects} (as paint.setFill)", has_doc, |s, p| { let paint = Paint::solid(s.last_solid); @@ -133,7 +148,7 @@ pub fn proxy_specs() -> Vec { "Apply Last Gradient", [], Some("."), - "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} apply the last gradient used (paint.recent lastGradient), fitted to each object, to the active proxy of the selection and the default (while the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, to the default only) → {objects} (as paint.setFill)", + "{stroke?: bool (default: the active proxy), ids?|id?, defaultsOnly?: bool, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} apply the last gradient used (paint.recent lastGradient), fitted to each object, to the active proxy of the selection and the default (while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool and no ids, id or item are given (a null ids or id counts as none), or `defaultsOnly: true` is given, to the default only) → {objects} (as paint.setFill)", has_doc, |s, p| { let paint = super::gradient::unplaced(&Paint::Gradient(Box::new(s.last_gradient.clone()))); @@ -161,7 +176,7 @@ pub fn proxy_specs() -> Vec { "Fill and Stroke", [], None, - "{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, a Live Paint group's first face's fill and first edge's stroke, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, a Live Paint group counting with its faces' fills and its edges' strokes, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors), fillOpacity, strokeOpacity: 0..100, the opacity of the fill item that paint.setFill {opacity} sets (the stroke item that paint.setStroke {opacity} sets), from the first selected object (or painted object in a selected group; a selected path of a compound path stands for its compound, and a Live Paint group for its faces' fills and its edges' strokes) that has one (a gradient mesh's first picked point's), or null with nothing selected (the defaults for new art), for an object selected in a symbol instance, while the Live Paint Bucket is the active tool, while the Type tool has characters selected, and when only type characters or objects without that item are selected}", + "{} → {fill, stroke: the paints the Fill/Stroke proxies show (the Appearance panel's active item for the proxy of its kind, else the first selected object's, a group's first painted object's, a Live Paint group's first face's fill and first edge's stroke, type: its first run's; else the defaults for new art; when that object is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso and no fill item is active, the fill is its first picked point's color), fillActive, fillMixed, strokeMixed: the selected objects' (or a selected group's contents') fills (strokes) differ, a Live Paint group counting with its faces' fills and its edges' strokes, shown as a \"?\" proxy (a gradient mesh with points picked counts with their colors), fillOpacity, strokeOpacity: 0..100, the opacity of the fill item that paint.setFill {opacity} sets (the stroke item that paint.setStroke {opacity} sets), from the first selected object (or painted object in a selected group; a selected path of a compound path stands for its compound, and a Live Paint group for its faces' fills and its edges' strokes) that has one (a gradient mesh's first picked point's), or null with nothing selected (the defaults for new art), for an object selected in a symbol instance, while the Live Paint Bucket is the active tool (for fillOpacity, also the Shape Builder), while the Type tool has characters selected, and when only type characters or objects without that item are selected}", always, proxies ), @@ -204,11 +219,11 @@ impl Session { /// The object whose fill (or stroke) the proxy shows, with the Appearance panel's active item /// when it stands for it (see [`Session::proxy_paints`]); None: the defaults for new art. With /// an object of a dynamic symbol instance selected ([`DocState::selected_symbol_part`]), that - /// object as the instance draws it. None while the Live Paint Bucket is the active tool (or - /// another tool works for it, [`Session::bucket_paints`]): the proxies show the colors it - /// paints with. + /// object as the instance draws it. None while the active tool paints with the chosen fill (or + /// stroke), or another tool works for it ([`Session::tool_paints`]): the proxy shows the color + /// it paints with. pub(crate) fn proxy_source(&self, stroke: bool) -> Option<(Cow<'_, Node>, Option)> { - if self.bucket_paints() { + if self.tool_paints(stroke) { return None; } let st = self.active()?; @@ -243,16 +258,16 @@ impl Session { /// `paint.setStroke {opacity}` sets): the item's, or for a gradient mesh with points picked the /// first picked point's. The rows the command would edit are read in order (a group without an /// active Appearance row stands for its contents), and the first that exists answers. `None` - /// with nothing selected, for an object selected in a symbol instance, while the Live Paint - /// Bucket is the active tool (or another tool works for it, [`Session::bucket_paints`]), while + /// with nothing selected, for an object selected in a symbol instance, while the active tool + /// paints with the chosen fill (or stroke), or another tool works for it ([`Session::tool_paints`]), while /// the Type tool has characters selected, and when only type /// characters, objects without that item or the art of graph designs in a graph series are /// selected. pub fn proxy_opacity(&self, stroke: bool) -> Option { let st = self.active()?; - // The Live Paint Bucket takes a fill or stroke chosen as the color it paints with, and the - // selection keeps its own (for_bucket). - if st.selection.symbol_part.is_some() || self.bucket_paints() { + // Such a tool takes a fill or stroke chosen as the color it paints with, and the selection + // keeps its own (for_tool). + if st.selection.symbol_part.is_some() || self.tool_paints(stroke) { return None; } // The command would give the opacity to the characters, which have none of their own. @@ -516,25 +531,40 @@ impl DocState { } } -/// Is `t` the Live Paint Bucket, or a tool armed to switch back to it after its pick? -fn works_for_bucket(t: &dyn vectorcraft_tools::Tool) -> bool { - t.id() == LIVE_PAINT_BUCKET || t.returns_to() == Some(LIVE_PAINT_BUCKET) +/// The id of tool `t`, or of the tool its armed pick switches back to, when that tool paints with +/// the chosen fill or stroke ([`painting_tool_of`]). +fn painter_of(t: &dyn vectorcraft_tools::Tool) -> Option<&'static str> { + let of = |id: &str| painting_tool_of(id, false).or_else(|| painting_tool_of(id, true)); + of(t.id()).or_else(|| t.returns_to().and_then(of)) } impl Session { - /// Did the Live Paint Bucket, or the Eyedropper armed for it, lend the active tool (a Cmd+click)? - pub(crate) fn lent_by_bucket(&self) -> bool { - self.lender.as_deref().is_some_and(works_for_bucket) + /// The tool that lent the active tool (a Cmd+click) when it paints with the chosen colors, or + /// the Eyedropper armed for such a tool did ([`painter_of`]). + pub(crate) fn lent_by_painter(&self) -> Option<&'static str> { + self.lender.as_deref().and_then(painter_of) } - /// Do the fill and stroke proxies, and the paint commands that name no objects, stand for the - /// colors the Live Paint Bucket paints with? They do while the bucket is the active tool, while - /// a Cmd+click with the bucket uses the Selection tool, and while the Eyedropper samples into a - /// stop of the bucket's gradient for the Gradient panel's eyedropper, up to and including the - /// sample its click takes before it switches back to the bucket. - pub fn bucket_paints(&self) -> bool { - // A Cmd+click lends the Selection tool to the bucket, or to the Eyedropper armed for it. - self.back_to_bucket || works_for_bucket(self.tool.as_ref()) || self.lent_by_bucket() + /// Do the fill proxy (the stroke proxy, with `stroke`), and the fill (stroke) commands that + /// name no objects, stand for the color the active tool paints with ([`painting_tool_of`]: the + /// Live Paint Bucket's fill and stroke, the Shape Builder's fill)? They do while such a tool is + /// active, while a Cmd+click with it uses the Selection tool, and while the Eyedropper samples + /// into a stop of its gradient for the Gradient panel's eyedropper, up to and including the + /// sample its click takes before it switches back to that tool. + pub fn tool_paints(&self, stroke: bool) -> bool { + self.painting_tool(stroke).is_some() + } + + /// The id of the tool whose fill (or stroke, `stroke`) the proxy stands for + /// ([`Session::tool_paints`]); None when it stands for the selection's. + pub(crate) fn painting_tool(&self, stroke: bool) -> Option<&'static str> { + let of = + |t: &dyn vectorcraft_tools::Tool| painting_tool_of(t.id(), stroke).or_else(|| t.returns_to().and_then(|id| painting_tool_of(id, stroke))); + // A Cmd+click lends the Selection tool to such a tool, or to the Eyedropper armed for it. + self.back_to_painter + .and_then(|id| painting_tool_of(id, stroke)) + .or_else(|| of(self.tool.as_ref())) + .or_else(|| self.lender.as_deref().and_then(of)) } /// The tool the active tool's armed one-shot pick switches back to after its click @@ -545,12 +575,14 @@ impl Session { /// [`DocState::proxy_mixed`] of the active document for the Appearance panel's active item. /// A gradient mesh with points picked ([`Session::fill_mesh_points`]) counts with their colors. - /// Neither is mixed while the Live Paint Bucket is the active tool ([`Session::proxy_source`]). + /// A proxy that stands for the color the active tool paints with ([`Session::tool_paints`]) is + /// not mixed ([`Session::proxy_source`]). pub fn proxy_mixed(&self) -> (bool, bool) { - if self.bucket_paints() { + if self.tool_paints(false) && self.tool_paints(true) { return (false, false); } - self.active().map_or((false, false), |st| st.proxy_mixed_with(self.appearance_item(), &self.fill_mesh_points())) + let (fill, stroke) = self.active().map_or((false, false), |st| st.proxy_mixed_with(self.appearance_item(), &self.fill_mesh_points())); + (fill && !self.tool_paints(false), stroke && !self.tool_paints(true)) } } @@ -735,8 +767,8 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) /// characters, to an object selected in a symbol instance, or to no target at all is an error. fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option, opacity: Option, fill: bool) -> Result { let cmd = if fill { "paint.setFill" } else { "paint.setStroke" }; - let bucket = bucket_color_params(s, p, cmd)?; - let p = bucket.as_ref().unwrap_or(p); + let for_tool = tool_color_params(s, p, cmd, !fill)?; + let p = for_tool.as_ref().unwrap_or(p); let focus = switch_or(p, "focus", true, cmd)?; // An opacity alone places no gradient, so `span` may only be "object" with it. let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?; @@ -1033,12 +1065,13 @@ fn names_no_target(p: &Value) -> bool { ["ids", "id"].iter().all(|k| p.get(k).is_none_or(Value::is_null)) && p.get("item").is_none() } -/// Is the Live Paint Bucket the active tool ([`Session::bucket_paints`]), or does `p` give +/// Does the active tool paint with the chosen fill (or stroke, `stroke`: [`Session::tool_paints`], +/// the Live Paint Bucket's fill and stroke, the Shape Builder's fill), or does `p` give /// `defaultsOnly: true`, while `p` names no `ids`, `id` or `item`? A fill, stroke or stroke weight -/// chosen then is what the bucket paints with, so it goes to the defaults and the selection keeps -/// its paint. -pub(crate) fn for_bucket(s: &Session, p: &Value) -> bool { - names_no_target(p) && (s.bucket_paints() || asks_defaults_only(p)) +/// of that kind chosen then is what the tool paints with, so it goes to the defaults and the +/// selection keeps its paint. +pub(crate) fn for_tool(s: &Session, p: &Value, stroke: bool) -> bool { + names_no_target(p) && (s.tool_paints(stroke) || asks_defaults_only(p)) } /// Does `p` give `defaultsOnly: true`? @@ -1046,17 +1079,18 @@ pub(crate) fn asks_defaults_only(p: &Value) -> bool { p.get("defaultsOnly") == Some(&Value::Bool(true)) } -/// `p` with `ids: []` (and without `defaultsOnly`) when [`for_bucket`]: the paint goes to the -/// defaults only. None otherwise. A bad `target` or `aligned` is refused first, as it is without -/// the bucket, and so is a `defaultsOnly` that is not a bool or comes with `ids`, `id` or `item`. -/// When the bucket routed the command, the journal entry notes `defaultsOnly: true`, so replaying -/// it with another tool active changes the defaults only as well. -pub(crate) fn bucket_color_params(s: &mut Session, p: &Value, cmd: &str) -> Result> { +/// `p` with `ids: []` (and without `defaultsOnly`) when [`for_tool`] for the fill (or stroke, +/// `stroke`): the paint goes to the defaults only. None otherwise. A bad `target` or `aligned` is +/// refused first, as it is when the selection takes the paint, and so is a `defaultsOnly` that is +/// not a bool or comes with `ids`, `id` or `item`. When the active tool routed the command, the +/// journal entry notes `defaultsOnly: true`, so replaying it with another tool active changes the +/// defaults only as well. +pub(crate) fn tool_color_params(s: &mut Session, p: &Value, cmd: &str, stroke: bool) -> Result> { let only = switch_or(p, "defaultsOnly", false, cmd)?; if only && !names_no_target(p) { return Err(bad(cmd, "`defaultsOnly` cannot be combined with `ids`, `id` or `item`")); } - if !for_bucket(s, p) { + if !for_tool(s, p, stroke) { return Ok(None); } super::appearance::aligned(p, cmd)?; @@ -1071,28 +1105,62 @@ pub(crate) fn bucket_color_params(s: &mut Session, p: &Value, cmd: &str) -> Resu Ok(Some(Value::Object(v))) } -/// Whether the paint commands that `cmd` runs with params of its own change only the defaults: -/// `p` gives `defaultsOnly: true`, or the Live Paint Bucket paints ([`Session::bucket_paints`]), -/// which the journal entry of `cmd` notes for a replay. -pub(crate) fn defaults_only(s: &mut Session, p: &Value, cmd: &str) -> Result { +/// The kind of gradient `p` of a gradient command (`cmd`) edits when the active tool can paint +/// with it: the kind `stroke` names, else the proxy in front's when the tool paints with it, else +/// the kind `p` edits on the selection (the Appearance panel's active row's). +pub(crate) fn tool_gradient_kind(s: &Session, p: &Value, cmd: &str) -> Result { + check_switches(p, &["stroke"], cmd)?; + // A tool that paints with both kinds (the Live Paint Bucket), or with neither, needs no kind. + Ok(if s.tool_paints(false) == s.tool_paints(true) || p.get("stroke").is_some_and(Value::is_boolean) { + p.get("stroke").and_then(Value::as_bool).unwrap_or(!s.fill_active) + } else if s.tool_paints(!s.fill_active) { + !s.fill_active + } else { + // A null `ids` or `id` names no target, as `for_tool` reads it. + let mut q = p.clone(); + if let Some(o) = q.as_object_mut() { + o.retain(|k, v| !(matches!(k.as_str(), "ids" | "id") && v.is_null())); + } + super::appearance::edits_stroke(s, &q, item_target(s, &q, cmd)?, !s.fill_active, cmd)? + }) +} + +/// [`tool_color_params`] for `paint.editGradient` or `gradient.presets.apply` (`cmd`), for the kind +/// [`tool_gradient_kind`] gives. The params name that kind as their `stroke` when `p` gives none, +/// since the selection's Appearance row no longer picks it. +pub(crate) fn tool_gradient_params(s: &mut Session, p: &Value, cmd: &str) -> Result> { + let stroke = tool_gradient_kind(s, p, cmd)?; + Ok(tool_color_params(s, p, cmd, stroke)?.map(|mut v| { + if p.get("stroke").is_none_or(Value::is_null) { + v["stroke"] = json!(stroke); + } + v + })) +} + +/// Whether the paint commands that `cmd` runs with params of its own for the fill (or the stroke, +/// `stroke`) change only the defaults: `p` gives `defaultsOnly: true`, or the active tool paints +/// with that kind ([`Session::tool_paints`]), which the journal entry of `cmd` notes for a replay. +pub(crate) fn defaults_only(s: &mut Session, p: &Value, cmd: &str, stroke: bool) -> Result { if switch_or(p, "defaultsOnly", false, cmd)? { s.note_defaults_only(); return Ok(true); } - let bucket = s.bucket_paints(); - if bucket { + let tool = s.tool_paints(stroke); + if tool { s.note_journal("defaultsOnly", json!(true)); s.note_defaults_only(); } - Ok(bucket) + Ok(tool) } impl Session { /// Note that the running command changed only the paint defaults, with the appearance new art /// takes from the selection now ([`Session::inherit_new_art`]). No appearance is captured - /// while inheritance does not run (New Art Has Basic Appearance on, or the bucket painting). + /// while inheritance does not run (New Art Has Basic Appearance on, or the active tool painting + /// with both the fill and the stroke). fn note_defaults_only(&mut self) { - let inherits = !self.prefs.new_art_basic && !self.bucket_paints(); + let inherits = !self.prefs.new_art_basic && !(self.tool_paints(false) && self.tool_paints(true)); self.defaults_only_ran = Some(if inherits { self.new_art_source() } else { None }); } } @@ -1534,8 +1602,17 @@ fn shared_paint(d: &Document, parts: &[NodeId], fill: bool) -> Option { } fn swap(s: &mut Session, p: &Value) -> Result { - let bucket = bucket_color_params(s, p, "paint.swap")?; - let p = bucket.as_ref().unwrap_or(p); + // The swap changes a fill, so it goes to the defaults only while the active tool paints with the chosen fill. + let for_tool = tool_color_params(s, p, "paint.swap", false)?; + let p = for_tool.as_ref().unwrap_or(p); + // A tool that paints with the fill only (the Shape Builder): the Stroke proxy shows the + // selection's stroke, which the current fill takes unless the proxy shows mixed strokes. With + // nothing selected it shows the stroke for new art, which the swap moves as it is. + // A swap with `defaultsOnly` and no such tool swaps the defaults alone. + let fill_only = s.tool_paints(false) && !s.tool_paints(true); + let shown_stroke = (for_tool.is_some() && fill_only && !s.proxy_mixed().1) + .then(|| s.proxy_source(true).map(|(n, item)| super::gradient::unplaced(&proxy_paint(&n, true, item)))) + .flatten(); let targets = paint_targets(s, p)?; let given = !targets.is_empty(); // A whole Live Paint group: its faces take the stroke its edges share and its edges the fill its faces share. @@ -1599,6 +1676,9 @@ fn swap(s: &mut Session, p: &Value) -> Result { s.paint.stroke_width = 1.0; } std::mem::swap(&mut s.paint.fill, &mut s.paint.stroke); + if let Some(stroke) = shown_stroke { + s.paint.fill = stroke; + } ok() } @@ -1606,8 +1686,9 @@ fn swap(s: &mut Session, p: &Value) -> Result { const LIVE_PAINT_DEFAULT_WEIGHT: f64 = 0.5; fn default_paint(s: &mut Session, p: &Value) -> Result { - let bucket = bucket_color_params(s, p, "paint.default")?; - let p = bucket.as_ref().unwrap_or(p); + // As with paint.swap, the new fill decides whether only the defaults change. + let for_tool = tool_color_params(s, p, "paint.default", false)?; + let p = for_tool.as_ref().unwrap_or(p); let targets = paint_targets(s, p)?; let given = !targets.is_empty(); // A whole Live Paint group: its faces lose their fill and its edges take a black 0.5 pt stroke. @@ -1687,9 +1768,9 @@ fn default_paint(s: &mut Session, p: &Value) -> Result { /// default when there are none) and remember the first target's new paint. The Appearance panel's /// active item of the proxy's kind is recoloured in each selected object's own stack instead. fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(Color) -> Color) -> Result { - let bucket = bucket_color_params(s, p, cmd)?; - let p = bucket.as_ref().unwrap_or(p); let stroke = stroke_param(s, p, cmd)?; + let for_tool = tool_color_params(s, p, cmd, stroke)?; + let p = for_tool.as_ref().unwrap_or(p); // An object of a dynamic symbol instance's art selected with Direct Selection: the solid color // it shows is recolored for this instance only. A gradient or pattern is refused, and so is type // whose characters differ in that paint, since one change holds one paint. diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index 78e56e8f33..420b3ed1eb 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -241,7 +241,7 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result { let change = StrokeChange::parse(p, C)?; // The stroke the Live Paint Bucket paints with changes; the selection keeps its own, and its // active Appearance row is not a target. - let bucket_p = super::paint::bucket_color_params(s, p, C)?; + let bucket_p = super::paint::tool_color_params(s, p, C, true)?; let bucket = bucket_p.is_some(); let p = bucket_p.as_ref().unwrap_or(p); let item = item_target(s, p, C)?.of_kind(s, false); @@ -397,7 +397,7 @@ fn stroke_step(s: &mut Session, p: &Value, up: bool) -> Result { let unit = s.stroke_unit(); // The weight the Live Paint Bucket paints with changes; the selection keeps its own, and its // active Appearance row is not a target. - let bucket_p = super::paint::bucket_color_params(s, p, c)?; + let bucket_p = super::paint::tool_color_params(s, p, c, true)?; let bucket = bucket_p.is_some(); let p = bucket_p.as_ref().unwrap_or(p); let item = item_target(s, p, c)?.of_kind(s, false); @@ -450,7 +450,7 @@ impl Session { /// selection's stroke. pub fn shown_stroke(&self) -> Option { let st = self.active()?; - if self.bucket_paints() { + if self.tool_paints(true) { return Some(self.new_art_stroke()); } if let Some(part) = st.selected_symbol_part() { @@ -622,7 +622,7 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result { if brush.is_some() && super::switch_or(p, "defaultsOnly", false, C)? { return Err(bad(C, "`defaultsOnly` cannot be combined with `brush`")); } - let bucket_p = if brush.is_none() { super::paint::bucket_color_params(s, p, C)? } else { None }; + let bucket_p = if brush.is_none() { super::paint::tool_color_params(s, p, C, true)? } else { None }; let bucket = bucket_p.is_some(); let p = bucket_p.as_ref().unwrap_or(p); let item = item_target(s, p, C)?.of_kind(s, false); diff --git a/crates/engine/src/cmd/swatchlib.rs b/crates/engine/src/cmd/swatchlib.rs index c4db83826e..1d4a57bde3 100644 --- a/crates/engine/src/cmd/swatchlib.rs +++ b/crates/engine/src/cmd/swatchlib.rs @@ -1585,7 +1585,7 @@ fn add(s: &mut Session, p: &Value) -> Result { let mut out = json!({"library": shown_library_id(s, &info.id), "added": added_names, "existing": names(&existing)}); if let (Some(cmd), Some((_, first))) = (apply, picked.first()) { let name = added.iter().chain(&existing).find(|(l, _)| *l == first.name).map_or(first.name.clone(), |(_, n)| n.clone()); - let only = super::paint::defaults_only(s, p, C)?; + let only = super::paint::defaults_only(s, p, C, cmd == "paint.setStroke")?; s.execute(cmd, &super::paint::with_defaults_only(json!({"swatch": name, "focus": focus}), only))?; // Adding and applying undo together. squash(s, undo_before, "Add to Swatches"); diff --git a/crates/engine/src/cmd/xform.rs b/crates/engine/src/cmd/xform.rs index fcb176a793..f12df3f229 100644 --- a/crates/engine/src/cmd/xform.rs +++ b/crates/engine/src/cmd/xform.rs @@ -30,7 +30,7 @@ pub fn specs() -> Vec { "Sample Color", [], None, - "{color (#rrggbbaa and #rgba are refused), stroke?: bool (default: whichever proxy is active), ids?, defaultsOnly?: bool, stop?: index, clearStroke?: bool} sample a color into the active fill/stroke (and the selection; `ids: []` changes only the paint default, and so does a sample without ids while the Live Paint Bucket is the active tool or with `defaultsOnly: true` (refused with ids), `stop` included); `clearStroke: true` requires `stroke: false`, `ids: []` and no `stop`, and clears the default stroke after sampling an image into the fill; with `stop`, recolor that stop of the gradient behind the proxy instead (paint.editGradient); with `stop` and objects in `ids`, whatever tool is active, the stops come from the topmost fill (or stroke) of the first object that paint.editGradient edits for those ids (a compound path for its member); in a CMYK document an RGB color is stored as CMYK through the color settings, as paint.setFill stores it", + "{color (#rrggbbaa and #rgba are refused), stroke?: bool (default: whichever proxy is active), ids?, defaultsOnly?: bool, stop?: index, clearStroke?: bool} sample a color into the active fill/stroke (and the selection; `ids: []` changes only the paint default, and so does a sample without ids while the Live Paint Bucket, or for a fill the Shape Builder, is the active tool or with `defaultsOnly: true` (refused with ids), `stop` included); `clearStroke: true` requires `stroke: false`, `ids: []` and no `stop`, and clears the default stroke after sampling an image into the fill; with `stop`, recolor that stop of the gradient behind the proxy instead (paint.editGradient); with `stop` and objects in `ids`, whatever tool is active, the stops come from the topmost fill (or stroke) of the first object that paint.editGradient edits for those ids (a compound path for its member); in a CMYK document an RGB color is stored as CMYK through the color settings, as paint.setFill stores it", has_doc, sample_color ), diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index f7f9197f1d..6dd833263b 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -22,6 +22,10 @@ pub struct Interaction { /// Conversion of new-art paints waits until a color-mode preview is accepted. pub(crate) deferred_color_mode: Option, pub(crate) color_mode_paints: Option<(vectorcraft_tools::PaintDefaults, vectorcraft_tools::PaintDefaults)>, + /// A preview ran while the active tool painted with the chosen fill or stroke + /// ([`crate::Session::tool_paints`]): the next preview and a cancel put back the new-art paints + /// from before the interaction, whichever tool is active then. + pub(crate) tool_paints: bool, /// Per-document state restored on cancel (current layer, highlighted Layers panel rows, /// isolation). pub active_layer: Option, diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 5560c26fcc..f0d60d9a71 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -74,11 +74,16 @@ pub struct Session { /// While Cmd lends `tool` (a selection tool) for a drag: the tool it was lent to, which comes /// back as it was at the release ([`Session::pointer`]). pub(crate) lender: Option>, - /// Set while tool actions that end by switching back to the Live Paint Bucket are applied (the - /// Eyedropper's sample into a stop of the bucket's gradient), and while a tool the bucket lent - /// is deactivated as it goes back: their paint commands change the colors the bucket paints - /// with ([`Session::bucket_paints`]). - pub(crate) back_to_bucket: bool, + /// While tool actions that end by switching back to a tool that paints with the chosen colors + /// are applied (the Eyedropper's sample into a stop of the Live Paint Bucket's gradient), and + /// while a tool such a tool lent is deactivated as it goes back, that tool's id: their paint + /// commands change the colors it paints with ([`Session::tool_paints`]). + pub(crate) back_to_painter: Option<&'static str>, + /// Whose gradient the stop was on when the Eyedropper was last armed to sample into one + /// (`tool.setOption {stop}`), when it was the gradient a tool paints with + /// ([`Session::painting_tool`]); None for a stop of the selection's paint. A pick armed for + /// such a stop samples only into a stop selected on that gradient, and otherwise ends. + pub(crate) stop_pick: Option, /// Pointer and key input that came while the tool computed an edit on another thread, each with /// its number and view, made in order once the edit is applied. held_input: std::collections::VecDeque<(u64, tooling::HeldInput, ViewInfo)>, diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 770cfd2bea..170137028a 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -59,7 +59,8 @@ impl Session { histories_seen: None, tool: vectorcraft_tools::create("selection"), lender: None, - back_to_bucket: false, + back_to_painter: None, + stop_pick: None, held_input: Default::default(), input_count: 0, edit_started_by: None, diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index cc7af44898..c82f7ca32c 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -518,6 +518,7 @@ impl Session { used_defaults_only: false, preview_paint: None, color_mode_paints: None, + tool_paints: false, deferred_color_mode: None, active_layer: st.active_layer, layer_rows: st.layer_rows.clone(), @@ -538,10 +539,11 @@ impl Session { if self.script_running() { return Err(EngineError::Busy); } - // While the Live Paint Bucket is active, paint previews change only the bucket's colors, so - // each preview starts from the colors the interaction began with; so does a preview with + // While the active tool paints with the chosen fill or stroke (the Live Paint Bucket, the + // Shape Builder), paint previews of that kind change only the colors it paints with, so each + // preview starts from the colors the interaction began with; so does a preview with // `defaultsOnly: true`, and one after it. - let bucket = self.bucket_paints(); + let tool_paints = self.tool_paints(false) || self.tool_paints(true); let (paint, restore_paint) = { let menu = self.menu.clone(); let st = self.doc_mut()?; @@ -556,7 +558,8 @@ impl Session { // A batch, or a preview that changed the new-art paints (a pattern rename), started from // the paints the interaction began with. it.used_defaults_only |= cmd::asks_defaults_only(params); - let restore_paint = bucket + it.tool_paints |= tool_paints; + let restore_paint = it.tool_paints || cmd == "command.batch" || it.used_defaults_only || it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p)) @@ -720,15 +723,17 @@ impl Session { self.clear_deferred_overlay_cache(); self.decoded_images.empty(); self.pending_paint = None; - // While the Live Paint Bucket is active, a previewed color is the bucket's color, which the - // cancel puts back as well, as it does a color previewed with `defaultsOnly: true`. - let bucket = self.bucket_paints(); + // A color previewed while the active tool painted with the chosen fill or stroke is the + // tool's color, which the cancel puts back as well, also after another tool was chosen, as + // it does a color previewed with `defaultsOnly: true`. + let tool_paints = self.tool_paints(false) || self.tool_paints(true); let used_defaults_only = self.active().and_then(|st| st.interaction.as_ref()).is_some_and(|it| it.used_defaults_only); if let Some(paint) = self .active() .and_then(|st| st.interaction.as_ref()) .filter(|it| { - bucket + tool_paints + || it.tool_paints || it.used_defaults_only || it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p)) || it.color_mode_paints.is_some() diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index 22560e5568..320d6ba70f 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -1899,6 +1899,303 @@ fn shape_builder_arrow_keys_pass_swatches_of_the_same_color() { assert_eq!(s.paint.fill, after, "the swatch after Twin B"); } +/// While the Shape Builder is active, with either Pick Color From, a fill chosen without `ids`, +/// `id` or `item` (a swatch, a color, Swap, Default) changes only the current fill: the selected +/// paths keep their fills, no undo step is recorded and the Fill proxy shows the chosen fill. A +/// stroke chosen then still paints the selection, since a merge takes no stroke from it. +#[test] +fn shape_builder_fill_choice_leaves_the_selection_unpainted() { + let fills = |s: &Session, ids: [NodeId; 2]| ids.map(|id| node(s, id).appearance.fill_paint()); + for mode in ["artwork", "swatches"] { + let mut s = session(); + let (a, b) = two(&mut s); + s.execute("swatch.new", &json!({"name": "Leaf", "color": "#00ff00"})).unwrap(); + s.select_tool("shapeBuilder", ViewInfo::default()).unwrap(); + s.set_tool_option_cmd(&json!({"tool": "shapeBuilder", "values": {"pickColorFrom": mode}})).unwrap(); + let before = fills(&s, [a, b]); + let steps = s.doc().unwrap().history.undo.len(); + let r = s.execute("paint.setFill", &json!({"swatch": "Leaf"})).unwrap(); + assert_eq!(r["objects"], 0, "{mode}"); + let leaf = s.paint.fill.clone(); + assert_eq!(leaf.color(), Some(Color::from_hex("#00ff00").unwrap()), "{mode}"); + for cmd in ["paint.swap", "paint.swap", "paint.default"] { + s.execute(cmd, &json!({})).unwrap(); + } + s.execute("paint.setFill", &json!({"swatch": "Leaf"})).unwrap(); + assert_eq!(fills(&s, [a, b]), before, "{mode}: the selected paths keep their fills"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{mode}: no undo step"); + assert_eq!(s.proxy_paints().0, leaf, "{mode}: the Fill proxy shows the chosen fill"); + // A stroke goes to the selection, and the Stroke proxy shows the selection's. + let r = s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap(); + assert!(r["objects"].as_u64().unwrap() > 0, "{mode}: {r}"); + let blue = Paint::solid(Color::from_hex("#0000ff").unwrap()); + assert_eq!(node(&s, a).appearance.stroke_paint(), blue, "{mode}"); + s.execute("stroke.set", &json!({"weight": 7})).unwrap(); + assert_eq!(node(&s, b).appearance.stroke_at(None).map(|l| l.width), Some(7.0), "{mode}: the selection takes the weight"); + assert_eq!(fills(&s, [a, b]), before, "{mode}"); + } +} + +/// While the Shape Builder is active, Swap Fill and Stroke gives the current fill the stroke the +/// Stroke proxy shows (the selection's), not a stroke for new art that no proxy shows, and the +/// selected path keeps its fill and stroke. With mixed strokes shown, the fill takes the stroke +/// for new art. +#[test] +fn shape_builder_swap_gives_the_fill_the_shown_stroke() { + let mut s = session(); + let (a, b) = two(&mut s); + s.execute("appearance.setNewArtBasic", &json!({"on": true})).unwrap(); + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + s.execute("paint.setStroke", &json!({"color": "#00ff00"})).unwrap(); + let green = Paint::solid(Color::from_hex("#00ff00").unwrap()); + s.paint.stroke = Paint::solid(Color::from_hex("#0000ff").unwrap()); + s.select_tool("shapeBuilder", ViewInfo::default()).unwrap(); + assert_eq!(s.proxy_paints().1, green, "the Stroke proxy shows the selection's stroke"); + // No stroke for new art: the old fill becomes a 1 pt stroke for new art, as without the tool. + (s.paint.stroke, s.paint.stroke_width) = (Paint::None, 0.0); + let before = node(&s, a).appearance; + s.execute("paint.swap", &json!({})).unwrap(); + assert_eq!(s.paint.fill, green, "the current fill takes the stroke the proxy showed"); + assert_eq!(s.paint.stroke_width, 1.0, "the old fill is a stroke that draws"); + assert_eq!(node(&s, a).appearance, before, "the selected path keeps its fill and stroke"); + // The Stroke proxy shows mixed strokes: the current fill takes the stroke for new art. + s.execute("paint.setStroke", &json!({"ids": [b.0], "color": "#ff00ff"})).unwrap(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + assert!(s.proxy_mixed().1, "the selection's strokes differ"); + let blue = Paint::solid(Color::from_hex("#0000ff").unwrap()); + s.paint.stroke = blue.clone(); + s.execute("paint.swap", &json!({})).unwrap(); + assert_eq!(s.paint.fill, blue, "no stroke of the selection was shown"); + // With nothing selected, the stroke for new art (a freeform gradient drawn as lines) moves to + // the fill as it is. + s.execute("select.set", &json!({"ids": []})).unwrap(); + s.execute("paint.editGradient", &json!({"stroke": true, "kind": "freeform", "mode": "lines"})).unwrap(); + let stroke = s.paint.stroke.clone(); + assert!(matches!(&stroke, Paint::Gradient(g) if g.freeform.is_some()), "{stroke:?}"); + s.execute("paint.swap", &json!({})).unwrap(); + assert_eq!(s.paint.fill, stroke, "the stroke for new art, unchanged"); +} + +/// While the Shape Builder is active, the fill chosen for it stays the current fill when the +/// selection changes, with New Art Has Basic Appearance on or off (off, new art still takes the +/// rest of the new selection's appearance), and the freeform point commands refuse the fill's +/// gradient, which lies on no object, instead of editing the selection's. +#[test] +fn shape_builder_fill_stays_across_selections() { + for basic in [false, true] { + let mut s = session(); + let (a, b) = two(&mut s); + s.execute("appearance.setNewArtBasic", &json!({"on": basic})).unwrap(); + // B's own fill is a freeform gradient, whose points the commands could edit. + s.execute("paint.editGradient", &json!({"ids": [b.0], "stroke": false, "kind": "freeform"})).unwrap(); + // B is linked to a graphic style. + s.execute("graphicStyle.new", &json!({"id": b.0, "name": "Bee"})).unwrap(); + s.execute("graphicStyle.apply", &json!({"name": "Bee", "ids": [b.0]})).unwrap(); + s.select_tool("shapeBuilder", ViewInfo::default()).unwrap(); + s.execute("paint.editGradient", &json!({"stroke": false, "kind": "freeform", "mode": "lines"})).unwrap(); + // The tool's freeform gradient has no points yet: its stops take the colors given. + let stops = json!([{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#0000ff"}]); + s.execute("paint.editGradient", &json!({"stroke": false, "stops": stops})).unwrap(); + let Paint::Gradient(g) = &s.paint.fill else { panic!("the tool's fill is not a gradient") }; + assert_eq!(g.gradient.stops[0].color, Color::from_hex("#ff0000").unwrap(), "{basic}: the stop color given"); + let chosen = s.paint.fill.clone(); + assert!(matches!(&chosen, Paint::Gradient(_)), "{basic}"); + s.execute("select.set", &json!({"ids": [b.0]})).unwrap(); + assert_eq!(s.paint.fill, chosen, "basic {basic}: the chosen fill stays"); + assert_eq!(s.paint.inherited, !basic, "basic {basic}: whether new art takes the selection's appearance"); + // New art with the chosen fill does not look like B's style, so it is not linked to it. + assert_eq!(s.paint.style, None, "basic {basic}"); + let before = [a, b].map(|id| node(&s, id)); + let e = s.execute("paint.freeform.setPoint", &json!({"index": 0, "color": "#ff0000"})).unwrap_err().to_string(); + assert!(e.contains("Shape Builder"), "{basic}: {e}"); + assert_eq!([a, b].map(|id| node(&s, id)), before, "basic {basic}: the selection keeps its paint"); + } +} + +/// While the Shape Builder is active with the Fill proxy in front, a gradient preset or edit that +/// names no kind goes to the tool's fill, also while a stroke row of the selection is the +/// Appearance panel's active row; with the Stroke proxy in front, an active fill row still keeps +/// the edit off the selection. +#[test] +fn shape_builder_gradient_edits_follow_the_proxy_in_front() { + let mut s = session(); + let (a, _) = two(&mut s); + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + let row = |s: &Session, fill: bool| node(s, a).appearance.items.iter().position(|it| it.is_fill() == fill).unwrap(); + s.select_tool("shapeBuilder", ViewInfo::default()).unwrap(); + let before = node(&s, a); + s.execute("appearance.setActiveItem", &json!({"index": row(&s, false)})).unwrap(); + s.fill_active = true; + s.execute("gradient.presets.apply", &json!({"name": "vignette"})).unwrap(); + assert!(matches!(s.paint.fill, Paint::Gradient(_)), "the tool's fill takes the preset"); + assert_eq!(node(&s, a).appearance, before.appearance, "the selection keeps its paint"); + s.execute("appearance.setActiveItem", &json!({"index": row(&s, true)})).unwrap(); + s.fill_active = false; + for (kind, ids) in [("diamond", None), ("linear", Some(Value::Null))] { + let tool_fill = s.paint.fill.clone(); + let mut p = json!({ "kind": kind }); + if let Some(ids) = ids { + p["ids"] = ids; + } + s.execute("paint.editGradient", &p).unwrap(); + assert_ne!(s.paint.fill, tool_fill, "{p}: the tool's fill takes the edit"); + assert_eq!(node(&s, a).appearance, before.appearance, "{p}: the selection keeps its paint"); + } + // A freeform stroke on the selection, its row active and the Fill proxy in front: a point + // edit without `stroke` is for the tool's fill, which has no points, and changes nothing. + s.execute("paint.editGradient", &json!({"ids": [a.0], "stroke": true, "kind": "freeform"})).unwrap(); + let stroked = node(&s, a); + s.execute("appearance.setActiveItem", &json!({"index": row(&s, false)})).unwrap(); + s.fill_active = true; + assert!(s.execute("paint.freeform.setPoint", &json!({"index": 0, "color": "#ff0000"})).is_err()); + assert_eq!(node(&s, a).appearance, stroked.appearance, "the selection's stroke keeps its points"); + // A `stroke` that is not a switch is reported as such. + let e = s.execute("paint.freeform.setPoint", &json!({"index": 0, "color": "#ff0000", "stroke": "true"})).unwrap_err(); + assert!(e.to_string().contains("stroke"), "{e}"); +} + +/// A fill previewed while the Shape Builder is active (a Color panel drag) is the tool's fill, +/// which a cancel puts back, also after another tool was chosen during the drag. +#[test] +fn shape_builder_fill_preview_is_put_back_by_a_cancel() { + let mut s = session(); + two(&mut s); + s.execute("appearance.setNewArtBasic", &json!({"on": true})).unwrap(); + s.select_tool("shapeBuilder", ViewInfo::default()).unwrap(); + let before = s.paint.fill.clone(); + s.begin_interaction("Color").unwrap(); + s.preview("paint.setFill", &json!({"color": "#ff00ff"})).unwrap(); + assert_eq!(s.paint.fill.color(), Some(Color::from_hex("#ff00ff").unwrap()), "the preview sets the tool's fill"); + s.select_tool("selection", ViewInfo::default()).unwrap(); + s.cancel_interaction().unwrap(); + assert_eq!(s.paint.fill, before, "the cancel puts the fill back"); +} + +/// With Pick Color From Color Swatches, a merge fills with the fill chosen while the Shape Builder +/// is active, and the Gradient panel's eyedropper samples into a stop of that fill's gradient. +#[test] +fn shape_builder_merge_fills_with_the_chosen_fill() { + let mut s = session(); + let (a, b) = two(&mut s); + s.execute("swatch.new", &json!({"name": "Leaf", "color": "#00ff00"})).unwrap(); + let v = ViewInfo::default(); + s.select_tool("shapeBuilder", v).unwrap(); + s.set_tool_option_cmd(&json!({"tool": "shapeBuilder", "values": {"pickColorFrom": "swatches"}})).unwrap(); + let (a0, b0) = (node(&s, a), node(&s, b)); + s.execute("paint.setFill", &json!({"swatch": "Leaf"})).unwrap(); + let leaf = s.paint.fill.clone(); + assert_eq!((node(&s, a), node(&s, b)), (a0, b0), "the selected paths keep their paint"); + // The tool's merge fills with the chosen swatch. + s.pointer(&PointerEvent::new(PointerKind::Down, 25.0, 50.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 75.0, 50.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, 75.0, 50.0), v).unwrap(); + assert_eq!(s.journal.last().unwrap().0, "shapeBuilder.merge"); + let d = &s.doc().unwrap().doc; + let fills: Vec = d.children(d.default_layer()).into_iter().flatten().map(|n| n.appearance.fill_paint()).collect(); + assert!(fills.contains(&leaf), "a merged shape filled with the swatch: {fills:?}"); + // A gradient and the Gradient panel's eyedropper sample into a stop of the gradient the tool + // paints with, and the art keeps its paint. + let art = |s: &Session| -> Vec { + let d = &s.doc().unwrap().doc; + d.children(d.default_layer()).into_iter().flatten().map(|n| Node::clone(n)).collect() + }; + let before = art(&s); + s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("shapeBuilder")); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + let Paint::Gradient(g) = &s.paint.fill else { panic!("the tool's fill is not a gradient") }; + assert_eq!(Paint::solid(g.gradient.stops[1].color), leaf, "the sampled stop"); + assert_eq!(art(&s), before, "the art keeps its paint"); + // Armed again, a pick whose stop went away when the Stroke proxy came to the front (the + // selection's stroke), also after the stop was cleared first, ends without copying an + // appearance onto the art. + for clear in [false, true] { + s.select_tool("shapeBuilder", v).unwrap(); + s.fill_active = true; + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("shapeBuilder")); + if clear { + s.execute("gradient.selectStop", &json!({"index": null})).unwrap(); + } + s.fill_active = false; + assert_eq!(s.selected_stop(), None); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + assert_eq!(art(&s), before, "the art keeps its paint (cleared first: {clear})"); + } + // With the Stroke proxy in front, a stop of the selection's stroke gradient is the selection's, + // and the pick samples into it. + s.execute("paint.editGradient", &json!({"stroke": true, "kind": "linear"})).unwrap(); + assert_ne!(art(&s), before, "the selection takes the stroke gradient"); + s.execute("gradient.selectStop", &json!({"index": 0})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("shapeBuilder")); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + assert_eq!(s.journal.last().unwrap().0, "paint.sampleColor", "the pick samples into the selection's stop"); + // A pick armed for a stop of the tool's fill does not sample into a stop selected since on + // the selection's stroke: it ends. + s.select_tool("shapeBuilder", v).unwrap(); + s.fill_active = true; + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("shapeBuilder")); + s.fill_active = false; + let stops = json!([{"offset": 0, "color": "#0000ff"}, {"offset": 1, "color": "#000000"}]); + s.execute("paint.editGradient", &json!({"stroke": true, "stops": stops})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 0})).unwrap(); + let armed = art(&s); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + assert_eq!(art(&s), armed, "the selection's stroke keeps its stops"); + s.execute("gradient.selectStop", &json!({"index": null})).unwrap(); + // A pick armed for another tool is not that stop's: with no stop selected, its click copies + // the appearance as usual. + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("selection")); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + assert_eq!(s.journal.last().unwrap().0, "appearance.copyFrom"); + // Choosing another tool drops the stop a pick was armed for. + s.select_tool("shapeBuilder", v).unwrap(); + s.fill_active = true; + s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap(); + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + s.set_tool_option("stop", &json!("shapeBuilder")); + assert!(s.stop_pick.is_some(), "the pick is armed for the tool's stop"); + s.select_tool("selection", v).unwrap(); + assert!(s.stop_pick.is_none(), "another tool was chosen"); + // Armed while the Eyedropper waits for a Cmd-drag it lent the Selection tool to, the pick + // still ends once the Stroke proxy comes to the front. + s.select_tool("shapeBuilder", v).unwrap(); + s.fill_active = true; + s.execute("gradient.selectStop", &json!({"index": 1})).unwrap(); + s.select_tool("eyedropper", v).unwrap(); + let lent = s.make_tool("selection"); + s.lender = Some(std::mem::replace(&mut s.tool, lent)); + s.set_tool_options(Some("eyedropper"), json!({"stop": "shapeBuilder"}).as_object().unwrap()); + s.give_back_tool(v).unwrap(); + assert_eq!(s.tool_id(), "eyedropper"); + s.fill_active = false; + let (armed, journal) = (art(&s), s.journal.len()); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 25.0, 50.0), v).unwrap(); + } + assert_eq!(art(&s), armed, "the art keeps its paint (armed during a loan)"); + let ran: Vec<&str> = s.journal.since(journal).iter().map(|j| j.0.as_str()).collect(); + assert!(!ran.contains(&"appearance.copyFrom"), "{ran:?}"); +} + /// The colors of the cursor swatch preview's chips, left to right, and which one is ringed. fn swatch_chips(s: &mut Session, v: ViewInfo) -> Vec<([u8; 4], bool)> { let mut chips: Vec<(f64, [u8; 4], bool)> = s diff --git a/crates/engine/src/tests/paintopacity.rs b/crates/engine/src/tests/paintopacity.rs index c2e80f983a..8caada9e72 100644 --- a/crates/engine/src/tests/paintopacity.rs +++ b/crates/engine/src/tests/paintopacity.rs @@ -460,7 +460,7 @@ fn the_eyedropper_armed_for_the_bucket_answers_no_opacity() { s.select_tool("eyedropper", ViewInfo::default()).unwrap(); assert_eq!(proxies(&mut s)["fillOpacity"], 100.0, "the Eyedropper alone shows the selection's"); s.set_tool_option("stop", &json!("livePaintBucket")); - assert!(s.bucket_paints()); + assert!(s.tool_paints(false) && s.tool_paints(true)); assert_eq!(proxies(&mut s)["fillOpacity"], Value::Null); assert_eq!(proxies(&mut s)["strokeOpacity"], Value::Null); } diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index ec10fa5467..222657ac1c 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -222,6 +222,8 @@ impl Session { self.deactivate_tool(view)?; self.keep_tool_settings(); self.tool = self.make_tool(id); + // A pick is armed for a stop after its tool is chosen (`note_stop_pick`). + self.stop_pick = None; if let Some(selection) = text_selection { self.tool.set_option("textSelection", &selection); } @@ -460,7 +462,7 @@ impl Session { /// Pen goes on drawing its path), less the work the gesture ended as a command would: a /// Cmd+click that takes the type being edited out of the selection ends its edit (#3779). pub(crate) fn give_back_tool(&mut self, view: ViewInfo) -> Result<()> { - let lent_by_bucket = self.lent_by_bucket(); + let lent_by_painter = self.lent_by_painter(); let Some(lender) = self.lender.take() else { return Ok(()) }; // The points the lent tool left picked go back to the tool it was lent to when that tool // picks mesh points, none when it unpicked them all (#8090). Group Selection and the @@ -470,12 +472,12 @@ impl Session { .then(|| self.tool.options().get("meshPoints").cloned()) .flatten() .filter(|p| lender.options().get("meshPoints") != Some(p)); - // The lent tool's last actions (a drag it cancels or keeps) still count as the Live Paint - // Bucket's when the bucket lent it ([`Session::bucket_paints`]). - let outer_bucket = self.back_to_bucket; - self.back_to_bucket |= lent_by_bucket; + // The lent tool's last actions (a drag it cancels or keeps) still count as those of the tool + // that lent it when that tool paints with the chosen colors ([`Session::tool_paints`]). + let outer_painter = self.back_to_painter; + self.back_to_painter = self.back_to_painter.or(lent_by_painter); let r = self.deactivate_tool(view); - self.back_to_bucket = outer_bucket; + self.back_to_painter = outer_painter; self.keep_tool_settings(); self.tool = lender; // Back with the Selection or Group Selection tool, a symbol part the lent Direct @@ -572,6 +574,7 @@ impl Session { let Some(st) = self.active.and_then(|i| self.docs.get(i)) else { return R::default() }; let (unit, stroke_unit) = (self.general_unit(), self.stroke_unit()); let smart_guides = view.smart_guides && !view.pixel_preview; + let (pick_stop, armed_for_tool) = self.pick_stop(); let cx = ToolContext { doc: &st.doc, ruler_origin: st.doc.ruler_origin_for(view.artboard), @@ -597,7 +600,8 @@ impl Session { corner_widgets: view.corner_widgets, shape_widgets: view.shape_widgets, fill_active: self.fill_active, - gradient_stop: self.selected_stop(), + gradient_stop: pick_stop, + tool_paints: self.tool_paints(!self.fill_active) || armed_for_tool, appearance_item: self.appearance_item(), constrain_angle: self.prefs.constrain_angle, keyboard_increment: self.prefs.keyboard_increment, @@ -1491,6 +1495,7 @@ impl Session { let before_press = self.options_before_press_set(); let sets_pressed = self.press_taken_by(self.tool.id()); self.tool.set_option(key, v); + self.note_stop_pick(key, self.tool.id() == "eyedropper"); self.tool_set_since_reset = true; self.keep_tool_settings(); self.keep_press_set(before_press, |k| sets_pressed && k == key, sets_pressed); @@ -1578,9 +1583,35 @@ impl Session { Self::restore_stores(&self.prefs, self.tool.as_mut(), |store| settings::stores(set).any(|(s, _)| s == store)); } self.keep_press_set(before_press, |k| sets_pressed && values.contains_key(k), sets_pressed); + // The Eyedropper waiting for a Cmd-drag it lent a selection tool to is armed as the active one. + if (active || lender) && values.contains_key("stop") { + let eyedropper = id.unwrap_or(self.tool.id()) == "eyedropper"; + self.note_stop_pick("stop", eyedropper); + } out } + /// After option `key` of the active tool, or of the tool waiting for a Cmd-drag it lent, is set + /// (`eyedropper`: that tool is the Eyedropper): an Eyedropper armed to sample into a stop of the + /// gradient a tool paints with (`stop`) keeps whose gradient that is ([`Session::stop_pick`]). + fn note_stop_pick(&mut self, key: &str, eyedropper: bool) { + if key == "stop" && eyedropper { + let selected = self.selected_stop().is_some(); + self.stop_pick = self.gradient_stop.map(|(_, owner)| owner).filter(|owner| selected && owner.painter().is_some()); + } + } + + /// The stop an armed Eyedropper pick samples into ([`ToolContext::gradient_stop`]): the + /// selected one, and for a pick armed for a stop of the gradient a tool paints with + /// ([`Session::stop_pick`]) only a stop still selected on that gradient. + fn pick_stop(&self) -> (Option, bool) { + let armed = self.stop_pick.filter(|owner| self.tool.returns_to().is_some_and(|id| owner.painter() == Some(id))); + match armed { + Some(owner) => (self.selected_stop().filter(|_| self.gradient_stop.is_some_and(|(_, o)| o == owner)), true), + None => (self.selected_stop(), false), + } + } + /// The tool that took the press under way: the active tool, or the tool that lent a selection /// tool for it (a Cmd-drag), which the dropped press gives its options back to. fn pressed_tool(&self) -> Option<&dyn Tool> { @@ -1748,10 +1779,16 @@ impl Session { self.put_back_interaction(); } let outer = std::mem::replace(&mut self.in_tool_actions, true); - let outer_bucket = self.back_to_bucket; - // The Eyedropper's sample into a stop of the Live Paint Bucket's gradient, which switches back to the bucket. - self.back_to_bucket |= - self.tool.id() == "eyedropper" && acts.iter().any(|a| matches!(a, Action::SwitchTool(t) if t == crate::cmd::LIVE_PAINT_BUCKET)); + let outer_painter = self.back_to_painter; + // The Eyedropper's sample into a stop of the gradient of a tool that paints with the chosen + // colors (the Live Paint Bucket, the Shape Builder), which switches back to that tool. + if self.tool.id() == "eyedropper" { + let back = acts.iter().find_map(|a| match a { + Action::SwitchTool(t) => crate::cmd::painting_tool_of(t, false).or_else(|| crate::cmd::painting_tool_of(t, true)), + _ => None, + }); + self.back_to_painter = self.back_to_painter.or(back); + } // A preview that settling applied (typing kept as its own step before a drag begins) shows // its warning in the status bar, as the tool's own commit shows its preview's. let r = if !outer && self.depth == 0 { @@ -1761,7 +1798,7 @@ impl Session { self.apply_tool_actions(acts) }; self.in_tool_actions = outer; - self.back_to_bucket = outer_bucket; + self.back_to_painter = outer_painter; if !outer && self.depth == 0 { self.trim_histories(); } diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs index 4d27c8f8e8..c1a661c4e3 100644 --- a/crates/mcp/src/tests.rs +++ b/crates/mcp/src/tests.rs @@ -776,6 +776,15 @@ fn set_paint_reports_how_many_objects_it_painted() { assert_eq!(v["objects"], 2, "{v}"); let v = paint(&mut s, 16, json!({"strokeWidth": 2})); assert_eq!(v["objects"], 2, "{v}"); + + // While the Shape Builder is the active tool, the fill goes to new art only and the stroke to + // the selection: the reply names the command that painted nothing. + let r = call(&mut s, 17, "select_tool", json!({"tool": "shapeBuilder"})); + assert_eq!(r["isError"], false, "{r}"); + let v = paint(&mut s, 18, json!({"fill": "#ff00ff", "stroke": "#00ffff"})); + assert_eq!(v["objects"], 2, "{v}"); + assert_eq!(v["unpainted"], json!(["paint.setFill"]), "{v}"); + assert!(v["note"].as_str().is_some_and(|n| n.contains("Shape Builder")), "{v}"); } /// #1003: type made on or in a path takes add_text's `color` too, over the current fill. diff --git a/crates/mcp/src/tools/definitions.rs b/crates/mcp/src/tools/definitions.rs index 931e910315..d8d215b86e 100644 --- a/crates/mcp/src/tools/definitions.rs +++ b/crates/mcp/src/tools/definitions.rs @@ -282,7 +282,7 @@ pub fn tool_definitions() -> Vec { tool( "set_paint", "Set paint", - "Set fill, stroke and/or stroke weight on the selection (or `ids`) and as the default for new art. Returns {applied, objects}: `objects` counts the objects painted, as paint.setFill, paint.setStroke and stroke.set report them (the largest of their counts); when it is 0, a `note` says that only the default for new art changed.", + "Set fill, stroke and/or stroke weight on the selection (or `ids`) and as the default for new art. Returns {applied, objects}: `objects` counts the objects painted, as paint.setFill, paint.setStroke and stroke.set report them (the largest of their counts); when it is 0, a `note` says that only the default for new art changed, and when only some of those commands painted no object, `unpainted` lists them with a `note`.", obj( json!({ "fill": paint_schema("Fill"), diff --git a/crates/mcp/src/tools/dispatch.rs b/crates/mcp/src/tools/dispatch.rs index 12c3b24f37..752f72b928 100644 --- a/crates/mcp/src/tools/dispatch.rs +++ b/crates/mcp/src/tools/dispatch.rs @@ -183,11 +183,16 @@ fn dispatch(b: &mut dyn Backend, name: &str, a: &Args) -> Result Result<(Vec>, Map), Str } /// Sets the paint `a` gives on `ids` (default: the selection) and as the default for new art. -/// Returns the paint applied and the most objects one of its edits painted (the `objects` of the -/// `paint.setFill`, `paint.setStroke` and `stroke.set` replies). -pub(super) fn apply_paint(b: &mut dyn Backend, a: &Args, ids: Option) -> Result<(Value, u64), String> { +/// Returns the paint applied, the most objects one of its edits painted (the `objects` of the +/// `paint.setFill`, `paint.setStroke` and `stroke.set` replies) and the commands among them that +/// painted no object. +pub(super) fn apply_paint(b: &mut dyn Backend, a: &Args, ids: Option) -> Result<(Value, u64, Vec<&'static str>), String> { let (steps, applied) = paint_steps(a)?; - let mut objects = 0; + let (mut objects, mut unpainted) = (0, vec![]); for (cmd, mut p) in steps { if let Some(ids) = &ids { p["ids"] = ids.clone(); } let r = exec(b, cmd, p)?; - objects = objects.max(r.get("objects").and_then(Value::as_u64).unwrap_or(0)); + let n = r.get("objects").and_then(Value::as_u64).unwrap_or(0); + if n == 0 { + unpainted.push(cmd); + } + objects = objects.max(n); } - Ok((Value::Object(applied), objects)) + Ok((Value::Object(applied), objects, unpainted)) } /// Checks `draw_path` / `draw_shape`'s `dash`, `cap`, `join`, `opacity`, `name` and `effects` diff --git a/crates/tools/src/context.rs b/crates/tools/src/context.rs index bc0f822c06..67658b4ea9 100644 --- a/crates/tools/src/context.rs +++ b/crates/tools/src/context.rs @@ -228,8 +228,16 @@ pub struct ToolContext<'a> { pub shape_widgets: bool, /// Which paint proxy is in front (true = Fill): the one the Gradient tool edits. pub fill_active: bool, - /// The selected gradient stop (`gradient.selectStop`), marked on the gradient annotator. + /// The selected gradient stop (`gradient.selectStop`), marked on the gradient annotator. For + /// an Eyedropper pick armed for a stop of the gradient a tool paints with, only a stop still + /// selected on that gradient. pub gradient_stop: Option, + /// Is [`Self::paint`]'s paint behind the proxy in front ([`Self::fill_active`]) the color the + /// active tool, or the tool an armed one-shot pick returns to, paints with (the Live Paint + /// Bucket's fill and stroke, the Shape Builder's fill), or was the pick armed for a stop of + /// that tool's paint? A pick armed for such a stop then ends once [`Self::gradient_stop`] no + /// longer names it, also after the stop was cleared or the other proxy came to the front. + pub tool_paints: bool, /// The Appearance panel's active fill/stroke (paint-order index into the first selected /// object's stack); paint tools show and edit that item. pub appearance_item: Option, diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 486de86876..acc5ff594e 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -639,6 +639,7 @@ pub(crate) mod testutil { shape_widgets: true, fill_active: true, gradient_stop: None, + tool_paints: false, appearance_item: None, constrain_angle: 0.0, keyboard_increment: 1.0, diff --git a/crates/tools/src/xform/eyedropper.rs b/crates/tools/src/xform/eyedropper.rs index 0c63f2f21c..134b9b6069 100644 --- a/crates/tools/src/xform/eyedropper.rs +++ b/crates/tools/src/xform/eyedropper.rs @@ -16,8 +16,9 @@ //! //! The Gradient panel's eyedropper sets the `stop` option (the tool to return to): the next click //! samples the colour under the cursor into the selected gradient stop (`paint.sampleColor -//! {stop}`) and switches back to that tool. Armed for the Live Paint Bucket, a click once its stop -//! is no longer selected ends the pick without sampling and switches back to the bucket. +//! {stop}`) and switches back to that tool. Armed for a stop of the gradient a tool paints with +//! (the Live Paint Bucket's, the Shape Builder's fill), a click once its stop is no longer +//! selected ends the pick without sampling and switches back to that tool. //! //! Gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso before switching //! to the Eyedropper stay picked (its `meshPoints` option), and go back to one of those tools @@ -559,9 +560,9 @@ impl Tool for EyedropperTool { self.brush_key_color = false; vec![Action::Dialog("brushKeyColor".into(), json!({ "color": color_json(&c) })), Action::SwitchTool(back)] } - Click::BackToBucket => { + Click::Back(back) => { self.stop = None; - vec![Action::SwitchTool("livePaintBucket".into())] + vec![Action::SwitchTool(back)] } Click::MeshPoints(id, points, color) => { let params = json!({ "id": id.0, "points": points, "color": color_json(&color), "keepModel": true }); @@ -691,8 +692,9 @@ enum Click { ImageTrace(Value), /// Brush Options › Key Color: this color, sampled from this object. BrushKeyColor(Color, NodeId), - /// A pick for a Live Paint Bucket stop that is no longer selected switches back unsampled. - BackToBucket, + /// A pick for a stop of the gradient a tool paints with (the Live Paint Bucket's, the Shape + /// Builder's fill) that is no longer selected switches back to that tool unsampled. + Back(String), /// The fill color goes to these points of this selected gradient mesh. MeshPoints(NodeId, Vec, Color), /// `appearance.copyFrom` this source, with `reverse` or `append` or neither. @@ -707,7 +709,7 @@ impl Click { /// The object of the document the click reads from or writes to. fn object(&self) -> Option { match self { - Click::ImageTrace(_) | Click::BackToBucket => None, + Click::ImageTrace(_) | Click::Back(_) => None, Click::BrushKeyColor(_, id) | Click::MeshPoints(id, ..) | Click::CopyFrom(id, _) | Click::Sample { source: id, .. } => Some(*id), } } @@ -728,13 +730,17 @@ impl EyedropperTool { let (c, source) = sample_at(cx, p)?; return Some(Click::BrushKeyColor(c, source)); } - // A pick for a stop of the Live Paint Bucket's gradient (the default paint's) ends without + // A pick for a stop of the gradient of a tool that paints with the chosen colors (the + // default paint's: the Live Paint Bucket's, or the Shape Builder's fill) ends without // sampling once that stop is no longer selected (a Cmd-click selected another object) or no // longer there (another paint was chosen): the click switches back. - let bucket_paint = if cx.fill_active { &cx.paint.fill } else { &cx.paint.stroke }; - let bucket_stop = cx.gradient_stop.filter(|i| matches!(bucket_paint, Paint::Gradient(g) if *i < g.gradient.stops.len())); - if self.stop.as_deref() == Some("livePaintBucket") && bucket_stop.is_none() { - return Some(Click::BackToBucket); + let tool_paint = if cx.fill_active { &cx.paint.fill } else { &cx.paint.stroke }; + let tool_stop = cx.gradient_stop.filter(|i| matches!(tool_paint, Paint::Gradient(g) if *i < g.gradient.stops.len())); + if cx.tool_paints + && tool_stop.is_none() + && let Some(back) = &self.stop + { + return Some(Click::Back(back.clone())); } let stop = self.stop.clone().zip(cx.gradient_stop); // A plain click on a selected gradient mesh gives the fill color to the point there, else @@ -934,19 +940,23 @@ mod tests { ] ); assert_eq!(t.options(), json!({"stop": null, "brushKeyColor": false}), "one sample only"); - // Armed for the Live Paint Bucket with its stop no longer selected, a click ends the pick. - cx.gradient_stop = None; - t.set_option("stop", &json!("livePaintBucket")); - let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 150.0)); - assert_eq!(a, vec![Action::SwitchTool("livePaintBucket".into())]); - assert_eq!(t.returns_to(), None); - // So does a click once the default paint has no such stop (here, a solid fill). - cx.gradient_stop = Some(1); - assert!(!matches!(cx.paint.fill, Paint::Gradient(_))); - t.set_option("stop", &json!("livePaintBucket")); - assert_eq!(t.returns_to(), Some("livePaintBucket")); - let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 150.0)); - assert_eq!(a, vec![Action::SwitchTool("livePaintBucket".into())]); + // Armed for a tool that paints with the chosen colors (the Live Paint Bucket, or the Shape + // Builder's fill) with its stop no longer selected, a click ends the pick. + cx.tool_paints = true; + for back in ["livePaintBucket", "shapeBuilder"] { + cx.gradient_stop = None; + t.set_option("stop", &json!(back)); + let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 150.0)); + assert_eq!(a, vec![Action::SwitchTool(back.into())]); + assert_eq!(t.returns_to(), None); + // So does a click once the default paint has no such stop (here, a solid fill). + cx.gradient_stop = Some(1); + assert!(!matches!(cx.paint.fill, Paint::Gradient(_))); + t.set_option("stop", &json!(back)); + assert_eq!(t.returns_to(), Some(back)); + let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 150.0)); + assert_eq!(a, vec![Action::SwitchTool(back.into())]); + } // Neither a Key Color pick nor an Image Trace ignored-color pick is a gradient stop's. t.set_option("brushKeyColor", &json!(true)); t.set_option("stop", &json!("livePaintBucket")); diff --git a/crates/ui-egui/src/dialogs/gradient_stop.rs b/crates/ui-egui/src/dialogs/gradient_stop.rs index d38eae5bb0..3ba900ff01 100644 --- a/crates/ui-egui/src/dialogs/gradient_stop.rs +++ b/crates/ui-egui/src/dialogs/gradient_stop.rs @@ -30,12 +30,12 @@ use craft::ui::text::NumberField; use egui::{Pos2, Ui, vec2}; use serde_json::{Value, json}; use vectorcraft_color::gradient::move_stop; -use vectorcraft_color::{Color, FreeformPoint, GradientKind, GradientStop, Paint}; +use vectorcraft_color::{Color, FreeformPoint, GradientStop, Paint}; use vectorcraft_geom::{Point, Rect}; use vectorcraft_tools::params::color_json; use crate::VectorcraftApp; -use crate::panels::gradient::{edit_point, set_stops, set_stops_keeping_models, shown_points}; +use crate::panels::gradient::{edit_point, edits_points, set_stops, set_stops_keeping_models, shown_points}; use crate::panels::{Live, active_paint, c32}; /// The dialog kind of the gradient stop popover. @@ -82,7 +82,7 @@ impl Target { fn selected(app: &VectorcraftApp) -> Option { let Paint::Gradient(g) = active_paint(app) else { return None }; - if g.gradient.kind == GradientKind::Freeform { + if edits_points(app, &g) { let f = shown_points(&g); let i = app.session.selected_freeform_point().filter(|i| *i < f.points.len())?; return Some(Target::Point(f.points[i], i)); @@ -390,7 +390,7 @@ pub(crate) fn open_at(app: &mut VectorcraftApp, index: usize, anchor: Anchor) { let Some(ctx) = app.ui_ctx.clone() else { return }; let Some(dialogs) = app.dialogs() else { return }; if let Paint::Gradient(g) = active_paint(app) - && g.gradient.kind != GradientKind::Freeform + && !edits_points(app, &g) && app.session.selected_stop() != Some(index) { // An index past the last stop selects nothing, and `selected` then finds nothing to edit. diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 1071d14108..fbf1be4ce8 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -527,10 +527,11 @@ pub(crate) fn current_paints(app: &VectorcraftApp) -> (Paint, Paint) { /// document revision, Appearance panel item and picked gradient mesh points (picking points /// changes no revision). pub(crate) fn mixed_paints(app: &VectorcraftApp, ctx: &egui::Context) -> (bool, bool) { - type Key = (u64, u64, Option, Vec<(NodeId, Vec)>, bool); + type Key = (u64, u64, Option, Vec<(NodeId, Vec)>, (bool, bool)); let Some(st) = app.session.active() else { return (false, false) }; - // Whether the proxies show the Live Paint Bucket's colors too. - let key: Key = (st.uid, st.revision, app.session.appearance_item(), app.session.fill_mesh_points(), app.session.bucket_paints()); + // Whether the proxies show the colors the active tool paints with (the Live Paint Bucket's, the Shape Builder's fill) too. + let tool = (app.session.tool_paints(false), app.session.tool_paints(true)); + let key: Key = (st.uid, st.revision, app.session.appearance_item(), app.session.fill_mesh_points(), tool); match pstate::>(ctx, "proxy-mixed") { Some((k, mixed)) if k == key => mixed, _ => { @@ -559,7 +560,7 @@ pub(crate) fn stroke_mixed(app: &VectorcraftApp, ctx: &egui::Context) -> StrokeM if character::text_editing(app).is_some() { return StrokeMixed { can_align: true, ..Default::default() }; } - if app.session.bucket_paints() { + if app.session.tool_paints(true) { return StrokeMixed { can_align: true, ..Default::default() }; } let Some(st) = app.session.active() else { return StrokeMixed::default() }; diff --git a/crates/ui-egui/src/panels/color.rs b/crates/ui-egui/src/panels/color.rs index 80f1be75a8..441200b9ee 100644 --- a/crates/ui-egui/src/panels/color.rs +++ b/crates/ui-egui/src/panels/color.rs @@ -27,7 +27,7 @@ use craft::ui::runtime::commands::CommandStates; use egui::Ui; use serde_json::{Map, Value, json}; use vectorcraft_color::cms; -use vectorcraft_color::{Color, GradientKind, Paint}; +use vectorcraft_color::{Color, Paint}; use super::{Live, active_paint, color_json, live_run, proxy_events}; use crate::VectorcraftApp; @@ -328,7 +328,9 @@ fn target_with(app: &VectorcraftApp, mixed: bool) -> Target { } let p = active_paint(app); match &p { - Paint::Gradient(g) if g.gradient.kind == GradientKind::Freeform => { + // A freeform gradient on art: its points. The one the active tool paints with has no points + // to edit (`paint.freeform.setPoint` refuses it), so its stops are edited below. + Paint::Gradient(g) if super::gradient::edits_points(app, g) => { // Like stops: without a selected point, the first. let f = super::gradient::shown_points(g); let index = app.session.selected_freeform_point().filter(|i| *i < f.points.len()).unwrap_or(0); diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 67e472fabb..b27c1906f5 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -1079,13 +1079,15 @@ fn hsl_rows(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cx: &Pic /// picks it), else that of the fill or stroke item /// ([`vectorcraft_engine::Session::proxy_opacity`]), which nothing selected and type characters /// do not have. A stop or point of a gradient on type characters belongs to the gradient, so the -/// row sets it. With nothing selected, or while the Live Paint Bucket paints -/// ([`vectorcraft_engine::Session::bucket_paints`]), the stop or point belongs to the defaults for -/// new art, which the row leaves alone, and an object selected in a symbol instance has no opacity -/// the row can set. +/// row sets it. With nothing selected, or while the active tool paints with the chosen fill or +/// stroke of the proxy in front ([`vectorcraft_engine::Session::tool_paints`]: the Live Paint +/// Bucket's, the Shape Builder's fill), the stop or point belongs to the defaults for new art, +/// which the row leaves alone, and an object selected in a symbol instance has no opacity the row +/// can set. fn shown_opacity(app: &VectorcraftApp, tgt: &Target) -> (f32, bool) { let stroke = !app.session.fill_active; - let selected = !app.session.bucket_paints() && app.session.active().is_some_and(|d| !d.selection.is_empty() && d.selection.symbol_part.is_none()); + let selected = + !app.session.tool_paints(stroke) && app.session.active().is_some_and(|d| !d.selection.is_empty() && d.selection.symbol_part.is_none()); let point = |index: usize| match super::active_paint(app) { Paint::Gradient(g) => super::gradient::shown_points(&g).points.get(index).map(|p| p.opacity), _ => None, diff --git a/crates/ui-egui/src/panels/gradient.rs b/crates/ui-egui/src/panels/gradient.rs index dab46642a2..609056dffc 100644 --- a/crates/ui-egui/src/panels/gradient.rs +++ b/crates/ui-egui/src/panels/gradient.rs @@ -134,7 +134,7 @@ pub(crate) fn dropped_link(app: &VectorcraftApp, params: &Value) -> Option<(Stri /// is selected. pub(crate) fn recolor_selected(app: &mut VectorcraftApp, c: Color, params: &Value) -> bool { let Paint::Gradient(g) = active_paint(app) else { return false }; - if g.gradient.kind == GradientKind::Freeform { + if edits_points(app, &g) { let Some(i) = app.session.selected_freeform_point().filter(|i| *i < shown_points(&g).points.len()) else { return false }; edit_point(app, "paint.freeform.setPoint", json!({ "index": i, "color": super::color_json(&c), "keepModel": true })); return true; @@ -203,6 +203,13 @@ pub(crate) fn draw_radios(app: &mut VectorcraftApp, ui: &mut Ui) { }); } +/// Do the panel, the stop popover and swatch drops edit the points of `g`, the gradient behind +/// the active proxy? Only for a freeform gradient on art: the one the active tool paints with +/// lies on no object, so its stops stand for its colors, as in the Color panel. +pub(crate) fn edits_points(app: &VectorcraftApp, g: &GradientPaint) -> bool { + g.gradient.kind == GradientKind::Freeform && !app.session.tool_paints(!app.session.fill_active) +} + /// The gradient behind the active proxy. fn current(app: &VectorcraftApp) -> Option { match active_paint(app) { @@ -316,8 +323,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) { }); }); let freeform = is_grad && kind == GradientKind::Freeform; + let points = is_grad && edits_points(app, &g); if hidden { - if !freeform { + if !points { stops_editor(app, ui, &g, is_grad); } return; @@ -341,10 +349,18 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) { }); // Along and across, the gradient follows the path: its angle and aspect ratio don't apply. let placed = stroke_mode.is_none_or(|m| m == StrokeGradientMode::Within); - if freeform { + if points { freeform_rows(app, ui, &g); return; } + // A freeform gradient the active tool paints with: the proxy and the Draw toggle, its stops and + // their fields. + if freeform { + draw_row(app, ui, shown_points(&g).mode); + stops_editor(app, ui, &g, is_grad); + host_fields(app, ui, &g.gradient, is_grad); + return; + } method_select(app, ui, &g, is_grad); spread_select(app, ui, &g, is_grad); // The proxy beside the angle and aspect ratio fields. @@ -537,10 +553,8 @@ pub(crate) fn edit_point(app: &mut VectorcraftApp, cmd: &str, mut params: Value) live_run(app, "Gradient", cmd, params, Live::Released); } -/// The freeform section: the proxy beside the Draw toggle, then the selected point's colour -/// (click: its popover, as a stop's), opacity and spread, and Delete Point. -fn freeform_rows(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint) { - let f = shown_points(g); +/// The proxy beside the Draw toggle of a freeform gradient, whose mode is `mode`. +fn draw_row(app: &mut VectorcraftApp, ui: &mut Ui, mode: FreeformMode) { let modes = icon_entries([ (FreeformMode::Points, "circle", tl!("Points: clicks add free points")), (FreeformMode::Lines, "spline", tl!("Lines: clicks add points joined by a line")), @@ -548,11 +562,18 @@ fn freeform_rows(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint) { Row::new().show(ui, |ui, _| { super::proxy(app, ui); Text::new(tl!("Draw:")).shade(Shade::Muted).show(ui); - let pick = Segmented::new(tl!("Draw"), Bind::given(f.mode), &modes).show(ui); + let pick = Segmented::new(tl!("Draw"), Bind::given(mode), &modes).show(ui); if let Some(m) = pick.events.committed() { set_draw_mode(app, *m); } }); +} + +/// The freeform section: the proxy beside the Draw toggle, then the selected point's colour +/// (click: its popover, as a stop's), opacity and spread, and Delete Point. +fn freeform_rows(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint) { + let f = shown_points(g); + draw_row(app, ui, f.mode); let sel = app.session.selected_freeform_point().filter(|i| *i < f.points.len()); let point = sel.and_then(|i| f.points.get(i)).copied(); Row::new().show(ui, |ui, _| { diff --git a/crates/ui-egui/src/panels/gradient/tests.rs b/crates/ui-egui/src/panels/gradient/tests.rs index 16f99658bc..9a71052c7c 100644 --- a/crates/ui-egui/src/panels/gradient/tests.rs +++ b/crates/ui-egui/src/panels/gradient/tests.rs @@ -38,6 +38,34 @@ fn a_swatch_color_on_a_stop_or_a_point_keeps_its_model_in_a_cmyk_document() { assert_eq!(g.freeform.map(|f| f.points[1].color), Some(orange)); } +/// While the Shape Builder paints with a freeform fill, which lies on no object, the panel shows +/// that fill's stops, and a swatch color recolors the selected stop instead of a point. Lines +/// mode gives the fill a freeform state without points, which the stops edit keeps. +#[test] +fn the_shape_builders_freeform_fill_is_edited_by_its_stops() { + let mut app = app(json!({"color": "#000000"})); + app.select_tool("shapeBuilder"); + app.run("paint.editGradient", json!({"stroke": false, "kind": "freeform", "mode": "lines"})).unwrap(); + let stops = json!([{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#0000ff"}]); + app.run("paint.editGradient", json!({"stroke": false, "stops": stops})).unwrap(); + let Paint::Gradient(g) = active_paint(&app) else { panic!("the tool's fill is not a gradient") }; + assert_eq!(g.freeform.as_ref().map(|f| (f.points.len(), f.mode)), Some((0, FreeformMode::Lines))); + assert_eq!(g.gradient.stops[0].color, Color::rgb8(255, 0, 0), "the stops edit keeps the supplied stops"); + app.run("gradient.selectStop", json!({"index": 1})).unwrap(); + let orange = Color::rgb8(255, 128, 0); + assert!(recolor_selected(&mut app, orange, &json!({})), "the selected stop takes the color"); + let Paint::Gradient(g) = active_paint(&app) else { panic!("the tool's fill is not a gradient") }; + assert_eq!(g.gradient.kind, GradientKind::Freeform); + assert_eq!(g.gradient.stops[0].color, Color::rgb8(255, 0, 0)); + assert_eq!(g.gradient.stops[1].color, orange); + assert_eq!(g.freeform.map(|f| f.mode), Some(FreeformMode::Lines)); + let rig = Rig::new(app); + for label in ["Draw", "Location", "Opacity", "Delete Stop"] { + let _ = rig.target(label); + } + assert!(rig.fixture.by_label("Delete Point").is_none(), "no point controls for the tool's fill"); +} + /// In a CMYK document Add to Swatches and Save to Swatches keep the gradient's RGB stops RGB. #[test] fn a_gradient_saved_as_a_swatch_keeps_its_stops_models_in_a_cmyk_document() { diff --git a/crates/ui-egui/src/panels/stroke.rs b/crates/ui-egui/src/panels/stroke.rs index f8075494f9..e47111a613 100644 --- a/crates/ui-egui/src/panels/stroke.rs +++ b/crates/ui-egui/src/panels/stroke.rs @@ -587,7 +587,7 @@ pub fn paint_profile(cx: &ContentPainterCx, rect: Rect, points: Option<&[(f64, f /// first member's. pub(crate) fn brush_keeps_size(app: &mut VectorcraftApp, shown: Option<&StrokeLayer>) -> Option { let st = app.session.active()?; - let bucket = app.session.bucket_paints(); + let bucket = app.session.tool_paints(true); if bucket || (st.selection.objects.is_empty() && st.selection.subjects().is_empty()) { let s = shown?; let name = s.brush.as_deref()?; diff --git a/docs/mcp.md b/docs/mcp.md index ef84276845..1f8a2f6e2e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -747,7 +747,7 @@ ends the wait, so the sampler can be shown again. The BSDs and headless sessions | `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,wheel?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. Remote, the events wait until the keys and other input sent before them (`press_key`, `type_text`) have reached the app, so a key pressed between two calls of one drag applies before the release. When that input is dropped because the document, a dialog or the focus changed first, the call fails and its events are not sent. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. | | `draw_path` | `{points \| d, closed?, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `points` is `[[x,y],…]` or `[{x,y,in?,out?,smooth?},…]`. `d` is SVG path data. The options are below. | | `draw_shape` | `{shape, …geometry, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `rectangle`/`ellipse`: `x,y,width,height` (plus `radius` for corners; an ellipse takes `anchors`, 2–1000, default 4). `polygon`: `cx,cy,radius,sides`. `star`: `cx,cy,radius1,radius2,points`. Polygons and stars take `rotation` in degrees clockwise (0: a corner or point straight up). `line`: `x1,y1,x2,y2`. | -| `set_paint` | `{fill?, stroke?, strokeWidth?, ids?}` | Applies to the selection (or `ids`) and becomes the default for new art. Returns `{applied, objects}`: `objects` is the number of objects painted, as the `objects` of the `paint.setFill`, `paint.setStroke` and `stroke.set` replies (the largest of them): a selected group counts the objects inside it. When it is 0, a `note` says that only the paint for new art changed. | +| `set_paint` | `{fill?, stroke?, strokeWidth?, ids?}` | Applies to the selection (or `ids`) and becomes the default for new art. Returns `{applied, objects}`: `objects` is the number of objects painted, as the `objects` of the `paint.setFill`, `paint.setStroke` and `stroke.set` replies (the largest of them): a selected group counts the objects inside it. When it is 0, a `note` says that only the paint for new art changed. When some of those commands painted objects and others painted none (a fill while the Shape Builder is the active tool, say), `unpainted` lists the commands that painted none, with a `note`. | | `press_key` | `{key, mods?}` | Remote: a real key event. Headless: runs the command or tool bound to that shortcut, or sends the key to the busy tool (digits too: `5` while dragging with the Perspective Selection tool; `e` while dragging a Selection or Group Selection marquee; `c` and `f` while dragging out an arc; `f`, `v`, `x` and `c` while dragging out a rectangular or polar grid). | | `type_text` | `{text}` | Remote only. | | `answer_dialog` | `{set?: [{field, value?}], action?}` | Remote only. Sets fields of the app's open dialog in the order given with one `ui.dialog.set {fields, action?}` (a missing `value` is `null`). The app stores all of them or none, then answers that same dialog with `action` in the same request: `confirm` (OK) or `cancel`. Another connection cannot open a dialog between the two steps. When the app refuses the `ui.dialog.set`, for example because no dialog is open, the call is an error and the dialog is not confirmed or canceled. `set` cannot change a `__` field other than the dialog's controls held under a `__` name (such as Save PDF's `__section` or the Preferences `__search`): the `__command` and `__params` of a `confirm` or `command` dialog, and every other `__` field that holds what OK acts on, are refused with "the `` dialog cannot set protected field ``", so OK runs what the dialog was opened for. `action` alone is sent as `ui.dialog.confirm` or `ui.dialog.cancel`. Give `set`, `action` or both; `set` holds at most 256 fields. `inspect_ui` shows the open dialog and its fields as `ui.dialog`. Returns `{dialog, result}`: the dialog after the fields were set (or `null`) and the reply to `confirm` or `cancel` (or `null`). After `invoke_menu` `app.quit`, `file.close` or `file.closeAll` replies `{"pending": "saveChanges"}`, `{action: "confirm"}` saves, `{set: [{field: "discard", value: true}], action: "confirm"}` closes without saving and `{action: "cancel"}` cancels the close or quit. | @@ -4154,9 +4154,10 @@ already walks Image Trace. Short agent entry points: moving and transforming, `path.moveAnchors`, `file.place` with `replace`, Puppet Warp, Delete and Cut, Group, Hide, Lock, Arrange, Expand, Recolor Artwork, plug-in filters, effects, the gradient commands, `gradient.selectStop`, the Appearance panel's rows and - `symbol.instance.setAppearance`. While the Live Paint Bucket is the active tool, `paint.editGradient` and - `gradient.presets.apply` without `ids`, `id` or `item` change the bucket's gradient instead, and - `gradient.selectStop` selects a stop of it. A Cmd-drag that lends the Selection or Group Selection tool selects the + `symbol.instance.setAppearance`. While the Live Paint Bucket, or for a fill the Shape Builder, is the active tool, + `paint.editGradient` and `gradient.presets.apply` without `ids`, `id` or `item` change the gradient the tool paints + with instead, and `gradient.selectStop` selects a stop of it. + A Cmd-drag that lends the Selection or Group Selection tool selects the instance whole first and moves it. `swatch.unused` and `recolor.colors` count the fills and strokes an instance keeps for objects of its art. Commands that change nothing in the document, such as `attributes.info`, `css.selection`, `css.export`, `effect.list` and `object.expand.info`, read the instance. These commands do not check for a selected object and use the instance: @@ -14083,8 +14084,19 @@ pointer show the current fill and the swatches before and after it), `selection` `straightLine`: a drag touches what the line from its first point to the pointer crosses), `highlightFill` (on by default; when it is off, merge mode shades no regions), `gapDetection` (off) with `gapLength` (pt, 0 to 72; 3), `clickStrokeSplitsPath` (In Merge Mode, Clicking Stroke Splits the Path; off), `highlightStroke` (Highlight Stroke When Editable; on) and `highlightColor` -(`#rrggbb` or a layer color's name; `#ff4f4f`, the layer color Red). The dialog's OK gives an error for a -`highlightColor` with an alpha part (`#rrggbbaa` or `#rgba`) and changes nothing. `tool.setOption` gives an error that +(`#rrggbb` or a layer color's name; `#ff4f4f`, the layer color Red). While the Shape Builder is the active tool, with +either `pickColorFrom`, a fill chosen without `ids`, `id` or `item` (`paint.setFill`, `paint.none`, `paint.lastColor`, +`paint.lastGradient`, `paint.editGradient`, `paint.invert`, `paint.complement`, `paint.sampleColor` and +`gradient.presets.apply` on the fill, a swatch or the Color Picker), changes only the current fill: the selected paths +keep their paint, and no undo step is recorded. With `swatches` the next merge fills with that fill; with `artwork` +merges still take the look of the art. The Fill proxy shows that fill, the `paint.freeform.*` commands on the fill give +an error, as with the Live Paint Bucket, and the fill a new selection shows does not replace it for new art. A stroke +chosen then (`paint.setStroke`, `stroke.set` and the other stroke commands) still goes to the selection. `paint.swap` +and `paint.default` without `ids` or `id` change only the paint for new art (`paint.default` resets all of it): the +selected paths keep their fills and strokes, and `paint.swap` gives the current fill the stroke the Stroke proxy shows +(the stroke for new art when the proxy shows mixed strokes). With New Art Has Basic Appearance off, the stroke for new +art then follows the selection again, as after any command. The dialog's OK gives an error for a `highlightColor` with +an alpha part (`#rrggbbaa` or `#rgba`) and changes nothing. `tool.setOption` gives an error that names the option and sets none of the values, whether the tool is chosen or not, for a switch that is not `true` or `false`, a `pickColorFrom` other than `artwork` or `swatches`, a `selection` other than `freeform` or `straightLine`, a `gapLength` that is not a number, a `highlightColor` that is not `#rrggbb`, `#rgb` (with or without `#`), a layer