mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 16:37:32 +00:00
Pen: the Info panel shows W, H, D and the angle while a drag pulls out a handle
While a Pen drag past the drag threshold shapes a handle, the Info panel shows the change in x and y, the distance and the angle from the anchor to the handle's end: the outgoing handle of a new, added or last anchor, and the incoming handle of the first anchor when the drag closes the path. Shift gives the constrained handle and Space moves the anchor with it. The readout clears on release, a dropped press and a tool change.
This commit is contained in:
@@ -272,8 +272,8 @@ pub trait Tool: Send {
|
||||
false
|
||||
}
|
||||
/// What the Info panel shows for the tool as it is now: the drag in progress (a move of the
|
||||
/// selection, a gradient vector, a Scale, Rotate, Reflect or Shear tool drag), or the
|
||||
/// Paintbrush's brush. None for a tool with nothing of its own to show.
|
||||
/// selection, a gradient vector, a handle the Pen pulls out, a Scale, Rotate, Reflect or Shear
|
||||
/// tool drag), or the Paintbrush's brush. None for a tool with nothing of its own to show.
|
||||
fn readout(&self, _cx: &ToolContext) -> Option<Readout> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
//! the other art and of the path being drawn, into line with them, onto the construction guides
|
||||
//! through the last anchor; with Shift held it slides along its 45° step into line. Hovering shows
|
||||
//! where the next one would go.
|
||||
//! While a drag pulls a handle out, the Info panel shows it from the anchor to the handle's end.
|
||||
|
||||
use serde_json::json;
|
||||
use vectorcraft_doc::{NodeId, NodeKind};
|
||||
@@ -62,6 +63,10 @@ pub struct PenTool {
|
||||
/// The pointer has moved past the drag threshold since the press: a press released inside it
|
||||
/// is a click, so the anchor stays a corner without handles.
|
||||
dragged: bool,
|
||||
/// The handle a drag past the threshold is pulling out, from the anchor it shapes to the
|
||||
/// handle's end as last previewed (the outgoing handle, or the incoming one of the first
|
||||
/// anchor closing the path): what the Info panel shows ([`Tool::readout`]).
|
||||
vector: Option<Vec2>,
|
||||
/// The last anchor of the path being drawn, while a click retracts its outgoing handle or a
|
||||
/// drag pulls a new one out: (path, subpath, anchor, its position).
|
||||
handle: Option<(NodeId, usize, usize, Point)>,
|
||||
@@ -256,6 +261,12 @@ impl Tool for PenTool {
|
||||
fn ends_on_escape(&self, cx: &ToolContext) -> bool {
|
||||
self.active(cx).is_some()
|
||||
}
|
||||
/// The handle a drag is pulling out of the anchor it shapes: the outgoing handle of a new or
|
||||
/// added anchor or of the last anchor, or the incoming handle of the first anchor closing the
|
||||
/// path. None for a click, a hover or an Alt gesture.
|
||||
fn readout(&self, _cx: &ToolContext) -> Option<crate::Readout> {
|
||||
self.vector.filter(|_| self.dragged && (self.drag.is_some() || self.handle.is_some())).map(crate::Readout::drag)
|
||||
}
|
||||
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
|
||||
let tol = cx.tol(5.0).max(cx.point_tol());
|
||||
// The path a press began is the selected one by the next event.
|
||||
@@ -292,6 +303,7 @@ impl Tool for PenTool {
|
||||
self.last = ev.pos;
|
||||
self.pressed = ev.pos;
|
||||
self.dragged = false;
|
||||
self.vector = None;
|
||||
if let Some((id, si, first, last, _)) = active {
|
||||
let end = last_anchor(cx, id, Some(si));
|
||||
let closing_end = end.filter(|(_, ai)| *ai > 0).map(|_| first);
|
||||
@@ -391,6 +403,7 @@ impl Tool for PenTool {
|
||||
if ev.mods.shift {
|
||||
h = a + vectorcraft_geom::constrain_angle_from(ev.pos - a, 45.0, cx.constrain_angle);
|
||||
}
|
||||
self.vector = Some(h - a);
|
||||
return vec![set_out_handle(id, si, ai, h)];
|
||||
}
|
||||
let Some(Place { at: mut a, path, subpath, closing, mut moved }) = self.drag else { return vec![] };
|
||||
@@ -412,6 +425,8 @@ impl Tool for PenTool {
|
||||
if ev.mods.shift {
|
||||
out_h = a + vectorcraft_geom::constrain_angle_from(ev.pos - a, 45.0, cx.constrain_angle);
|
||||
}
|
||||
// A closing drag shapes the first anchor's incoming handle, which mirrors the pointer.
|
||||
self.vector = Some(if closing { a - out_h } else { out_h - a });
|
||||
let alt = ev.mods.alt;
|
||||
let Some(id) = path else {
|
||||
// First anchor of a new path: re-issue create with handles.
|
||||
@@ -436,6 +451,7 @@ impl Tool for PenTool {
|
||||
}
|
||||
PointerKind::Up => {
|
||||
self.snap.clear();
|
||||
self.vector = None;
|
||||
if let Some(mut t) = self.convert.take() {
|
||||
return t.pointer(cx, ev);
|
||||
}
|
||||
@@ -465,6 +481,7 @@ impl Tool for PenTool {
|
||||
self.first = None;
|
||||
self.handle = None;
|
||||
self.convert = None;
|
||||
self.vector = None;
|
||||
self.snap.clear();
|
||||
vec![]
|
||||
}
|
||||
@@ -476,6 +493,7 @@ impl Tool for PenTool {
|
||||
let placing = self.drag.take().is_some();
|
||||
self.first = None;
|
||||
let handling = self.handle.take().is_some();
|
||||
self.vector = None;
|
||||
// Finish the preview as it stands; clearing state alone leaves its transaction open.
|
||||
let mut acts = self.convert.take().map(|mut t| t.deactivate(cx)).unwrap_or_default();
|
||||
if placing || handling {
|
||||
|
||||
@@ -970,3 +970,128 @@ fn continuing_a_compound_member_at_its_first_anchor_reverses_that_path_by_id() {
|
||||
);
|
||||
assert_eq!((pen.path, pen.subpath), (Some(a), Some(0)));
|
||||
}
|
||||
|
||||
/// A context with snapping off, so each point goes where the pointer is.
|
||||
fn plain<'a>(d: &'a vectorcraft_doc::Document, s: &'a Selection, p: &'a crate::PaintDefaults) -> ToolContext<'a> {
|
||||
ToolContext { zoom: 1.0, smart_guides: false, snap_to_point: false, snap_to_pixel: false, snap_to_grid: false, ..cx(d, s, p) }
|
||||
}
|
||||
|
||||
fn drag_readout(dx: f64, dy: f64) -> Option<crate::Readout> {
|
||||
Some(crate::Readout::Drag { dx, dy })
|
||||
}
|
||||
|
||||
/// The Info panel shows the handle a drag pulls out of a new anchor, from the anchor to the
|
||||
/// handle's end, once the drag passes the threshold and until the button comes up.
|
||||
#[test]
|
||||
fn info_readout_tracks_the_handle_of_a_new_anchor() {
|
||||
let (d, s, p) = (vectorcraft_doc::Document::new(500.0, 500.0), Selection::default(), paint());
|
||||
let cx = plain(&d, &s, &p);
|
||||
let mut t = PenTool::default();
|
||||
assert_eq!(t.readout(&cx), None, "hovering");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0));
|
||||
assert_eq!(t.readout(&cx), None, "pressed");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 101.0, 101.0));
|
||||
assert_eq!(t.readout(&cx), None, "inside the drag threshold");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 130.0, 60.0));
|
||||
let r = t.readout(&cx);
|
||||
assert_eq!(r, drag_readout(30.0, -40.0));
|
||||
let (dist, angle) = r.and_then(|r| r.distance_angle()).unwrap_or_default();
|
||||
assert!((dist - 50.0).abs() < 1e-9 && (angle - 53.130_102_354_155_98).abs() < 1e-9, "{dist} {angle}");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 130.0, 60.0));
|
||||
assert_eq!(t.readout(&cx), None, "released");
|
||||
// A click shows nothing.
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 200.0, 200.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 201.0, 200.0));
|
||||
assert_eq!(t.readout(&cx), None);
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 201.0, 200.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 250.0, 250.0));
|
||||
assert_eq!(t.readout(&cx), None, "hovering after a click");
|
||||
}
|
||||
|
||||
/// An anchor added to the path being drawn and the first anchor closing it: the handle the drag
|
||||
/// shapes is measured from the anchor it belongs to.
|
||||
#[test]
|
||||
fn info_readout_tracks_added_and_closing_anchors() {
|
||||
let pts = [Point::new(100.0, 300.0), Point::new(200.0, 300.0), Point::new(200.0, 400.0)];
|
||||
let (d, _, s) = drawing(vectorcraft_geom::SubPath::polyline(&pts, false));
|
||||
let p = paint();
|
||||
let cx = plain(&d, &s, &p);
|
||||
let mut t = PenTool { drawing: true, ..PenTool::default() };
|
||||
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 300.0, 400.0));
|
||||
assert!(matches!(&a[..], [Action::Begin(_), Action::Preview(c, _)] if c == "path.appendAnchor"), "{a:?}");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 330.0, 440.0));
|
||||
assert_eq!(t.readout(&cx), drag_readout(30.0, 40.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 330.0, 440.0));
|
||||
assert_eq!(t.readout(&cx), None);
|
||||
// A press on the first anchor, a pixel off it, closes: the readout is that anchor's incoming
|
||||
// handle, which mirrors the pointer.
|
||||
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 101.0, 301.0));
|
||||
assert!(matches!(&a[..], [Action::Begin(c), _] if c == "Close Path"), "{a:?}");
|
||||
let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 130.0, 260.0));
|
||||
let [Action::Preview(c, v)] = acts.as_slice() else { panic!("not a close preview: {acts:?}") };
|
||||
assert_eq!((c.as_str(), &v["in"]), ("path.close", &json!([70.0, 340.0])));
|
||||
assert_eq!(t.readout(&cx), drag_readout(-30.0, 40.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 130.0, 260.0));
|
||||
assert_eq!(t.readout(&cx), None);
|
||||
}
|
||||
|
||||
/// A drag from the last anchor pulls its outgoing handle out on its own; with Shift the readout
|
||||
/// gives the constrained handle the preview shows.
|
||||
#[test]
|
||||
fn info_readout_tracks_the_last_anchor_handle() {
|
||||
let (d, id, s) = drawing(vectorcraft_geom::SubPath::polyline(&[Point::new(10.0, 300.0), Point::new(60.0, 300.0)], false));
|
||||
let p = paint();
|
||||
let cx = plain(&d, &s, &p);
|
||||
let mut t = PenTool { drawing: true, ..PenTool::default() };
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 60.0, 300.0));
|
||||
assert_eq!(t.readout(&cx), None, "a click retracts the handle");
|
||||
assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 70.0, 280.0)), vec![set_out(id, 1, 70.0, 280.0)]);
|
||||
assert_eq!(t.readout(&cx), drag_readout(10.0, -20.0));
|
||||
let shift = Mods { shift: true, ..Mods::default() };
|
||||
// 26.6° from the anchor: Shift turns it to the 45° step nearest.
|
||||
let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 80.0, 290.0).with_mods(shift));
|
||||
let [Action::Preview(_, v)] = acts.as_slice() else { panic!("not a handle preview: {acts:?}") };
|
||||
let (hx, hy) = (v["x"].as_f64().unwrap_or(f64::NAN), v["y"].as_f64().unwrap_or(f64::NAN));
|
||||
assert!(((hx - 60.0) + (hy - 300.0)).abs() < 1e-9, "constrained to 45°: {v}");
|
||||
assert_eq!(t.readout(&cx), drag_readout(hx - 60.0, hy - 300.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 80.0, 290.0));
|
||||
assert_eq!(t.readout(&cx), None);
|
||||
}
|
||||
|
||||
/// Space moves the anchor and its handles together, so the handle keeps its length; Alt leaves
|
||||
/// the incoming handle behind and the readout follows the outgoing one.
|
||||
#[test]
|
||||
fn info_readout_follows_space_and_alt() {
|
||||
let (d, s, p) = (vectorcraft_doc::Document::new(500.0, 500.0), Selection::default(), paint());
|
||||
let cx = plain(&d, &s, &p);
|
||||
let mut t = PenTool::default();
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 400.0, 420.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 450.0, 420.0));
|
||||
assert_eq!(t.readout(&cx), drag_readout(50.0, 0.0));
|
||||
let space = Mods { space: true, ..Mods::default() };
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 450.0, 380.0).with_mods(space));
|
||||
assert_eq!(t.readout(&cx), drag_readout(50.0, 0.0), "the anchor moved with the handle");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 460.0, 400.0));
|
||||
assert_eq!(t.readout(&cx), drag_readout(60.0, 20.0), "measured from the moved anchor");
|
||||
let alt = Mods { alt: true, ..Mods::default() };
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 400.0, 450.0).with_mods(alt));
|
||||
assert_eq!(t.readout(&cx), drag_readout(0.0, 70.0));
|
||||
}
|
||||
|
||||
/// A dropped press and switching tools clear the readout.
|
||||
#[test]
|
||||
fn info_readout_clears_on_a_dropped_press_and_deactivate() {
|
||||
let (d, s, p) = (vectorcraft_doc::Document::new(500.0, 500.0), Selection::default(), paint());
|
||||
let cx = plain(&d, &s, &p);
|
||||
let mut t = PenTool::default();
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 120.0, 100.0));
|
||||
assert_eq!(t.readout(&cx), drag_readout(20.0, 0.0));
|
||||
t.drop_press(&cx);
|
||||
assert_eq!(t.readout(&cx), None, "dropped");
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0));
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 100.0, 130.0));
|
||||
assert_eq!(t.readout(&cx), drag_readout(0.0, 30.0));
|
||||
t.deactivate(&cx);
|
||||
assert_eq!(t.readout(&cx), None, "deactivated");
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -446,7 +446,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| Control bar: Paragraph: link and Align left/center/right while type is selected (#5372) | done | After the Character controls, as the public documentation has the Control panel format paragraphs ([Paragraph panel overview](https://helpx.adobe.com/illustrator/using/formatting-paragraphs.html), [Align text](https://helpx.adobe.com/illustrator/using/align-text.html)); the link opens the Paragraph panel in a popover, as Character: does with the Character panel. The bar trims from its right end: X/Y/W/H, Distribute, Align, area type vertical alignment, then these buttons, then the link. The three-button set is our choice for room; all seven alignments are in the popover. `panels/paragraph/tests.rs` headless tests (`the_control_bar_shows_the_paragraph_alignment_of_the_selected_type`, `the_control_bar_trims_its_paragraph_section_after_the_controls_to_its_right`) |
|
||||
| Pathfinder shape results keep their source names and SVG IDs | done | #1293; Minus Front keeps the back name, Minus Back the front name; Unite/Intersect/Exclude use the backmost named input; compound output carries it once; geometry and paint unchanged |
|
||||
| Attributes fill-rule controls with a compound member selected | done | Edits the compound's rule; direction still edits only the member; rendered-hole and Undo/Redo regression tests (#1197) |
|
||||
| Info panel follows the tool in use: W and H show the change in x and y, with the distance and the angle, while the selection moves or the Gradient tool draws a vector; the Scale tool's percentages; the center and angles of a Rotate, Reflect or Shear tool drag; the Zoom tool's magnification; the Paintbrush's brush. W and H follow Use Preview Bounds, several selected objects show only the paint and type they share, and Show Options names a tint or a gradient swatch | done | `info.readout`; `Tool::readout`; behavior from the Info panel overview in the [archived user guide](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=76); number formats, the rows shown between drags and the Direct Selection and Group Selection readouts are VectorCraft's own |
|
||||
| Info panel follows the tool in use: W and H show the change in x and y, with the distance and the angle, while the selection moves, the Gradient tool draws a vector or a Pen drag pulls out an anchor's handle; the Scale tool's percentages; the center and angles of a Rotate, Reflect or Shear tool drag; the Zoom tool's magnification; the Paintbrush's brush. W and H follow Use Preview Bounds, several selected objects show only the paint and type they share, and Show Options names a tint or a gradient swatch | done | `info.readout`; `Tool::readout`; behavior from the Info panel overview in the [archived user guide](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=76); number formats, the rows shown between drags and the Direct Selection and Group Selection readouts are VectorCraft's own |
|
||||
| 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) |
|
||||
|
||||
Reference in New Issue
Block a user