mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #8628 from dotCooCoo/fix/live-paint-bucket-fill-color
Live Paint: a color chosen with the Live Paint Bucket is the color it paints with
This commit is contained in:
@@ -850,6 +850,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;
|
||||
pub use plugin_call::{Location, ParamsPlace, key_location, location_in, location_keys};
|
||||
pub use select::SIMILAR;
|
||||
pub(crate) use vectorcraft_doc::range::parse_range;
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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), 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?, 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. 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",
|
||||
"{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), 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?, 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. 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), only the default changes (the paint the bucket paints with)",
|
||||
has_doc,
|
||||
edit_gradient
|
||||
),
|
||||
@@ -42,7 +42,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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 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 → {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 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}",
|
||||
always,
|
||||
select_stop
|
||||
),
|
||||
@@ -61,7 +61,9 @@ pub(crate) fn active_gradient(s: &Session) -> Option<GradientPaint> {
|
||||
fn select_stop(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "gradient.selectStop";
|
||||
// No document is needed for the default paint's gradient, so this does not use `refuse_symbol_part`.
|
||||
if 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, whose stops can be
|
||||
// selected with a part picked.
|
||||
if s.tool_id() != super::paint::LIVE_PAINT_BUCKET && s.active().is_some_and(|st| st.selection.symbol_part.is_some()) {
|
||||
return Err(super::brushsym::part_only());
|
||||
}
|
||||
let index = match p.get("index") {
|
||||
@@ -82,8 +84,10 @@ fn select_stop(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
/// 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 and the Appearance panel's active item. Selecting other art, picking a part of the
|
||||
/// instance, toggling the proxy or picking another item leaves no stop selected.
|
||||
/// 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.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) struct StopOwner {
|
||||
doc: Option<usize>,
|
||||
@@ -91,6 +95,7 @@ pub(crate) struct StopOwner {
|
||||
part: bool,
|
||||
fill: bool,
|
||||
item: Option<usize>,
|
||||
bucket: bool,
|
||||
}
|
||||
|
||||
impl StopOwner {
|
||||
@@ -102,6 +107,7 @@ impl StopOwner {
|
||||
part: st.is_some_and(|d| d.selection.symbol_part.is_some()),
|
||||
fill: s.fill_active,
|
||||
item: s.appearance_item(),
|
||||
bucket: s.tool_id() == super::paint::LIVE_PAINT_BUCKET,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -525,6 +531,9 @@ fn apply_gradient_edit_in_model(
|
||||
|
||||
fn edit_gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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);
|
||||
let item = item_target(s, p, C)?;
|
||||
let stroke = edits_stroke(s, p, item, !s.fill_active, C)?;
|
||||
check_switches(p, &["reverse", "dither"], C)?;
|
||||
@@ -619,7 +628,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})?;
|
||||
if let Some(m) = mode
|
||||
&& !selected
|
||||
&& p.get("ids").is_none()
|
||||
&& (bucket.is_some() || p.get("ids").is_none())
|
||||
&& let Some(st) = s.new_art_stroke_mut()
|
||||
{
|
||||
st.gradient_mode = m;
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Apply Gradient Preset",
|
||||
[],
|
||||
None,
|
||||
"{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, 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 → {name, ids: the objects painted (none: only the default changed)}",
|
||||
"{name: a preset's name (gradient.presets.list), stroke?, item?, ids?|id?, 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), only the default changes, by the active proxy) → {name, ids: the objects painted (none: only the default changed)}",
|
||||
has_doc,
|
||||
apply
|
||||
),
|
||||
@@ -207,6 +207,10 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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);
|
||||
let stroke = edits_stroke(s, p, item_target(s, p, C)?, !s.fill_active, C)?;
|
||||
let g = &preset.gradient;
|
||||
let mut edit = p.clone();
|
||||
|
||||
@@ -206,9 +206,10 @@ impl Session {
|
||||
}
|
||||
|
||||
/// After each command: with New Art Has Basic Appearance off, new art takes the appearance of
|
||||
/// the first selected object (so the last selection's once nothing is selected).
|
||||
/// 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.
|
||||
pub(crate) fn inherit_new_art(&mut self) {
|
||||
if self.prefs.new_art_basic {
|
||||
if self.prefs.new_art_basic || self.tool_id() == super::paint::LIVE_PAINT_BUCKET {
|
||||
return;
|
||||
}
|
||||
let Some(st) = self.active() else { return };
|
||||
|
||||
@@ -14,6 +14,10 @@ use super::{
|
||||
};
|
||||
use crate::{DocState, EngineError};
|
||||
|
||||
/// The Live Paint Bucket's tool id. While it is active, a fill or stroke color chosen for no
|
||||
/// object in particular is the color it paints with ([`apply_paint`]).
|
||||
pub(crate) const LIVE_PAINT_BUCKET: &str = "livePaintBucket";
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![
|
||||
cmd!(
|
||||
@@ -21,7 +25,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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), ids?|id?, 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 or item are given), the paint goes to those characters 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 (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 → {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), ids?|id?, 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 or item are given), the paint goes to those characters 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 (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), only the default changes (the color the bucket paints with) and the selection keeps its paint → {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)
|
||||
),
|
||||
@@ -39,7 +43,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Swap Fill and Stroke",
|
||||
[],
|
||||
Some("Shift+X"),
|
||||
"{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. 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)",
|
||||
"{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. 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), only the defaults change",
|
||||
has_doc,
|
||||
swap
|
||||
),
|
||||
@@ -48,7 +52,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Default Fill and Stroke",
|
||||
[],
|
||||
Some("D"),
|
||||
"{ids?|id?} 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. 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)",
|
||||
"{ids?|id?} 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. 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), only the defaults change",
|
||||
has_doc,
|
||||
default_paint
|
||||
),
|
||||
@@ -69,7 +73,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"None",
|
||||
[],
|
||||
Some("/"),
|
||||
"{} set the active proxy (fill or stroke) to None, as paint.setFill or paint.setStroke with none does → {objects}",
|
||||
"{} 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, only the default changes) → {objects}",
|
||||
has_doc,
|
||||
|s, _| {
|
||||
let f = s.fill_active;
|
||||
@@ -96,7 +100,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
|
||||
"Invert",
|
||||
[],
|
||||
None,
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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) 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, 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?, 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) 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), 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)
|
||||
),
|
||||
@@ -105,7 +109,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
|
||||
"Complement",
|
||||
[],
|
||||
None,
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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; honours the Appearance panel's active item and a selected object of a dynamic symbol instance as paint.invert does; with nothing selected, the default; no undo step when no color changes → {changed}",
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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; 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), 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())
|
||||
),
|
||||
@@ -114,7 +118,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
|
||||
"Apply Last Color",
|
||||
[],
|
||||
Some(","),
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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 → {objects} (as paint.setFill)",
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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), to the default only) → {objects} (as paint.setFill)",
|
||||
has_doc,
|
||||
|s, p| {
|
||||
let paint = Paint::solid(s.last_solid);
|
||||
@@ -126,7 +130,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
|
||||
"Apply Last Gradient",
|
||||
[],
|
||||
Some("."),
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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 → {objects} (as paint.setFill)",
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, 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), 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())));
|
||||
@@ -196,8 +200,12 @@ 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.
|
||||
/// object as the instance draws it. None while the Live Paint Bucket is the active tool: the
|
||||
/// proxies show the colors it paints with.
|
||||
pub(crate) fn proxy_source(&self, stroke: bool) -> Option<(Cow<'_, Node>, Option<usize>)> {
|
||||
if self.tool_id() == LIVE_PAINT_BUCKET {
|
||||
return None;
|
||||
}
|
||||
let st = self.active()?;
|
||||
if let Some(part) = st.selected_symbol_part() {
|
||||
return Some((Cow::Owned(part), None));
|
||||
@@ -331,7 +339,11 @@ impl DocState {
|
||||
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`]).
|
||||
pub fn proxy_mixed(&self) -> (bool, bool) {
|
||||
if self.tool_id() == LIVE_PAINT_BUCKET {
|
||||
return (false, false);
|
||||
}
|
||||
self.active().map_or((false, false), |st| st.proxy_mixed_with(self.appearance_item(), &self.fill_mesh_points()))
|
||||
}
|
||||
}
|
||||
@@ -478,6 +490,8 @@ fn apply_to_proxy(s: &mut Session, p: &Value, paint: Paint, cmd: &str) -> Result
|
||||
/// remember the paint. Replies `{objects}`: how many objects took the paint.
|
||||
pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) -> Result<Value> {
|
||||
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 focus = switch_or(p, "focus", true, cmd)?;
|
||||
let span = spans_targets(p, &paint).map_err(|e| bad(cmd, e))?;
|
||||
// Characters selected with the Type tool take the paint, not the whole type object (#1063).
|
||||
@@ -682,6 +696,27 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
|
||||
Ok(json!({"objects": ids.iter().collect::<std::collections::BTreeSet<_>>().len()}))
|
||||
}
|
||||
|
||||
/// Is the Live Paint Bucket the active tool 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 {
|
||||
// A null `ids` or `id` is no target, as `given_nodes` reads it; `item: null` names the top row.
|
||||
s.tool_id() == LIVE_PAINT_BUCKET && ["ids", "id"].iter().all(|k| p.get(k).is_none_or(Value::is_null)) && p.get("item").is_none()
|
||||
}
|
||||
|
||||
/// `p` with `ids: []` 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.
|
||||
pub(crate) fn bucket_color_params(s: &Session, p: &Value, cmd: &str) -> Result<Option<Value>> {
|
||||
if !for_bucket(s, p) {
|
||||
return Ok(None);
|
||||
}
|
||||
super::appearance::aligned(p, cmd)?;
|
||||
super::appearance::targets_contents(p)?;
|
||||
let mut v = p.as_object().cloned().unwrap_or_default();
|
||||
v.insert("ids".into(), json!([]));
|
||||
Ok(Some(Value::Object(v)))
|
||||
}
|
||||
|
||||
/// The instance whose object is selected with Direct Selection, and that object's path
|
||||
/// ([`super::brushsym::selected_part`]), when `p` names no `ids`, `id` or `item`: the paint commands
|
||||
/// then change that object. A bad `target` or `aligned` is refused as it is for any other selection.
|
||||
@@ -987,6 +1022,8 @@ pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option<usize>
|
||||
}
|
||||
|
||||
fn swap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let bucket = bucket_color_params(s, p, "paint.swap")?;
|
||||
let p = bucket.as_ref().unwrap_or(p);
|
||||
let targets = paint_targets(s, p)?;
|
||||
let given = !targets.is_empty();
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets);
|
||||
@@ -1028,6 +1065,8 @@ fn swap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let bucket = bucket_color_params(s, p, "paint.default")?;
|
||||
let p = bucket.as_ref().unwrap_or(p);
|
||||
let targets = paint_targets(s, p)?;
|
||||
let given = !targets.is_empty();
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets);
|
||||
@@ -1078,6 +1117,8 @@ fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
/// 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<Value> {
|
||||
let bucket = bucket_color_params(s, p, cmd)?;
|
||||
let p = bucket.as_ref().unwrap_or(p);
|
||||
let stroke = stroke_param(s, p, cmd)?;
|
||||
// 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
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Stroke Options",
|
||||
["Window", "Stroke"],
|
||||
None,
|
||||
"{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", 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)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads → {objects: how many objects took the stroke options}",
|
||||
"{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", 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)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes, and the weight it writes to the topmost visible stroke, for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads. 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), only the stroke for new art changes (the bucket paints edges with its color and weight) → {objects: how many objects took the stroke options}",
|
||||
has_doc,
|
||||
stroke_set
|
||||
),
|
||||
@@ -31,7 +31,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Stroke Weight Up",
|
||||
[],
|
||||
Some("Cmd+Alt+."),
|
||||
"{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn. On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row 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) → {objects}",
|
||||
"{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn, and so while the Live Paint Bucket is the active tool and no ids or id are given (a null one counts as none). On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row 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) → {objects}",
|
||||
has_doc,
|
||||
|s, p| stroke_step(s, p, true)
|
||||
),
|
||||
@@ -49,7 +49,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Stroke Options",
|
||||
[],
|
||||
None,
|
||||
"{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn)",
|
||||
"{arrowScale?: [start %, end %], swapArrows?: bool, flipProfile?: \"along\"|\"across\", brush?: name|null, item?: stroke item index|null, aligned?: bool (as stroke.set), ids?|id?, target?: \"object\"|\"contents\"} Stroke panel extras (with nothing selected, all but brush set up the next object drawn, and so while the Live Paint Bucket is the active tool and no ids, id, item or brush are given, a null ids or id counting as none)",
|
||||
has_doc,
|
||||
stroke_advanced
|
||||
),
|
||||
@@ -233,9 +233,20 @@ fn own_stroke_or_leaves(s: &Session, p: &Value) -> Result<Vec<vectorcraft_doc::N
|
||||
fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "stroke.set";
|
||||
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 = bucket_p.is_some();
|
||||
let p = bucket_p.as_ref().unwrap_or(p);
|
||||
let item = item_target(s, p, C)?.of_kind(s, false);
|
||||
let mut ids = if item == ItemTarget::Top { own_stroke_or_leaves(s, p)? } else { item.targets(s, p)? };
|
||||
let new_art = no_targets(&ids, p);
|
||||
let mut ids = if bucket {
|
||||
vec![]
|
||||
} else if item == ItemTarget::Top {
|
||||
own_stroke_or_leaves(s, p)?
|
||||
} else {
|
||||
item.targets(s, p)?
|
||||
};
|
||||
let new_art = bucket || no_targets(&ids, p);
|
||||
let given = !ids.is_empty();
|
||||
// The art of a graph design in a series keeps the design's stroke.
|
||||
ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
|
||||
@@ -371,9 +382,14 @@ pub(crate) fn step_weight(w: f64, unit: Unit, up: bool) -> f64 {
|
||||
fn stroke_step(s: &mut Session, p: &Value, up: bool) -> Result<Value> {
|
||||
let c = if up { "stroke.weightUp" } else { "stroke.weightDown" };
|
||||
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 = bucket_p.is_some();
|
||||
let p = bucket_p.as_ref().unwrap_or(p);
|
||||
let item = item_target(s, p, c)?.of_kind(s, false);
|
||||
let ids = item.targets(s, p)?;
|
||||
if no_targets(&ids, p) {
|
||||
let ids = if bucket { vec![] } else { item.targets(s, p)? };
|
||||
if bucket || no_targets(&ids, p) {
|
||||
let w = step_weight(s.paint.stroke_width, unit, up);
|
||||
s.paint.stroke_width = w;
|
||||
if let Some(st) = s.new_art_stroke_mut() {
|
||||
@@ -415,10 +431,14 @@ impl Session {
|
||||
/// the first selected object's (a group's first painted object's) top stroke, type's first
|
||||
/// run's character stroke; with an object of a dynamic symbol instance selected
|
||||
/// ([`DocState::selected_symbol_part`]), that object's as the instance draws it; with nothing
|
||||
/// selected, the next object drawn's ([`Session::new_art_stroke`]). None without a document or
|
||||
/// the selection's stroke.
|
||||
/// selected, the next object drawn's ([`Session::new_art_stroke`]), and so while the Live Paint
|
||||
/// Bucket is the active tool (the stroke it paints with). None without a document or the
|
||||
/// selection's stroke.
|
||||
pub fn shown_stroke(&self) -> Option<StrokeLayer> {
|
||||
let st = self.active()?;
|
||||
if self.tool_id() == super::paint::LIVE_PAINT_BUCKET {
|
||||
return Some(self.new_art_stroke());
|
||||
}
|
||||
if let Some(part) = st.selected_symbol_part() {
|
||||
return node_stroke(&part);
|
||||
}
|
||||
@@ -568,9 +588,14 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if scale.is_none() && flip.is_none() && !swap && brush.is_none() {
|
||||
return Err(bad(C, "nothing to change"));
|
||||
}
|
||||
// As stroke.set: the stroke the Live Paint Bucket paints with changes; the selection keeps its own.
|
||||
// A brush still goes to the selection.
|
||||
let bucket_p = if brush.is_none() { super::paint::bucket_color_params(s, p, C)? } 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);
|
||||
let ids = item.targets(s, p)?;
|
||||
let new_art = no_targets(&ids, p);
|
||||
let ids = if bucket { vec![] } else { item.targets(s, p)? };
|
||||
let new_art = bucket || no_targets(&ids, p);
|
||||
// The art of a graph design in a series keeps the design's stroke.
|
||||
let ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
|
||||
let arrows_and_profile = |st: &mut StrokeLayer| {
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Sample Color",
|
||||
[],
|
||||
None,
|
||||
"{color (#rrggbbaa and #rgba are refused), stroke?: bool (default: whichever proxy is active), ids?, stop?: index, clearStroke?: bool} sample a color into the active fill/stroke (and the selection; `ids: []` changes only the paint default); `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); 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?, 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, `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); in a CMYK document an RGB color is stored as CMYK through the color settings, as paint.setFill stores it",
|
||||
has_doc,
|
||||
sample_color
|
||||
),
|
||||
|
||||
@@ -321,6 +321,9 @@ 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.
|
||||
let bucket = self.tool_id() == cmd::LIVE_PAINT_BUCKET;
|
||||
let (paint, restore_paint) = {
|
||||
let menu = self.menu.clone();
|
||||
let st = self.doc_mut()?;
|
||||
@@ -334,8 +337,10 @@ impl Session {
|
||||
st.doc = it.doc.clone();
|
||||
// A batch, or a preview that changed the new-art paints (a pattern rename), started from
|
||||
// the paints the interaction began with.
|
||||
let restore_paint =
|
||||
cmd == "command.batch" || it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch") || it.color_mode_paints.is_some();
|
||||
let restore_paint = bucket
|
||||
|| cmd == "command.batch"
|
||||
|| it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch")
|
||||
|| it.color_mode_paints.is_some();
|
||||
let paint = it.paint.clone();
|
||||
it.preview_paint = None;
|
||||
it.color_mode_paints = None;
|
||||
@@ -478,10 +483,13 @@ 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.
|
||||
let bucket = self.tool_id() == cmd::LIVE_PAINT_BUCKET;
|
||||
if let Some(paint) = self
|
||||
.active()
|
||||
.and_then(|st| st.interaction.as_ref())
|
||||
.filter(|it| it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch") || it.color_mode_paints.is_some())
|
||||
.filter(|it| bucket || it.preview.as_ref().is_some_and(|(id, _)| id == "command.batch") || it.color_mode_paints.is_some())
|
||||
.map(|it| it.paint.clone())
|
||||
{
|
||||
self.paint = paint;
|
||||
|
||||
@@ -3189,6 +3189,283 @@ fn live_paint_stroke_edge() {
|
||||
assert!(s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [300, 300]})).is_err());
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, a fill or stroke color chosen without `ids`, `id` or
|
||||
/// `item` becomes the color the bucket paints with: the selected Live Paint group and other
|
||||
/// selected art keep their paint, and the next bucket click paints one face in that color. Given
|
||||
/// `ids`, the paint still goes to those objects.
|
||||
#[test]
|
||||
fn live_paint_bucket_color_choice_leaves_the_selection_unpainted() {
|
||||
use vectorcraft_tools::builder::{edges, faces};
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
let rect_fill = node(&s, rect).appearance.fill_paint();
|
||||
s.execute("select.set", &json!({"ids": [g.0, rect.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
let before = node(&s, g);
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let magenta = Paint::solid(Color::from_hex("#ff00ff").unwrap());
|
||||
let r = s.execute("paint.setFill", &json!({"color": "#ff00ff"})).unwrap();
|
||||
assert_eq!(r["objects"], 0);
|
||||
s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap();
|
||||
assert_eq!(s.paint.fill, magenta, "the bucket's fill color");
|
||||
assert_eq!(s.paint.stroke, Paint::solid(Color::from_hex("#0000ff").unwrap()));
|
||||
assert_eq!(node(&s, g), before, "the group keeps its paint");
|
||||
assert_eq!(node(&s, rect).appearance.fill_paint(), rect_fill, "other selected art keeps its paint");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "no undo step");
|
||||
// The proxies show the bucket's colors, not the selection's.
|
||||
assert_eq!(s.proxy_paints(), (magenta.clone(), s.paint.stroke.clone()));
|
||||
assert_eq!(s.proxy_mixed(), (false, false));
|
||||
// Invert recolors the bucket's color, not the selection.
|
||||
s.execute("paint.invert", &json!({"stroke": false})).unwrap();
|
||||
assert_eq!(s.paint.fill, Paint::solid(Color::from_hex("#00ff00").unwrap()));
|
||||
assert_eq!(node(&s, g), before, "Invert leaves the group as it was");
|
||||
// A previewed color (the Color Picker) that is canceled puts the bucket's color back.
|
||||
s.begin_interaction("Fill Color").unwrap();
|
||||
s.preview("paint.setFill", &json!({"color": "#123456"})).unwrap();
|
||||
assert_eq!(s.paint.fill, Paint::solid(Color::from_hex("#123456").unwrap()));
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(s.paint.fill, Paint::solid(Color::from_hex("#00ff00").unwrap()), "the canceled color is not kept");
|
||||
// With New Art Has Basic Appearance off, the selection's appearance does not replace them.
|
||||
s.execute("appearance.setNewArtBasic", &json!({"on": false})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#ff00ff"})).unwrap();
|
||||
assert_eq!(s.paint.fill, magenta, "the bucket's fill color stays");
|
||||
// The bucket paints the face it clicks in the color chosen.
|
||||
let r = s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50]})).unwrap();
|
||||
let face = NodeId(r["face"].as_u64().unwrap());
|
||||
let gn = node(&s, g);
|
||||
assert_eq!(faces(&gn).iter().filter(|f| f.appearance.fill_paint() == magenta).map(|f| f.id).collect::<Vec<_>>(), vec![face]);
|
||||
assert!(edges(&gn).iter().all(|e| e.appearance.fill_paint().is_none()));
|
||||
// Named objects still take the paint.
|
||||
s.execute("paint.setFill", &json!({"color": "#00ff00", "ids": [rect.0]})).unwrap();
|
||||
assert_eq!(node(&s, rect).appearance.fill_paint(), Paint::solid(Color::from_hex("#00ff00").unwrap()));
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, each paint and stroke command run without `ids`, `id` or
|
||||
/// `item` changes only the fill, stroke or weight the bucket paints with: the selection keeps its
|
||||
/// paint and no undo step is recorded. Each command runs in its own session, and every command that
|
||||
/// fails is listed.
|
||||
#[test]
|
||||
fn live_paint_bucket_paint_and_stroke_commands_leave_the_selection_unpainted() {
|
||||
let red = Paint::solid(Color::from_hex("#ff0000").unwrap());
|
||||
let cyan = Paint::solid(Color::from_hex("#00ffff").unwrap());
|
||||
let blue = Color::from_hex("#0000ff").unwrap();
|
||||
let is_gradient = |p: &Paint| matches!(p, Paint::Gradient(_));
|
||||
type Check = Box<dyn Fn(&Session) -> bool>;
|
||||
let cases: Vec<(&str, Value, Check)> = vec![
|
||||
(
|
||||
"paint.swap",
|
||||
json!({}),
|
||||
Box::new({
|
||||
let red = red.clone();
|
||||
move |s: &Session| s.paint.stroke == red
|
||||
}),
|
||||
),
|
||||
("paint.default", json!({}), Box::new(|s: &Session| s.paint.fill == Paint::solid(Color::WHITE))),
|
||||
("paint.none", json!({}), Box::new(|s: &Session| s.paint.fill == Paint::None)),
|
||||
("paint.lastColor", json!({"stroke": false}), Box::new(move |s: &Session| s.paint.fill == Paint::solid(blue))),
|
||||
("paint.lastGradient", json!({"stroke": false}), Box::new(move |s: &Session| is_gradient(&s.paint.fill))),
|
||||
(
|
||||
"paint.complement",
|
||||
json!({"stroke": false}),
|
||||
Box::new({
|
||||
let cyan = cyan.clone();
|
||||
move |s: &Session| s.paint.fill == cyan
|
||||
}),
|
||||
),
|
||||
(
|
||||
"paint.sampleColor",
|
||||
json!({"color": "#00ffff", "stroke": false}),
|
||||
Box::new({
|
||||
let cyan = cyan.clone();
|
||||
move |s: &Session| s.paint.fill == cyan
|
||||
}),
|
||||
),
|
||||
// A null `ids` or `id` names no object, as it does for every other command.
|
||||
("paint.setFill", json!({"color": "#00ffff", "ids": null, "id": null}), Box::new(move |s: &Session| s.paint.fill == cyan)),
|
||||
("paint.editGradient", json!({"stroke": false, "angle": 45}), Box::new(move |s: &Session| is_gradient(&s.paint.fill))),
|
||||
(
|
||||
"paint.editGradient",
|
||||
json!({"stroke": true, "strokeMode": "along"}),
|
||||
Box::new(move |s: &Session| {
|
||||
is_gradient(&s.paint.stroke) && s.new_art_stroke().gradient_mode == vectorcraft_doc::StrokeGradientMode::Along
|
||||
}),
|
||||
),
|
||||
("stroke.set", json!({"weight": 5}), Box::new(|s: &Session| s.paint.stroke_width == 5.0 && s.shown_stroke().map(|st| st.width) == Some(5.0))),
|
||||
("stroke.weightUp", json!({}), Box::new(|s: &Session| s.paint.stroke_width == 3.0)),
|
||||
("stroke.weightDown", json!({}), Box::new(|s: &Session| s.paint.stroke_width == 1.0)),
|
||||
("stroke.set", json!({"weight": 6, "ids": null}), Box::new(|s: &Session| s.paint.stroke_width == 6.0)),
|
||||
("stroke.weightUp", json!({"id": null}), Box::new(|s: &Session| s.paint.stroke_width == 3.0)),
|
||||
(
|
||||
"stroke.setAdvanced",
|
||||
json!({"arrowScale": [150, 200]}),
|
||||
Box::new(|s: &Session| s.shown_stroke().map(|st| st.arrow_scale) == Some((150.0, 200.0))),
|
||||
),
|
||||
];
|
||||
let mut failed = vec![];
|
||||
for (cmd, params, check) in cases {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("select.set", &json!({"ids": [g.0, rect.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.paint.fill = red.clone();
|
||||
s.paint.stroke_width = 2.0;
|
||||
s.last_solid = blue;
|
||||
let (group, art) = (node(&s, g), node(&s, rect));
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
if let Err(e) = s.execute(cmd, ¶ms) {
|
||||
failed.push(format!("{cmd}: {e}"));
|
||||
continue;
|
||||
}
|
||||
if !check(&s) {
|
||||
failed.push(format!("{cmd}: the bucket's paint did not change as expected"));
|
||||
}
|
||||
if node(&s, g) != group || node(&s, rect) != art {
|
||||
failed.push(format!("{cmd}: the selection was painted"));
|
||||
}
|
||||
if s.doc().unwrap().history.undo.len() != steps {
|
||||
failed.push(format!("{cmd}: an undo step was recorded"));
|
||||
}
|
||||
}
|
||||
assert!(failed.is_empty(), "{failed:#?}");
|
||||
}
|
||||
|
||||
/// With the Live Paint Bucket active, objects named with `ids` still take a stroke, and a brush
|
||||
/// still goes to the selection.
|
||||
#[test]
|
||||
fn live_paint_bucket_named_objects_and_brushes_still_take_the_stroke() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("select.set", &json!({"ids": [g.0, rect.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 4, "ids": [rect.0]})).unwrap();
|
||||
assert_eq!(node(&s, rect).appearance.stroke_width(), 4.0);
|
||||
// A brush still goes to the selection.
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
s.execute("stroke.setAdvanced", &json!({"brush": "3 pt. Round"})).unwrap();
|
||||
assert_eq!(node(&s, rect).appearance.stroke().and_then(|st| st.brush.clone()).as_deref(), Some("3 pt. Round"));
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active and the Fill proxy is in front, a gradient preset and a
|
||||
/// color sampled into a gradient stop change the bucket's fill, even when the selection's active
|
||||
/// Appearance row is a stroke.
|
||||
#[test]
|
||||
fn live_paint_bucket_gradient_preset_and_sampled_stop_follow_the_active_proxy() {
|
||||
let mut s = session();
|
||||
live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
s.execute("appearance.setActiveItem", &json!({"index": 1})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.execute("paint.toggleActive", &json!({"fill": true})).unwrap();
|
||||
assert_eq!(s.appearance_item(), Some(1), "the stroke row stays active");
|
||||
let (art, stroke) = (node(&s, rect), s.paint.stroke.clone());
|
||||
s.execute("gradient.presets.apply", &json!({"name": "vignette"})).unwrap();
|
||||
let Paint::Gradient(g) = &s.paint.fill else { panic!("the bucket's fill is not a gradient") };
|
||||
assert_eq!(g.gradient.kind, vectorcraft_color::GradientKind::Radial);
|
||||
assert_eq!(s.paint.stroke, stroke, "the bucket's stroke stays");
|
||||
s.execute("paint.sampleColor", &json!({"color": "#00ffff", "stop": 0})).unwrap();
|
||||
let Paint::Gradient(g) = &s.paint.fill else { panic!("the bucket's fill is not a gradient") };
|
||||
assert_eq!(g.gradient.stops[0].color, Color::from_hex("#00ffff").unwrap(), "the sampled stop");
|
||||
assert_eq!(node(&s, rect), art, "the selection keeps its paint");
|
||||
}
|
||||
|
||||
/// A gradient stop selected on the selection's gradient is not selected once the Live Paint
|
||||
/// Bucket is active (its proxies show the default paint), and one selected on the bucket's
|
||||
/// gradient is not selected once another tool is chosen.
|
||||
#[test]
|
||||
fn live_paint_bucket_and_the_selection_keep_their_own_selected_stop() {
|
||||
let mut s = session();
|
||||
live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap();
|
||||
s.execute("gradient.selectStop", &json!({"index": 1})).unwrap();
|
||||
assert_eq!(s.selected_stop(), Some(1));
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
assert_eq!(s.selected_stop(), None, "the selection's stop is not the bucket's");
|
||||
s.execute("paint.editGradient", &json!({"stroke": false, "kind": "linear"})).unwrap();
|
||||
s.execute("gradient.selectStop", &json!({"index": 0})).unwrap();
|
||||
assert_eq!(s.selected_stop(), Some(0));
|
||||
s.select_tool("selection", ViewInfo::default()).unwrap();
|
||||
assert_eq!(s.selected_stop(), None, "the bucket's stop is not the selection's");
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, a paint or stroke command with a bad `target` or
|
||||
/// `aligned` is refused, as it is with the Selection tool, and the bucket's fill, stroke and weight
|
||||
/// stay.
|
||||
#[test]
|
||||
fn live_paint_bucket_refuses_a_bad_target_or_aligned() {
|
||||
let refused = [
|
||||
("paint.setFill", json!({"color": "#00ffff", "target": "bogus"})),
|
||||
("paint.invert", json!({"ids": null, "aligned": "bad"})),
|
||||
("paint.complement", json!({"aligned": "bad"})),
|
||||
("stroke.set", json!({"weight": 6, "target": "bogus"})),
|
||||
("stroke.set", json!({"weight": 6, "aligned": "bad"})),
|
||||
("stroke.weightUp", json!({"target": "bogus"})),
|
||||
("stroke.weightUp", json!({"aligned": "bad"})),
|
||||
("stroke.weightDown", json!({"target": "bogus"})),
|
||||
("stroke.weightDown", json!({"aligned": "bad"})),
|
||||
("paint.swap", json!({"aligned": "bad"})),
|
||||
("paint.default", json!({"target": "bogus"})),
|
||||
];
|
||||
for tool in ["selection", "livePaintBucket"] {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
|
||||
s.select_tool(tool, ViewInfo::default()).unwrap();
|
||||
let before = (s.paint.fill.clone(), s.paint.stroke.clone(), s.paint.stroke_width);
|
||||
for (cmd, p) in &refused {
|
||||
assert!(s.execute(cmd, p).is_err(), "{tool}: {cmd} {p}");
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone(), s.paint.stroke_width), before, "{tool}: {cmd} {p}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, each preview of a paint command in one interaction starts
|
||||
/// from the colors the interaction began with, so previewing a swap twice and committing swaps once.
|
||||
#[test]
|
||||
fn live_paint_bucket_previews_start_from_the_interaction_colors() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap();
|
||||
let (fill, stroke) = (s.paint.fill.clone(), s.paint.stroke.clone());
|
||||
s.begin_interaction("Swap").unwrap();
|
||||
s.preview("paint.swap", &json!({})).unwrap();
|
||||
s.preview("paint.swap", &json!({})).unwrap();
|
||||
s.commit_interaction().unwrap();
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone()), (stroke, fill), "one swap");
|
||||
}
|
||||
|
||||
/// A color chosen with the Live Paint Bucket is the current fill: a tool held for a moment (the
|
||||
/// Hand) and let go leaves it in place, so the bucket paints with it afterwards, with New Art Has
|
||||
/// Basic Appearance off and on.
|
||||
#[test]
|
||||
fn a_held_tool_keeps_the_live_paint_bucket_color() {
|
||||
for basic in [false, true] {
|
||||
let mut s = session();
|
||||
live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("paint.setFill", &json!({"color": "#00ff00", "ids": [rect.0]})).unwrap();
|
||||
s.execute("appearance.setNewArtBasic", &json!({"on": basic})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#ff00ff"})).unwrap();
|
||||
let magenta = Paint::solid(Color::from_hex("#ff00ff").unwrap());
|
||||
s.select_tool("hand", ViewInfo::default()).unwrap();
|
||||
assert_eq!(s.paint.fill, magenta, "basic {basic}: the Hand keeps the current fill");
|
||||
s.switch_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
assert_eq!(s.paint.fill, magenta, "basic {basic}: the bucket paints with its color");
|
||||
assert_eq!(s.proxy_paints().0, magenta, "basic {basic}: the Fill proxy shows it");
|
||||
assert_eq!(node(&s, rect).appearance.fill_paint(), Paint::solid(Color::from_hex("#00ff00").unwrap()), "basic {basic}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The undo and redo depths, the unsaved state and the revision of the active document.
|
||||
fn history_state(s: &Session) -> (usize, usize, bool, u64) {
|
||||
let st = s.doc().unwrap();
|
||||
|
||||
@@ -1154,6 +1154,39 @@ fn the_fill_and_stroke_proxies_show_the_picked_object() {
|
||||
assert_eq!(proxy_colors(&mut s), (Some("#0000ff".into()), None));
|
||||
}
|
||||
|
||||
/// With an object of a dynamic symbol instance picked and the Live Paint Bucket active, the stroke
|
||||
/// weight commands step the weight the bucket paints with and leave the instance as it is.
|
||||
#[test]
|
||||
fn live_paint_bucket_weight_steps_with_a_picked_symbol_object() {
|
||||
let mut s = session();
|
||||
let inst = pair(&mut s, "dynamic");
|
||||
s.execute("symbol.instance.selectPart", &json!({"id": inst.0, "path": [1]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.paint.stroke_width = 2.0;
|
||||
for (cmd, weight) in [("stroke.weightUp", 3.0), ("stroke.weightDown", 2.0)] {
|
||||
assert_eq!(s.execute(cmd, &json!({})).unwrap()["objects"], 0, "{cmd}");
|
||||
assert_eq!(s.paint.stroke_width, weight, "{cmd}");
|
||||
}
|
||||
assert_eq!(overrides(&s, inst), 0);
|
||||
}
|
||||
|
||||
/// With an object of a dynamic symbol instance picked and the Live Paint Bucket active, a gradient
|
||||
/// stop of the bucket's fill can be selected and cleared, and the instance keeps its art.
|
||||
#[test]
|
||||
fn live_paint_bucket_selects_its_gradient_stop_with_a_picked_symbol_object() {
|
||||
let mut s = session();
|
||||
let inst = pair(&mut s, "dynamic");
|
||||
s.execute("symbol.instance.selectPart", &json!({"id": inst.0, "path": [1]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.fill_active = true;
|
||||
s.execute("paint.editGradient", &json!({"kind": "linear"})).unwrap();
|
||||
s.execute("gradient.selectStop", &json!({"index": 1})).unwrap();
|
||||
assert_eq!(s.selected_stop(), Some(1));
|
||||
s.execute("gradient.selectStop", &json!({"index": null})).unwrap();
|
||||
assert_eq!(s.selected_stop(), None);
|
||||
assert_eq!(overrides(&s, inst), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selecting_a_guide_too_lets_go_of_the_picked_object() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -187,7 +187,7 @@ fn dispatch(b: &mut dyn Backend, name: &str, a: &Args) -> Result<ToolResult, Str
|
||||
let mut reply = json!({"applied": applied, "objects": objects});
|
||||
if objects == 0 {
|
||||
reply["note"] = json!(
|
||||
"no object was painted (nothing selected, or `ids` is empty or holds no object this paint applies to): only the paint for new art changed"
|
||||
"no object was painted (nothing selected, the Live Paint Bucket is the active tool and no `ids` were given, or `ids` is empty or holds no object this paint applies to): only the paint for new art changed"
|
||||
);
|
||||
}
|
||||
j(reply)
|
||||
|
||||
@@ -338,9 +338,10 @@ 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<usize>, Vec<(NodeId, Vec<usize>)>);
|
||||
type Key = (u64, u64, Option<usize>, Vec<(NodeId, Vec<usize>)>, &'static str);
|
||||
let Some(st) = app.session.active() else { return (false, false) };
|
||||
let key: Key = (st.uid, st.revision, app.session.appearance_item(), app.session.fill_mesh_points());
|
||||
// The tool too: while the Live Paint Bucket is active the proxies show its colors.
|
||||
let key: Key = (st.uid, st.revision, app.session.appearance_item(), app.session.fill_mesh_points(), app.session.tool_id());
|
||||
match pstate::<Option<(Key, (bool, bool))>>(ctx, "proxy-mixed") {
|
||||
Some((k, mixed)) if k == key => mixed,
|
||||
_ => {
|
||||
@@ -363,10 +364,15 @@ pub(crate) fn current_stroke(app: &VectorcraftApp) -> Option<StrokeLayer> {
|
||||
/// Which Stroke panel values the selection doesn't share and whether Align Stroke applies
|
||||
/// ([`vectorcraft_engine::DocState::stroke_mixed`]), cached per document revision. While the Type
|
||||
/// tool edits text, the selected characters' stroke shows as it is, and aligns to their glyphs.
|
||||
/// While the Live Paint Bucket is active, the panel shows the one stroke it paints with, as it does
|
||||
/// with nothing selected.
|
||||
pub(crate) fn stroke_mixed(app: &VectorcraftApp, ctx: &egui::Context) -> StrokeMixed {
|
||||
if character::text_editing(app).is_some() {
|
||||
return StrokeMixed { can_align: true, ..Default::default() };
|
||||
}
|
||||
if app.session.tool_id() == "livePaintBucket" {
|
||||
return StrokeMixed { can_align: true, ..Default::default() };
|
||||
}
|
||||
let Some(st) = app.session.active() else { return StrokeMixed::default() };
|
||||
let key = (st.uid, st.revision);
|
||||
match pstate::<Option<((u64, u64), StrokeMixed)>>(ctx, "stroke-mixed") {
|
||||
|
||||
@@ -500,14 +500,16 @@ pub(crate) const PROFILE_DROPDOWN_WIDTH: f32 = 100.0;
|
||||
|
||||
/// While a width profile changes none of the strokes the Profile list edits, because each draws
|
||||
/// with a brush: whether any of them has a profile. None while a profile changes one of them.
|
||||
/// With nothing selected the list sets up the next object drawn, whose stroke is `shown` (the
|
||||
/// stroke the panels show). Otherwise it edits the strokes `stroke.set` targets
|
||||
/// With nothing selected, and while the Live Paint Bucket is active, the list sets up the next
|
||||
/// object drawn, whose stroke is `shown` (the stroke the panels show). Otherwise it edits the
|
||||
/// strokes `stroke.set` targets
|
||||
/// ([`vectorcraft_engine::Session::brushed_strokes_profiled`], cached per document revision and
|
||||
/// active Appearance row), such as a selected group's own stroke while `shown` is its first
|
||||
/// member's.
|
||||
pub(crate) fn brush_keeps_size(app: &VectorcraftApp, ctx: &egui::Context, shown: Option<&StrokeLayer>) -> Option<bool> {
|
||||
let st = app.session.active()?;
|
||||
if st.selection.objects.is_empty() && st.selection.subjects().is_empty() {
|
||||
let bucket = app.session.tool_id() == "livePaintBucket";
|
||||
if bucket || (st.selection.objects.is_empty() && st.selection.subjects().is_empty()) {
|
||||
let s = shown?;
|
||||
let name = s.brush.as_deref()?;
|
||||
return super::brushes::document_brushes(st).iter().any(|b| b.name == name).then_some(s.profile.is_some());
|
||||
|
||||
@@ -139,6 +139,21 @@ fn dropdown_is_dimmed_while_the_brush_keeps_its_size() {
|
||||
assert_eq!(listed(&ctx, &mut app).len(), WidthProfile::PRESETS.len());
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, the dropdown follows the stroke the bucket paints with,
|
||||
/// not a selected line that draws with a brush.
|
||||
#[test]
|
||||
fn the_live_paint_bucket_stroke_decides_whether_the_dropdown_is_dimmed() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app_with_line();
|
||||
let id = app.session.active().unwrap().selection.objects[0].0;
|
||||
run(&mut app, "brush.apply", json!({"ids": [id], "name": "3 pt. Round"}));
|
||||
assert!(dimmed(&ctx, &app));
|
||||
app.session.select_tool("livePaintBucket", Default::default()).unwrap();
|
||||
assert!(current_stroke(&app).is_some_and(|s| s.brush.is_none()), "the bucket's stroke has no brush");
|
||||
assert!(!dimmed(&ctx, &app));
|
||||
assert_eq!(listed(&ctx, &mut app).len(), WidthProfile::PRESETS.len());
|
||||
}
|
||||
|
||||
/// With an Appearance panel stroke row active, the dropdown follows that row: a brushed row below
|
||||
/// a plain top stroke dims it, and the plain row does not.
|
||||
#[test]
|
||||
|
||||
@@ -121,6 +121,27 @@ fn align_stroke_styles_the_characters_the_type_tool_selects() {
|
||||
assert_eq!(aligns, [vectorcraft_doc::StrokeAlign::Outside, vectorcraft_doc::StrokeAlign::Center], "only the selected characters");
|
||||
}
|
||||
|
||||
/// While the Live Paint Bucket is active, the Stroke panel shows the one stroke the bucket paints
|
||||
/// with, even when the selected objects' strokes differ, as it does with nothing selected.
|
||||
#[test]
|
||||
fn the_stroke_panel_shows_the_live_paint_bucket_stroke_as_one_stroke() {
|
||||
let mut app = app_with_rect();
|
||||
let a = app.session.active().unwrap().selection.objects[0].0;
|
||||
let b = run(&mut app, "shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 40}))["id"].as_u64().unwrap();
|
||||
run(&mut app, "stroke.set", json!({"weight": 1, "ids": [a]}));
|
||||
run(&mut app, "stroke.set", json!({"weight": 7, "ids": [b]}));
|
||||
run(&mut app, "select.set", json!({ "ids": [] }));
|
||||
let none_selected = stroke_mixed(&app, &egui::Context::default());
|
||||
assert!(none_selected.can_align, "Align Stroke applies with nothing selected");
|
||||
run(&mut app, "select.set", json!({ "ids": [a, b] }));
|
||||
let mixed = stroke_mixed(&app, &egui::Context::default());
|
||||
assert!(mixed.weight, "the selection's weights differ");
|
||||
app.session.select_tool("livePaintBucket", Default::default()).unwrap();
|
||||
let mixed = stroke_mixed(&app, &egui::Context::default());
|
||||
assert_eq!(mixed, none_selected, "one stroke that Align Stroke applies to, as with nothing selected");
|
||||
assert_eq!(stroke::shown_weight(&app, current_stroke(&app).as_ref(), &mixed), Some(app.session.paint.stroke_width));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_weight_presets_run_from_a_quarter_point_to_a_hundred() {
|
||||
let pt = stroke::weight_presets(vectorcraft_doc::Unit::Points);
|
||||
|
||||
+18
-2
@@ -3891,8 +3891,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`. 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
|
||||
`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
|
||||
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:
|
||||
`edit.copy` copies the instance whole; `document.exportSelection`, `document.export` with `selectionOnly` and
|
||||
@@ -4681,6 +4683,20 @@ already walks Image Trace. Short agent entry points:
|
||||
another scope, or one that is not an array of the group's edge ids or names an edge twice, is an error and changes
|
||||
nothing. `livePaint.fill` and `livePaint.strokeEdge` refuse a `scope` other than `"one"` with `points`. Both replies add `count`, the number of
|
||||
faces or edges the click reaches, including those that already had the paint.
|
||||
While the Live Paint Bucket is the active tool, a fill or stroke color chosen without `ids`, `id` or `item`
|
||||
(`paint.setFill`, `paint.setStroke`, `paint.none`, `paint.lastColor`, `paint.lastGradient`, `paint.editGradient`,
|
||||
`paint.invert`, `paint.complement`, `paint.sampleColor`, `gradient.presets.apply`, a swatch or the Color Picker), and
|
||||
`paint.swap` or `paint.default` without `ids` or `id`, becomes the color the bucket paints with, and a stroke weight
|
||||
(`stroke.set`, `stroke.weightUp`, `stroke.weightDown`) becomes the weight it paints with. The selection keeps its
|
||||
paint, and no undo step is recorded. A null `ids` or `id` counts as left out. The Stroke panel's other options
|
||||
(`stroke.set`, `stroke.setAdvanced` without `brush`) change the stroke for new art and leave the selection as it is;
|
||||
the bucket takes only the color and weight of that stroke. A stop selected on the bucket's gradient
|
||||
(`gradient.selectStop`) is deselected when another tool is chosen, when the first selected object changes, when an
|
||||
object of a symbol instance's art is picked or released, when the other proxy comes to the front, and when the
|
||||
Appearance panel's active row changes. The Fill and Stroke proxies (`paint.proxies`) show those colors, never mixed, the Stroke panel shows
|
||||
that stroke as it does with nothing selected, and with New Art Has Basic Appearance off the selection's appearance
|
||||
does not replace them after a command. They are also the fill and stroke for new art, so another tool chosen
|
||||
afterwards keeps them until a command or a new selection changes them.
|
||||
With the Live Paint Bucket selected and no drag in progress, Left and Right without Shift, Alt or Cmd/Ctrl (which
|
||||
keep their shortcuts) run `paint.setFill {swatch, ids: []}` (or
|
||||
`paint.setStroke` when the Stroke proxy is in front) with the color swatch before or after the active paint in the
|
||||
|
||||
Reference in New Issue
Block a user