Skip to content

Commit

Permalink
Fix point nudging to work in document space (#2095)
Browse files Browse the repository at this point in the history
* Modified Path tool Behaviour

* Make the code simpler and more self-descriptive

* Make it work for transformed layers

---------

Co-authored-by: Keavon Chambers <[email protected]>
  • Loading branch information
November-6 and Keavon authored Nov 6, 2024
1 parent f1b0d8f commit b3a196c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions editor/src/messages/tool/common_functionality/shape_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,24 @@ impl ShapeState {
}

/// Move the selected points by dragging the mouse.
pub fn move_selected_points(&self, handle_lengths: Option<OpposingHandleLengths>, document: &DocumentMessageHandler, delta: DVec2, equidistant: bool, responses: &mut VecDeque<Message>) {
pub fn move_selected_points(
&self,
handle_lengths: Option<OpposingHandleLengths>,
document: &DocumentMessageHandler,
delta: DVec2,
equidistant: bool,
responses: &mut VecDeque<Message>,
in_viewport_space: bool,
) {
for (&layer, state) in &self.selected_shape_state {
let Some(vector_data) = document.network_interface.compute_modified_vector(layer) else {
continue;
};
let Some(vector_data) = document.network_interface.compute_modified_vector(layer) else { continue };

let opposing_handles = handle_lengths.as_ref().and_then(|handle_lengths| handle_lengths.get(&layer));

let transform = document.metadata().transform_to_viewport(layer);
let delta = transform.inverse().transform_vector2(delta);
let transform_to_viewport_space = document.metadata().transform_to_viewport(layer);
let transform_to_document_space = document.metadata().transform_to_document(layer);
let delta_transform = if in_viewport_space { transform_to_viewport_space } else { transform_to_document_space };
let delta = delta_transform.inverse().transform_vector2(delta);

for &point in state.selected_points.iter() {
let handle = match point {
Expand Down Expand Up @@ -654,7 +663,8 @@ impl ShapeState {
let new_relative = if equidistant {
-(handle_position - anchor_position)
} else {
let transform = document.metadata().document_to_viewport.inverse() * transform;
// TODO: Is this equivalent to `transform_to_document_space`? If changed, the before and after should be tested.
let transform = document.metadata().document_to_viewport.inverse() * transform_to_viewport_space;
let Some(other_position) = other.to_manipulator_point().get_position(&vector_data) else {
continue;
};
Expand Down
4 changes: 2 additions & 2 deletions editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl PathToolData {
let previous_mouse = document.metadata().document_to_viewport.transform_point2(self.previous_mouse_position);
let snapped_delta = shape_editor.snap(&mut self.snap_manager, &self.snap_cache, document, input, previous_mouse);
let handle_lengths = if equidistant { None } else { self.opposing_handle_lengths.take() };
shape_editor.move_selected_points(handle_lengths, document, snapped_delta, equidistant, responses);
shape_editor.move_selected_points(handle_lengths, document, snapped_delta, equidistant, responses, true);
self.previous_mouse_position += document.metadata().document_to_viewport.inverse().transform_vector2(snapped_delta);
}
}
Expand Down Expand Up @@ -786,7 +786,7 @@ impl Fsm for PathToolFsmState {
}
(_, PathToolMessage::PointerMove { .. }) => self,
(_, PathToolMessage::NudgeSelectedPoints { delta_x, delta_y }) => {
shape_editor.move_selected_points(tool_data.opposing_handle_lengths.take(), document, (delta_x, delta_y).into(), true, responses);
shape_editor.move_selected_points(tool_data.opposing_handle_lengths.take(), document, (delta_x, delta_y).into(), true, responses, false);

PathToolFsmState::Ready
}
Expand Down

0 comments on commit b3a196c

Please sign in to comment.