Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space shifts the anchor (and handles) while pressed #2065

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ pub fn input_mappings() -> Mapping {
entry!(KeyDown(Backspace); modifiers=[Accel], action_dispatch=PathToolMessage::DeleteAndBreakPath),
entry!(KeyDown(Delete); modifiers=[Accel, Shift], action_dispatch=PathToolMessage::BreakPath),
entry!(KeyDown(Backspace); modifiers=[Accel, Shift], action_dispatch=PathToolMessage::BreakPath),
entry!(KeyDown(Space); action_dispatch=PathToolMessage::SelectAnchorAndHandle),
entry!(KeyUp(Space); action_dispatch=PathToolMessage::ResumeOriginalSelection),
entry!(KeyDown(MouseLeft); action_dispatch=PathToolMessage::MouseDown { ctrl: Control, shift: Shift }),
entry!(KeyDown(MouseRight); action_dispatch=PathToolMessage::RightClick),
entry!(KeyDown(Escape); action_dispatch=PathToolMessage::Escape),
Expand Down
47 changes: 47 additions & 0 deletions editor/src/messages/tool/common_functionality/shape_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,53 @@ impl ShapeState {
}
}

/// Selects handles and anchor connected to current handle
pub fn select_handles_and_anchor(&mut self, network_interface: &NodeNetworkInterface) {
let mut points_to_select = Vec::new();
let mut anchors_to_select = Vec::new();

for &layer in self.selected_shape_state.keys() {
let Some(vector_data) = network_interface.compute_modified_vector(layer) else {
continue;
};

for point in self.selected_points() {
let anchor = point.get_anchor(&vector_data);
anchors_to_select.push((layer, anchor));

if let Some(handles) = point.get_handle_pair(&vector_data) {
//handle[0] is selected, handle[1] is other
points_to_select.push((layer, handles[1].to_manipulator_point()));
}
}
}

for (layer, anchor) in anchors_to_select {
if let Some(state) = self.selected_shape_state.get_mut(&layer) {
match anchor {
Some(anchor) => state.select_point(ManipulatorPointId::Anchor(anchor)),
None => continue,
}
}
}
for (layer, point) in points_to_select {
if let Some(state) = self.selected_shape_state.get_mut(&layer) {
state.select_point(point);
}
}
}

pub fn select_points_by_manipulator_id(&mut self, points: &Vec<ManipulatorPointId>) {
let layers_to_modify: Vec<_> = self.selected_shape_state.keys().cloned().collect();

for layer in layers_to_modify {
if let Some(state) = self.selected_shape_state.get_mut(&layer) {
for point in points {
state.select_point(*point);
}
}
}
}
/// Converts a nearby clicked anchor point's handles between sharp (zero-length handles) and smooth (pulled-apart handle(s)).
/// If both handles aren't zero-length, they are set that. If both are zero-length, they are stretched apart by a reasonable amount.
/// This can can be activated by double clicking on an anchor with the Path tool.
Expand Down
42 changes: 42 additions & 0 deletions editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum PathToolMessage {
SelectedPointYChanged {
new_y: f64,
},
SelectAnchorAndHandle,
ResumeOriginalSelection,
}

impl ToolMetadata for PathTool {
Expand Down Expand Up @@ -188,6 +190,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
DeselectAllPoints,
BreakPath,
DeleteAndBreakPath,
ResumeOriginalSelection,
),
PathToolFsmState::Dragging => actions!(PathToolMessageDiscriminant;
Escape,
Expand All @@ -198,6 +201,8 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
Delete,
BreakPath,
DeleteAndBreakPath,
SelectAnchorAndHandle,
ResumeOriginalSelection,
),
PathToolFsmState::DrawingBox => actions!(PathToolMessageDiscriminant;
FlipSmoothSharp,
Expand All @@ -209,6 +214,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
DeleteAndBreakPath,
Escape,
RightClick,
ResumeOriginalSelection,
),
PathToolFsmState::InsertPoint => actions!(PathToolMessageDiscriminant;
Enter,
Expand All @@ -218,6 +224,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
Delete,
RightClick,
GRS,
ResumeOriginalSelection,
),
}
}
Expand Down Expand Up @@ -262,9 +269,20 @@ struct PathToolData {
snap_cache: SnapCache,
double_click_handled: bool,
auto_panning: AutoPanning,
selected_points_before_space: Vec<ManipulatorPointId>,
space_held: bool,
}

impl PathToolData {
fn add_selected_points(&mut self, points: Vec<ManipulatorPointId>) -> PathToolFsmState {
self.selected_points_before_space = points;
PathToolFsmState::Dragging
}

fn remove_selected_points(&mut self) {
self.selected_points_before_space.clear();
}

fn start_insertion(&mut self, responses: &mut VecDeque<Message>, segment: ClosestSegment) -> PathToolFsmState {
if self.segment.is_some() {
warn!("Segment was `Some(..)` before `start_insertion`")
Expand Down Expand Up @@ -604,6 +622,29 @@ impl Fsm for PathToolFsmState {

PathToolFsmState::Ready
}
(PathToolFsmState::Dragging, PathToolMessage::SelectAnchorAndHandle) => {
if tool_data.space_held {
return PathToolFsmState::Dragging;
}
tool_data.space_held = true;
tool_data.add_selected_points(tool_action_data.shape_editor.selected_points().cloned().collect());
tool_action_data.shape_editor.select_handles_and_anchor(&tool_action_data.document.network_interface);
responses.add(PathToolMessage::SelectedPointUpdated);
responses.add(OverlaysMessage::Draw);
PathToolFsmState::Dragging
}
(PathToolFsmState::Dragging, PathToolMessage::ResumeOriginalSelection) => {
tool_data.space_held = false;
tool_action_data.shape_editor.deselect_all_points();
tool_action_data.shape_editor.select_points_by_manipulator_id(&tool_data.selected_points_before_space);
responses.add(PathToolMessage::SelectedPointUpdated);
PathToolFsmState::Dragging
}
(PathToolFsmState::Ready, PathToolMessage::ResumeOriginalSelection) => {
tool_data.space_held = false;
tool_data.remove_selected_points();
PathToolFsmState::Ready
}
(_, PathToolMessage::DragStop { equidistant }) => {
let equidistant = input.keyboard.get(equidistant as usize);

Expand Down Expand Up @@ -729,6 +770,7 @@ impl Fsm for PathToolFsmState {
HintInfo::keys([Key::Alt], "Toggle Colinear Handles"),
// TODO: Switch this to the "Alt" key (since it's equivalent to the "From Center" modifier when drawing a line). And show this only when a handle is being dragged.
HintInfo::keys([Key::Shift], "Equidistant Handles"),
HintInfo::keys([Key::Space], "Drag anchor"),
// TODO: Add "Snap 15°" modifier with the "Shift" key (only when a handle is being dragged).
// TODO: Add "Lock Angle" modifier with the "Ctrl" key (only when a handle is being dragged).
]),
Expand Down