From 0daad87499236e6b968f5f6cab0d4215f05988fb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 08:50:04 -0800 Subject: [PATCH 1/7] Brushes: Options of Selected Object changes one brushed path's brush settings without changing the brush MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Brushes panel menu gains Options of Selected Object…. It opens the brush type's options dialog for the selected brushed paths, without the Name row, and OK stores the changed values on those paths' strokes only. The brush and its other strokes keep their settings. - brush.objectOptions {ids?, params?, reset?} sets the settings, clears them with reset, and returns them when given neither. It refuses params with reset, a selection with no brushed path, brushes of different types, a bristle brush, a field the type does not take and a value of the wrong kind. One undo step, none when nothing changes. - The stroke saves the settings as brush_options in the native file, and the brush renderer, the expansion of pattern tiles whose brushes vary at random and color conversion of Hue Shift keys read them. - Applying another brush, removing the brush or a brush change carried by Global Edit clears them; renaming the brush keeps them. - Docs: docs/mcp.md, docs/ui-parity.md; i18n rows for the new strings. --- crates/brush/src/lib.rs | 195 +++++++++++++++++- crates/brush/src/tests.rs | 61 ++++++ crates/doc/src/appearance/layers.rs | 6 + crates/engine/src/cmd/brushsym.rs | 13 +- crates/engine/src/cmd/brushsym/brushes.rs | 90 +++++++- crates/engine/src/cmd/buildcmds.rs | 1 + crates/engine/src/cmd/colormgmt.rs | 21 +- crates/engine/src/cmd/expand.rs | 18 +- crates/engine/src/cmd/globaledit.rs | 7 +- crates/engine/src/cmd/stroke.rs | 4 + crates/engine/src/tests/brushsym.rs | 110 ++++++++++ crates/engine/src/tests/globaledit.rs | 18 ++ crates/engine/src/tests/objexpand.rs | 22 ++ crates/engine/tests/command_sweep.rs | 11 + crates/mcp/src/ui_catalog.rs | 6 + .../ui-egui/src/dialogs/brush_art_options.rs | 14 +- crates/ui-egui/src/dialogs/brush_options.rs | 134 +++++++++++- .../src/dialogs/brush_options/tests.rs | 85 ++++++++ crates/ui-egui/src/i18n/bg.tsv | 2 + crates/ui-egui/src/i18n/bs.tsv | 2 + crates/ui-egui/src/i18n/ca.tsv | 6 + crates/ui-egui/src/i18n/cs.tsv | 6 + crates/ui-egui/src/i18n/da.tsv | 6 + crates/ui-egui/src/i18n/de.tsv | 6 + crates/ui-egui/src/i18n/el.tsv | 6 + crates/ui-egui/src/i18n/es.tsv | 6 + crates/ui-egui/src/i18n/fi.tsv | 6 + crates/ui-egui/src/i18n/fr.tsv | 6 + crates/ui-egui/src/i18n/gu.tsv | 2 + crates/ui-egui/src/i18n/hi.tsv | 6 + crates/ui-egui/src/i18n/hu.tsv | 6 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 6 + crates/ui-egui/src/i18n/ja.tsv | 6 + crates/ui-egui/src/i18n/ka.tsv | 6 + crates/ui-egui/src/i18n/ko.tsv | 6 + crates/ui-egui/src/i18n/nl.tsv | 6 + crates/ui-egui/src/i18n/pl.tsv | 6 + crates/ui-egui/src/i18n/pt-br.tsv | 6 + crates/ui-egui/src/i18n/ru.tsv | 6 + crates/ui-egui/src/i18n/sv.tsv | 6 + crates/ui-egui/src/i18n/tr.tsv | 6 + crates/ui-egui/src/i18n/uk.tsv | 6 + crates/ui-egui/src/i18n/vi.tsv | 6 + crates/ui-egui/src/i18n/zh-hans.tsv | 6 + crates/ui-egui/src/i18n/zh-hant.tsv | 6 + crates/ui-egui/src/menus/run.rs | 1 + crates/ui-egui/src/menus/state.rs | 1 + crates/ui-egui/src/menus/ui_commands.rs | 6 + crates/ui-egui/src/palette.rs | 1 + crates/ui-egui/src/panels/brushes.rs | 6 + docs/mcp.md | 16 +- docs/ui-parity.md | 1 + 53 files changed, 976 insertions(+), 24 deletions(-) diff --git a/crates/brush/src/lib.rs b/crates/brush/src/lib.rs index 0b48f586cd..7f83931f25 100644 --- a/crates/brush/src/lib.rs +++ b/crates/brush/src/lib.rs @@ -753,6 +753,185 @@ impl Brush { } } +// ---------- stroke options ---------- + +/// The Scatter brush fields a stroke can set for itself ([`BrushKind::stroke_option_keys`]). +#[derive(Serialize, Deserialize)] +struct ScatterOptions { + size: (f64, f64), + spacing: (f64, f64), + scatter: (f64, f64), + rotation: (f64, f64), + modes: Option<[Variation; 4]>, + rotation_relative_to_path: bool, + colorization: Colorization, +} + +/// The Art brush fields a stroke can set for itself. +#[derive(Serialize, Deserialize)] +struct ArtOptions { + width: f64, + width_mode: Option, + width_max: Option, + flip_along: bool, + flip_across: bool, + overlap: bool, + colorization: Colorization, +} + +/// The Pattern brush fields a stroke can set for itself. +#[derive(Serialize, Deserialize)] +struct PatternOptions { + scale: f64, + spacing: f64, + fit: PatternFit, + flip_along: bool, + flip_across: bool, + colorization: Colorization, +} + +impl BrushKind { + /// The definition fields, by their `brush.options` names, that one stroke can set for itself + /// (the Brushes panel's Options of Selected Object, [`StrokeLayer::brush_options`]). A Bristle + /// brush has none. + pub fn stroke_option_keys(&self) -> &'static [&'static str] { + match self { + BrushKind::Calligraphic(_) => &["angle", "roundness", "size", "variation", "modes"], + BrushKind::Scatter(_) => &["size", "spacing", "scatter", "rotation", "modes", "rotation_relative_to_path", "colorization"], + BrushKind::Art(_) => &["width", "width_mode", "width_max", "flip_along", "flip_across", "overlap", "colorization"], + BrushKind::Pattern(_) => &["scale", "spacing", "fit", "flip_along", "flip_across", "colorization"], + BrushKind::Bristle(_) => &[], + } + } + + /// The values of [`Self::stroke_option_keys`], as a JSON object. + fn option_values(&self) -> serde_json::Value { + let v = match self { + BrushKind::Calligraphic(c) => serde_json::to_value(c), + BrushKind::Scatter(s) => serde_json::to_value(ScatterOptions { + size: s.size, + spacing: s.spacing, + scatter: s.scatter, + rotation: s.rotation, + modes: s.modes, + rotation_relative_to_path: s.rotation_relative_to_path, + colorization: s.colorization, + }), + BrushKind::Art(a) => serde_json::to_value(ArtOptions { + width: a.width, + width_mode: a.width_mode, + width_max: a.width_max, + flip_along: a.flip_along, + flip_across: a.flip_across, + overlap: a.overlap, + colorization: a.colorization, + }), + BrushKind::Pattern(p) => serde_json::to_value(PatternOptions { + scale: p.scale, + spacing: p.spacing, + fit: p.fit, + flip_along: p.flip_along, + flip_across: p.flip_across, + colorization: p.colorization, + }), + BrushKind::Bristle(_) => Ok(serde_json::Value::Object(serde_json::Map::new())), + }; + v.unwrap_or_default() + } + + /// Set the values of [`Self::stroke_option_keys`] from `v` (as [`Self::option_values`] gives + /// them). An error when a value is of the wrong kind. + fn set_option_values(&mut self, v: serde_json::Value) -> Result<(), serde_json::Error> { + match self { + BrushKind::Calligraphic(c) => *c = serde_json::from_value(v)?, + BrushKind::Scatter(s) => { + let o: ScatterOptions = serde_json::from_value(v)?; + (s.size, s.spacing, s.scatter, s.rotation, s.modes) = (o.size, o.spacing, o.scatter, o.rotation, o.modes); + (s.rotation_relative_to_path, s.colorization) = (o.rotation_relative_to_path, o.colorization); + } + BrushKind::Art(a) => { + let o: ArtOptions = serde_json::from_value(v)?; + (a.width, a.width_mode, a.width_max, a.flip_along, a.flip_across) = (o.width, o.width_mode, o.width_max, o.flip_along, o.flip_across); + (a.overlap, a.colorization) = (o.overlap, o.colorization); + } + BrushKind::Pattern(p) => { + let o: PatternOptions = serde_json::from_value(v)?; + (p.scale, p.spacing, p.fit, p.flip_along, p.flip_across, p.colorization) = + (o.scale, o.spacing, o.fit, o.flip_along, o.flip_across, o.colorization); + } + BrushKind::Bristle(_) => {} + } + Ok(()) + } +} + +impl Brush { + /// The brush as a stroke whose own settings are `options` draws it: each field of + /// [`BrushKind::stroke_option_keys`] in `options` replaces the brush's value (a `colorization` + /// object changes only the fields it gives), and the values are kept within their ranges + /// ([`Brush::sanitize`]). Fields the type does not take are passed over. An error when a value + /// is of the wrong kind. + pub fn with_stroke_options(&self, options: &serde_json::Map) -> Result { + let keys = self.kind.stroke_option_keys(); + let mut values = self.kind.option_values(); + let Some(o) = values.as_object_mut() else { return Ok(self.clone()) }; + for (k, v) in options { + if !keys.contains(&k.as_str()) { + continue; + } + match (o.get_mut(k).and_then(serde_json::Value::as_object_mut), v.as_object()) { + (Some(inner), Some(fields)) if k == "colorization" => { + for (f, fv) in fields { + inner.insert(f.clone(), fv.clone()); + } + } + _ => { + o.insert(k.clone(), v.clone()); + } + } + } + // A Hue Shift without a key takes the art's main color, as `Brush::from_json` gives it. + if let Some(c) = o.get_mut("colorization").and_then(serde_json::Value::as_object_mut) + && c.get("method").and_then(serde_json::Value::as_str) == Some("hueShift") + && c.get("key").is_none_or(serde_json::Value::is_null) + { + let key = art_colors(self.art()).first().copied().unwrap_or(vectorcraft_color::Color::BLACK); + c.insert("key".into(), serde_json::to_value(key).map_err(|e| e.to_string())?); + } + let mut b = self.clone(); + b.kind.set_option_values(values).map_err(|e| e.to_string())?; + b.sanitize(); + Ok(b) + } + + /// The stroke options of `options` that make the brush draw differently: each field of + /// [`BrushKind::stroke_option_keys`] whose value, after [`Self::with_stroke_options`], differs + /// from the brush's own, with that value (kept within its range). An error for a field the + /// type does not take and for a value of the wrong kind. + pub fn stroke_options_that_differ( + &self, + options: &serde_json::Map, + ) -> Result, String> { + let keys = self.kind.stroke_option_keys(); + if let Some(k) = options.keys().find(|k| !keys.contains(&k.as_str())) { + return Err(if keys.is_empty() { + format!("a {} brush has no options of its own on a stroke", self.kind.label().to_lowercase()) + } else { + format!("a {} brush's stroke options do not include `{k}` (they are {})", self.kind.label().to_lowercase(), keys.join(", ")) + }); + } + let edited = self.with_stroke_options(options)?.kind.option_values(); + let own = self.kind.option_values(); + Ok(keys + .iter() + .filter_map(|k| { + let v = edited.get(*k)?; + (own.get(*k) != Some(v)).then(|| ((*k).to_string(), v.clone())) + }) + .collect()) + } +} + // ---------- library ---------- /// The brush library of `doc`: its stored brushes, or the defaults when it has none. @@ -842,8 +1021,22 @@ fn tolerance(scale: f64) -> f64 { /// Filled art for one brushed stroke along `bp`, in `doc`. Pieces are in document space with id /// 0, and never draw a brushed stroke (so they never recurse): their own strokes carry no brush, /// and what they draw by name that would draw one is left out ([`leave_out_brushed`]). -/// Stroke-level opacity/blend are the caller's job (`StrokeLayer::opacity`). +/// Stroke-level opacity/blend are the caller's job (`StrokeLayer::opacity`). The stroke's own +/// brush settings ([`StrokeLayer::brush_options`]) replace the brush's values +/// ([`Brush::with_stroke_options`]); settings that do not read draw the brush as it is. pub fn stroke_pieces(doc: &Document, brush: &Brush, bp: &BezPath, stroke: &StrokeLayer) -> Vec { + let edited; + let brush = if stroke.brush_options.is_empty() { + brush + } else { + match brush.with_stroke_options(&stroke.brush_options) { + Ok(b) => { + edited = b; + &edited + } + Err(_) => brush, + } + }; let w = if stroke.width > 0.0 { stroke.width } else { 1.0 }; let mut out = match &brush.kind { BrushKind::Calligraphic(c) => calli::calligraphic(c, bp, w, stroke, &brush.name), diff --git a/crates/brush/src/tests.rs b/crates/brush/src/tests.rs index de178c76ac..cb4e560ff5 100644 --- a/crates/brush/src/tests.rs +++ b/crates/brush/src/tests.rs @@ -1,3 +1,4 @@ +use serde_json::json; use vectorcraft_color::{Color, Paint}; use vectorcraft_doc::{Appearance, Document, Node, NodeId, NodeKind, StrokeLayer}; use vectorcraft_geom::{Affine, BezPath, Point, Rect, Vec2, shapes}; @@ -2037,3 +2038,63 @@ fn a_straight_run_keeps_the_same_node_kinds_as_a_bend() { } } } + +/// `options` as a stroke's own brush settings. +fn with_options(options: serde_json::Value) -> StrokeLayer { + StrokeLayer { brush_options: options.as_object().cloned().unwrap_or_default(), ..stroke(1.0) } +} + +#[test] +fn a_strokes_own_options_change_its_art_and_leave_the_brush() { + let doc = Document::new(1.0, 1.0); + let brush = art_brush(rect_art(10.0, 4.0), ArtScale::Stretch); + let path = line(20.0, 50.0, 220.0, 50.0); + let half = stroke_pieces(&doc, &brush, &path, &with_options(json!({"width": 50.0}))); + assert!(near(bounds(&half).height(), 2.0, 1e-6), "width 50% halves the art across the stroke: {:?}", bounds(&half)); + assert!(near(bounds(&stroke_pieces(&doc, &brush, &path, &stroke(1.0))).height(), 4.0, 1e-6), "a stroke without options draws the brush"); + let BrushKind::Art(a) = &brush.kind else { panic!("art brush") }; + assert_eq!(a.width, 100.0, "the brush keeps its width"); + // A calligraphic stroke's own size and angle. + let nib = stroke_pieces(&doc, &calli(0.0, 20.0, 10.0), &line(0.0, 0.0, 100.0, 0.0), &with_options(json!({"angle": 90.0}))); + assert!(near(bounds(&nib).height(), 10.0, 0.05), "{:?}", bounds(&nib)); + // A pattern stroke's own scale doubles the tiles across it. + let pattern = pattern_brush(PatternFit::Stretch, false); + let plain = bounds(&stroke_pieces(&doc, &pattern, &path, &stroke(1.0))).height(); + let doubled = bounds(&stroke_pieces(&doc, &pattern, &path, &with_options(json!({"scale": 200.0})))).height(); + assert!(near(doubled, plain * 2.0, 1e-6), "{plain} → {doubled}"); +} + +#[test] +fn stroke_options_are_checked_and_kept_within_their_ranges() { + let brush = art_brush(rect_art(10.0, 4.0), ArtScale::Stretch); + let map = |v: serde_json::Value| v.as_object().cloned().unwrap_or_default(); + // Out of range: clamped; equal to the brush's own value: left out. + let got = brush.stroke_options_that_differ(&map(json!({"width": 5000.0, "flip_along": false}))).unwrap(); + assert_eq!(serde_json::Value::Object(got), json!({"width": 1000.0})); + // A field the type does not take, and a value of the wrong kind, are errors. + assert!(brush.stroke_options_that_differ(&map(json!({"angle": 10.0}))).unwrap_err().contains("angle")); + assert!(brush.stroke_options_that_differ(&map(json!({"width": "wide"}))).is_err()); + let bristle = Brush { name: "b".into(), kind: BrushKind::Bristle(Bristle::default()) }; + assert!(bristle.stroke_options_that_differ(&map(json!({"size": 2.0}))).is_err()); + assert!(bristle.stroke_options_that_differ(&map(json!({}))).unwrap().is_empty()); + // A colorization object changes only the fields it gives: Hue Shift keeps the key it has. + let key = Color::rgb(0.0, 0.0, 1.0); + let hue = Brush { + name: "h".into(), + kind: BrushKind::Art(ArtBrush { art: rect_art(10.0, 4.0), colorization: Colorization::HueShift { key }, ..Default::default() }), + }; + let tints = hue.with_stroke_options(&map(json!({"colorization": {"method": "tints"}}))).unwrap(); + assert_eq!(tints.kind.colorization(), Colorization::Tints); + let back = hue.stroke_options_that_differ(&map(json!({"colorization": {"method": "hueShift"}}))).unwrap(); + assert!(back.is_empty(), "the brush's own colorization: {back:?}"); + // Hue Shift without a key takes the art's main color, as brush.options gives it. + let keyless = tints.stroke_options_that_differ(&map(json!({"colorization": {"method": "hueShift"}}))).unwrap(); + let want = art_colors(tints.art()).first().copied().unwrap_or(Color::BLACK); + assert_eq!(keyless["colorization"]["method"], json!("hueShift")); + assert_eq!(keyless["colorization"]["key"], serde_json::to_value(want).unwrap()); + // Settings that do not read draw the brush as it is. + let doc = Document::new(1.0, 1.0); + let path = line(20.0, 50.0, 220.0, 50.0); + let odd = stroke_pieces(&doc, &brush, &path, &with_options(json!({"width": [1, 2]}))); + assert!(near(bounds(&odd).height(), 4.0, 1e-6)); +} diff --git a/crates/doc/src/appearance/layers.rs b/crates/doc/src/appearance/layers.rs index f8a58758d8..5e07dc6cde 100644 --- a/crates/doc/src/appearance/layers.rs +++ b/crates/doc/src/appearance/layers.rs @@ -71,6 +71,11 @@ pub struct StrokeLayer { /// Brush applied to the stroke (by brush name). #[serde(default, skip_serializing_if = "Option::is_none")] pub brush: Option, + /// This stroke's own brush settings (the Brushes panel's Options of Selected Object): brush + /// definition fields, by their `brush.options` names, that replace the brush's values on this + /// stroke only. Empty: the stroke draws the brush as it is. `vectorcraft-brush` reads them. + #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] + pub brush_options: serde_json::Map, #[serde(default = "one", skip_serializing_if = "crate::skip::is_one")] pub opacity: f32, #[serde(default, skip_serializing_if = "crate::skip::is_default")] @@ -170,6 +175,7 @@ impl StrokeLayer { arrow_scale: (100.0, 100.0), profile: None, brush: None, + brush_options: serde_json::Map::new(), opacity: 1.0, blend: BlendMode::Normal, visible: true, diff --git a/crates/engine/src/cmd/brushsym.rs b/crates/engine/src/cmd/brushsym.rs index 1046cada1c..4a9339f2ca 100644 --- a/crates/engine/src/cmd/brushsym.rs +++ b/crates/engine/src/cmd/brushsym.rs @@ -33,8 +33,8 @@ mod symbols; pub(crate) use brushes::{apply_brush, brush_targets, stroke_paint}; use brushes::{ - brush_apply, brush_delete, brush_duplicate, brush_freehand, brush_get, brush_list, brush_move, brush_new, brush_options, brush_place_art, - brush_remove, brush_replace_art, brush_selection_art, brush_set_current, brush_unused, expand_brush, + brush_apply, brush_delete, brush_duplicate, brush_freehand, brush_get, brush_list, brush_move, brush_new, brush_object_options, brush_options, + brush_place_art, brush_remove, brush_replace_art, brush_selection_art, brush_set_current, brush_unused, expand_brush, }; pub(crate) use dynamic::{edit_part, fit_parts, part_only, selected_part}; use dynamic::{symbol_instance_reset, symbol_instance_select_part, symbol_instance_set_appearance}; @@ -166,6 +166,15 @@ pub fn specs() -> Vec { has_doc, brush_options ), + cmd!( + "brush.objectOptions", + "Options of Selected Object…", + [], + None, + "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, or stroke.setAdvanced with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", + has_doc, + brush_object_options + ), cmd!( "object.expandBrush", "Expand Brush Strokes", diff --git a/crates/engine/src/cmd/brushsym/brushes.rs b/crates/engine/src/cmd/brushsym/brushes.rs index 7fd8c9aa9a..007e47f5ce 100644 --- a/crates/engine/src/cmd/brushsym/brushes.rs +++ b/crates/engine/src/cmd/brushsym/brushes.rs @@ -1,7 +1,7 @@ use super::{ AppearanceItem, Arc, BTreeSet, Bristle, Brush, BrushKind, Color, Document, EngineError, Node, NodeId, NodeKind, Paint, Result, Session, Value, anchor, bad, brush, check_numbers, find_command, id_param, ids_json, json, name_param, names_param, ok, roots, selection_art, set_unknown, - str_param, + str_param, switch_or, }; // ---------- brushes ---------- @@ -57,6 +57,8 @@ pub(crate) fn apply_brush(d: &mut Document, ids: &[NodeId], name: &str, stroke: st.width = 1.0; } st.brush = Some(name.to_string()); + // The path's own brush settings (Options of Selected Object) go with the brush they set. + st.brush_options.clear(); } } } @@ -85,6 +87,7 @@ pub(super) fn brush_remove(s: &mut Session, p: &Value) -> Result { for it in &mut n.appearance.items { if let AppearanceItem::Stroke(st) = it { st.brush = None; + st.brush_options.clear(); } } } @@ -129,13 +132,17 @@ fn merge(base: &mut Value, patch: &Value) { } } -/// Sets brush `to` on the strokes in `items` that paint with brush `from`. +/// Sets brush `to` on the strokes in `items` that paint with brush `from`. A renamed brush keeps +/// each stroke's own settings for it; a stroke left without a brush loses them. fn set_stroke_brush(items: &mut [AppearanceItem], from: &str, to: Option<&str>) { for it in items { if let AppearanceItem::Stroke(st) = it && st.brush.as_deref() == Some(from) { st.brush = to.map(str::to_string); + if to.is_none() { + st.brush_options.clear(); + } } } } @@ -494,6 +501,85 @@ pub(super) fn brush_options(s: &mut Session, p: &Value) -> Result { Ok(json!({ "name": out })) } +/// Options of Selected Object: set the brush settings of the brushed strokes of the selected paths +/// (or `ids`) on those strokes only, leaving the brush as it is. `params` adds to each stroke's +/// own settings, `reset` clears them; without either, nothing changes and the settings are given. +pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result { + const C: &str = "brush.objectOptions"; + let params = match p.get("params") { + None | Some(Value::Null) => serde_json::Map::new(), + Some(Value::Object(o)) => o.clone(), + Some(_) => { + let key = "params"; + return Err(bad(C, format!("`{key}` must be an object"))); + } + }; + let reset = switch_or(p, "reset", false, C)?; + if reset && !params.is_empty() { + return Err(bad(C, "give `params` or `reset`, not both")); + } + let d = &s.doc()?.doc; + let lib = brush::library(d); + let ids = brush_targets(d, &roots(s, p)?); + // Each brushed stroke: its path, its place in the appearance, its brush and its settings now. + let mut strokes = vec![]; + for id in &ids { + let Some(n) = d.node(*id) else { continue }; + for (i, it) in n.appearance.items.iter().enumerate() { + let AppearanceItem::Stroke(st) = it else { continue }; + if let Some(b) = st.brush.as_deref().and_then(|name| lib.iter().find(|b| b.name == name)) { + strokes.push((*id, i, b, &st.brush_options)); + } + } + } + let Some(&(_, _, first, _)) = strokes.first() else { return Err(bad(C, "no path painted with a brush is selected")) }; + if strokes.iter().any(|(_, _, b, _)| b.kind.type_id() != first.kind.type_id()) { + return Err(bad(C, "the selected paths are painted with brushes of different types")); + } + // Only a bristle brush has none. + if first.kind.stroke_option_keys().is_empty() { + return Err(bad(C, "a bristle brush has no options of its own on a path")); + } + let out: Vec = ids.iter().copied().filter(|id| strokes.iter().any(|(s, ..)| s == id)).collect(); + // Without params or reset the settings are only given: nothing is normalized or changed. + if !reset && params.is_empty() { + let keys = first.kind.stroke_option_keys(); + let own: serde_json::Map = + strokes[0].3.iter().filter(|(k, _)| keys.contains(&k.as_str())).map(|(k, v)| (k.clone(), v.clone())).collect(); + return Ok(json!({ "ids": ids_json(&out), "changed": [], "options": own })); + } + let mut changes = vec![]; + let mut options = None; + for (id, i, b, own) in &strokes { + let next = if reset { + serde_json::Map::new() + } else { + // Settings saved for another type of brush are left out. + let keys = b.kind.stroke_option_keys(); + let mut merged: serde_json::Map = + own.iter().filter(|(k, _)| keys.contains(&k.as_str())).map(|(k, v)| (k.clone(), v.clone())).collect(); + merged.extend(params.clone()); + b.stroke_options_that_differ(&merged).map_err(|e| bad(C, e))? + }; + options.get_or_insert_with(|| next.clone()); + if &next != *own { + changes.push((*id, *i, next)); + } + } + let changed: Vec = ids.iter().copied().filter(|id| changes.iter().any(|(c, ..)| c == id)).collect(); + if !changes.is_empty() { + s.edit("Options of Selected Object", |d, _| { + for (id, i, next) in changes { + if let Some(AppearanceItem::Stroke(st)) = d.node_mut(id).and_then(|n| n.appearance.items.get_mut(i)) { + st.brush_options = next; + } + } + Ok(()) + })?; + } + Ok(json!({ "ids": ids_json(&out), "changed": ids_json(&changed), "options": options.unwrap_or_default() })) +} + /// The name `brush.placeArt` gives each pattern brush tile it places, by tile, in the order it /// places them; `brush.replaceArt` reads a group of that name as that tile. const TILE_NAMES: [&str; 5] = ["Side Tile", "Outer Corner Tile", "Inner Corner Tile", "Start Tile", "End Tile"]; diff --git a/crates/engine/src/cmd/buildcmds.rs b/crates/engine/src/cmd/buildcmds.rs index f694a2b144..99f73b564e 100644 --- a/crates/engine/src/cmd/buildcmds.rs +++ b/crates/engine/src/cmd/buildcmds.rs @@ -658,6 +658,7 @@ fn fit_to_edge(row: &mut AppearanceItem, run: Option<(f64, bool, bool, bool)>) { } s.profile = None; s.brush = None; + s.brush_options.clear(); } if !starts { s.start_arrow = None; diff --git a/crates/engine/src/cmd/colormgmt.rs b/crates/engine/src/cmd/colormgmt.rs index 5922787723..40ff3e1592 100644 --- a/crates/engine/src/cmd/colormgmt.rs +++ b/crates/engine/src/cmd/colormgmt.rs @@ -628,10 +628,12 @@ fn map_art_colors(n: &mut vectorcraft_doc::Node, f: &mut dyn FnMut(&Color, proof } /// `f` applied to the colors in `n`'s subtree that [`proof::map_node_colors`] does not visit: the -/// effect colors ([`map_effect_colors`]), the series paints and label styles a graph keeps +/// effect colors ([`map_effect_colors`]), the Hue Shift key colors of strokes' own brush settings +/// ([`map_stroke_brush_keys`]), the series paints and label styles a graph keeps /// ([`map_graph_colors`]) and the art of every opacity mask. fn map_more_colors(n: &mut vectorcraft_doc::Node, f: &mut dyn FnMut(&Color, proof::Link) -> Color) { map_effect_colors(&mut n.appearance, f); + map_stroke_brush_keys(&mut n.appearance, f); if let Some(e) = n.extras_if_any() { if let Some(g) = e.graph.as_deref_mut() { map_graph_colors(g, f); @@ -647,6 +649,23 @@ fn map_more_colors(n: &mut vectorcraft_doc::Node, f: &mut dyn FnMut(&Color, proo } } +/// `f` applied to the Hue Shift key color of each stroke's own brush settings in appearance `a` +/// (Options of Selected Object, `colorization.key` of [`StrokeLayer::brush_options`]); a key +/// that does not read is left as it is. +/// +/// [`StrokeLayer::brush_options`]: vectorcraft_doc::StrokeLayer::brush_options +fn map_stroke_brush_keys(a: &mut vectorcraft_doc::Appearance, f: &mut dyn FnMut(&Color, proof::Link) -> Color) { + for it in &mut a.items { + let vectorcraft_doc::AppearanceItem::Stroke(st) = it else { continue }; + let Some(c) = st.brush_options.get_mut("colorization").and_then(Value::as_object_mut) else { continue }; + let Some(key) = c.get("key").and_then(|k| serde_json::from_value::(k.clone()).ok()) else { continue }; + let n = f(&key, None); + if n != key { + c.insert("key".into(), json!(n)); + } + } +} + /// Whether art color `c` is the Hue Shift key color `key`, with the tolerance the brush's /// colorization matches it with. fn matches_key(c: &Color, key: &Color) -> bool { diff --git a/crates/engine/src/cmd/expand.rs b/crates/engine/src/cmd/expand.rs index 43975fe4e4..6e8bbc2448 100644 --- a/crates/engine/src/cmd/expand.rs +++ b/crates/engine/src/cmd/expand.rs @@ -1147,21 +1147,27 @@ fn random_brushes_baked<'a>( std::borrow::Cow::Owned(def) } -/// Does brush `name` of `brushes` draw different art for different points: a calligraphic or -/// scatter brush with Random variation, or a bristle brush? -fn draws_random_art(brushes: &[vectorcraft_brush::Brush], name: &str) -> bool { +/// Does brush `name` of `brushes`, with the stroke's own brush settings `options`, draw different +/// art for different points: a calligraphic or scatter brush with Random variation, or a bristle +/// brush? +fn draws_random_art(brushes: &[vectorcraft_brush::Brush], name: &str, options: &serde_json::Map) -> bool { use vectorcraft_brush::{BrushKind, Variation}; - brushes.iter().find(|b| b.name == name).is_some_and(|b| match &b.kind { + let Some(brush) = brushes.iter().find(|b| b.name == name) else { return false }; + let edited = if options.is_empty() { None } else { brush.with_stroke_options(options).ok() }; + let b = edited.as_ref().unwrap_or(brush); + match &b.kind { BrushKind::Calligraphic(c) => c.modes().contains(&Variation::Random), BrushKind::Scatter(s) => s.modes().contains(&Variation::Random), BrushKind::Bristle(_) => true, BrushKind::Art(_) | BrushKind::Pattern(_) => false, - }) + } } /// Is `n` a path with a visible stroke whose brush varies at random ([`draws_random_art`])? fn random_brushed(brushes: &[vectorcraft_brush::Brush], n: &Node) -> bool { - let random = |st: &vectorcraft_doc::appearance::StrokeLayer| st.visible && st.brush.as_deref().is_some_and(|b| draws_random_art(brushes, b)); + let random = |st: &vectorcraft_doc::appearance::StrokeLayer| { + st.visible && st.brush.as_deref().is_some_and(|b| draws_random_art(brushes, b, &st.brush_options)) + }; matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) && n.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(st) if random(st))) } diff --git a/crates/engine/src/cmd/globaledit.rs b/crates/engine/src/cmd/globaledit.rs index 879767d8be..29fbf97fac 100644 --- a/crates/engine/src/cmd/globaledit.rs +++ b/crates/engine/src/cmd/globaledit.rs @@ -769,6 +769,7 @@ fn give_item(a: &AppearanceItem, b: &AppearanceItem, m: &AppearanceItem, n: &mut arrow_scale, profile, brush, + brush_options, opacity, blend, visible, @@ -781,7 +782,11 @@ fn give_item(a: &AppearanceItem, b: &AppearanceItem, m: &AppearanceItem, n: &mut bearing: _, rotation: _, } = m; - give_fields!(a, b, n: paint, width, cap, join, miter_limit, align, dash, start_arrow, end_arrow, arrow_scale, profile, brush, opacity, blend, visible, effects, arrow_align, overprint, gradient_mode); + give_fields!(a, b, n: paint, width, cap, join, miter_limit, align, dash, start_arrow, end_arrow, arrow_scale, profile, brush, brush_options, opacity, blend, visible, effects, arrow_align, overprint, gradient_mode); + // A stroke's own brush settings go with the brush they set: a new brush takes the model's. + if a.brush != b.brush { + n.brush_options = brush_options.clone(); + } } _ => {} } diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index 09ae0b8e41..369c8ef8e5 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -542,6 +542,10 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result { let Some(st) = n.appearance.stroke_at_mut(index) else { return Ok(()) }; arrows_and_profile(st); if let Some(b) = &brush { + // The path's own brush settings (Options of Selected Object) go with the brush they set. + if st.brush != *b { + st.brush_options.clear(); + } st.brush = b.clone(); } Ok(()) diff --git a/crates/engine/src/tests/brushsym.rs b/crates/engine/src/tests/brushsym.rs index bc4ce76c83..b313ec64c3 100644 --- a/crates/engine/src/tests/brushsym.rs +++ b/crates/engine/src/tests/brushsym.rs @@ -81,6 +81,116 @@ fn apply_and_remove_brush_with_undo() { assert!(s.execute("brush.apply", &json!({"name": "Nope"})).is_err()); } +/// The own brush settings of the first stroke of `id`. +fn own_options(s: &Session, id: NodeId) -> Value { + Value::Object(node(s, id).appearance.stroke().map(|st| st.brush_options.clone()).unwrap_or_default()) +} + +/// The height of the brush art of `id`, drawn along a level line. +fn art_height(s: &Session, id: NodeId) -> f64 { + let d = &s.doc().unwrap().doc; + vectorcraft_brush::pieces_bounds(&vectorcraft_brush::node_pieces(d, &node(s, id)).unwrap()).unwrap().height() +} + +#[test] +fn options_of_selected_object_change_one_path_and_leave_the_brush() { + let mut s = session(); + let a = line(&mut s); + let b = line(&mut s); + select(&mut s, &[a, b]); + s.execute("brush.apply", &json!({"name": "Arrow"})).unwrap(); + let width = s.execute("brush.get", &json!({"name": "Arrow"})).unwrap()["width"].clone(); + select(&mut s, &[a]); + let steps = undo_steps(&s); + let r = s.execute("brush.objectOptions", &json!({"params": {"width": 50, "flip_along": false}})).unwrap(); + assert_eq!(r["changed"], json!([a.0])); + assert_eq!(own_options(&s, a), json!({"width": 50.0}), "flip_along equals the brush's own value and is dropped"); + assert_eq!(own_options(&s, b), json!({})); + assert_eq!(s.execute("brush.get", &json!({"name": "Arrow"})).unwrap()["width"], width, "the brush keeps its width"); + assert_eq!(undo_steps(&s), steps + 1); + assert!((art_height(&s, a) * 2.0 - art_height(&s, b)).abs() < 1e-6, "{} vs {}", art_height(&s, a), art_height(&s, b)); + // The same settings again, and a call without params, change nothing and add no undo step. + assert_eq!(s.execute("brush.objectOptions", &json!({"params": {"width": 50}})).unwrap()["changed"], json!([])); + assert_eq!(s.execute("brush.objectOptions", &json!({})).unwrap()["options"], json!({"width": 50.0})); + assert_eq!(undo_steps(&s), steps + 1); + // An edit of the brush reaches the settings the path does not set. + s.execute("brush.options", &json!({"name": "Arrow", "params": {"width": 200, "flip_across": true}})).unwrap(); + assert_eq!(own_options(&s, a), json!({"width": 50.0})); + // The settings are saved in the native file. + let back = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap(); + let st = back.node(a).and_then(|n| n.appearance.stroke().cloned()).unwrap(); + assert_eq!(Value::Object(st.brush_options), json!({"width": 50.0})); + // Undo puts the path back on the brush's settings. + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(own_options(&s, a), json!({})); + s.execute("edit.redo", &json!({})).unwrap(); + assert_eq!(own_options(&s, a), json!({"width": 50.0})); + // Reset clears them, and so do applying a brush and removing it. + s.execute("brush.objectOptions", &json!({"reset": true})).unwrap(); + assert_eq!(own_options(&s, a), json!({})); + s.execute("brush.objectOptions", &json!({"params": {"overlap": true}})).unwrap(); + s.execute("brush.apply", &json!({"name": "Arrow"})).unwrap(); + assert_eq!(own_options(&s, a), json!({})); + s.execute("brush.objectOptions", &json!({"params": {"overlap": true}})).unwrap(); + s.execute("brush.remove", &json!({})).unwrap(); + assert_eq!(own_options(&s, a), json!({})); + // Stroke Options' brush change clears them as well, and keeping the same brush keeps them. + s.execute("brush.apply", &json!({"name": "Arrow"})).unwrap(); + s.execute("brush.objectOptions", &json!({"params": {"overlap": true}})).unwrap(); + s.execute("stroke.setAdvanced", &json!({"brush": "Arrow"})).unwrap(); + assert_eq!(own_options(&s, a), json!({"overlap": true})); + s.execute("stroke.setAdvanced", &json!({"brush": null})).unwrap(); + assert_eq!(own_options(&s, a), json!({})); + // Asking for the settings changes nothing, even when the brush has come to equal them. + s.execute("brush.apply", &json!({"name": "Arrow"})).unwrap(); + s.execute("brush.objectOptions", &json!({"params": {"overlap": true}})).unwrap(); + s.execute("brush.options", &json!({"name": "Arrow", "params": {"overlap": true}})).unwrap(); + let steps = undo_steps(&s); + assert_eq!(s.execute("brush.objectOptions", &json!({})).unwrap()["options"], json!({"overlap": true})); + assert_eq!(own_options(&s, a), json!({"overlap": true})); + assert_eq!(undo_steps(&s), steps); +} + +#[test] +fn options_of_selected_object_keys_convert_with_the_document() { + let mut s = session(); + let a = line(&mut s); + s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0]})).unwrap(); + let key = json!({"model": "rgb", "r": 0.2, "g": 0.6, "b": 0.3}); + s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"colorization": {"method": "hueShift", "key": key}}})).unwrap(); + assert_eq!(own_options(&s, a)["colorization"]["key"]["model"], json!("rgb")); + s.execute("file.documentColorMode", &json!({"mode": "cmyk"})).unwrap(); + assert_eq!(own_options(&s, a)["colorization"]["key"]["model"], json!("cmyk"), "{}", own_options(&s, a)); +} + +#[test] +fn options_of_selected_object_refuse_what_they_cannot_set() { + let mut s = session(); + let a = line(&mut s); + let c = line(&mut s); + let plain = rect(&mut s, 10.0, 10.0, 20.0, 20.0); + s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0]})).unwrap(); + s.execute("brush.apply", &json!({"name": "3 pt. Round", "ids": [c.0]})).unwrap(); + let steps = undo_steps(&s); + let err = |s: &mut Session, p: Value| s.execute("brush.objectOptions", &p).unwrap_err().to_string(); + assert!(err(&mut s, json!({"ids": [plain.0], "params": {"width": 50}})).contains("brush")); + assert!(err(&mut s, json!({"ids": [a.0, c.0], "params": {"width": 50}})).contains("different types")); + assert!(err(&mut s, json!({"ids": [a.0], "params": {"angle": 10}})).contains("angle")); + assert!(!err(&mut s, json!({"ids": [a.0], "params": {"width": "wide"}})).is_empty()); + assert!(!err(&mut s, json!({"ids": [a.0], "params": [1]})).is_empty()); + assert!(err(&mut s, json!({"ids": [a.0], "params": {"width": 50}, "reset": true})).contains("reset")); + assert!(err(&mut s, json!({"ids": [a.0], "reset": "yes"})).contains("reset")); + s.execute("brush.apply", &json!({"name": "Bristle Round", "ids": [c.0]})).unwrap(); + let steps_bristle = undo_steps(&s); + assert!(err(&mut s, json!({"ids": [c.0], "params": {"size": 2}})).contains("bristle")); + assert_eq!(undo_steps(&s), steps_bristle); + assert_eq!(steps + 1, steps_bristle, "only the bristle brush's apply added a step"); + // Values outside their ranges are clamped, as brush.options clamps them. + s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"width": 1e308}})).unwrap(); + assert_eq!(own_options(&s, a), json!({"width": 1000.0})); +} + #[test] fn apply_adds_a_stroke_when_missing_and_reaches_into_groups() { let mut s = session(); diff --git a/crates/engine/src/tests/globaledit.rs b/crates/engine/src/tests/globaledit.rs index 9a4cb7d138..3bfe6039fa 100644 --- a/crates/engine/src/tests/globaledit.rs +++ b/crates/engine/src/tests/globaledit.rs @@ -454,6 +454,24 @@ fn a_stroke_weight_change_leaves_each_members_own_fill_and_stroke_colour() { assert_eq!((fill(&s, a), fill(&s, c)), (a_fill, c_fill)); } +#[test] +fn a_brush_change_clears_each_members_own_brush_settings_and_other_changes_keep_them() { + let mut s = session(); + let [a, b, c, ..] = squares(&mut s); + s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0, b.0, c.0]})).unwrap(); + s.execute("brush.objectOptions", &json!({"ids": [b.0], "params": {"width": 50}})).unwrap(); + let own = |s: &Session, id: NodeId| Value::Object(node(s, id).appearance.stroke().unwrap().brush_options.clone()); + assert_eq!(own(&s, b), json!({"width": 50.0})); + start(&mut s, a, json!({})); + s.execute("stroke.set", &json!({"weight": 3})).unwrap(); + assert_eq!(own(&s, b), json!({"width": 50.0}), "a weight change keeps the copy's own settings"); + s.execute("brush.apply", &json!({"name": "Diamonds"})).unwrap(); + for id in [a, b, c] { + assert_eq!(node(&s, id).appearance.stroke().unwrap().brush.as_deref(), Some("Diamonds")); + assert_eq!(own(&s, id), json!({}), "the settings for the old brush go with it"); + } +} + #[test] fn a_fill_colour_change_reaches_the_fills_and_not_the_strokes() { let mut s = session(); diff --git a/crates/engine/src/tests/objexpand.rs b/crates/engine/src/tests/objexpand.rs index 3788185ae6..5b680b02e9 100644 --- a/crates/engine/src/tests/objexpand.rs +++ b/crates/engine/src/tests/objexpand.rs @@ -1313,6 +1313,28 @@ fn a_random_brush_in_the_tile_art_draws_every_tile_alike() { } } +#[test] +fn a_path_set_to_random_by_its_own_brush_options_draws_every_tile_alike() { + // The brush scatters at fixed values; the tile path's own settings (Options of Selected + // Object) make it scatter at random, so the expanded tiles must still match the canvas. + let mut s = session(); + let tile = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 12, "height": 12}))["id"].as_u64().unwrap(); + run(&mut s, "paint.setFill", json!({"none": true})); + run(&mut s, "paint.setStroke", json!({"color": "#000000"})); + run(&mut s, "brush.apply", json!({"name": "Confetti"})); + run(&mut s, "brush.options", json!({"name": "Confetti", "params": {"modes": ["fixed", "fixed", "fixed", "fixed"]}})); + run(&mut s, "brush.objectOptions", json!({"ids": [tile], "params": {"modes": ["random", "random", "random", "random"]}})); + run(&mut s, "object.pattern.make", json!({"ids": [tile], "name": "Confetti", "width": 60, "height": 60, "edit": false})); + run(&mut s, "select.set", json!({"ids": [tile]})); + run(&mut s, "edit.clear", json!({})); + run(&mut s, "shape.rectangle", json!({"x": 20, "y": 20, "width": 160, "height": 160})); + run(&mut s, "paint.setFill", json!({"swatch": "Confetti"})); + run(&mut s, "paint.setStroke", json!({"none": true})); + let before = render(&s); + expand_to_tiles(&mut s); + assert_eq!(differing(&before, &render(&s), 64), 0, "every tile as on the canvas"); +} + #[test] fn roughen_in_the_tile_art_of_a_scaled_pattern_keeps_its_detail() { // Roughen's detail is per inch: the canvas roughens the 10 pt square and scales the tile, so diff --git a/crates/engine/tests/command_sweep.rs b/crates/engine/tests/command_sweep.rs index fce3742d11..2713109b7f 100644 --- a/crates/engine/tests/command_sweep.rs +++ b/crates/engine/tests/command_sweep.rs @@ -604,6 +604,17 @@ fn structured_junk() { ("brush.options", json!({"name": "Arrow", "params": {"width": -5, "direction": "diagonal", "flip_along": "yes"}})), ("brush.options", json!({"name": "Chain", "params": {"scale": 1e308, "spacing": -1e308, "fit": "approximate", "flip_across": true}})), ("brush.options", json!({"name": "Chain", "params": {"scale": 0, "spacing": 1e308, "fit": "nope", "side": null}})), + ("brush.apply", json!({"name": "Chain", "id": 2})), + ( + "brush.objectOptions", + json!({"id": 2, "params": {"scale": 1e308, "spacing": -1e308, "fit": "approximate", "colorization": {"method": "hueShift"}}}), + ), + ("brush.objectOptions", json!({"id": 2, "params": {"scale": "x", "fit": "nope", "side": null}})), + ( + "brush.objectOptions", + json!({"id": 2, "params": {"colorization": {"method": "hueShift", "key": {"model": "rgb", "r": 1e308, "g": -1e308, "b": 0}}}}), + ), + ("brush.objectOptions", json!({"ids": [1e308, -1], "params": {}, "reset": true})), ("path.curvature", json!({"points": [{"x": 0, "y": 0}]})), ("path.curvatureEdit", json!({"id": 2, "op": "move", "anchor": 1000, "x": 0, "y": 0})), ("path.curvatureEdit", json!({"id": 2, "op": "move", "anchor": 0, "x": 1e308, "y": -1e308})), diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c41e6fe86f..cb63f15b71 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -903,6 +903,12 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "", "{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options", ), + ( + "ui.brushObjectOptions", + "Options of Selected Object…", + "", + "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened, and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", + ), ( "ui.graphicStyleOptions", "Graphic Style Options…", diff --git a/crates/ui-egui/src/dialogs/brush_art_options.rs b/crates/ui-egui/src/dialogs/brush_art_options.rs index 8bc0e66a2e..62d4a2e368 100644 --- a/crates/ui-egui/src/dialogs/brush_art_options.rs +++ b/crates/ui-egui/src/dialogs/brush_art_options.rs @@ -472,6 +472,13 @@ fn art_body(ui: &mut egui::Ui, d: &mut Dialog) { d.fields.insert("widthMode".into(), json!(m.id())); } }); + // A path sets its own width, flips, overlap and colorization, not how the art scales or runs. + if d.bool(super::brush_options::OBJECT) { + flips(ui, d); + ui.add_space(4.0); + super::form::check(ui, d, "overlap", tl!("Overlap")); + return; + } ui.add_space(4.0); widgets::section_header(ui, tl!("Brush Scale Options")); let scales = [ @@ -532,8 +539,11 @@ fn pattern_body(ui: &mut egui::Ui, d: &mut Dialog) { slider_row(ui, d, "scale", tl!("Scale:"), PatternBrush::SCALE_RANGE); widgets::label_row(ui, tl!("Spacing:"), LABEL_W, |ui| number(ui, d, "spacing", PatternBrush::SPACING_RANGE, "%", true)); ui.add_space(6.0); - tiles(ui, d); - ui.add_space(6.0); + // The tiles belong to the brush; a path sets its own scale, spacing, flips, fit and colorization. + if !d.bool(super::brush_options::OBJECT) { + tiles(ui, d); + ui.add_space(6.0); + } flips(ui, d); widgets::section_header(ui, tl!("Fit")); let fits = [("stretch", tl!("Stretch to fit")), ("addSpace", tl!("Add space to fit")), ("approximate", tl!("Approximate path"))]; diff --git a/crates/ui-egui/src/dialogs/brush_options.rs b/crates/ui-egui/src/dialogs/brush_options.rs index bcc880958a..501ed7ec8d 100644 --- a/crates/ui-egui/src/dialogs/brush_options.rs +++ b/crates/ui-egui/src/dialogs/brush_options.rs @@ -17,10 +17,17 @@ //! New Brush opens the dialog for a brush that does not exist yet ([`open_new`]), with `__create` //! and, for dropped art, `__ids`: OK runs `brush.new` instead, which gives a name another brush has //! a number, and Cancel adds nothing. +//! +//! The panel menu's Options of Selected Object opens the dialog on the brush of the first selected +//! brushed path, with that path's own settings ([`open_object`]), with `__object`, `__targets` (the +//! brushed paths) and `__opened` (the values it opened with). It has no name, and of the Art and +//! Pattern brush options only those a path can set for itself. OK runs `brush.objectOptions` with +//! the values changed since it opened: the paths change and the brush stays as it is. use egui::{Color32, Sense, Stroke, pos2, vec2}; use serde_json::{Map, Value, json}; use vectorcraft_brush::{Bristle, Brush, BrushKind, Calligraphic, Variation}; +use vectorcraft_doc::{AppearanceItem, NodeId, NodeKind}; use super::swatch_options::{grid, label}; use super::{DialogSpec, brush_art_options, form}; @@ -39,6 +46,15 @@ const CREATE: &str = "__create"; /// The field of such a dialog holding the ids of the art dropped on the Brushes panel. const IDS: &str = "__ids"; +/// The field of a Brush Options dialog that Options of Selected Object opened. +pub(super) const OBJECT: &str = "__object"; + +/// The field of such a dialog holding the brushed paths it sets. +const TARGETS: &str = "__targets"; + +/// The field of such a dialog holding the `brush.objectOptions` params it opened with. +const OPENED: &str = "__opened"; + /// Calligraphic values: (field, label, suffix, decimals), in [`Calligraphic::RANGES`] order. const CALLI: [(&str, &str, &str, usize); 3] = [("angle", "Angle:", "°", 0), ("roundness", "Roundness:", "%", 0), ("size", "Size:", " pt", 1)]; @@ -73,6 +89,9 @@ const NIB_W: f32 = 120.0; const STROKE_W: f32 = 400.0; fn heading(d: &Dialog) -> String { + if d.bool(OBJECT) { + return tl!("Options of Selected Object").into(); + } match d.str("__type").as_str() { "bristle" => tl!("Bristle Brush Options").into(), "calligraphic" => tl!("Calligraphic Brush Options").into(), @@ -146,6 +165,96 @@ fn target(app: &VectorcraftApp) -> Option { selected.or_else(|| vectorcraft_brush::current(&st.doc)) } +/// The brush that the first brushed stroke of path `id` paints with, in library `lib`. +fn stroke_brush<'a>(app: &VectorcraftApp, lib: &'a [Brush], id: NodeId) -> Option<&'a Brush> { + let n = app.session.active()?.doc.node(id)?; + n.appearance.items.iter().find_map(|i| match i { + AppearanceItem::Stroke(st) => st.brush.as_deref().and_then(|name| lib.iter().find(|b| b.name == name)), + AppearanceItem::Fill(_) => None, + }) +} + +/// Can Options of Selected Object open: does a selected path or compound path (or one in a +/// selected group, but not a path inside a compound path, as `brush.objectOptions` takes them) +/// paint with a brush, are all their brushes of one type, and can a path set options of its own +/// for that type? These are the selections `brush.objectOptions` takes. +pub fn object_available(app: &VectorcraftApp) -> bool { + let Some(st) = app.session.active() else { return false }; + let ids = st.selection.subjects(); + if ids.is_empty() { + return false; + } + let lib = vectorcraft_brush::library(&st.doc); + let doc = &st.doc; + // The brush of every brushed stroke of the paths the command sets. + let mut brushes: Vec<&Brush> = vec![]; + for id in ids { + let Some(n) = doc.node(*id) else { continue }; + n.walk(&mut |c| { + let own = matches!(c.kind, NodeKind::Path { guide: false, clipping: false, .. } | NodeKind::Compound { .. }); + let in_compound = doc.parent_of(c.id).and_then(|p| doc.node(p)).is_some_and(|p| matches!(p.kind, NodeKind::Compound { .. })); + if !own || in_compound { + return; + } + for i in &c.appearance.items { + if let AppearanceItem::Stroke(s) = i + && let Some(b) = s.brush.as_deref().and_then(|name| lib.iter().find(|b| b.name == name)) + { + brushes.push(b); + } + } + }); + } + let Some(first) = brushes.first() else { return false }; + !first.kind.stroke_option_keys().is_empty() && brushes.iter().all(|b| b.kind.type_id() == first.kind.type_id()) +} + +/// Open Options of Selected Object: the Brush Options of the brush the first selected brushed path +/// paints with, at that path's own settings, without the name and with only the options a path can +/// set for itself. +pub fn open_object(app: &mut VectorcraftApp) -> Result { + let r = app.run("brush.objectOptions", json!({}))?; + let targets = r["ids"].clone(); + let first = targets.get(0).and_then(Value::as_u64).map(NodeId).ok_or("no path painted with a brush is selected")?; + let lib = vectorcraft_brush::library(&app.session.active().ok_or("no document open")?.doc); + let b = stroke_brush(app, &lib, first).ok_or("no path painted with a brush is selected")?; + let own: Map = serde_json::from_value(r["options"].clone()).unwrap_or_default(); + let edited = b.with_stroke_options(&own)?; + let def = serde_json::to_value(&edited).map_err(|e| e.to_string())?; + let mut f = fields(&edited, def)?; + f.insert("__brush".into(), json!(b.name)); + f.insert(OBJECT.into(), json!(true)); + f.insert(TARGETS.into(), targets); + let mut d = Dialog { kind: KIND.into(), fields: f }; + let opened = object_params(&d, b.kind.stroke_option_keys()); + d.fields.insert(OPENED.into(), Value::Object(opened)); + d.fields.insert("__keys".into(), json!(b.kind.stroke_option_keys())); + app.ui.dialog = Some(d); + Ok(Value::Null) +} + +/// The fields' `brush.options` params that a path can set for itself (`keys`). +fn object_params(d: &Dialog, keys: &[&str]) -> Map { + match params(d) { + Value::Object(p) => p.into_iter().filter(|(k, _)| keys.contains(&k.as_str())).collect(), + _ => Map::new(), + } +} + +/// OK of Options of Selected Object: `brush.objectOptions` on the paths it opened for, with the +/// values changed since it opened. The dialog closes when they are set. +fn confirm_object(app: &mut VectorcraftApp, d: &Dialog) -> Result { + let keys: Vec = d.fields.get("__keys").and_then(|v| serde_json::from_value(v.clone()).ok()).unwrap_or_default(); + let keys: Vec<&str> = keys.iter().map(String::as_str).collect(); + let opened = d.fields.get(OPENED).and_then(Value::as_object).cloned().unwrap_or_default(); + let changed: Map = object_params(d, &keys).into_iter().filter(|(k, v)| opened.get(k) != Some(v)).collect(); + let r = app.run("brush.objectOptions", json!({ "ids": d.fields.get(TARGETS).cloned().unwrap_or_default(), "params": changed })); + if r.is_ok() { + app.ui.dialog = None; + } + r +} + /// Open the Brush Options of a new brush of type `ty` (`calligraphic` | `scatter` | `art` | /// `bristle` | `pattern`), the second step of New Brush. The fields start from the type's default /// values and the name "New Brush", numbered when another brush has it. A scatter or art @@ -240,7 +349,13 @@ fn create(app: &mut VectorcraftApp, d: &Dialog) -> Result { /// OK: make the new brush when New Brush opened the dialog, else edit the brush. fn ok(app: &mut VectorcraftApp, d: &Dialog) -> Result { - if d.bool(CREATE) { create(app, d) } else { confirm(app, d) } + if d.bool(CREATE) { + create(app, d) + } else if d.bool(OBJECT) { + confirm_object(app, d) + } else { + confirm(app, d) + } } /// The value of field `key` within `range`. @@ -279,13 +394,16 @@ fn params(d: &Dialog) -> Value { } fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { - grid(ui, |ui| { - label(ui, tl!("Name:")); - let max = if d.str("__type") == "bristle" { Bristle::MAX_NAME_CHARS } else { usize::MAX }; - form::text_edit_limited(ui, d, "name", 240.0, max); - ui.end_row(); - }); - ui.add_space(10.0); + // Options of Selected Object sets a path's settings, not the brush, so it has no name. + if !d.bool(OBJECT) { + grid(ui, |ui| { + label(ui, tl!("Name:")); + let max = if d.str("__type") == "bristle" { Bristle::MAX_NAME_CHARS } else { usize::MAX }; + form::text_edit_limited(ui, d, "name", 240.0, max); + ui.end_row(); + }); + ui.add_space(10.0); + } match d.str("__type").as_str() { "bristle" => bristle_body(app, ui, d), "calligraphic" => calligraphic_body(app, ui, d), diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index 9ff55da454..e997e92805 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -862,3 +862,88 @@ fn art_width_and_pattern_scale_have_sliders() { let shown = tree(|ui| super::super::show(&mut app, ui.ctx())); assert_eq!(slider_value(&shown, "Scale:"), (Some(100.0), Some(1.0), Some(10000.0), Some("100%".into()))); } + +/// A level line, selected, painted with brush `brush`. +fn brushed_line(app: &mut VectorcraftApp, y: f64, brush: &str) -> u64 { + let id = app.run("shape.line", json!({"x1": 20, "y1": y, "x2": 220, "y2": y})).unwrap()["id"].as_u64().unwrap(); + app.run("brush.apply", json!({"name": brush, "ids": [id]})).unwrap(); + id +} + +/// The own brush settings of the first stroke of path `id`. +fn own_options(app: &VectorcraftApp, id: u64) -> Value { + let st = app.session.active().unwrap().doc.node(NodeId(id)).and_then(|n| n.appearance.stroke().cloned()).unwrap(); + Value::Object(st.brush_options) +} + +fn select(app: &mut VectorcraftApp, ids: &[u64]) { + app.run("select.set", json!({ "ids": ids })).unwrap(); +} + +#[test] +fn options_of_selected_object_set_one_paths_art_brush_settings() { + let mut app = app(); + let a = brushed_line(&mut app, 50.0, "Arrow"); + let b = brushed_line(&mut app, 100.0, "Arrow"); + select(&mut app, &[a]); + assert!(object_available(&app)); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + let text = shown(&mut app); + for label in ["Options of Selected Object", "Width:", "Flip Along", "Flip Across", "Overlap", "Colorization", "OK"] { + assert!(text.contains(label), "{label} in {text}"); + } + for label in ["Name:", "Brush Scale Options", "Direction:"] { + assert!(!text.contains(label), "{label} in {text}"); + } + set(&mut app, json!({"width": 50})); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(own_options(&app, a), json!({"width": 50.0})); + assert_eq!(own_options(&app, b), json!({})); + assert_eq!(app.run("brush.get", json!({"name": "Arrow"})).unwrap()["width"], json!(100.0), "the brush keeps its width"); + // Opened again, it shows the path's own width, and OK without a change changes nothing. + app.run("ui.brushObjectOptions", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().f64("width", 0.0), 50.0); + super::super::confirm(&mut app).unwrap(); + assert_eq!(own_options(&app, a), json!({"width": 50.0})); +} + +#[test] +fn options_of_selected_object_show_what_a_path_can_set_for_each_type() { + let mut app = app(); + // Calligraphic: OK without a change leaves the path on the brush's settings. + let c = brushed_line(&mut app, 40.0, "6 pt. Flat"); + select(&mut app, &[c]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + let text = shown(&mut app); + for label in ["Angle:", "Roundness:", "Size:"] { + assert!(text.contains(label), "{label} in {text}"); + } + super::super::confirm(&mut app).unwrap(); + assert_eq!(own_options(&app, c), json!({})); + // Pattern: scale, spacing, flips and fit, not the tiles. + let p = brushed_line(&mut app, 80.0, "Diamonds"); + select(&mut app, &[p]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + let text = shown(&mut app); + for label in ["Scale:", "Spacing:", "Fit", "Flip Along"] { + assert!(text.contains(label), "{label} in {text}"); + } + assert!(!text.contains("Side Tile"), "{text}"); + set(&mut app, json!({"scale": 200})); + super::super::confirm(&mut app).unwrap(); + assert_eq!(own_options(&app, p), json!({"scale": 200.0})); + // Bristle brushes, nothing selected and two brush types are refused. + let r = brushed_line(&mut app, 120.0, "Bristle Round"); + select(&mut app, &[r]); + assert!(!object_available(&app)); + assert!(app.run("ui.brushObjectOptions", json!({})).is_err()); + select(&mut app, &[c, p]); + assert!(!object_available(&app), "the menu item is off for two brush types"); + assert!(app.run("ui.brushObjectOptions", json!({})).is_err()); + assert!(app.ui.dialog.is_none()); + select(&mut app, &[p, r]); + assert!(!object_available(&app), "the menu item is off for a pattern and a bristle brush"); + app.run("select.none", json!({})).unwrap(); + assert!(!object_available(&app)); +} diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 8534505172..f1e8ec1cb7 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -347,6 +347,8 @@ font-technology Variable Променливи Brush Definition Дефиниция на четка Brush Libraries Библиотеки с четки Brush Options… Опции за четката… + Options of Selected Object… Опции на избрания обект… + Options of Selected Object Опции на избрания обект Brush Strokes Щрихи с четка Brushes Четки Built-in Libraries Вградени библиотеки diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 1a1b1bdbff..4471934ea8 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -3362,6 +3362,8 @@ theme Appearance Izgled Break Link to Symbol Prekini vezu sa simbolom Brush Definition Definicija četkice Brush Options… Opcije četkice… + Options of Selected Object… Opcije odabranog objekta… + Options of Selected Object Opcije odabranog objekta Current Brush Trenutna četkica Current Symbol Trenutni simbol Delete Brush Izbriši četkicu diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index a7fcccfe2f..562b519a4d 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -582,6 +582,12 @@ antiAlias Sharp Nítid Brush Libraries Menu Menú de biblioteques de pinzells Brush Library Biblioteca de pinzells Brush Options… Opcions del pinzell… + Options of Selected Object… Opcions de l’objecte seleccionat… + Options of Selected Object Opcions de l’objecte seleccionat +@msg no path painted with a brush is selected no hi ha cap traçat pintat amb un pinzell seleccionat +@msg the selected paths are painted with brushes of different types els traçats seleccionats estan pintats amb pinzells de tipus diferents +@msg give `params` or `reset`, not both indiqueu `params` o `reset`, no tots dos +@msg a bristle brush has no options of its own on a path un pinzell de cerres no té opcions pròpies en un traçat Brush Scale Options Opcions d’escala del pinzell Brush Size Mida del pinzell Brush Strokes Traços del pinzell diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index acab417f65..79856ad8dc 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -3412,6 +3412,12 @@ theme Appearance Motiv Break Link to Symbol Zrušit propojení se symbolem Brush Definition Definice štětce Brush Options… Možnosti štětce… + Options of Selected Object… Možnosti vybraného objektu… + Options of Selected Object Možnosti vybraného objektu +@msg no path painted with a brush is selected není vybrána žádná cesta malovaná štětcem +@msg the selected paths are painted with brushes of different types vybrané cesty jsou malovány štětci různých typů +@msg give `params` or `reset`, not both zadejte `params` nebo `reset`, ne obojí +@msg a bristle brush has no options of its own on a path štětinový štětec nemá na cestě vlastní možnosti Current Brush Aktuální štětec Current Symbol Aktuální symbol Delete Brush Odstranit štětec diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 9e74a00a64..02a92cbd40 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -3754,6 +3754,12 @@ theme Appearance Udseende Break Link to Symbol Bryd link til symbol Brush Definition Penseldefinition Brush Options… Penselindstillinger… + Options of Selected Object… Indstillinger for markeret objekt… + Options of Selected Object Indstillinger for markeret objekt +@msg no path painted with a brush is selected ingen sti malet med en pensel er markeret +@msg the selected paths are painted with brushes of different types de markerede stier er malet med pensler af forskellige typer +@msg give `params` or `reset`, not both angiv `params` eller `reset`, ikke begge +@msg a bristle brush has no options of its own on a path en børstepensel har ingen egne indstillinger på en sti Current Brush Aktuel pensel Current Symbol Aktuelt symbol Delete Brush Slet pensel diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 527b1c89e8..830635f8b1 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -335,6 +335,12 @@ font-technology Variable Variabel Brush Definition Pinseldefinition Brush Libraries Pinsel-Bibliotheken Brush Options… Pinseloptionen… + Options of Selected Object… Optionen für ausgewähltes Objekt… + Options of Selected Object Optionen für ausgewähltes Objekt +@msg no path painted with a brush is selected kein mit einem Pinsel gemalter Pfad ausgewählt +@msg the selected paths are painted with brushes of different types die ausgewählten Pfade sind mit Pinseln verschiedener Typen gemalt +@msg give `params` or `reset`, not both `params` oder `reset` angeben, nicht beides +@msg a bristle brush has no options of its own on a path ein Borstenpinsel hat auf einem Pfad keine eigenen Optionen Brush Strokes Pinselstriche Brushes Pinsel Built-in Libraries Integrierte Bibliotheken diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index a7dd7ed926..bc016388d5 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -338,6 +338,12 @@ font-technology Variable Μεταβλητές Brush Definition Ορισμός πινέλου Brush Libraries Βιβλιοθήκες πινέλων Brush Options… Επιλογές πινέλου… + Options of Selected Object… Επιλογές επιλεγμένου αντικειμένου… + Options of Selected Object Επιλογές επιλεγμένου αντικειμένου +@msg no path painted with a brush is selected δεν έχει επιλεγεί διαδρομή βαμμένη με πινέλο +@msg the selected paths are painted with brushes of different types οι επιλεγμένες διαδρομές είναι βαμμένες με πινέλα διαφορετικών τύπων +@msg give `params` or `reset`, not both δώστε `params` ή `reset`, όχι και τα δύο +@msg a bristle brush has no options of its own on a path ένα πινέλο με τρίχες δεν έχει δικές του επιλογές σε διαδρομή Brush Strokes Πινελιές Brushes Πινέλα Built-in Libraries Ενσωματωμένες βιβλιοθήκες diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index cf3d0bbf96..451a6f063d 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -360,6 +360,12 @@ font-technology Variable Variables Brush Definition Definición del pincel Brush Libraries Bibliotecas de pinceles Brush Options… Opciones de pincel… + Options of Selected Object… Opciones del objeto seleccionado… + Options of Selected Object Opciones del objeto seleccionado +@msg no path painted with a brush is selected no hay ningún trazado pintado con un pincel seleccionado +@msg the selected paths are painted with brushes of different types los trazados seleccionados están pintados con pinceles de tipos distintos +@msg give `params` or `reset`, not both indique `params` o `reset`, no ambos +@msg a bristle brush has no options of its own on a path un pincel de cerdas no tiene opciones propias en un trazado Brush Strokes Trazos de pincel Brushes Pinceles Built-in Libraries Bibliotecas integradas diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 24b7858169..9b0895a4d4 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -3351,6 +3351,12 @@ theme Appearance Ulkoasu Break Link to Symbol Katkaise linkki symboliin Brush Definition Siveltimen määritys Brush Options… Siveltimen asetukset… + Options of Selected Object… Valitun objektin asetukset… + Options of Selected Object Valitun objektin asetukset +@msg no path painted with a brush is selected siveltimellä maalattua polkua ei ole valittu +@msg the selected paths are painted with brushes of different types valitut polut on maalattu eri tyyppisillä siveltimillä +@msg give `params` or `reset`, not both anna `params` tai `reset`, ei molempia +@msg a bristle brush has no options of its own on a path harjassiveltimellä ei ole polulla omia asetuksia Current Brush Nykyinen sivellin Current Symbol Nykyinen symboli Delete Brush Poista sivellin diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 8303bbae94..5cde2a4ec4 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -361,6 +361,12 @@ font-technology Variable Variables Brush Definition Définition de la forme Brush Libraries Bibliothèques de formes Brush Options… Options de forme… + Options of Selected Object… Options de l’objet sélectionné… + Options of Selected Object Options de l’objet sélectionné +@msg no path painted with a brush is selected aucun tracé peint avec une forme n’est sélectionné +@msg the selected paths are painted with brushes of different types les tracés sélectionnés sont peints avec des formes de types différents +@msg give `params` or `reset`, not both indiquez `params` ou `reset`, pas les deux +@msg a bristle brush has no options of its own on a path une forme Soies n’a pas d’options propres sur un tracé Brush Strokes Contours de forme Brushes Formes Built-in Libraries Bibliothèques intégrées diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 551c39d1f8..3d508daaa8 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -446,6 +446,8 @@ Brush Library બ્રશ લાઇબ્રેરી Brush Options બ્રશ વિકલ્પો Brush Options… બ્રશ વિકલ્પો… + Options of Selected Object… પસંદ કરેલા ઑબ્જેક્ટના વિકલ્પો… + Options of Selected Object પસંદ કરેલા ઑબ્જેક્ટના વિકલ્પો Brush Scale Options બ્રશ સ્કેલ વિકલ્પો Brush Strokes બ્રશ સ્ટ્રોક Brushes બ્રશ diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 6a135dccaa..557e8e72c5 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -691,6 +691,12 @@ antiAlias Sharp शार्प Brush Library ब्रश लाइब्रेरी Brush Options ब्रश ऑप्शन्स Brush Options… ब्रश ऑप्शन्स… + Options of Selected Object… सिलेक्टेड ऑब्जेक्ट के ऑप्शन्स… + Options of Selected Object सिलेक्टेड ऑब्जेक्ट के ऑप्शन्स +@msg no path painted with a brush is selected ब्रश से पेंट किया गया कोई पाथ नहीं चुना गया +@msg the selected paths are painted with brushes of different types चुने गए पाथ अलग-अलग प्रकार के ब्रश से पेंट किए गए हैं +@msg give `params` or `reset`, not both `params` या `reset` दें, दोनों नहीं +@msg a bristle brush has no options of its own on a path ब्रिसल ब्रश के किसी पाथ पर अपने ऑप्शन्स नहीं होते Brush Scale Options ब्रश स्केल ऑप्शन्स Brush Size ब्रश साइज़ Brush Strokes ब्रश स्ट्रोक्स diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 09a9797d3e..53d2a83f3e 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -495,6 +495,12 @@ font-technology Variable Változó Brush Definition Ecsetdefiníció Brush Libraries Ecsetkönyvtárak Brush Options… Ecset beállításai… + Options of Selected Object… Kijelölt objektum beállításai… + Options of Selected Object Kijelölt objektum beállításai +@msg no path painted with a brush is selected nincs kijelölt ecsettel festett útvonal +@msg the selected paths are painted with brushes of different types a kijelölt útvonalak különböző típusú ecsetekkel vannak festve +@msg give `params` or `reset`, not both `params` vagy `reset` adható meg, a kettő együtt nem +@msg a bristle brush has no options of its own on a path a sörteecsetnek nincsenek saját beállításai egy útvonalon Brush Scale Options Ecsetméretezési beállítások Brush Strokes Ecsetvonások Brushes Ecsetek diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 32283beade..931fdd92c6 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -3145,6 +3145,8 @@ theme Appearance Tampilan Break Link to Symbol Putuskan tautan ke simbol Brush Definition Definisi kuas Brush Options… Opsi kuas… + Options of Selected Object… Opsi objek yang dipilih… + Options of Selected Object Opsi objek yang dipilih Current Brush Kuas saat ini Current Symbol Simbol saat ini Delete Brush Hapus kuas diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 2c8cc708dc..857889158a 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -360,6 +360,12 @@ font-technology Variable Variabili Brush Definition Definizione pennello Brush Libraries Librerie pennelli Brush Options… Opzioni pennello… + Options of Selected Object… Opzioni dell’oggetto selezionato… + Options of Selected Object Opzioni dell’oggetto selezionato +@msg no path painted with a brush is selected nessun tracciato dipinto con un pennello selezionato +@msg the selected paths are painted with brushes of different types i tracciati selezionati sono dipinti con pennelli di tipi diversi +@msg give `params` or `reset`, not both indica `params` o `reset`, non entrambi +@msg a bristle brush has no options of its own on a path un pennello a setole non ha opzioni proprie su un tracciato Brush Strokes Pennellate Brushes Pennelli Built-in Libraries Librerie integrate diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index bd03123f11..3bdebe7723 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -1200,6 +1200,12 @@ antiAlias Sharp シャープ Brush Affects: ブラシの影響: Brush Definition ブラシの定義 Brush Options… ブラシオプション… + Options of Selected Object… 選択中のオブジェクトのオプション… + Options of Selected Object 選択中のオブジェクトのオプション +@msg no path painted with a brush is selected ブラシで描かれたパスが選択されていません +@msg the selected paths are painted with brushes of different types 選択したパスは種類の異なるブラシで描かれています +@msg give `params` or `reset`, not both `params` と `reset` は同時に指定できません +@msg a bristle brush has no options of its own on a path 剛毛ブラシにはパスごとのオプションがありません Built-in presets are read-only: New… starts an editable copy. 組み込みのプリセットは読み取り専用です。「新規…」で編集可能なコピーを作成できます。 Built-in presets don't change: New makes a copy you can edit. 組み込みのプリセットは変更できません。「新規」で編集可能なコピーを作成します。 Built-in presets don't change: New… starts an editable copy. 組み込みのプリセットは変更できません。「新規…」で編集できる複製を作成します。 diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 54445dffb9..0b7f193fc8 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -2988,6 +2988,12 @@ theme Appearance იერსახე Break Link to Symbol სიმბოლოსთან კავშირის გაწყვეტა Brush Definition ფუნჯის განსაზღვრება Brush Options… ფუნჯის პარამეტრები… + Options of Selected Object… მონიშნული ობიექტის პარამეტრები… + Options of Selected Object მონიშნული ობიექტის პარამეტრები +@msg no path painted with a brush is selected ფუნჯით დახატული კონტური მონიშნული არ არის +@msg the selected paths are painted with brushes of different types მონიშნული კონტურები სხვადასხვა ტიპის ფუნჯებითაა დახატული +@msg give `params` or `reset`, not both მიუთითეთ `params` ან `reset`, არა ორივე +@msg a bristle brush has no options of its own on a path ჯაგრის ფუნჯს კონტურზე საკუთარი პარამეტრები არ აქვს Current Brush მიმდინარე ფუნჯი Current Symbol მიმდინარე სიმბოლო Delete Brush ფუნჯის წაშლა diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 2f91553467..066ea9b05d 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -1190,6 +1190,12 @@ antiAlias Sharp 날카롭게 Brush Affects: 브러시 적용 대상: Brush Definition 브러시 정의 Brush Options… 브러시 옵션… + Options of Selected Object… 선택한 오브젝트 옵션… + Options of Selected Object 선택한 오브젝트 옵션 +@msg no path painted with a brush is selected 브러시로 칠한 패스가 선택되지 않았습니다 +@msg the selected paths are painted with brushes of different types 선택한 패스가 서로 다른 유형의 브러시로 칠해져 있습니다 +@msg give `params` or `reset`, not both `params`와 `reset` 중 하나만 지정하세요 +@msg a bristle brush has no options of its own on a path 강모 브러시는 패스별 옵션이 없습니다 Built-in presets are read-only: New… starts an editable copy. 기본 제공 프리셋은 읽기 전용입니다. 새로 만들기…를 누르면 편집 가능한 복사본이 만들어집니다. Built-in presets don't change: New makes a copy you can edit. 기본 제공 프리셋은 변경되지 않습니다. 새로 만들기를 누르면 편집 가능한 복사본이 만들어집니다. Built-in presets don't change: New… starts an editable copy. 기본 제공 프리셋은 변경되지 않습니다. 새로 만들기…를 누르면 편집 가능한 복사본이 만들어집니다. diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index b8eede91bd..2d768bb883 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -3663,6 +3663,12 @@ theme Appearance Vormgeving Break Link to Symbol Koppeling met symbool verbreken Brush Definition Penseeldefinitie Brush Options… Penseelopties… + Options of Selected Object… Opties voor geselecteerd object… + Options of Selected Object Opties voor geselecteerd object +@msg no path painted with a brush is selected geen met een penseel geschilderd pad geselecteerd +@msg the selected paths are painted with brushes of different types de geselecteerde paden zijn geschilderd met penselen van verschillende typen +@msg give `params` or `reset`, not both geef `params` of `reset`, niet beide +@msg a bristle brush has no options of its own on a path een borstelpenseel heeft geen eigen opties op een pad Current Brush Huidig penseel Current Symbol Huidig symbool Delete Brush Penseel verwijderen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index b846ae308c..7c73cfc6e5 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -3291,6 +3291,12 @@ theme Appearance Wygląd Break Link to Symbol Zerwij łącze z symbolem Brush Definition Definicja pędzla Brush Options… Opcje pędzla… + Options of Selected Object… Opcje zaznaczonego obiektu… + Options of Selected Object Opcje zaznaczonego obiektu +@msg no path painted with a brush is selected nie zaznaczono ścieżki malowanej pędzlem +@msg the selected paths are painted with brushes of different types zaznaczone ścieżki są malowane pędzlami różnych typów +@msg give `params` or `reset`, not both podaj `params` albo `reset`, nie oba +@msg a bristle brush has no options of its own on a path pędzel włosiankowy nie ma własnych opcji na ścieżce Current Brush Bieżący pędzel Current Symbol Bieżący symbol Delete Brush Usuń pędzel diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 9b74bba16e..198a39e4e4 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -330,6 +330,12 @@ antiAlias Sharp Nítido Brush Definition Definição do Pincel Brush Libraries Bibliotecas de Pincéis Brush Options… Opções de Pincel… + Options of Selected Object… Opções do Objeto Selecionado… + Options of Selected Object Opções do Objeto Selecionado +@msg no path painted with a brush is selected nenhum demarcador pintado com pincel selecionado +@msg the selected paths are painted with brushes of different types os demarcadores selecionados estão pintados com pincéis de tipos diferentes +@msg give `params` or `reset`, not both informe `params` ou `reset`, não ambos +@msg a bristle brush has no options of its own on a path um pincel de cerdas não tem opções próprias em um demarcador Brush Strokes Traços de Pincel Brushes Pincéis Built-in Libraries Bibliotecas Integradas diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index cd904e1224..6be2e96f1a 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -358,6 +358,12 @@ font-technology Variable Вариативные Brush Definition Определение кисти Brush Libraries Библиотеки кистей Brush Options… Параметры кисти… + Options of Selected Object… Параметры выделенного объекта… + Options of Selected Object Параметры выделенного объекта +@msg no path painted with a brush is selected не выделен контур, нарисованный кистью +@msg the selected paths are painted with brushes of different types выделенные контуры нарисованы кистями разных типов +@msg give `params` or `reset`, not both укажите `params` или `reset`, но не оба +@msg a bristle brush has no options of its own on a path у щетинной кисти нет собственных параметров на контуре Brush Strokes Мазки кисти Brushes Кисти Built-in Libraries Встроенные библиотеки diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 5d20472e7b..12f7d06d4c 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -349,6 +349,12 @@ font-technology Variable Variabla Brush Definition Penseldefinition Brush Libraries Penselbibliotek Brush Options… Penselalternativ… + Options of Selected Object… Alternativ för markerat objekt… + Options of Selected Object Alternativ för markerat objekt +@msg no path painted with a brush is selected ingen bana målad med en pensel är markerad +@msg the selected paths are painted with brushes of different types de markerade banorna är målade med penslar av olika typer +@msg give `params` or `reset`, not both ange `params` eller `reset`, inte båda +@msg a bristle brush has no options of its own on a path en borstpensel har inga egna alternativ på en bana Brush Strokes Penseldrag Brushes Penslar Built-in Libraries Inbyggda bibliotek diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 9bdf0c5036..2a8319bbe2 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -344,6 +344,12 @@ font-technology Variable Değişken Brush Definition Fırça Tanımı Brush Libraries Fırça Kitaplıkları Brush Options… Fırça Seçenekleri… + Options of Selected Object… Seçili Nesnenin Seçenekleri… + Options of Selected Object Seçili Nesnenin Seçenekleri +@msg no path painted with a brush is selected fırçayla boyanmış yol seçilmedi +@msg the selected paths are painted with brushes of different types seçili yollar farklı türde fırçalarla boyanmış +@msg give `params` or `reset`, not both `params` veya `reset` verin, ikisini birden değil +@msg a bristle brush has no options of its own on a path kıl fırçanın bir yolda kendine ait seçenekleri yoktur Brush Strokes Fırça Darbeleri Brushes Fırçalar Built-in Libraries Yerleşik Kütüphaneler diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 7395cdec64..9c8e7efaae 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -354,6 +354,12 @@ font-technology Variable Варіативні Brush Definition Визначення пензля Brush Libraries Бібліотеки пензлів Brush Options… Параметри пензля… + Options of Selected Object… Параметри виділеного об’єкта… + Options of Selected Object Параметри виділеного об’єкта +@msg no path painted with a brush is selected не виділено контур, намальований пензлем +@msg the selected paths are painted with brushes of different types виділені контури намальовано пензлями різних типів +@msg give `params` or `reset`, not both укажіть `params` або `reset`, але не обидва +@msg a bristle brush has no options of its own on a path щетинний пензель не має власних параметрів на контурі Brush Strokes Мазки пензля Brushes Пензлі Built-in Libraries Вбудовані бібліотеки diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 8df980ee37..0be0fbea43 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -413,6 +413,12 @@ font-technology Variable Biến thiên Brush Definition Định nghĩa cọ Brush Libraries Thư viện cọ Brush Options… Tùy chọn cọ… + Options of Selected Object… Tùy chọn của đối tượng đã chọn… + Options of Selected Object Tùy chọn của đối tượng đã chọn +@msg no path painted with a brush is selected chưa chọn đường được vẽ bằng cọ +@msg the selected paths are painted with brushes of different types các đường đã chọn được vẽ bằng các loại cọ khác nhau +@msg give `params` or `reset`, not both chỉ cung cấp `params` hoặc `reset`, không cả hai +@msg a bristle brush has no options of its own on a path cọ lông không có tùy chọn riêng trên một đường Brush Scale Options Tùy chọn tỷ lệ cọ Brush Strokes Nét cọ Brushes Cọ diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index ca19647856..01a4c7448b 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -308,6 +308,12 @@ antiAlias Sharp 锐利 Brush Definition 画笔定义 Brush Libraries 画笔库 Brush Options… 画笔选项… + Options of Selected Object… 所选对象的选项… + Options of Selected Object 所选对象的选项 +@msg no path painted with a brush is selected 未选择用画笔绘制的路径 +@msg the selected paths are painted with brushes of different types 所选路径使用了不同类型的画笔 +@msg give `params` or `reset`, not both 请提供 `params` 或 `reset`,不能同时提供 +@msg a bristle brush has no options of its own on a path 鬃毛画笔在路径上没有自己的选项 Brush Strokes 画笔描边 Brushes 画笔 Built-in Libraries 内置库 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 748ff1848b..def9b22041 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -322,6 +322,12 @@ font-technology Variable 可變 Brush Definition 筆刷定義 Brush Libraries 筆刷資料庫 Brush Options… 筆刷選項… + Options of Selected Object… 所選物件的選項… + Options of Selected Object 所選物件的選項 +@msg no path painted with a brush is selected 未選取以筆刷繪製的路徑 +@msg the selected paths are painted with brushes of different types 所選路徑使用了不同類型的筆刷 +@msg give `params` or `reset`, not both 請提供 `params` 或 `reset`,不能同時提供 +@msg a bristle brush has no options of its own on a path 鬃毛筆刷在路徑上沒有自己的選項 Brush Strokes 筆刷筆畫 Brushes 筆刷 Built-in Libraries 內建資料庫 diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index df3f08b55e..33f9b6ba04 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -788,6 +788,7 @@ fn run_ui_part7(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option crate::dialogs::new_brush::open(app, p.get("ids").cloned()), "ui.brushOptions" => crate::dialogs::brush_options::open(app, s("name").as_deref()), + "ui.brushObjectOptions" => crate::dialogs::brush_options::open_object(app), "tool.options" => crate::toolbar::open_options(app, &s("tool").unwrap_or_default()), _ => return None, }; diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 98c13ec06e..147e486227 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -285,6 +285,7 @@ pub fn enabled(app: &VectorcraftApp, id: &str) -> bool { "ui.sampleScreenColor" => crate::screen_color::available(app), "ui.newBrush" => app.session.active().is_some(), "ui.brushOptions" => crate::dialogs::brush_options::available(app), + "ui.brushObjectOptions" => crate::dialogs::brush_options::object_available(app), "ui.hyphenation" | "ui.justification" | "ui.tateChuYokoSettings" | "ui.warichuSettings" => { crate::panels::character::text_style(app).is_some() } diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index fc43b1ed3e..cd38009f9b 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -904,6 +904,12 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "", "{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options", ), + ( + "ui.brushObjectOptions", + "Options of Selected Object…", + "", + "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened, and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", + ), ( "ui.graphicStyleOptions", "Graphic Style Options…", diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 3e7fb53316..acde0e9805 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -15,6 +15,7 @@ const WRAPPED: &[(&str, &str)] = &[ ("layer.delete", "ui.layerDelete"), ("brush.new", "ui.newBrush"), ("brush.options", "ui.brushOptions"), + ("brush.objectOptions", "ui.brushObjectOptions"), ("symbol.options", "ui.symbolOptions"), ("svgFilter.import", "ui.importSvgFilter"), ("text.convertListToText", "type.convertListToText"), diff --git a/crates/ui-egui/src/panels/brushes.rs b/crates/ui-egui/src/panels/brushes.rs index 0b540a4ba5..c1ff6286a4 100644 --- a/crates/ui-egui/src/panels/brushes.rs +++ b/crates/ui-egui/src/panels/brushes.rs @@ -523,6 +523,12 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { { app.status(e); } + // The selected brushed paths' own settings: the brush stays as it is. + if menu_item(ui, tl!("Options of Selected Object…"), brush_options::object_available(app), false) + && let Err(e) = app.run("ui.brushObjectOptions", json!({})) + { + app.status(e); + } ui.separator(); // Selects the brushes no stroke paints with, for Delete Brush and Duplicate Brush. if menu_item(ui, tl!("Select All Unused"), app.session.active().is_some(), false) diff --git a/docs/mcp.md b/docs/mcp.md index 494b4f4ef6..a9bfeae56f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3317,7 +3317,7 @@ already walks Image Trace. Short agent entry points: - Brushes: `brush.list`, `brush.get {name}`, `brush.apply {name, ids?}`, `brush.new {type, name?, params?, ids?}`, `brush.setCurrent {name}`, `brush.options {name, params?, newName?}`, `brush.delete {name} | {names}`, `brush.duplicate {name, newName?} | {names}`, `brush.freehand {…path.freehand params, brush?}`, - `object.expandBrush {ids?}`. `brush.freehand` draws the plain path when `brush` is left out or null. It refuses a + `object.expandBrush {ids?}`, `brush.objectOptions {ids?, params?, reset?}`. `brush.freehand` draws the plain path when `brush` is left out or null. It refuses a `brush` that is not a string with "`brush` must be a string", a name that no brush in the document has (an empty name included) with "no brush named ``", and a `style` other than "pencil" or "brush"; the document does not change and no undo step is recorded. The Paintbrush skips a tool brush or current brush that has been deleted and @@ -3347,6 +3347,20 @@ already walks Image Trace. Short agent entry points: words. Corner tiles also take `autoCentered`, `autoBetween`, `autoSliced` and `autoOverlap`. A swatch choice copies its whole art and tile frame into the brush. `original` keeps the current art and clears its swatch label. `side_tile: "none"` fails with "You must choose a side pattern." An unknown swatch name also fails; neither error edits the brush or adds an Undo step. + `brush.objectOptions {ids?, params?, reset?}` (the Brushes panel menu's Options of Selected Object…, from the + [Modify brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/modify-brushes.html) + page) changes the brush settings of the selected brushed paths on those paths only; the brush and its other strokes + keep their settings. The fields a path can set are VectorCraft's own choice: calligraphic `angle`, `roundness`, + `size`, `variation` and `modes`; scatter `size`, `spacing`, `scatter`, `rotation`, `modes`, + `rotation_relative_to_path` and `colorization`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`, + `overlap` and `colorization`; pattern `scale`, `spacing`, `fit`, `flip_along`, `flip_across` and `colorization`. + Values outside their ranges are clamped as in `brush.options`, a `colorization` object changes only the fields it + gives, and a setting equal to the brush's own value is dropped. `reset: true` clears a path's settings. The command + refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different + types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes. + `brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in + `stroke.setAdvanced` and removing the brush clear the path's settings, and renaming the brush keeps them. Without + `params` or `reset` the command only returns the first path's settings. The native file saves them on the stroke as `brush_options`. - Pen tilt, bearing and barrel rotation (#764): `path.freehand` and `brush.freehand` take points as `[x, y, pressure, tiltX, tiltY, rotation]` or `{x, y, pressure?, tiltX?, tiltY?, rotation?}`, with `null` for what a point lacks, and a `pointer_gesture` event takes `tiltX`, `tiltY` and `rotation`, which the Paintbrush records. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 082e565bd2..59a0450418 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -433,6 +433,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Make Compound Path on a group (such as outlined type) keeps its backmost path's paint; compound paths joined into one keep their holes | done | #1537 | | Symbol libraries: Window › Symbol Libraries (Basic Shapes, UI Frames, Map Markers, Inventory Icons, Skill Icons, User Defined, Other Library…, Save Symbols…) and the Symbols panel's Symbol Libraries Menu button and its menu's Open Symbol Library / Save Symbol Library…; a click on a library symbol adds it to the document's Symbols (one undo step, it becomes the current symbol), Shift/Cmd-clicks select for Add to Symbols, and a symbol dragged onto the canvas is added and placed where it is dropped | done | [public source](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-or-import-symbol-libraries.html), [Symbols panel options](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html), [placing from a library](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-and-place-symbols.html); `window.symbolLibrary`, `window.symbolLibrary.other`, `ui.saveSymbolLibrary` (dialog `saveSymbolLibrary`), `window.userSymbolLibrary1`…`10`; `panels::tests_symbol_libraries`; five built-in libraries (Basic Shapes, UI Frames with default 9-slice, Map Markers, Inventory Icons, Skill Icons; original, generated in code) | | Brush libraries: Window › Brush Libraries (Art Ribbons, Ink and Wash, Calligraphic Nibs, Bristle Brushes, Pattern Borders, Scatter Shapes, Game Trails, Energy Beams, Dry Media, Tech Circuit, User Defined, Other Library…, Save Brushes…) and the Brushes panel's Brush Libraries Menu button and its menu's Open Brush Library / Save Brush Library…; a click on a library brush adds it to the document's Brushes (one undo step, it becomes the current brush, and selected paths take it in the same step), Shift/Cmd-clicks select for Add to Brushes, a brush dragged onto a path is added and applied to it and one dragged onto the Brushes panel is added; thumbnails render with the library's patterns and symbols | done | [public source](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/create-new-brush-libraries.html), [import brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/import-brushes-from-brush-libraries-or-other-files.html), [Brushes panel overview](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/brushes-panel-overview.html); `window.brushLibrary`, `window.brushLibrary.other`, `ui.saveBrushLibrary` (dialog `saveBrushLibrary`), `window.userBrushLibrary1`…`10`; `panels::tests_brush_libraries`; ten built-in libraries (original, generated in code) | +| Brushes panel menu › Options of Selected Object…: changes the selected brushed paths' brush settings on those paths only, leaving the brush and its other strokes as they are; the brush type's options dialog opens without the Name row (and without an art brush's scale and direction options or a pattern brush's tiles), and OK sends only the values changed in it | done | [Modify brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/modify-brushes.html), [Brushes panel overview](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/brushes-panel-overview.html); `brush.objectOptions`, `ui.brushObjectOptions`; which fields a path can set is VectorCraft's own choice (calligraphic, scatter, art and pattern brushes; not bristle); `options_of_selected_object_*` tests in `crates/engine/src/tests/brushsym.rs` and `crates/ui-egui/src/dialogs/brush_options/tests.rs`, brush tests in `crates/brush/src/tests.rs` | | Symbols panel: New Symbol opens Symbol Options (Name) before making the symbol; Alt-click skips it | partial | #1560 (#1566); Registration 9-point grid in Symbol Options (`symbol.new` / `symbol.place`); Export Type (Graphic / Movie Clip) and Enable Guides for 9-Slice Scaling (scaled instances keep their corners; in symbol editing mode the guides are drawn over the art and the Selection tool drags them); Symbol Type (Dynamic Symbol / Static Symbol, new symbols dynamic; #4938) | | Dynamic symbols: an instance changes the fill, stroke, opacity and blend of objects in its symbol's art and stays linked; Reset in the Properties panel's Quick Actions and the Symbols panel menu (Reset Symbol Instance) | partial | #4938; `symbol.instance.setAppearance` (by child-index path) and `symbol.instance.reset`; redefining keeps the changes, Break Link bakes them; Direct Selection of a path, compound path or type object inside an instance, with the Fill/Stroke controls setting its solid fill or stroke, is on canvas; on-canvas editing beyond a solid fill and stroke, and `.ai` read and write, remain | | Pathfinder Trim, Merge and Crop remove strokes; Merge joins same-fill objects whatever their strokes | done | #1570 (#1572) | From 87acb57d0dbad837b1cc0549167a1d293f301733 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:17:25 -0800 Subject: [PATCH 2/7] Brushes: Options of Selected Object keeps each path's values the dialog did not change With several brushed paths selected, editing one end of a range in the dialog sent the whole range, so every path took the first path's other end. The dialog now sends only the items and colorization fields that changed, and brush.objectOptions reads a null item of an array as each path's own item, else the brush's. A null mode keeps the mode the path has with its other values, and modes that change nothing are not stored. --- crates/brush/src/lib.rs | 46 +++++++++++++++++-- crates/brush/src/tests.rs | 20 ++++++++ crates/engine/src/cmd/brushsym.rs | 2 +- crates/engine/src/cmd/brushsym/brushes.rs | 15 +++++- crates/engine/src/tests/brushsym.rs | 23 ++++++++++ crates/ui-egui/src/dialogs/brush_options.rs | 19 +++++++- .../src/dialogs/brush_options/tests.rs | 17 +++++++ crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/mcp.md | 4 +- 9 files changed, 138 insertions(+), 10 deletions(-) diff --git a/crates/brush/src/lib.rs b/crates/brush/src/lib.rs index 7f83931f25..718a552f32 100644 --- a/crates/brush/src/lib.rs +++ b/crates/brush/src/lib.rs @@ -865,12 +865,26 @@ impl BrushKind { } } +/// Stroke option value `new` with each `null` item of an array taken from the same place in +/// `current`, an array of the same length: a stroke option that changes some items of a range or a +/// list of modes and keeps the others ([`Brush::with_stroke_options`]). Any other `new` is given as +/// it is. +pub fn keep_items(new: &serde_json::Value, current: &serde_json::Value) -> serde_json::Value { + match (new, current) { + (serde_json::Value::Array(n), serde_json::Value::Array(c)) if n.len() == c.len() => { + serde_json::Value::Array(n.iter().zip(c).map(|(n, c)| if n.is_null() { c.clone() } else { n.clone() }).collect()) + } + _ => new.clone(), + } +} + impl Brush { /// The brush as a stroke whose own settings are `options` draws it: each field of /// [`BrushKind::stroke_option_keys`] in `options` replaces the brush's value (a `colorization` /// object changes only the fields it gives), and the values are kept within their ranges - /// ([`Brush::sanitize`]). Fields the type does not take are passed over. An error when a value - /// is of the wrong kind. + /// ([`Brush::sanitize`]). A `null` item of an array keeps the brush's item there + /// ([`keep_items`]). Fields the type does not take are passed over. An error when a value is of + /// the wrong kind. pub fn with_stroke_options(&self, options: &serde_json::Map) -> Result { let keys = self.kind.stroke_option_keys(); let mut values = self.kind.option_values(); @@ -885,8 +899,11 @@ impl Brush { inner.insert(f.clone(), fv.clone()); } } + // Set below, once the values the modes may follow are in. + _ if k == "modes" => {} _ => { - o.insert(k.clone(), v.clone()); + let current = o.get(k).cloned().unwrap_or_default(); + o.insert(k.clone(), keep_items(v, ¤t)); } } } @@ -899,7 +916,28 @@ impl Brush { c.insert("key".into(), serde_json::to_value(key).map_err(|e| e.to_string())?); } let mut b = self.clone(); - b.kind.set_option_values(values).map_err(|e| e.to_string())?; + b.kind.set_option_values(values.clone()).map_err(|e| e.to_string())?; + if let Some(m) = options.get("modes") + && keys.contains(&"modes") + { + // A null item keeps the mode the brush with the other settings has: modes it leaves to + // its values follow the stroke's values, as they are kept within their ranges. Modes + // equal to those are left as the brush has them, so they keep following the values. + b.sanitize(); + let current = match &b.kind { + BrushKind::Calligraphic(c) => serde_json::to_value(c.modes()).unwrap_or_default(), + BrushKind::Scatter(s) => serde_json::to_value(s.modes()).unwrap_or_default(), + _ => serde_json::Value::Null, + }; + let modes = keep_items(m, ¤t); + if modes != current { + if let Some(o) = values.as_object_mut() { + o.insert("modes".into(), modes); + } + b = self.clone(); + b.kind.set_option_values(values).map_err(|e| e.to_string())?; + } + } b.sanitize(); Ok(b) } diff --git a/crates/brush/src/tests.rs b/crates/brush/src/tests.rs index cb4e560ff5..46779d8e2d 100644 --- a/crates/brush/src/tests.rs +++ b/crates/brush/src/tests.rs @@ -2098,3 +2098,23 @@ fn stroke_options_are_checked_and_kept_within_their_ranges() { let odd = stroke_pieces(&doc, &brush, &path, &with_options(json!({"width": [1, 2]}))); assert!(near(bounds(&odd).height(), 4.0, 1e-6)); } + +#[test] +fn null_stroke_option_items_keep_the_items_the_stroke_has() { + let map = |v: serde_json::Value| v.as_object().cloned().unwrap_or_default(); + // A scatter brush at fixed sizes, with no modes of its own: they follow its values. + let b = Brush { name: "s".into(), kind: BrushKind::Scatter(Scatter { size: (100.0, 100.0), ..Default::default() }) }; + let BrushKind::Scatter(s) = b.with_stroke_options(&map(json!({"size": [null, 150]}))).unwrap().kind else { panic!("scatter") }; + assert_eq!(s.size, (100.0, 150.0), "the smallest size stays the brush's"); + // A stroke whose sizes vary keeps that random size mode when it sets only the spacing mode. + let e = b.with_stroke_options(&map(json!({"size": [50, 80], "modes": [null, "pressure", null, null]}))).unwrap(); + let BrushKind::Scatter(s) = e.kind else { panic!("scatter") }; + assert_eq!(s.modes(), [Variation::Random, Variation::Pressure, Variation::Fixed, Variation::Fixed]); + // The kept modes follow the values as they are kept within their ranges. + let c = calli(0.0, 100.0, 3.0).with_stroke_options(&map(json!({"variation": [-2, 0, 0], "modes": [null, "pressure", null]}))).unwrap(); + let BrushKind::Calligraphic(c) = c.kind else { panic!("calligraphic") }; + assert_eq!(c.modes(), [Variation::Fixed, Variation::Pressure, Variation::Fixed]); + // Modes that change nothing are no setting of the stroke's: they keep following its values. + let same = b.stroke_options_that_differ(&map(json!({"modes": [null, null, null, null]}))).unwrap(); + assert!(same.is_empty(), "{same:?}"); +} diff --git a/crates/engine/src/cmd/brushsym.rs b/crates/engine/src/cmd/brushsym.rs index 2712339b6f..0e2cd79cd6 100644 --- a/crates/engine/src/cmd/brushsym.rs +++ b/crates/engine/src/cmd/brushsym.rs @@ -171,7 +171,7 @@ pub fn specs() -> Vec { "Options of Selected Object…", [], None, - "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, or stroke.setAdvanced with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", + "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, or stroke.setAdvanced with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", has_doc, brush_object_options ), diff --git a/crates/engine/src/cmd/brushsym/brushes.rs b/crates/engine/src/cmd/brushsym/brushes.rs index 00e286bd98..de2109c065 100644 --- a/crates/engine/src/cmd/brushsym/brushes.rs +++ b/crates/engine/src/cmd/brushsym/brushes.rs @@ -558,7 +558,20 @@ pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result let keys = b.kind.stroke_option_keys(); let mut merged: serde_json::Map = own.iter().filter(|(k, _)| keys.contains(&k.as_str())).map(|(k, v)| (k.clone(), v.clone())).collect(); - merged.extend(params.clone()); + // A colorization object changes only the fields it gives, and a null item of an + // array keeps the stroke's own item (else the brush's). + for (k, v) in ¶ms { + let next = match (merged.get(k), v) { + (Some(Value::Object(mine)), Value::Object(fields)) if k == "colorization" => { + let mut c = mine.clone(); + c.extend(fields.clone()); + Value::Object(c) + } + (Some(mine), _) => brush::keep_items(v, mine), + (None, _) => v.clone(), + }; + merged.insert(k.clone(), next); + } b.stroke_options_that_differ(&merged).map_err(|e| bad(C, e))? }; options.get_or_insert_with(|| next.clone()); diff --git a/crates/engine/src/tests/brushsym.rs b/crates/engine/src/tests/brushsym.rs index e881c448eb..41db8291e0 100644 --- a/crates/engine/src/tests/brushsym.rs +++ b/crates/engine/src/tests/brushsym.rs @@ -152,6 +152,29 @@ fn options_of_selected_object_change_one_path_and_leave_the_brush() { assert_eq!(undo_steps(&s), steps); } +#[test] +fn options_of_selected_object_null_items_keep_each_paths_own() { + let mut s = session(); + let a = line(&mut s); + let b = line(&mut s); + s.execute("brush.apply", &json!({"name": "Confetti", "ids": [a.0, b.0]})).unwrap(); + let brush_size = s.execute("brush.get", &json!({"name": "Confetti"})).unwrap()["size"].clone(); + s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"size": [50, 80]}})).unwrap(); + s.execute("brush.objectOptions", &json!({"ids": [b.0], "params": {"size": [60, 120]}})).unwrap(); + let steps = undo_steps(&s); + // Only the smallest size changes: each path keeps its own largest size. + let r = s.execute("brush.objectOptions", &json!({"ids": [a.0, b.0], "params": {"size": [40, null]}})).unwrap(); + assert_eq!(r["changed"], json!([a.0, b.0])); + assert_eq!(own_options(&s, a)["size"], json!([40.0, 80.0])); + assert_eq!(own_options(&s, b)["size"], json!([40.0, 120.0])); + assert_eq!(undo_steps(&s), steps + 1, "one undo step for both paths"); + // A path without its own value keeps the brush's item. + let c = line(&mut s); + s.execute("brush.apply", &json!({"name": "Confetti", "ids": [c.0]})).unwrap(); + s.execute("brush.objectOptions", &json!({"ids": [c.0], "params": {"size": [null, 150]}})).unwrap(); + assert_eq!(own_options(&s, c)["size"], json!([brush_size[0], 150.0]), "brush size {brush_size}"); +} + #[test] fn options_of_selected_object_keys_convert_with_the_document() { let mut s = session(); diff --git a/crates/ui-egui/src/dialogs/brush_options.rs b/crates/ui-egui/src/dialogs/brush_options.rs index 501ed7ec8d..310cd36f6b 100644 --- a/crates/ui-egui/src/dialogs/brush_options.rs +++ b/crates/ui-egui/src/dialogs/brush_options.rs @@ -241,13 +241,28 @@ fn object_params(d: &Dialog, keys: &[&str]) -> Map { } } +/// What of option value `now` changed from `was`, the value it opened with: `None` when nothing +/// did; of a range or a list of modes, the items that changed with `null` for the others, and of a +/// colorization, the fields that changed. The paths keep their own values for the rest. +fn changed_part(was: Option<&Value>, now: Value) -> Option { + match (was, now) { + (Some(w), n) if *w == n => None, + (Some(Value::Array(w)), Value::Array(n)) if w.len() == n.len() => { + Some(Value::Array(w.iter().zip(n).map(|(w, n)| if *w == n { Value::Null } else { n }).collect())) + } + (Some(Value::Object(w)), Value::Object(n)) => Some(Value::Object(n.into_iter().filter(|(f, v)| w.get(f) != Some(v)).collect())), + (_, n) => Some(n), + } +} + /// OK of Options of Selected Object: `brush.objectOptions` on the paths it opened for, with the -/// values changed since it opened. The dialog closes when they are set. +/// values changed since it opened ([`changed_part`]). The dialog closes when they are set. fn confirm_object(app: &mut VectorcraftApp, d: &Dialog) -> Result { let keys: Vec = d.fields.get("__keys").and_then(|v| serde_json::from_value(v.clone()).ok()).unwrap_or_default(); let keys: Vec<&str> = keys.iter().map(String::as_str).collect(); let opened = d.fields.get(OPENED).and_then(Value::as_object).cloned().unwrap_or_default(); - let changed: Map = object_params(d, &keys).into_iter().filter(|(k, v)| opened.get(k) != Some(v)).collect(); + let changed: Map = + object_params(d, &keys).into_iter().filter_map(|(k, v)| changed_part(opened.get(&k), v).map(|v| (k, v))).collect(); let r = app.run("brush.objectOptions", json!({ "ids": d.fields.get(TARGETS).cloned().unwrap_or_default(), "params": changed })); if r.is_ok() { app.ui.dialog = None; diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index e997e92805..43e4886aac 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -908,6 +908,23 @@ fn options_of_selected_object_set_one_paths_art_brush_settings() { assert_eq!(own_options(&app, a), json!({"width": 50.0})); } +#[test] +fn options_of_selected_object_change_only_the_values_edited_on_each_path() { + let mut app = app(); + let a = brushed_line(&mut app, 50.0, "Confetti"); + let b = brushed_line(&mut app, 100.0, "Confetti"); + app.run("brush.objectOptions", json!({"ids": [a], "params": {"size": [50, 80]}})).unwrap(); + app.run("brush.objectOptions", json!({"ids": [b], "params": {"size": [60, 120]}})).unwrap(); + select(&mut app, &[a, b]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + // The dialog shows the first path's values; only the smallest size is edited. + assert_eq!(app.ui.dialog.as_ref().unwrap().f64("sizeMax", 0.0), 80.0); + set(&mut app, json!({"sizeMin": 40})); + super::super::confirm(&mut app).unwrap(); + assert_eq!(own_options(&app, a)["size"], json!([40.0, 80.0])); + assert_eq!(own_options(&app, b)["size"], json!([40.0, 120.0]), "the second path keeps its own largest size"); +} + #[test] fn options_of_selected_object_show_what_a_path_can_set_for_each_type() { let mut app = app(); diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 3bd80b11d3..98f87430ee 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -920,7 +920,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.brushObjectOptions", "Options of Selected Object…", "", - "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened, and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", + "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened (one end of a range or one colorization field changed leaves each path's other values as they are), and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", ), ( "ui.graphicStyleOptions", diff --git a/docs/mcp.md b/docs/mcp.md index 816bcb2346..8c54dbd3d9 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3424,7 +3424,9 @@ already walks Image Trace. Short agent entry points: `rotation_relative_to_path` and `colorization`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`, `overlap` and `colorization`; pattern `scale`, `spacing`, `fit`, `flip_along`, `flip_across` and `colorization`. Values outside their ranges are clamped as in `brush.options`, a `colorization` object changes only the fields it - gives, and a setting equal to the brush's own value is dropped. `reset: true` clears a path's settings. The command + gives, a `null` item of an array (`size: [40, null]`) keeps each path's own item, else the brush's, and a setting + equal to the brush's own value is dropped. The dialog sends only the items and fields changed in it, so editing one + end of a range leaves each selected path's other end as it was. `reset: true` clears a path's settings. The command refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes. `brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in From 74370b1cdb3651ef3f9bbd1a7f08152fe56bc4d5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:49:11 -0800 Subject: [PATCH 3/7] Brushes: a Paintbrush stroke that changes a path's brush clears the path's own brush settings Extending a path with brush.freehand and another brush set the new brush but kept the settings Options of Selected Object stored for the old one. They are now cleared, as brush.apply clears them. --- crates/engine/src/cmd/brushsym.rs | 2 +- crates/engine/src/cmd/draw2/freehand.rs | 6 +++++- crates/engine/src/tests/brushsym.rs | 18 ++++++++++++++++++ docs/mcp.md | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/brushsym.rs b/crates/engine/src/cmd/brushsym.rs index 0e2cd79cd6..c8efc87d1b 100644 --- a/crates/engine/src/cmd/brushsym.rs +++ b/crates/engine/src/cmd/brushsym.rs @@ -171,7 +171,7 @@ pub fn specs() -> Vec { "Options of Selected Object…", [], None, - "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, or stroke.setAdvanced with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", + "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", has_doc, brush_object_options ), diff --git a/crates/engine/src/cmd/draw2/freehand.rs b/crates/engine/src/cmd/draw2/freehand.rs index 977f3f921a..817d01ea82 100644 --- a/crates/engine/src/cmd/draw2/freehand.rs +++ b/crates/engine/src/cmd/draw2/freehand.rs @@ -174,9 +174,13 @@ fn no_stroke(name: &str) -> EngineError { bad("brush.freehand", format!("cannot apply brush `{name}`: path has no stroke")) } -/// Sets brush `name` on the stroke of object `id` of `d`. +/// Sets brush `name` on the stroke of object `id` of `d`. The stroke's own settings for another +/// brush (Options of Selected Object) are cleared. fn set_brush(d: &mut Document, id: NodeId, name: &str) { if let Some(st) = d.node_mut(id).and_then(|n| n.appearance.stroke_mut()) { + if st.brush.as_deref() != Some(name) { + st.brush_options.clear(); + } st.brush = Some(name.to_string()); } } diff --git a/crates/engine/src/tests/brushsym.rs b/crates/engine/src/tests/brushsym.rs index 41db8291e0..8aa440ea26 100644 --- a/crates/engine/src/tests/brushsym.rs +++ b/crates/engine/src/tests/brushsym.rs @@ -175,6 +175,24 @@ fn options_of_selected_object_null_items_keep_each_paths_own() { assert_eq!(own_options(&s, c)["size"], json!([brush_size[0], 150.0]), "brush size {brush_size}"); } +#[test] +fn options_of_selected_object_go_when_a_freehand_stroke_changes_the_brush() { + let mut s = session(); + let a = line(&mut s); + s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0]})).unwrap(); + s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"width": 50}})).unwrap(); + let extend = |s: &mut Session, brush: &str, points: Value| { + s.execute("brush.freehand", &json!({"points": points, "style": "brush", "brush": brush, "extend": {"id": a.0}})).unwrap(); + }; + // Continuing the path with its own brush keeps the settings. + extend(&mut s, "Arrow", json!([[0, 0], [40, 30], [80, 10]])); + assert_eq!(own_options(&s, a), json!({"width": 50.0})); + // Another brush, with a stroke or with only the brush changing, clears them. + extend(&mut s, "Diamonds", json!([[0, 0]])); + assert_eq!(brush_of(&s, a).as_deref(), Some("Diamonds")); + assert_eq!(own_options(&s, a), json!({})); +} + #[test] fn options_of_selected_object_keys_convert_with_the_document() { let mut s = session(); diff --git a/docs/mcp.md b/docs/mcp.md index 8c54dbd3d9..0e67062c1d 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3430,7 +3430,8 @@ already walks Image Trace. Short agent entry points: refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes. `brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in - `stroke.setAdvanced` and removing the brush clear the path's settings, and renaming the brush keeps them. Without + `stroke.setAdvanced`, Global Edit or a `brush.freehand` extend, and removing the brush clear the path's settings, + and renaming the brush keeps them. Without `params` or `reset` the command only returns the first path's settings. The native file saves them on the stroke as `brush_options`. - Pen tilt, bearing and barrel rotation (#764): `path.freehand` and `brush.freehand` take points as `[x, y, pressure, tiltX, tiltY, rotation]` or `{x, y, pressure?, tiltX?, tiltY?, rotation?}`, with `null` for what a From 9226a0bf74976c96be3382103bda1d549318e63a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 12:14:51 -0800 Subject: [PATCH 4/7] Plug-ins: brush.objectOptions is a command a plug-in may call The plug-in call list places every registered command in ALLOWED or DENIED, and every_command_is_reviewed fails while brush.objectOptions is in neither. It edits the selected paths' brush settings the way brush.options edits a brush, so it joins brush.options in ALLOWED. --- crates/engine/src/cmd/plugin_call/reviewed.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/engine/src/cmd/plugin_call/reviewed.rs b/crates/engine/src/cmd/plugin_call/reviewed.rs index 67d0fec2a3..2580048b84 100644 --- a/crates/engine/src/cmd/plugin_call/reviewed.rs +++ b/crates/engine/src/cmd/plugin_call/reviewed.rs @@ -118,6 +118,7 @@ pub(super) const ALLOWED: &[&str] = &[ "brush.list", "brush.move", "brush.new", + "brush.objectOptions", "brush.options", "brush.placeArt", "brush.remove", From 628bd5229c56c4725deb48b95610fa2a089b0aa2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 13:18:05 -0800 Subject: [PATCH 5/7] Brushes: Options of Selected Object keeps the mode each path draws with when a value changes A path without modes of its own takes them from its values, so a changed calligraphic variation or scatter range could change the mode the dialog showed (a Random size became Fixed when its two ends met). brush.objectOptions now keeps each path's drawn mode for every item params does not set, and still sets the modes params give. The params text also says which way the calligraphic angle and the scatter rotation turn, as every_turn_param_says_which_way_it_turns requires. --- crates/engine/src/cmd/brushsym.rs | 2 +- crates/engine/src/cmd/brushsym/brushes.rs | 43 +++++++++++++++++++ crates/engine/src/tests/brushsym.rs | 32 ++++++++++++++ .../src/dialogs/brush_options/tests.rs | 35 +++++++++++++++ docs/mcp.md | 9 ++-- 5 files changed, 117 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/brushsym.rs b/crates/engine/src/cmd/brushsym.rs index c8efc87d1b..21679f9702 100644 --- a/crates/engine/src/cmd/brushsym.rs +++ b/crates/engine/src/cmd/brushsym.rs @@ -171,7 +171,7 @@ pub fn specs() -> Vec { "Options of Selected Object…", [], None, - "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle, roundness, size, variation, modes; scatter size, spacing, scatter, rotation, modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", + "{ids?|id?, params?: {…the fields brush.options takes that a path can set for itself: calligraphic angle (counter-clockwise from level), roundness, size, variation, modes; scatter size, spacing, scatter, rotation (counter-clockwise), modes, rotation_relative_to_path, colorization; art width, width_mode, width_max, flip_along, flip_across, overlap, colorization; pattern scale, spacing, fit, flip_along, flip_across, colorization (values outside their ranges are clamped; a colorization object changes only the fields it gives; a null item of an array such as size: [40, null] keeps each stroke's own item, else the brush's)}, reset?: bool} set the brush settings of the brushed strokes of the selected paths on those strokes only, leaving the brush and its other strokes as they are (the Brushes panel's Options of Selected Object); params add to each stroke's own settings, a mode params does not set (no modes, or a null item) stays the one each stroke draws with when a changed variation or range would change it, a setting equal to the brush's own value is dropped, and reset: true clears them so the strokes draw the brush again; without params or reset nothing changes; one undo step, none when nothing changes. The brushes' own edits (brush.options) still reach the settings a stroke does not set, applying a brush (brush.apply, stroke.setAdvanced or a brush.freehand extend with another brush) or removing it clears them, and a renamed brush keeps them. Refused with nothing painted with a brush selected, for paths painted with brushes of different types, for a bristle brush, for a field the type does not take and for a value of the wrong kind → {ids: the brushed paths, changed: the paths whose settings changed, options: the first stroke's own settings}", has_doc, brush_object_options ), diff --git a/crates/engine/src/cmd/brushsym/brushes.rs b/crates/engine/src/cmd/brushsym/brushes.rs index de2109c065..8ddeb99b29 100644 --- a/crates/engine/src/cmd/brushsym/brushes.rs +++ b/crates/engine/src/cmd/brushsym/brushes.rs @@ -558,6 +558,7 @@ pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result let keys = b.kind.stroke_option_keys(); let mut merged: serde_json::Map = own.iter().filter(|(k, _)| keys.contains(&k.as_str())).map(|(k, v)| (k.clone(), v.clone())).collect(); + let was = merged.clone(); // A colorization object changes only the fields it gives, and a null item of an // array keeps the stroke's own item (else the brush's). for (k, v) in ¶ms { @@ -572,6 +573,7 @@ pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result }; merged.insert(k.clone(), next); } + keep_drawn_modes(b, &was, ¶ms, &mut merged); b.stroke_options_that_differ(&merged).map_err(|e| bad(C, e))? }; options.get_or_insert_with(|| next.clone()); @@ -593,6 +595,47 @@ pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result Ok(json!({ "ids": ids_json(&out), "changed": ids_json(&changed), "options": options.unwrap_or_default() })) } +/// The modes brush `b` draws with, for a Calligraphic or a Scatter brush. +fn drawn_modes(b: &Brush) -> Option> { + let modes = match &b.kind { + BrushKind::Calligraphic(c) => serde_json::to_value(c.modes()), + BrushKind::Scatter(s) => serde_json::to_value(s.modes()), + _ => return None, + }; + match modes { + Ok(Value::Array(m)) => Some(m), + _ => None, + } +} + +/// Keep each mode a stroke of brush `b` draws with (with its own settings `was`) that `params` +/// does not set (no `modes`, or a `null` item) and that `merged`, its settings with `params`, +/// would change. A mode the stroke leaves to its values follows them, so without this a changed +/// variation or range would also change the mode. +fn keep_drawn_modes( + b: &Brush, + was: &serde_json::Map, + params: &serde_json::Map, + merged: &mut serde_json::Map, +) { + let given = match params.get("modes") { + None | Some(Value::Null) => vec![], + Some(Value::Array(m)) => m.clone(), + // A value of the wrong kind is refused when the settings are checked. + Some(_) => return, + }; + let (Some(before), Some(after)) = + (b.with_stroke_options(was).ok().as_ref().and_then(drawn_modes), b.with_stroke_options(merged).ok().as_ref().and_then(drawn_modes)) + else { + return; + }; + if before == after { + return; + } + let kept = before.into_iter().zip(after).enumerate().map(|(j, (w, a))| if given.get(j).is_some_and(|g| !g.is_null()) { a } else { w }).collect(); + merged.insert("modes".into(), Value::Array(kept)); +} + /// The name `brush.placeArt` gives each pattern brush tile it places, by tile, in the order it /// places them; `brush.replaceArt` reads a group of that name as that tile. const TILE_NAMES: [&str; 5] = ["Side Tile", "Outer Corner Tile", "Inner Corner Tile", "Start Tile", "End Tile"]; diff --git a/crates/engine/src/tests/brushsym.rs b/crates/engine/src/tests/brushsym.rs index 8aa440ea26..d99d9ab38b 100644 --- a/crates/engine/src/tests/brushsym.rs +++ b/crates/engine/src/tests/brushsym.rs @@ -175,6 +175,38 @@ fn options_of_selected_object_null_items_keep_each_paths_own() { assert_eq!(own_options(&s, c)["size"], json!([brush_size[0], 150.0]), "brush size {brush_size}"); } +/// The size mode the first stroke of `id`, painted with Confetti, draws with. +fn confetti_size_mode(s: &Session, id: NodeId) -> vectorcraft_brush::Variation { + let lib = vectorcraft_brush::library(&s.doc().unwrap().doc); + let b = lib.iter().find(|b| b.name == "Confetti").unwrap(); + match b.with_stroke_options(own_options(s, id).as_object().unwrap()).unwrap().kind { + vectorcraft_brush::BrushKind::Scatter(sc) => sc.modes()[0], + k => panic!("not a scatter brush: {k:?}"), + } +} + +#[test] +fn options_of_selected_object_keep_the_modes_each_path_draws_with() { + use vectorcraft_brush::Variation; + let mut s = session(); + let a = line(&mut s); + let b = line(&mut s); + select(&mut s, &[a, b]); + s.execute("brush.apply", &json!({"name": "Confetti"})).unwrap(); + // Confetti's sizes vary at random from 60% to 140%; the second path's follow the pressure. + select(&mut s, &[b]); + s.execute("brush.objectOptions", &json!({"params": {"modes": ["pressure", null, null, null]}})).unwrap(); + assert_eq!((confetti_size_mode(&s, a), confetti_size_mode(&s, b)), (Variation::Random, Variation::Pressure)); + // One size with no mode keeps each path's mode. + select(&mut s, &[a, b]); + s.execute("brush.objectOptions", &json!({"params": {"size": [80, 80]}})).unwrap(); + assert_eq!((confetti_size_mode(&s, a), confetti_size_mode(&s, b)), (Variation::Random, Variation::Pressure)); + assert_eq!(own_options(&s, a)["size"], json!([80.0, 80.0])); + // A mode the params give is set on each path. + s.execute("brush.objectOptions", &json!({"params": {"size": [70, 90], "modes": ["fixed", null, null, null]}})).unwrap(); + assert_eq!((confetti_size_mode(&s, a), confetti_size_mode(&s, b)), (Variation::Fixed, Variation::Fixed)); +} + #[test] fn options_of_selected_object_go_when_a_freehand_stroke_changes_the_brush() { let mut s = session(); diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index 43e4886aac..037c953db5 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -925,6 +925,41 @@ fn options_of_selected_object_change_only_the_values_edited_on_each_path() { assert_eq!(own_options(&app, b)["size"], json!([40.0, 120.0]), "the second path keeps its own largest size"); } +/// The modes the first stroke of path `id` draws its brush `brush` with. +fn drawn_modes(app: &VectorcraftApp, id: u64, brush: &str) -> Vec { + let lib = vectorcraft_brush::library(&app.session.active().unwrap().doc); + let b = lib.iter().find(|b| b.name == brush).unwrap(); + let own = own_options(app, id); + match b.with_stroke_options(own.as_object().unwrap()).unwrap().kind { + BrushKind::Calligraphic(c) => c.modes().to_vec(), + BrushKind::Scatter(s) => s.modes().to_vec(), + _ => vec![], + } +} + +#[test] +fn options_of_selected_object_keep_the_modes_they_show_when_a_value_changes() { + let mut app = app(); + // Confetti's size varies at random from 60% to 140%; a size of 60% to 60% leaves the mode the + // dialog shows. + let s = brushed_line(&mut app, 50.0, "Confetti"); + select(&mut app, &[s]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().str("sizeMode"), "random"); + set(&mut app, json!({"sizeMax": 60})); + super::super::confirm(&mut app).unwrap(); + assert_eq!(own_options(&app, s)["size"], json!([60.0, 60.0])); + assert_eq!(drawn_modes(&app, s, "Confetti")[0], Variation::Random); + // 6 pt. Flat's angle is Fixed; a variation set without a mode keeps it Fixed. + let c = brushed_line(&mut app, 100.0, "6 pt. Flat"); + select(&mut app, &[c]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().str("angleMode"), "fixed"); + set(&mut app, json!({"angleVariation": 30})); + super::super::confirm(&mut app).unwrap(); + assert_eq!(drawn_modes(&app, c, "6 pt. Flat")[0], Variation::Fixed); +} + #[test] fn options_of_selected_object_show_what_a_path_can_set_for_each_type() { let mut app = app(); diff --git a/docs/mcp.md b/docs/mcp.md index 0e67062c1d..2b40a47327 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3419,14 +3419,17 @@ already walks Image Trace. Short agent entry points: `brush.objectOptions {ids?, params?, reset?}` (the Brushes panel menu's Options of Selected Object…, from the [Modify brushes](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/apply-and-edit-strokes/modify-brushes.html) page) changes the brush settings of the selected brushed paths on those paths only; the brush and its other strokes - keep their settings. The fields a path can set are VectorCraft's own choice: calligraphic `angle`, `roundness`, - `size`, `variation` and `modes`; scatter `size`, `spacing`, `scatter`, `rotation`, `modes`, + keep their settings. The fields a path can set are VectorCraft's own choice: calligraphic `angle` (counter-clockwise from + level), `roundness`, `size`, `variation` and `modes`; scatter `size`, `spacing`, `scatter`, `rotation` + (counter-clockwise), `modes`, `rotation_relative_to_path` and `colorization`; art `width`, `width_mode`, `width_max`, `flip_along`, `flip_across`, `overlap` and `colorization`; pattern `scale`, `spacing`, `fit`, `flip_along`, `flip_across` and `colorization`. Values outside their ranges are clamped as in `brush.options`, a `colorization` object changes only the fields it gives, a `null` item of an array (`size: [40, null]`) keeps each path's own item, else the brush's, and a setting equal to the brush's own value is dropped. The dialog sends only the items and fields changed in it, so editing one - end of a range leaves each selected path's other end as it was. `reset: true` clears a path's settings. The command + end of a range leaves each selected path's other end as it was. A mode that `params` does not set (no `modes`, or + a `null` item) stays the one each path draws with, so a changed calligraphic variation or scatter range does not + change it. `reset: true` clears a path's settings. The command refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes. `brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in From 592dcec59cb591a876c67f1d4b95e4e859039021 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 15:59:51 -0800 Subject: [PATCH 6/7] MCP: regenerate the UI command catalog for Options of Selected Object The catalog's params text for ui.brushObjectOptions now matches the desktop table, which says that changing one end of a range or one colorization field leaves each path's other values as they are. --- crates/mcp/src/ui_catalog.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index be0028cc72..59bfe792bb 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -919,7 +919,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.brushObjectOptions", "Options of Selected Object…", "", - "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened, and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", + "{} open the Brushes panel menu's Options of Selected Object (dialog `brushOptions` with `__object`): the Brush Options of the brush that the first selected brushed path paints with, at that path's own settings, without the name field; Art shows width, widthMax/widthMode, flipAlong, flipAcross and overlap, and Pattern scale, spacing, flipAlong, flipAcross and fit, each with colorization; OK runs brush.objectOptions on the brushed paths selected when it opened, with the values changed since it opened (one end of a range or one colorization field changed leaves each path's other values as they are), and the brush stays as it is. An error with nothing painted with a brush selected, for paths painted with brushes of different types and for a bristle brush", ), ( "ui.graphicStyleOptions", From be12c9ed368e728a70835c732d0f1fb9ea1fd5d3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 17:52:41 -0800 Subject: [PATCH 7/7] Brushes: Options of Selected Object keeps a path's null modes and largest width, and its document - A calligraphic path's `modes: null` (modes that follow its values) stays when another value changes, instead of falling back to the brush's modes. - An art `width` without a `width_max` keeps the largest width of each path whose width follows the pen, so editing Width no longer moves the other end. - OK changes nothing when another document has become the active one since the dialog opened, as Delete Brush does. --- crates/brush/src/lib.rs | 10 ++++-- crates/brush/src/tests.rs | 17 +++++++++ crates/engine/src/cmd/brushsym/brushes.rs | 25 +++++++++++++ crates/engine/src/tests/brushsym.rs | 35 +++++++++++++++++++ crates/ui-egui/src/dialogs/brush_options.rs | 21 ++++++++--- .../src/dialogs/brush_options/tests.rs | 20 +++++++++++ docs/mcp.md | 4 ++- 7 files changed, 124 insertions(+), 8 deletions(-) diff --git a/crates/brush/src/lib.rs b/crates/brush/src/lib.rs index 718a552f32..7129279b31 100644 --- a/crates/brush/src/lib.rs +++ b/crates/brush/src/lib.rs @@ -804,10 +804,16 @@ impl BrushKind { } } - /// The values of [`Self::stroke_option_keys`], as a JSON object. + /// The values of [`Self::stroke_option_keys`], as a JSON object. Calligraphic modes left to the + /// values are a `null` `modes`, so a stroke that sets them so keeps that setting. fn option_values(&self) -> serde_json::Value { let v = match self { - BrushKind::Calligraphic(c) => serde_json::to_value(c), + BrushKind::Calligraphic(c) => serde_json::to_value(c).map(|mut v| { + if let Some(o) = v.as_object_mut() { + o.entry("modes").or_insert(serde_json::Value::Null); + } + v + }), BrushKind::Scatter(s) => serde_json::to_value(ScatterOptions { size: s.size, spacing: s.spacing, diff --git a/crates/brush/src/tests.rs b/crates/brush/src/tests.rs index 46779d8e2d..437ec4028f 100644 --- a/crates/brush/src/tests.rs +++ b/crates/brush/src/tests.rs @@ -2118,3 +2118,20 @@ fn null_stroke_option_items_keep_the_items_the_stroke_has() { let same = b.stroke_options_that_differ(&map(json!({"modes": [null, null, null, null]}))).unwrap(); assert!(same.is_empty(), "{same:?}"); } + +#[test] +fn a_null_calligraphic_modes_setting_stays_when_another_value_changes() { + let map = |v: serde_json::Value| v.as_object().cloned().unwrap_or_default(); + // A brush whose modes are its own, and a stroke whose modes follow its values instead. + let mut b = calli(0.0, 100.0, 3.0); + if let BrushKind::Calligraphic(c) = &mut b.kind { + c.modes = Some([Variation::Pressure; 3]); + } + let got = b.stroke_options_that_differ(&map(json!({"modes": null, "angle": 30.0}))).unwrap(); + assert_eq!(serde_json::Value::Object(got), json!({"modes": null, "angle": 30.0})); + let BrushKind::Calligraphic(c) = b.with_stroke_options(&map(json!({"modes": null, "angle": 30.0}))).unwrap().kind else { panic!("calligraphic") }; + assert_eq!(c.modes(), [Variation::Fixed; 3], "the stroke draws with the modes its values give"); + // A brush whose modes follow its values: a null `modes` is the brush's own and is left out. + let plain = calli(0.0, 100.0, 3.0).stroke_options_that_differ(&map(json!({"modes": null}))).unwrap(); + assert!(plain.is_empty(), "{plain:?}"); +} diff --git a/crates/engine/src/cmd/brushsym/brushes.rs b/crates/engine/src/cmd/brushsym/brushes.rs index 8ddeb99b29..5f7687fb47 100644 --- a/crates/engine/src/cmd/brushsym/brushes.rs +++ b/crates/engine/src/cmd/brushsym/brushes.rs @@ -574,6 +574,7 @@ pub(super) fn brush_object_options(s: &mut Session, p: &Value) -> Result merged.insert(k.clone(), next); } keep_drawn_modes(b, &was, ¶ms, &mut merged); + keep_largest_width(b, &was, ¶ms, &mut merged); b.stroke_options_that_differ(&merged).map_err(|e| bad(C, e))? }; options.get_or_insert_with(|| next.clone()); @@ -636,6 +637,30 @@ fn keep_drawn_modes( merged.insert("modes".into(), Value::Array(kept)); } +/// Keep the largest width a stroke of art brush `b` draws with (with its own settings `was`) when +/// `params` sets `width` and no `width_max`. Without a `width_max` of its own the largest width is +/// the width, so without this a changed width would also change the largest width. +fn keep_largest_width( + b: &Brush, + was: &serde_json::Map, + params: &serde_json::Map, + merged: &mut serde_json::Map, +) { + if params.get("width").is_none_or(Value::is_null) || params.get("width_max").is_some_and(|m| !m.is_null()) { + return; + } + let art = |o: &serde_json::Map| match b.with_stroke_options(o).ok().map(|b| b.kind) { + Some(BrushKind::Art(a)) => Some(a), + _ => None, + }; + let (Some(before), Some(after)) = (art(was), art(merged)) else { return }; + let follows_pen = |a: &brush::ArtBrush| a.width_mode.is_some_and(|m| m.follows_pen()); + // Only a width that followed the pen has a largest width, and only one that still does uses it. + if before.width_max.is_none() && follows_pen(&before) && follows_pen(&after) && after.width != before.width { + merged.insert("width_max".into(), json!(before.width)); + } +} + /// The name `brush.placeArt` gives each pattern brush tile it places, by tile, in the order it /// places them; `brush.replaceArt` reads a group of that name as that tile. const TILE_NAMES: [&str; 5] = ["Side Tile", "Outer Corner Tile", "Inner Corner Tile", "Start Tile", "End Tile"]; diff --git a/crates/engine/src/tests/brushsym.rs b/crates/engine/src/tests/brushsym.rs index 02bf2b4a6f..957f6ea6a4 100644 --- a/crates/engine/src/tests/brushsym.rs +++ b/crates/engine/src/tests/brushsym.rs @@ -207,6 +207,41 @@ fn options_of_selected_object_keep_the_modes_each_path_draws_with() { assert_eq!((confetti_size_mode(&s, a), confetti_size_mode(&s, b)), (Variation::Fixed, Variation::Fixed)); } +/// The widths (%) the first stroke of `id`, painted with Arrow, draws with at the lightest and the +/// heaviest pressure. +fn arrow_width_range(s: &Session, id: NodeId) -> (f64, f64) { + let lib = vectorcraft_brush::library(&s.doc().unwrap().doc); + let b = lib.iter().find(|b| b.name == "Arrow").unwrap(); + match b.with_stroke_options(own_options(s, id).as_object().unwrap()).unwrap().kind { + vectorcraft_brush::BrushKind::Art(a) => a.width_range(), + k => panic!("not an art brush: {k:?}"), + } +} + +#[test] +fn options_of_selected_object_keep_each_paths_largest_width_when_the_width_changes() { + let mut s = session(); + let a = line(&mut s); + let b = line(&mut s); + s.execute("brush.apply", &json!({"name": "Arrow", "ids": [a.0, b.0]})).unwrap(); + // Both widths follow the pressure; the first path's largest width is its width, the second + // path's is its own. + s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"width": 100, "width_mode": "pressure"}})).unwrap(); + s.execute("brush.objectOptions", &json!({"ids": [b.0], "params": {"width": 100, "width_mode": "pressure", "width_max": 150}})).unwrap(); + assert_eq!((arrow_width_range(&s, a), arrow_width_range(&s, b)), ((100.0, 100.0), (100.0, 150.0))); + // The width the path has already changes nothing. + let steps = undo_steps(&s); + assert_eq!(s.execute("brush.objectOptions", &json!({"ids": [a.0], "params": {"width": 100}})).unwrap()["changed"], json!([])); + assert_eq!(own_options(&s, a), json!({"width_mode": "pressure"})); + assert_eq!(undo_steps(&s), steps); + // A new smallest width leaves each path's largest width as it was. + s.execute("brush.objectOptions", &json!({"ids": [a.0, b.0], "params": {"width": 50}})).unwrap(); + assert_eq!((arrow_width_range(&s, a), arrow_width_range(&s, b)), ((50.0, 100.0), (50.0, 150.0))); + // A largest width the params give is set on each path. + s.execute("brush.objectOptions", &json!({"ids": [a.0, b.0], "params": {"width": 40, "width_max": 120}})).unwrap(); + assert_eq!((arrow_width_range(&s, a), arrow_width_range(&s, b)), ((40.0, 120.0), (40.0, 120.0))); +} + #[test] fn options_of_selected_object_go_when_a_freehand_stroke_changes_the_brush() { let mut s = session(); diff --git a/crates/ui-egui/src/dialogs/brush_options.rs b/crates/ui-egui/src/dialogs/brush_options.rs index 310cd36f6b..eafe697a0f 100644 --- a/crates/ui-egui/src/dialogs/brush_options.rs +++ b/crates/ui-egui/src/dialogs/brush_options.rs @@ -20,9 +20,10 @@ //! //! The panel menu's Options of Selected Object opens the dialog on the brush of the first selected //! brushed path, with that path's own settings ([`open_object`]), with `__object`, `__targets` (the -//! brushed paths) and `__opened` (the values it opened with). It has no name, and of the Art and -//! Pattern brush options only those a path can set for itself. OK runs `brush.objectOptions` with -//! the values changed since it opened: the paths change and the brush stays as it is. +//! brushed paths), `__opened` (the values it opened with) and `__doc` (the uid of the document). It +//! has no name, and of the Art and Pattern brush options only those a path can set for itself. OK +//! runs `brush.objectOptions` with the values changed since it opened: the paths change and the +//! brush stays as it is. OK after another document has become the active one changes nothing. use egui::{Color32, Sense, Stroke, pos2, vec2}; use serde_json::{Map, Value, json}; @@ -55,6 +56,9 @@ const TARGETS: &str = "__targets"; /// The field of such a dialog holding the `brush.objectOptions` params it opened with. const OPENED: &str = "__opened"; +/// The field of such a dialog holding the uid of the document it opened in. +const DOC: &str = "__doc"; + /// Calligraphic values: (field, label, suffix, decimals), in [`Calligraphic::RANGES`] order. const CALLI: [(&str, &str, &str, usize); 3] = [("angle", "Angle:", "°", 0), ("roundness", "Roundness:", "%", 0), ("size", "Size:", " pt", 1)]; @@ -216,7 +220,8 @@ pub fn open_object(app: &mut VectorcraftApp) -> Result { let r = app.run("brush.objectOptions", json!({}))?; let targets = r["ids"].clone(); let first = targets.get(0).and_then(Value::as_u64).map(NodeId).ok_or("no path painted with a brush is selected")?; - let lib = vectorcraft_brush::library(&app.session.active().ok_or("no document open")?.doc); + let st = app.session.active().ok_or("no document open")?; + let (lib, doc) = (vectorcraft_brush::library(&st.doc), st.uid); let b = stroke_brush(app, &lib, first).ok_or("no path painted with a brush is selected")?; let own: Map = serde_json::from_value(r["options"].clone()).unwrap_or_default(); let edited = b.with_stroke_options(&own)?; @@ -225,6 +230,7 @@ pub fn open_object(app: &mut VectorcraftApp) -> Result { f.insert("__brush".into(), json!(b.name)); f.insert(OBJECT.into(), json!(true)); f.insert(TARGETS.into(), targets); + f.insert(DOC.into(), json!(doc)); let mut d = Dialog { kind: KIND.into(), fields: f }; let opened = object_params(&d, b.kind.stroke_option_keys()); d.fields.insert(OPENED.into(), Value::Object(opened)); @@ -256,8 +262,13 @@ fn changed_part(was: Option<&Value>, now: Value) -> Option { } /// OK of Options of Selected Object: `brush.objectOptions` on the paths it opened for, with the -/// values changed since it opened ([`changed_part`]). The dialog closes when they are set. +/// values changed since it opened ([`changed_part`]). The dialog closes when they are set. When +/// another document has become the active one, it closes as Cancel does and changes nothing. fn confirm_object(app: &mut VectorcraftApp, d: &Dialog) -> Result { + if d.fields.get(DOC).and_then(Value::as_u64) != app.session.active().map(|doc| doc.uid) { + app.ui.dialog = None; + return Ok(json!({})); + } let keys: Vec = d.fields.get("__keys").and_then(|v| serde_json::from_value(v.clone()).ok()).unwrap_or_default(); let keys: Vec<&str> = keys.iter().map(String::as_str).collect(); let opened = d.fields.get(OPENED).and_then(Value::as_object).cloned().unwrap_or_default(); diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index 037c953db5..fd6721ca69 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -999,3 +999,23 @@ fn options_of_selected_object_show_what_a_path_can_set_for_each_type() { app.run("select.none", json!({})).unwrap(); assert!(!object_available(&app)); } + +#[test] +fn options_of_selected_object_change_nothing_after_another_document_became_active() { + let mut app = app(); + let a = brushed_line(&mut app, 50.0, "Arrow"); + select(&mut app, &[a]); + app.run("ui.brushObjectOptions", json!({})).unwrap(); + set(&mut app, json!({"width": 50})); + // A second document with a brushed path of the same id becomes the active one. + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + app.run("document.activate", json!({"index": 1})).unwrap(); + let other = brushed_line(&mut app, 50.0, "Arrow"); + assert_eq!(other, a); + // OK closes the dialog as Cancel does. + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(own_options(&app, other), json!({}), "the second document's path keeps the brush's settings"); + app.run("document.activate", json!({"index": 0})).unwrap(); + assert_eq!(own_options(&app, a), json!({}), "the first document's path keeps the brush's settings"); +} diff --git a/docs/mcp.md b/docs/mcp.md index bee403373d..509ca8f849 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3468,7 +3468,9 @@ already walks Image Trace. Short agent entry points: equal to the brush's own value is dropped. The dialog sends only the items and fields changed in it, so editing one end of a range leaves each selected path's other end as it was. A mode that `params` does not set (no `modes`, or a `null` item) stays the one each path draws with, so a changed calligraphic variation or scatter range does not - change it. `reset: true` clears a path's settings. The command + change it. An art `width` without a `width_max` keeps the largest width of each path whose width follows the pen, + and a calligraphic path's `modes: null` (modes that follow its values) stays when another value changes. The dialog + changes nothing when another document has become the active one. `reset: true` clears a path's settings. The command refuses `params` together with `reset`, a selection with no brushed path, paths whose brushes are of different types, a bristle brush and a field the type does not take. It records one undo step, and none when nothing changes. `brush.options` edits still reach the settings a path does not set, `brush.apply`, a brush change in