Fix fast drag with path tool eating handles (#763)

* Fix fast drag with path tool eating handles

* Remove extra space

* Import ordering

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-08-27 18:19:20 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 3c2bc04c3c
commit cac92ad9a2
8 changed files with 18 additions and 31 deletions
+2 -3
View File
@@ -971,14 +971,13 @@ impl Document {
}
Some(responses)
}
Operation::MoveSelectedManipulatorPoints { layer_path, delta, absolute_position } => {
Operation::MoveSelectedManipulatorPoints { layer_path, delta } => {
if let Ok(viewspace) = self.generate_transform_relative_to_viewport(&layer_path) {
let objectspace = &viewspace.inverse();
let delta = objectspace.transform_vector2(DVec2::new(delta.0, delta.1));
let absolute_position = objectspace.transform_point2(DVec2::new(absolute_position.0, absolute_position.1));
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_subpath_mut() {
shape.move_selected(delta, absolute_position, &viewspace);
shape.move_selected(delta);
}
}
self.mark_as_dirty(&layer_path)?;
@@ -1,7 +1,6 @@
use super::{
consts::{ManipulatorType, SELECTION_THRESHOLD},
manipulator_point::ManipulatorPoint,
};
use super::consts::ManipulatorType;
use super::manipulator_point::ManipulatorPoint;
use glam::{DAffine2, DVec2};
use serde::{Deserialize, Serialize};
@@ -95,22 +94,14 @@ impl ManipulatorGroup {
}
/// Move the selected points by the provided transform.
pub fn move_selected_points(&mut self, delta: DVec2, absolute_position: DVec2, viewspace: &DAffine2) {
pub fn move_selected_points(&mut self, delta: DVec2) {
let mirror_angle = self.editor_state.mirror_angle_between_handles;
// Invert distance since we want it to start disabled
let mirror_distance = !self.editor_state.mirror_distance_between_handles;
// TODO Use an ID as opposed to distance, stopgap for now
// Transformed into viewspace so SELECTION_THRESHOLD is in pixels
let is_drag_target = |point: &mut ManipulatorPoint| -> bool { viewspace.transform_point2(absolute_position).distance(viewspace.transform_point2(point.position)) < SELECTION_THRESHOLD };
// Move the point absolutely or relatively depending on if the point is under the cursor (the last selected point)
let move_point = |point: &mut ManipulatorPoint, delta: DVec2, absolute_position: DVec2| {
if is_drag_target(point) {
point.position = absolute_position;
} else {
point.position += delta;
}
let move_point = |point: &mut ManipulatorPoint, delta: DVec2| {
point.position += delta;
assert!(point.position.is_finite(), "Point is not finite!")
};
@@ -139,7 +130,7 @@ impl ManipulatorGroup {
// If the anchor is selected, ignore any handle mirroring/dragging and drag all points
if self.is_anchor_selected() {
for point in self.points_mut() {
move_point(point, delta, absolute_position);
move_point(point, delta);
}
return;
}
@@ -147,7 +138,7 @@ impl ManipulatorGroup {
// If the anchor isn't selected, but both handles are, drag only handles
if self.both_handles_selected() {
for point in self.selected_handles_mut() {
move_point(point, delta, absolute_position);
move_point(point, delta);
}
return;
}
@@ -156,7 +147,7 @@ impl ManipulatorGroup {
// Drag the single handle
let reflect_center = self.points[ManipulatorType::Anchor].as_ref().unwrap().position;
let selected_handle = self.selected_handles_mut().next().unwrap();
move_point(selected_handle, delta, absolute_position);
move_point(selected_handle, delta);
// Move the opposing handle symmetrically if our mirroring flags allow
let selected_handle = &selected_handle.clone();
+2 -2
View File
@@ -179,9 +179,9 @@ impl Subpath {
}
/// Move the selected points by the delta vector
pub fn move_selected(&mut self, delta: DVec2, absolute_position: DVec2, viewspace: &DAffine2) {
pub fn move_selected(&mut self, delta: DVec2) {
self.selected_manipulator_groups_any_points_mut()
.for_each(|manipulator_group| manipulator_group.move_selected_points(delta, absolute_position, viewspace));
.for_each(|manipulator_group| manipulator_group.move_selected_points(delta));
}
/// Delete the selected points from the [Subpath]
-1
View File
@@ -122,7 +122,6 @@ pub enum Operation {
MoveSelectedManipulatorPoints {
layer_path: Vec<LayerId>,
delta: (f64, f64),
absolute_position: (f64, f64),
},
MoveManipulatorPoint {
layer_path: Vec<LayerId>,