mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-24 03:21:34 +01:00
Add Anchor: Alt selects or copies the whole subpath
In the reference application Alt does not turn Add Anchor Point into Delete Anchor Point: an Alt click on a segment selects every anchor of its subpath and adds nothing, an Alt drag moves a copy of the subpath (the copy ends up selected), an Alt click on an anchor deletes nothing, and the cursor is the arrow with a plus. The overlay now does the same under Add Anchor, reusing Direct Selection's Alt segment press (`PathEdit::DuplicateSubpath`, or the subpath itself on a path that takes no copies). Delete Anchor with Alt still adds an anchor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
18ffc07519
commit
4d78bb2de2
5 files changed
+97
-20
No files matched your search
@@ -3,7 +3,7 @@
|
||||
|
||||
use super::tool::ICON_BOX;
|
||||
use super::{PathTool, PenTool};
|
||||
use craft_behavior::{CancelReason, Cursor, CursorBadge, PaintedCursor, PointerButton};
|
||||
use craft_behavior::{CancelReason, Cursor, CursorBadge, CursorIcon, PaintedCursor, PointerButton};
|
||||
use craft_keymap::Mods;
|
||||
use craft_ui::canvas::{CanvasTool, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer};
|
||||
use craft_ui::primitives::{Draw, ToolIcon};
|
||||
@@ -22,7 +22,7 @@ const CONVERT_TIP: Vec2 = Vec2::new(ICON_BOX / 2.0, 5.5);
|
||||
/// describes; it takes no press.
|
||||
/// - Cursor off the overlay's parts: the crosshair under the canvas's precise cursor
|
||||
/// ([`CanvasSpace::precise`](craft_ui::canvas::CanvasSpace::precise)); with ⌘ Direct Selection's arrow; else Add
|
||||
/// Anchor the arrow (a click there adds nothing; with ⌥, Delete Anchor, the pen with "-"), Delete Anchor the pen
|
||||
/// Anchor the arrow (a click there adds nothing; with ⌥ the arrow with "+"), Delete Anchor the pen
|
||||
/// with "-" (with ⌥, Add Anchor, the pen with "+"), Convert Point its icon, Direct Selection the arrow. Over a part
|
||||
/// the overlay sets its own cursor.
|
||||
#[derive(Debug)]
|
||||
@@ -53,7 +53,7 @@ pub(super) fn cursor_of(tool: PathTool, mods: Mods, precise: bool) -> PaintedCur
|
||||
match tool {
|
||||
_ if precise => PaintedCursor::Crosshair,
|
||||
_ if mods.cmd => PaintedCursor::arrow(false),
|
||||
PathTool::AddAnchor if mods.alt => pen(CursorBadge::Subtract),
|
||||
PathTool::AddAnchor if mods.alt => PaintedCursor::badged(CursorIcon::Default, CursorBadge::Add),
|
||||
PathTool::DeleteAnchor if mods.alt => pen(CursorBadge::Add),
|
||||
PathTool::DeleteAnchor => pen(CursorBadge::Subtract),
|
||||
PathTool::ConvertPoint => PaintedCursor::tool(ToolIcon::ConvertPoint.icon(), CONVERT_TIP, None),
|
||||
|
||||
@@ -67,9 +67,11 @@ pub enum BezierTool {
|
||||
/// Anchors drawn, not edited (PhotoCraft's Path Selection and Pen tools).
|
||||
Anchors,
|
||||
/// Add Anchor Point: a press on a segment inserts an anchor at the hit's `t` ([`PathEdit::InsertAnchor`]); a drag
|
||||
/// moves the new anchor, which is selected; ⌥ makes it Delete Anchor Point. Hover: the segment mark with the
|
||||
/// anchor a click adds ([`HitMark`]) and the pen with "+"; over an anchor the arrow; the crosshair under the
|
||||
/// canvas's precise cursor ([`CanvasSpace::precise`]).
|
||||
/// moves the new anchor, which is selected. With ⌥ a click on a segment selects its whole subpath and a drag moves a
|
||||
/// copy of it ([`PathEdit::DuplicateSubpath`]; the subpath itself on a path that takes no copies), and a press on
|
||||
/// an anchor does nothing. Hover: the segment mark with the
|
||||
/// anchor a click adds ([`HitMark`]) and the pen with "+"; over an anchor the arrow; with ⌥ no mark and the arrow
|
||||
/// with "+"; the crosshair under the canvas's precise cursor ([`CanvasSpace::precise`]).
|
||||
AddAnchor,
|
||||
/// Delete Anchor Point: a click on an anchor reports [`delete`](BezierOutput::delete) of that anchor; ⌥ makes it
|
||||
/// Add Anchor Point, except that a ⌥ click on an anchor selects its whole subpath. Hover: the anchor mark.
|
||||
@@ -578,6 +580,8 @@ impl<'a> BezierOverlay<'a> {
|
||||
return self.target(hit, start, mods, paths);
|
||||
}
|
||||
match hit {
|
||||
// Add Anchor with ⌥ takes the whole subpath as Direct's ⌥ does (PhotoCraft #12709).
|
||||
BezierHit::Segment { .. } if self.tool.takes_subpath(mods) => self.target(hit, start, mods, paths),
|
||||
BezierHit::Segment { path, segment, t } if self.tool.adds(mods) => {
|
||||
Target::Insert { path, segment, t, from: Self::segment_point(paths, path, segment, t) }
|
||||
}
|
||||
@@ -658,7 +662,7 @@ impl<'a> BezierOverlay<'a> {
|
||||
self.report.select = Some(self.selecting(path, anchors.clone(), None));
|
||||
// pc: crates/ui-egui/src/tools/direct_select.rs `alt_duplicates` (#13211): Photoshop was not
|
||||
// measured with ⌘, Ctrl or ⇧ held too; those move the subpath.
|
||||
let copies = self.tool == BezierTool::Direct
|
||||
let copies = matches!(self.tool, BezierTool::Direct | BezierTool::AddAnchor)
|
||||
&& !mods.cmd
|
||||
&& !mods.ctrl
|
||||
&& !mods.shift
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The Add Anchor Point, Delete Anchor Point, Auto Add/Delete and Curvature tools of [`BezierOverlay`](super::BezierOverlay):
|
||||
//! which parts each tool takes a press on, what a click reports and what the hover mark shows.
|
||||
|
||||
use craft_behavior::{Cursor, CursorBadge, PaintedCursor};
|
||||
use craft_behavior::{Cursor, CursorBadge, CursorIcon, PaintedCursor};
|
||||
use craft_keymap::Mods;
|
||||
use craft_ui::primitives::ToolIcon;
|
||||
use egui::Vec2;
|
||||
@@ -10,13 +10,13 @@ use super::{AnchorDelete, BezierHit, BezierTool, PathSelection, Report};
|
||||
use crate::ui::pen::tool::ICON_BOX;
|
||||
|
||||
impl BezierTool {
|
||||
/// The tool a press acts as: [`BezierTool::AddAnchor`] and [`BezierTool::DeleteAnchor`] swap while ⌥ is held;
|
||||
/// every other tool is itself. (⌘ making the pointer Direct Selection is the host's, through
|
||||
/// The tool a press acts as: [`BezierTool::DeleteAnchor`] acts as [`BezierTool::AddAnchor`] while ⌥ is held;
|
||||
/// every other tool is itself. Add Anchor keeps itself under ⌥, where a segment press takes the whole subpath
|
||||
/// ([`BezierTool::takes_subpath`]). (⌘ making the pointer Direct Selection is the host's, through
|
||||
/// [`PathMode`](crate::ui::pen::PathMode).)
|
||||
pub(super) fn acting(self, mods: Mods) -> BezierTool {
|
||||
// pc: crates/ui-egui/src/tools/anchor_tools.rs:27-35 `effective`.
|
||||
// pc: crates/ui-egui/src/tools/anchor_tools.rs:27-35 `effective`; Add Anchor with ⌥ (PhotoCraft #12709).
|
||||
match (self, mods.alt) {
|
||||
(BezierTool::AddAnchor, true) => BezierTool::DeleteAnchor,
|
||||
(BezierTool::DeleteAnchor, true) => BezierTool::AddAnchor,
|
||||
(tool, _) => tool,
|
||||
}
|
||||
@@ -74,9 +74,15 @@ impl BezierTool {
|
||||
self == BezierTool::DeleteAnchor && mods.alt
|
||||
}
|
||||
|
||||
/// Whether a press on a segment adds an anchor: Add Anchor, or Auto Add/Delete, unless ⌥ swaps Add for Delete.
|
||||
/// Whether a press on a segment adds an anchor: Add Anchor without ⌥, Delete Anchor with ⌥, or Auto Add/Delete.
|
||||
pub(super) fn adds(self, mods: Mods) -> bool {
|
||||
matches!(self.acting(mods), BezierTool::AddAnchor | BezierTool::AutoAddDelete)
|
||||
matches!(self.acting(mods), BezierTool::AddAnchor | BezierTool::AutoAddDelete) && !self.takes_subpath(mods)
|
||||
}
|
||||
|
||||
/// Whether a press on a segment takes its whole subpath instead, as Direct's ⌥ does: Add Anchor with ⌥, where a
|
||||
/// click selects the subpath and a drag moves a copy of it, as in the reference application.
|
||||
pub(super) fn takes_subpath(self, mods: Mods) -> bool {
|
||||
self == BezierTool::AddAnchor && mods.alt
|
||||
}
|
||||
|
||||
/// Whether the tool shows the hover mark of what a press would take.
|
||||
@@ -134,15 +140,17 @@ pub(super) fn hover_mark(tool: BezierTool, hit: BezierHit, mods: Mods, selection
|
||||
|
||||
/// The cursor over `hit`, a part the tool takes, with `mods` held; `precise` is the canvas's precise cursor
|
||||
/// ([`CanvasSpace::precise`](craft_ui::canvas::CanvasSpace::precise)). Add Anchor shows the pen with "+" over a
|
||||
/// segment a click splits and the arrow over an anchor, the crosshair when precise. Under ⌥ (Delete Anchor) and ⌘ the
|
||||
/// cursor stays the host tool's, as it does off the parts.
|
||||
/// segment a click splits and the arrow over an anchor, the crosshair when precise; with ⌥ the arrow with "+" over
|
||||
/// every part. Delete Anchor with ⌥ shows Add Anchor's cursors. Under ⌘ the cursor stays the host tool's, as it does
|
||||
/// off the parts.
|
||||
pub(super) fn hover_cursor(tool: BezierTool, hit: BezierHit, mods: Mods, precise: bool) -> Option<Cursor> {
|
||||
// pc: crates/ui-egui/src/canvas/tool_cursor.rs, crates/ui-egui/src/tools/anchor_tools.rs (#12729).
|
||||
// pc: crates/ui-egui/src/canvas/tool_cursor.rs, crates/ui-egui/src/tools/anchor_tools.rs (#12729, #12709).
|
||||
if tool.acting(mods) != BezierTool::AddAnchor || mods.cmd {
|
||||
return None;
|
||||
}
|
||||
let cursor = match hit {
|
||||
_ if precise => PaintedCursor::Crosshair,
|
||||
_ if tool.takes_subpath(mods) => PaintedCursor::badged(CursorIcon::Default, CursorBadge::Add),
|
||||
// The pen's tip is the bottom left corner of the icon's box.
|
||||
BezierHit::Segment { .. } => PaintedCursor::tool(ToolIcon::Pen.icon(), Vec2::Y * ICON_BOX, Some(CursorBadge::Add)),
|
||||
BezierHit::Anchor { .. } | BezierHit::Handle { .. } => PaintedCursor::arrow(false),
|
||||
|
||||
@@ -62,7 +62,7 @@ impl PathMode {
|
||||
/// | Pen | ⇧ or ⌥, drawing; ⇧, not drawing | `Anchors` | `Pen` | true |
|
||||
/// | Curvature | none or ⇧ or ⌥, not drawing | `Curvature` | `Curvature` | true |
|
||||
/// | Curvature | drawing | `Anchors` | `Curvature` | true |
|
||||
/// | Add Anchor, Delete Anchor | no ⌘ | `AddAnchor`, `DeleteAnchor` (the overlay swaps them with ⌥) | `Pen` if `drawing` (shown, not sensing), else `None` | false |
|
||||
/// | Add Anchor, Delete Anchor | no ⌘ | `AddAnchor`, `DeleteAnchor` (with ⌥ the overlay makes Delete add and Add take whole subpaths) | `Pen` if `drawing` (shown, not sensing), else `None` | false |
|
||||
/// | Convert Point | no ⌘ | `Convert` | as Add Anchor | false |
|
||||
/// | Direct Selection | any | `Direct` | as Add Anchor | false |
|
||||
///
|
||||
|
||||
@@ -744,8 +744,73 @@ fn add_anchor_shows_the_pen_with_plus_over_a_segment_and_the_arrow_over_an_ancho
|
||||
}
|
||||
}
|
||||
|
||||
// Add Anchor with ⌥ takes the whole subpath, as the reference application does (PhotoCraft #12709), instead of
|
||||
// turning into Delete Anchor: a click on a segment selects every anchor of its subpath and adds nothing; a drag moves
|
||||
// a copy of the subpath, which ends up selected, the source staying; a press on an anchor deletes and selects nothing;
|
||||
// there is no hover mark and the cursor is the arrow with "+" over the parts. Delete Anchor with ⌥ still adds.
|
||||
#[trial]
|
||||
fn alt_under_add_anchor_selects_or_copies_the_whole_subpath() {
|
||||
use craft_behavior::{Cursor, CursorBadge, PaintedCursor};
|
||||
let add_anchor = || {
|
||||
let mut h = two_paths();
|
||||
h.update(|st| st.tool = BezierTool::AddAnchor);
|
||||
h.fixture.hold(egui::Modifiers::ALT);
|
||||
h
|
||||
};
|
||||
let click = |h: &mut Harness, at: Pos2| {
|
||||
h.press_at(at);
|
||||
h.release_at(at);
|
||||
};
|
||||
let segment = p(110.0, 60.0);
|
||||
|
||||
let mut h = add_anchor();
|
||||
let at = h.screen(segment);
|
||||
h.move_to(at);
|
||||
h.fixture.frame(Vec::new());
|
||||
let arrow_plus = Some(Cursor::Painted(PaintedCursor::badged(craft_behavior::CursorIcon::Default, CursorBadge::Add)));
|
||||
assert_eq!(craft_ui::runtime::cursor::current(h.fixture.ctx()), arrow_plus);
|
||||
assert_eq!(h.state.borrow().hover.map(|hit| hit.path()), Some(1));
|
||||
click(&mut h, at);
|
||||
{
|
||||
let st = h.state.borrow();
|
||||
assert_eq!(st.selection, sel(1, &[(0, 0), (0, 1), (0, 2), (0, 3)]));
|
||||
assert!(st.changes.is_empty() && st.seen.is_empty() && st.deletes.is_empty(), "{:?} {:?} {:?}", st.changes, st.seen, st.deletes);
|
||||
assert_eq!(st.paths, [path_a(), path_b()]);
|
||||
}
|
||||
|
||||
let mut h = add_anchor();
|
||||
let at = h.screen(segment);
|
||||
h.drag(at, vec2(0.0, 50.0));
|
||||
{
|
||||
let st = h.state.borrow();
|
||||
assert!(matches!(st.changes.last(), Some(PathEdit::DuplicateSubpath { path: 1, subpath: 0, .. })), "{:?}", st.changes);
|
||||
assert_eq!((st.seen.first(), st.seen.last()), (Some(&Seen::Begin), Some(&Seen::Commit)), "{:?}", st.seen);
|
||||
let subs = &st.paths[0].subpaths;
|
||||
assert_eq!(subs.len(), 2);
|
||||
assert_eq!(subs[0], path_a().subpaths[0], "the source stays");
|
||||
assert!(subs[1].knots.iter().zip(&subs[0].knots).all(|(copy, source)| near(copy.anchor, source.anchor + Vec2::new(0.0, 50.0))));
|
||||
assert_eq!(st.selection, sel(1, &[(1, 0), (1, 1), (1, 2), (1, 3)]), "the copy is selected");
|
||||
}
|
||||
|
||||
let mut h = add_anchor();
|
||||
let at = h.screen(p(160.0, 60.0));
|
||||
click(&mut h, at);
|
||||
{
|
||||
let st = h.state.borrow();
|
||||
assert!(st.deletes.is_empty() && st.changes.is_empty(), "{:?} {:?}", st.deletes, st.changes);
|
||||
assert_eq!(st.selection, PathSelection::default());
|
||||
}
|
||||
|
||||
let mut h = two_paths();
|
||||
h.update(|st| st.tool = BezierTool::DeleteAnchor);
|
||||
h.fixture.hold(egui::Modifiers::ALT);
|
||||
let at = h.screen(segment);
|
||||
click(&mut h, at);
|
||||
assert!(matches!(h.last_change(), Some(PathEdit::InsertAnchor { path: 1, .. })), "{:?}", h.last_change());
|
||||
}
|
||||
|
||||
// The anchor tools' canvas tool: a press off the paths begins nothing (it never starts a path), and off the paths the
|
||||
// cursor says what a click does: the arrow for Add Anchor (the pen with "-" under ⌥, where a click deletes), the pen
|
||||
// cursor says what a click does: the arrow for Add Anchor (with "+" under ⌥, PhotoCraft #12709), the pen
|
||||
// with "-" for Delete Anchor, the Convert Point icon, the arrow for Direct Selection and under ⌘, the crosshair when
|
||||
// the canvas's cursor is precise.
|
||||
#[trial]
|
||||
@@ -778,7 +843,7 @@ fn the_anchor_tools_take_no_press_off_the_paths_and_show_their_own_cursor() {
|
||||
|
||||
assert_eq!(cursor_at(&mut h, egui::Modifiers::NONE), arrow);
|
||||
let with_alt = cursor_at(&mut h, egui::Modifiers::ALT);
|
||||
assert!(pen(CursorBadge::Subtract, &with_alt), "{with_alt:?}");
|
||||
assert_eq!(with_alt, Some(Cursor::Painted(PaintedCursor::badged(craft_behavior::CursorIcon::Default, CursorBadge::Add))));
|
||||
assert_eq!(cursor_at(&mut h, egui::Modifiers::COMMAND), arrow);
|
||||
|
||||
h.update(|st| {
|
||||
|
||||
Reference in new issue
Block a user