Outline draft: only a draft built with locking_shift_drags (the Freeform Pen) locks a shift drag; the Lasso's shift adds to the selection

This commit is contained in:
aiongg
2026-11-16 23:36:47 +00:00
parent 2b8741d72c
commit 4b8f3c8608
2 changed files with 15 additions and 4 deletions
+14 -3
View File
@@ -28,7 +28,8 @@ pub enum DraftKind {
/// again; releasing ⌥ with the button up closes. ⌥ held at the press means subtract (the
/// tool's operation), not straight segments, until it is released and pressed again; with
/// nothing selected it starts straight segments at once. ⇧ puts each clicked vertex on the
/// horizontal, vertical or 45° line through the previous one, and holds a freehand drag to one such line.
/// horizontal, vertical or 45° line through the previous one, and a draft built with
/// [`locking_shift_drags`](OutlineDraft::locking_shift_drags) (the Freeform Pen) holds a freehand drag to one such line.
#[default]
Mixed,
/// The Polygonal Lasso: each click adds a vertex, ⇧ (without ⌥) puts it in the nearest of
@@ -152,6 +153,9 @@ pub struct OutlineDraft {
document: Option<u64>,
/// A ⇧ freehand drag's line: where it began and the unit direction it locked to (the nearest of eight).
lock: Option<(Point, Vec2)>,
/// Whether ⇧ holds a freehand drag to one line (the Freeform Pen); the Lasso's ⇧ at the press adds to the
/// selection and its drag stays free.
locks_shift_drag: bool,
}
impl OutlineDraft {
@@ -168,9 +172,16 @@ impl OutlineDraft {
alt_from_press: false,
document: None,
lock: None,
locks_shift_drag: false,
}
}
/// This draft with ⇧ holding a freehand drag to one of eight directions (see [`DraftKind::Mixed`]).
pub fn locking_shift_drags(mut self) -> Self {
self.locks_shift_drag = true;
self
}
/// The rules this draft follows.
pub fn kind(&self) -> DraftKind {
self.kind
@@ -274,12 +285,12 @@ impl OutlineDraft {
Some(DraftEvent::Changed)
}
/// Where a freehand point of `at` goes. With ⇧ held a Mixed draft's drag follows one line: once the pointer has
/// Where a freehand point of `at` goes. With ⇧ held a [`locking_shift_drags`](Self::locking_shift_drags) Mixed draft's drag follows one line: once the pointer has
/// travelled [`LOCK_DISTANCE`] screen points from the last vertex, the nearest of eight directions from there
/// is locked and every later point is the pointer's projection onto it, however the pointer wanders, until ⇧ is
/// released. Before the lock the point stays at the vertex. Otherwise [`shift_step`](Self::shift_step).
fn drag_step(&mut self, at: DraftPoint) -> Point {
if self.kind != DraftKind::Mixed || !at.mods.shift || self.polygonal {
if !self.locks_shift_drag || self.kind != DraftKind::Mixed || !at.mods.shift || self.polygonal {
self.lock = None;
return self.shift_step(at);
}
+1 -1
View File
@@ -72,7 +72,7 @@ fn shift_steps_keep_the_shorter_diagonal_offset() {
#[test]
fn shift_holds_a_freehand_drag_to_one_line() {
let shift = |x: f64, y: f64| DraftPoint::new(Point::new(x, y), Mods::SHIFT, 1.0);
let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH);
let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH).locking_shift_drags();
draft.press(at(10.0, 60.0, 1.0), true);
for (x, y) in [(30.0, 63.0), (50.0, 55.0), (80.0, 68.0), (100.0, 52.0)] {
draft.drag(shift(x, y));