Skip to content
Open
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
64 changes: 44 additions & 20 deletions editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,6 @@ impl PathToolData {
let drag_start = self.drag_start_pos;
let opposite_delta = drag_start - current_mouse;

shape_editor.move_selected_points_and_segments(None, document, opposite_delta, false, true, false, None, false, responses);

// Calculate the projected delta and shift the points along that delta
let delta = current_mouse - drag_start;
let axis = if delta.x.abs() >= delta.y.abs() { Axis::X } else { Axis::Y };
Expand All @@ -1161,7 +1159,8 @@ impl PathToolData {
_ => DVec2::new(delta.x, 0.),
};

shape_editor.move_selected_points_and_segments(None, document, projected_delta, false, true, false, None, false, responses);
// Apply the two deltas combined
shape_editor.move_selected_points_and_segments(None, document, opposite_delta + projected_delta, false, true, false, None, false, responses);
}

fn stop_snap_along_axis(&mut self, shape_editor: &mut ShapeState, document: &DocumentMessageHandler, input: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) {
Expand All @@ -1177,12 +1176,11 @@ impl PathToolData {
_ => DVec2::new(opposite_delta.x, 0.),
};

shape_editor.move_selected_points_and_segments(None, document, opposite_projected_delta, false, true, false, None, false, responses);

// Calculate what actually would have been the original delta for the point, and apply that
let delta = current_mouse - drag_start;

shape_editor.move_selected_points_and_segments(None, document, delta, false, true, false, None, false, responses);
// Apply the two deltas combined
shape_editor.move_selected_points_and_segments(None, document, opposite_projected_delta + delta, false, true, false, None, false, responses);

self.snapping_axis = None;
}
Expand Down Expand Up @@ -1509,24 +1507,50 @@ impl PathToolData {
self.previous_mouse_position += document_to_viewport.inverse().transform_vector2(snapped_delta);
} else {
let Some(axis) = self.snapping_axis else { return };
let projected_delta = match axis {
Axis::X => DVec2::new(unsnapped_delta.x, 0.),
Axis::Y => DVec2::new(0., unsnapped_delta.y),
_ => DVec2::new(unsnapped_delta.x, 0.),
};
shape_editor.move_selected_points_and_segments(handle_lengths, document, projected_delta, equidistant, true, false, opposite, false, responses);
self.previous_mouse_position += document_to_viewport.inverse().transform_vector2(unsnapped_delta);
}

// Constantly checking and changing the snapping axis based on current mouse position
if snap_axis && self.snapping_axis.is_some() {
let Some(current_axis) = self.snapping_axis else { return };
// Constantly checking and changing the snapping axis based on current mouse position
let total_delta = self.drag_start_pos - input.mouse.position;
let mut current_axis = axis;
if (total_delta.x.abs() > total_delta.y.abs() && axis == Axis::Y) || (total_delta.y.abs() > total_delta.x.abs() && axis == Axis::X) {
current_axis = if axis == Axis::X { Axis::Y } else { Axis::X };
}

let document_to_viewport = document.metadata().document_to_viewport;

if (total_delta.x.abs() > total_delta.y.abs() && current_axis == Axis::Y) || (total_delta.y.abs() > total_delta.x.abs() && current_axis == Axis::X) {
self.stop_snap_along_axis(shape_editor, document, input, responses);
self.start_snap_along_axis(shape_editor, document, input, responses);
// Correct the position from the old axis projection to the new one
if current_axis != axis {
let previous_delta = previous_mouse - self.drag_start_pos;
let current_delta = current_mouse - self.drag_start_pos;

// Where the shape currently IS
let previous_projected = match axis {
Axis::X => DVec2::new(previous_delta.x, 0.),
Axis::Y => DVec2::new(0., previous_delta.y),
_ => DVec2::new(previous_delta.x, 0.),
};

// Where we want to GO
let current_projected = match current_axis {
Axis::X => DVec2::new(current_delta.x, 0.),
Axis::Y => DVec2::new(0., current_delta.y),
_ => DVec2::new(current_delta.x, 0.),
};

let snap_delta = current_projected - previous_projected;
shape_editor.move_selected_points_and_segments(handle_lengths, document, snap_delta, equidistant, true, false, opposite, false, responses);

self.snapping_axis = Some(current_axis);
} else {
// Standard incremental move along the same axis
let projected_delta = match axis {
Axis::X => DVec2::new(unsnapped_delta.x, 0.),
Axis::Y => DVec2::new(0., unsnapped_delta.y),
_ => DVec2::new(unsnapped_delta.x, 0.),
};
shape_editor.move_selected_points_and_segments(handle_lengths, document, projected_delta, equidistant, true, false, opposite, false, responses);
}

self.previous_mouse_position += document_to_viewport.inverse().transform_vector2(unsnapped_delta);
}
}

Expand Down