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:
parent
9f21a8ae6b
commit
c28d618291
|
|
@ -86,7 +86,6 @@ pub enum DocumentMessage {
|
|||
MoveSelectedManipulatorPoints {
|
||||
layer_path: Vec<LayerId>,
|
||||
delta: (f64, f64),
|
||||
absolute_position: (f64, f64),
|
||||
},
|
||||
NudgeSelectedLayers {
|
||||
delta_x: f64,
|
||||
|
|
|
|||
|
|
@ -436,10 +436,10 @@ impl MessageHandler<DocumentMessage, (&InputPreprocessorMessageHandler, &FontCac
|
|||
.into(),
|
||||
);
|
||||
}
|
||||
MoveSelectedManipulatorPoints { layer_path, delta, absolute_position } => {
|
||||
MoveSelectedManipulatorPoints { layer_path, delta } => {
|
||||
self.backup(responses);
|
||||
if let Ok(_layer) = self.graphene_document.layer(&layer_path) {
|
||||
responses.push_back(DocumentOperation::MoveSelectedManipulatorPoints { layer_path, delta, absolute_position }.into());
|
||||
responses.push_back(DocumentOperation::MoveSelectedManipulatorPoints { layer_path, delta }.into());
|
||||
}
|
||||
}
|
||||
NudgeSelectedLayers { delta_x, delta_y } => {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ impl ShapeEditor {
|
|||
);
|
||||
// Snap the selected point to the cursor
|
||||
if let Ok(viewspace) = document.generate_transform_relative_to_viewport(shape_layer_path) {
|
||||
self.move_selected_points(mouse_position - viewspace.transform_point2(point_position), mouse_position, responses)
|
||||
self.move_selected_points(mouse_position - viewspace.transform_point2(point_position), responses)
|
||||
}
|
||||
|
||||
return Some(points);
|
||||
|
|
@ -171,13 +171,12 @@ impl ShapeEditor {
|
|||
}
|
||||
|
||||
/// Move the selected points by dragging the mouse.
|
||||
pub fn move_selected_points(&self, delta: DVec2, absolute_position: DVec2, responses: &mut VecDeque<Message>) {
|
||||
pub fn move_selected_points(&self, delta: DVec2, responses: &mut VecDeque<Message>) {
|
||||
for layer_path in &self.selected_layers {
|
||||
responses.push_back(
|
||||
DocumentMessage::MoveSelectedManipulatorPoints {
|
||||
layer_path: layer_path.clone(),
|
||||
delta: (delta.x, delta.y),
|
||||
absolute_position: (absolute_position.x, absolute_position.y),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ impl Fsm for PathToolFsmState {
|
|||
|
||||
// Move the selected points by the mouse position
|
||||
let snapped_position = tool_data.snap_manager.snap_position(responses, document, input.mouse.position);
|
||||
tool_data.shape_editor.move_selected_points(snapped_position - tool_data.drag_start_pos, snapped_position, responses);
|
||||
tool_data.shape_editor.move_selected_points(snapped_position - tool_data.drag_start_pos, responses);
|
||||
tool_data.drag_start_pos = snapped_position;
|
||||
PathToolFsmState::Dragging
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ pub enum Operation {
|
|||
MoveSelectedManipulatorPoints {
|
||||
layer_path: Vec<LayerId>,
|
||||
delta: (f64, f64),
|
||||
absolute_position: (f64, f64),
|
||||
},
|
||||
MoveManipulatorPoint {
|
||||
layer_path: Vec<LayerId>,
|
||||
|
|
|
|||
Loading…
Reference in New Issue