mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
draw: Shift while dragging a Bezier handle turns it to the nearest 45 degrees about its anchor
This commit is contained in:
@@ -212,6 +212,8 @@ enum Target {
|
||||
knot: KnotRef,
|
||||
side: HandleSide,
|
||||
from: Point,
|
||||
/// The handle's anchor at the press: ⇧ turns the handle about it.
|
||||
anchor: Point,
|
||||
},
|
||||
/// A curved segment, grabbed at `t` where it passes `from`.
|
||||
Bend {
|
||||
@@ -635,7 +637,8 @@ impl<'a> BezierOverlay<'a> {
|
||||
let knot_at = |path: u64, knot: KnotRef| Self::path(paths, path).and_then(|p| p.knot(knot));
|
||||
match (self.tool, hit) {
|
||||
(_, BezierHit::Handle { path, knot, side }) if self.tool != BezierTool::Curvature => {
|
||||
Target::Handle { path, knot, side, from: knot_at(path, knot).map_or(Point::ZERO, |k| k.handle(side)) }
|
||||
let at = knot_at(path, knot);
|
||||
Target::Handle { path, knot, side, from: at.map_or(Point::ZERO, |k| k.handle(side)), anchor: at.map_or(Point::ZERO, |k| k.anchor) }
|
||||
}
|
||||
(BezierTool::Curvature, BezierHit::Anchor { path, knot }) => {
|
||||
self.report.select = Some(self.selecting(path, vec![knot], None));
|
||||
@@ -728,8 +731,10 @@ impl<'a> BezierOverlay<'a> {
|
||||
Target::Anchors { path, anchors, from } => {
|
||||
PathEdit::MoveAnchors { path: *path, anchors: anchors.clone(), by: snapped(*from + locked(delta)) - *from }
|
||||
}
|
||||
&Target::Handle { path, knot, side, from } => {
|
||||
PathEdit::MoveHandle { path, knot, side, to: snapped(from + delta), alone: tool == BezierTool::Convert || mods.alt }
|
||||
&Target::Handle { path, knot, side, from, anchor } => {
|
||||
// ⇧ turns the handle to the nearest 45° about its anchor, as the Pen's pull does.
|
||||
let to = if mods.shift { handle_45(anchor, from + delta) } else { snapped(from + delta) };
|
||||
PathEdit::MoveHandle { path, knot, side, to, alone: tool == BezierTool::Convert || mods.alt }
|
||||
}
|
||||
&Target::Bend { path, segment, t, from } => PathEdit::BendSegment { path, segment, t, by: snapped(from + delta) - from },
|
||||
&Target::Convert { path, knot } => PathEdit::Convert { path, knot, out: Some(snapped(view.to_doc(pointer))) },
|
||||
|
||||
@@ -739,6 +739,33 @@ fn shift_keeps_an_anchor_drag_on_the_axis_or_the_diagonal() {
|
||||
}
|
||||
}
|
||||
|
||||
// ⇧ during a handle drag turns the handle to the nearest 45° about its anchor, also when pressed mid-drag: about 20°
|
||||
// lands on the axis, about 40° on the diagonal, and photocraft#15760's measured (-78, +140) on (-78, +78); without ⇧
|
||||
// the handle follows the pointer.
|
||||
#[trial]
|
||||
fn shift_locks_a_handle_drag_to_the_nearest_45_degrees() {
|
||||
let anchor = p(260.0, 60.0);
|
||||
let cases =
|
||||
[(p(360.0, 96.0), p(360.0, 60.0)), (p(340.0, 127.0), p(327.0, 127.0)), (anchor + Vec2::new(-78.0, 140.0), anchor + Vec2::new(-78.0, 78.0))];
|
||||
for (shift, (target, locked)) in cases.iter().flat_map(|c| [(true, *c), (false, *c)]) {
|
||||
let mut h = two_paths();
|
||||
h.update(|st| st.selection = sel(1, &[(0, 2)]));
|
||||
let handle = h.screen(p(290.0, 100.0));
|
||||
let to = h.screen(target);
|
||||
h.press_at(handle);
|
||||
h.move_to(handle + (to - handle) * 0.5);
|
||||
if shift {
|
||||
h.fixture.hold(egui::Modifiers::SHIFT);
|
||||
}
|
||||
h.move_to(to);
|
||||
let Some(PathEdit::MoveHandle { to: got, .. }) = h.last_change() else { panic!("a handle move: {:?}", h.last_change()) };
|
||||
h.release_at(to);
|
||||
h.fixture.hold(egui::Modifiers::NONE);
|
||||
let want = if shift { locked } else { target };
|
||||
assert!(got.distance(want) < 1e-3, "shift {shift}: {target:?} gives {got:?}, wants {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Anchor with only some subpaths' anchors shown (#12769): a click on a hidden anchor deletes nothing and
|
||||
// edits nothing, selects that anchor and shows only its subpath; the next click on it deletes it.
|
||||
#[trial]
|
||||
|
||||
Reference in New Issue
Block a user