diff --git a/crates/engine/src/tests/persp_text.rs b/crates/engine/src/tests/persp_text.rs index 443913a635..b2b41a9630 100644 --- a/crates/engine/src/tests/persp_text.rs +++ b/crates/engine/src/tests/persp_text.rs @@ -378,6 +378,60 @@ fn flare_spiral_and_polar_grid_draw_in_perspective() { assert_eq!(attached(&s, NodeId(r["id"].as_u64().unwrap())).map(|a| a.0), Some(Plane::Left)); } +/// Alt-click (Option-click on macOS) with the Flare tool draws one flare with the tool's options as +/// one undo step, without a dialog. On the active plane it is the flare the click-opened Flare Tool +/// Options draw there; without the grid it is drawn flat. A plain click opens the dialog. +#[test] +fn an_alt_click_with_the_flare_tool_draws_the_flare_the_click_dialog_draws() { + use vectorcraft_tools::{PointerEvent, PointerKind}; + let (mut s, _) = persp_session(); + s.execute("perspective.grid.show", &json!({"visible": true})).unwrap(); + s.execute("perspective.plane.set", &json!({"plane": "left"})).unwrap(); + let v = ViewInfo::default(); + s.select_tool("flare", v).unwrap(); + s.set_tool_option_cmd(&json!({"tool": "flare", "values": {"diameter": 40, "rays": 6, "ringsOn": false}})).unwrap(); + let options = s.tool_options_of("flare"); + let at = Point::new(300.0, 380.0); + let alt = Mods { alt: true, ..Default::default() }; + let alt_click = |s: &mut Session| { + s.pointer(&PointerEvent::new(PointerKind::Down, at.x, at.y).with_mods(alt), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, at.x, at.y).with_mods(alt), v).unwrap() + }; + let n = undo_len(&s); + assert_eq!(alt_click(&mut s), vec![], "no dialog"); + assert_eq!(undo_len(&s), n + 1); + assert_eq!(s.journal.last().unwrap().0, "perspective.draw"); + let id = *s.doc().unwrap().selection.objects.first().unwrap(); + assert_eq!(attached(&s, id).map(|a| a.0), Some(Plane::Left)); + let drawn = node(&s, id).geometric_bounds().unwrap(); + assert_eq!(s.tool_options_of("flare"), options, "the click leaves the options as they are"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.doc().unwrap().doc.node(id).is_none()); + s.execute("edit.redo", &json!({})).unwrap(); + assert_eq!(node(&s, id).geometric_bounds(), Some(drawn)); + s.execute("edit.undo", &json!({})).unwrap(); + let params = vectorcraft_tools::extra::flare_params(&options, at); + let (cmd, p) = crate::perspective_click(&s, "shape.flare", ¶ms, at).unwrap(); + let dialog = NodeId(s.execute(&cmd, &p).unwrap()["id"].as_u64().unwrap()); + assert_eq!(node(&s, dialog).geometric_bounds(), Some(drawn), "the flare the dialog's OK draws"); + // A click above the ground plane's horizon draws nothing and reports the error. + s.execute("perspective.plane.set", &json!({"plane": "ground"})).unwrap(); + let above = grid(&s).horizon - 50.0; + let n = undo_len(&s); + s.pointer(&PointerEvent::new(PointerKind::Down, at.x, above).with_mods(alt), v).unwrap(); + assert!(s.pointer(&PointerEvent::new(PointerKind::Up, at.x, above).with_mods(alt), v).is_err()); + assert_eq!(undo_len(&s), n); + // Without the grid the flare is drawn flat; a plain click opens the dialog. + s.execute("perspective.grid.show", &json!({"visible": false})).unwrap(); + assert_eq!(alt_click(&mut s), vec![]); + assert_eq!(s.journal.last().unwrap().0, "shape.flare"); + let flat = *s.doc().unwrap().selection.objects.first().unwrap(); + assert_eq!(attached(&s, flat), None); + s.pointer(&PointerEvent::new(PointerKind::Down, at.x, at.y), v).unwrap(); + let ui = s.pointer(&PointerEvent::new(PointerKind::Up, at.x, at.y), v).unwrap(); + assert_eq!(ui, vec![UiRequest::Dialog("flare".into(), json!({"x": at.x, "y": at.y}))]); +} + #[test] fn click_to_size_dialogs_draw_on_the_active_plane_in_plane_units() { let (mut s, _) = persp_session(); diff --git a/crates/tools/src/extra.rs b/crates/tools/src/extra.rs index fee24c340b..4c6a6c6d45 100644 --- a/crates/tools/src/extra.rs +++ b/crates/tools/src/extra.rs @@ -2,7 +2,8 @@ //! //! Flare: drag sets the center and its size and turns the rays as the pointer moves up or down //! (Shift holds their turn, ↑/↓ add or remove rays and Ctrl/Cmd keeps the center's size while the -//! drag sizes the halo; click without dragging opens the Flare Tool Options), then a click sets the +//! drag sizes the halo; click without dragging opens the Flare Tool Options, and Alt-click (Option +//! on macOS) draws a flare there with them at once), then a click sets the //! end point of the rings (↑/↓ add or remove rings and ~ places them anew); Space held during //! either drag moves the flare. The rest comes //! from the tool's options (the Flare Tool Options, which last). Reshape: a click on a selected @@ -59,6 +60,9 @@ pub struct FlareTool { /// The pointer at the last press or drag, from which Space held moves the flare. last: Point, began: bool, + /// Whether Alt (Option on macOS) was held when the button went down for the center: a release + /// without a drag then draws a flare with the options at once. + alt_press: bool, /// Ray count changed with ↑/↓ during the center drag (None = the options' count). rays: Option, /// Ring count changed with ↑/↓ while the rings' end point is placed (None = the options' count). @@ -89,6 +93,7 @@ impl Default for FlareTool { hover: Point::ZERO, last: Point::ZERO, began: false, + alt_press: false, rays: None, rings: None, ring_seed: None, @@ -225,6 +230,20 @@ impl FlareTool { fn center_diameter(&self, dist: f64) -> f64 { self.held.map_or(2.0 * dist, |(d, ..)| d) } + + /// Alt-click (Option-click on macOS) at `c`: one flare drawn with the options as they are, as one + /// command, so a refusal (a click beyond the plane's horizon) reaches the caller as an error. + /// While the perspective grid shows with an active plane, the flare goes on that plane with its + /// sizes in plane units from the click, as the Flare Tool Options opened by a click draw it. + fn click_flare(&self, cx: &ToolContext, c: Point) -> Vec { + let params = flare_params(&self.options(), c); + let grid = crate::distort::perspective::PerspectiveGrid::current(cx.doc); + if grid.visible && grid.plane != crate::distort::perspective::Plane::None { + vec![Action::Exec("perspective.draw".into(), json!({ "command": "shape.flare", "params": params, "at": [c.x, c.y] }))] + } else { + vec![Action::Exec("shape.flare".into(), params)] + } + } } impl Tool for FlareTool { @@ -252,6 +271,7 @@ impl Tool for FlareTool { self.held = None; self.growth = None; self.turn = 0.0; + self.alt_press = ev.mods.alt; } self.last = ev.pos; vec![] @@ -298,6 +318,8 @@ impl Tool for FlareTool { self.placed = Some((c, self.center_diameter(p.distance(c)))); self.held = None; vec![] + } else if std::mem::take(&mut self.alt_press) { + self.click_flare(cx, c) } else { vec![Action::Dialog("flare".into(), json!({ "x": c.x, "y": c.y }))] } @@ -855,6 +877,91 @@ mod tests { } } + /// Alt-click (Option-click on macOS): with Alt held when the button goes down, a release without + /// a drag draws one flare at the click with the options as they are, Rays and Rings off included, + /// and opens no dialog. A plain click, or Alt pressed only for the release, opens the Flare Tool + /// Options; an Alt drag draws the flare in two stages as any drag does; Escape drops the press. + #[test] + fn alt_click_draws_a_flare_with_the_options_at_once() { + use crate::testutil::*; + use vectorcraft_doc::Selection; + let (d, _) = doc_with_rect(); + let s = Selection::default(); + let p = paint(); + let cx = cx(&d, &s, &p); + let alt = Mods { alt: true, ..Default::default() }; + let click = |t: &mut FlareTool, down: Mods, up: Mods| { + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0, 140.0).with_mods(down)); + t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 120.0, 140.0).with_mods(up)) + }; + let mut t = FlareTool::default(); + for (k, v) in [("diameter", json!(40)), ("rays", json!(7)), ("growth", json!(80)), ("ringsOn", json!(false))] { + t.set_option(k, &v); + } + let options = t.options(); + let a = click(&mut t, alt, alt); + let c = Point::new(120.0, 140.0); + let v = flare_params(&options, c); + assert_eq!(a, vec![Action::Exec("shape.flare".into(), v.clone())]); + assert_eq!( + (v["cx"].as_f64(), v["cy"].as_f64(), v["diameter"].as_f64(), v["rays"].as_u64(), v["growth"].as_f64(), v["rings"].as_u64()), + (Some(120.0), Some(140.0), Some(40.0), Some(7), Some(80.0), Some(0)) + ); + assert_eq!(t.options(), options, "the click leaves the options as they are"); + assert!(!t.busy()); + // Alt let go before the release still counts; Alt pressed only for the release does not. + assert_eq!(click(&mut t, alt, Mods::default()), vec![Action::Exec("shape.flare".into(), v)]); + let dialog = vec![Action::Dialog("flare".into(), json!({ "x": 120.0, "y": 140.0 }))]; + assert_eq!(click(&mut t, Mods::default(), alt), dialog); + assert_eq!(click(&mut t, Mods::default(), Mods::default()), dialog, "a plain click after an Alt-click opens the dialog"); + // An Alt drag places the center and waits for the rings' end point, as any drag does. + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0).with_mods(alt)); + assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 140.0, 100.0).with_mods(alt)).first(), Some(&Action::Begin("Flare".into()))); + assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 140.0, 100.0).with_mods(alt)), vec![]); + assert!(t.placed.is_some()); + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 300.0, 200.0).with_mods(alt)); + let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 300.0, 200.0).with_mods(alt)); + assert_eq!(a.last(), Some(&Action::Commit)); + assert_eq!((flare_preview(&a)["diameter"].as_f64(), flare_preview(&a)["x2"].as_f64()), (Some(80.0), Some(300.0))); + // Escape before the release drops the press: no flare and no dialog. + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0, 140.0).with_mods(alt)); + assert_eq!(t.key(&cx, ToolKey::Escape, Mods::default()), vec![]); + assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 120.0, 140.0).with_mods(alt)), vec![]); + } + + /// With the perspective grid showing and a plane active, an Alt-click draws the flare on that + /// plane from the click (`perspective.draw` with `at`), as the click-opened dialog does. + #[test] + fn alt_click_draws_on_the_active_perspective_plane() { + use crate::distort::perspective::{PerspectiveGrid, Plane}; + use crate::testutil::*; + use vectorcraft_doc::Selection; + let (mut d, _) = doc_with_rect(); + let s = Selection::default(); + let p = paint(); + let alt = Mods { alt: true, ..Default::default() }; + let c = Point::new(300.0, 380.0); + let mut t = FlareTool::default(); + PerspectiveGrid { visible: true, plane: Plane::Left, ..PerspectiveGrid::current(&d) }.store(&mut d); + let mut alt_click = |d: &vectorcraft_doc::Document| { + let cx = cx(d, &s, &p); + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, c.x, c.y).with_mods(alt)); + t.pointer(&cx, &PointerEvent::new(PointerKind::Up, c.x, c.y).with_mods(alt)) + }; + let params = flare_params(&FlareTool::default().options(), c); + let on_plane = json!({ "command": "shape.flare", "params": params, "at": [c.x, c.y] }); + assert_eq!(alt_click(&d), vec![Action::Exec("perspective.draw".into(), on_plane)]); + // With no active plane, or the grid hidden, the flare is drawn flat. + for g in [ + PerspectiveGrid { plane: Plane::None, ..PerspectiveGrid::current(&d) }, + PerspectiveGrid { visible: false, ..PerspectiveGrid::current(&d) }, + ] { + let mut d = d.clone(); + g.store(&mut d); + assert_eq!(alt_click(&d), vec![Action::Exec("shape.flare".into(), params.clone())]); + } + } + /// Equal vertical travel gives equal rotation, regardless of event partitioning. #[test] fn flare_drag_turns_the_rays_and_shift_holds_their_turn() { diff --git a/docs/mcp.md b/docs/mcp.md index 044b452de5..e84fce5279 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -11359,7 +11359,10 @@ desktop app. The Flare tool's are its Flare Tool Options (dialog `flareOptions`) (Option on macOS) is held, the dialog's Cancel button reads Reset. Reset puts every option back to the tool's default, leaves a click's `x` and `y` unchanged and keeps the dialog open; `ui.dialogReset` does the same. OK keeps the options (`tool.setOption {tool: "flare", values}`) and the next flare dragged out uses them; a click with the tool opens the -same dialog, and its OK also draws a flare there. While the center is dragged out, each drag update in which the +same dialog, and its OK also draws a flare there. An Alt-click (Option-click on macOS; Alt held when the button goes +down, with no drag) opens no dialog: it draws a flare there at once with the options as they are, in one undo step, +through `shape.flare`, or through `perspective.draw` with `at` on the active perspective plane as the dialog's OK does, +and leaves the options unchanged. While the center is dragged out, each drag update in which the pointer's document y grows adds one degree per document point to `shape.flare`'s `rotation` (it turns only the rays), decreasing y subtracts the same rate, and unchanged y leaves it. This application rate is independent of event frequency; Shift held keeps the turn as it is. Space held keeps the turn as well. Once the center drag has passed its starting distance, and in the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 04f9907fec..b8fedb069c 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1099,6 +1099,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Dialogs move by dragging their heading (the band down from the top edge, as a title bar), stay on screen and keep where they were moved for the session; the form dialogs' choices are dropdowns (Offset Path's Joins, Average's and Shear's and Reflect's axis), and Offset Path lists Offset, Joins, Miter Limit and previews (#423). - Dialogs open with their first field focused and its value selected: type a value and press Enter (Move, Rotate, Scale…). A dialog opened from a menu takes the keyboard focus every time it opens, not only the first (#1367), and one whose first field starts greyed out (Blend Options on Smooth Color, Layers Panel Options) gives the focus to that field once it is enabled (#1395). Number fields in panels, the Control bar and dialogs (preferences too) step with Up/Down, or with the mouse wheel over the hovered field without requiring focus (#485, #5949: a notch a step; the panel under it then stays put, and a disabled field leaves the wheel to scrolling) (Shift: ten, Ctrl/Cmd: a tenth of their unit), applied at once. A field takes the wheel only when the pointer was moved onto it after the field last moved or was covered by a window or overlay, and the wheel stream began there; a stream that began elsewhere, such as a panel scrolled under a still pointer, stays there until 0.5 s pass with no wheel input or the pointer is pressed on a field (VectorCraft's own rule and value). - While Alt (Option on macOS) is held, the Flare Tool Options' Cancel button reads Reset, which puts every option back to the Flare tool's default and leaves the dialog open (`ui.dialogReset`). + - An Alt-click (Option-click on macOS) with the Flare tool draws a flare centered at the click at once, without opening the Flare Tool Options, as [the help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf) describes for a default flare. As VectorCraft's own rules, the flare takes the tool's current options (the defaults until they are changed), Alt counts when it is held as the button goes down, a drag with Alt still draws the flare in two stages, and on the active perspective plane the flare is the one the click dialog's OK draws there (`alt_click_draws_a_flare_with_the_options_at_once`, `alt_click_draws_on_the_active_perspective_plane`, `an_alt_click_with_the_flare_tool_draws_the_flare_the_click_dialog_draws`). - While a flare's center is dragged out, Ctrl (Command on macOS) keeps the center's size and the drag sizes the halo; while its rings' end point is placed, Up/Down Arrow add and remove rings and ~ places them anew (`shape.flare`'s `ringSeed`) ([Draw and edit flares](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/draw-and-edit-flares.html); `flare_arrows_change_the_rays_then_the_rings`, `flare_tilde_places_the_rings_anew`, `flare_ctrl_keeps_the_center_and_the_drag_sizes_the_halo`). - A plain step of a number field (Up/Down or a wheel notch) goes to the next whole unit in its direction and a Ctrl/Cmd step goes to the next tenth, so 5.1 mm steps up to 6 mm and down to 5 mm (#2881). A Shift step adds or takes ten and keeps the fraction. - In the number, text and color fields of the panels and the Control bar, Shift+Enter (Shift+Return) applies the value and keeps the field active with its value selected; a text box of several lines takes it as a line break. In a dialog, Shift+Enter applies the value and confirms the dialog, as Enter does.