Remove additional boolean for mirroring distance (#965)

Removed the additional boolean for mirroring distance
This commit is contained in:
Oliver Davies
2023-01-13 15:00:20 -08:00
committed by Keavon Chambers
parent cc7ec9409d
commit e849993f27
9 changed files with 21 additions and 62 deletions
+5 -15
View File
@@ -1113,42 +1113,32 @@ impl Document {
} }
Some(responses) Some(responses)
} }
Operation::MoveSelectedManipulatorPoints { layer_path, delta } => { Operation::MoveSelectedManipulatorPoints { layer_path, delta, mirror_distance } => {
if let Ok(viewspace) = self.generate_transform_relative_to_viewport(&layer_path) { if let Ok(viewspace) = self.generate_transform_relative_to_viewport(&layer_path) {
let objectspace = &viewspace.inverse(); let objectspace = &viewspace.inverse();
let delta = objectspace.transform_vector2(DVec2::new(delta.0, delta.1)); let delta = objectspace.transform_vector2(DVec2::new(delta.0, delta.1));
let layer = self.layer_mut(&layer_path)?; let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_subpath_mut() { if let Some(shape) = layer.as_subpath_mut() {
shape.move_selected(delta); shape.move_selected(delta, mirror_distance);
} }
} }
self.mark_as_dirty(&layer_path)?; self.mark_as_dirty(&layer_path)?;
Some([vec![DocumentChanged, LayerChanged { path: layer_path.clone() }], update_thumbnails_upstream(&layer_path)].concat()) Some([vec![DocumentChanged, LayerChanged { path: layer_path.clone() }], update_thumbnails_upstream(&layer_path)].concat())
} }
Operation::SetManipulatorHandleMirroring { Operation::SetManipulatorHandleMirroring { layer_path, id, mirror_angle } => {
layer_path,
id,
mirror_distance,
mirror_angle,
} => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) { if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
if let Some(manipulator_group) = shape.manipulator_groups_mut().by_id_mut(id) { if let Some(manipulator_group) = shape.manipulator_groups_mut().by_id_mut(id) {
manipulator_group.editor_state.mirror_distance_between_handles = mirror_distance;
manipulator_group.editor_state.mirror_angle_between_handles = mirror_angle; manipulator_group.editor_state.mirror_angle_between_handles = mirror_angle;
self.mark_as_dirty(&layer_path)?; self.mark_as_dirty(&layer_path)?;
} }
} }
Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat()) Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat())
} }
Operation::SetSelectedHandleMirroring { Operation::SetSelectedHandleMirroring { layer_path, toggle_angle } => {
layer_path,
toggle_distance,
toggle_angle,
} => {
let layer = self.layer_mut(&layer_path)?; let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_subpath_mut() { if let Some(shape) = layer.as_subpath_mut() {
for manipulator_group in shape.selected_manipulator_groups_any_points_mut() { for manipulator_group in shape.selected_manipulator_groups_any_points_mut() {
manipulator_group.toggle_mirroring(toggle_distance, toggle_angle); manipulator_group.toggle_mirroring(toggle_angle);
} }
} }
// This does nothing visually so we don't need to send any messages // This does nothing visually so we don't need to send any messages
+1 -2
View File
@@ -144,6 +144,7 @@ pub enum Operation {
MoveSelectedManipulatorPoints { MoveSelectedManipulatorPoints {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
delta: (f64, f64), delta: (f64, f64),
mirror_distance: bool,
}, },
MoveManipulatorPoint { MoveManipulatorPoint {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
@@ -272,12 +273,10 @@ pub enum Operation {
SetManipulatorHandleMirroring { SetManipulatorHandleMirroring {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
id: u64, id: u64,
mirror_distance: bool,
mirror_angle: bool, mirror_angle: bool,
}, },
SetSelectedHandleMirroring { SetSelectedHandleMirroring {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
toggle_distance: bool,
toggle_angle: bool, toggle_angle: bool,
}, },
} }
@@ -96,6 +96,7 @@ pub enum DocumentMessage {
MoveSelectedManipulatorPoints { MoveSelectedManipulatorPoints {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
delta: (f64, f64), delta: (f64, f64),
mirror_distance: bool,
}, },
NodeGraphFrameGenerate, NodeGraphFrameGenerate,
NodeGraphFrameImaginate { NodeGraphFrameImaginate {
@@ -183,7 +184,6 @@ pub enum DocumentMessage {
}, },
ToggleSelectedHandleMirroring { ToggleSelectedHandleMirroring {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
toggle_distance: bool,
toggle_angle: bool, toggle_angle: bool,
}, },
Undo, Undo,
@@ -496,9 +496,9 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
.into(), .into(),
); );
} }
MoveSelectedManipulatorPoints { layer_path, delta } => { MoveSelectedManipulatorPoints { layer_path, delta, mirror_distance } => {
if let Ok(_layer) = self.document_legacy.layer(&layer_path) { if let Ok(_layer) = self.document_legacy.layer(&layer_path) {
responses.push_back(DocumentOperation::MoveSelectedManipulatorPoints { layer_path, delta }.into()); responses.push_back(DocumentOperation::MoveSelectedManipulatorPoints { layer_path, delta, mirror_distance }.into());
} }
} }
NodeGraphFrameGenerate => { NodeGraphFrameGenerate => {
@@ -826,19 +826,8 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
responses.push_back(DocumentOperation::ToggleLayerVisibility { path: layer_path }.into()); responses.push_back(DocumentOperation::ToggleLayerVisibility { path: layer_path }.into());
responses.push_back(BroadcastEvent::DocumentIsDirty.into()); responses.push_back(BroadcastEvent::DocumentIsDirty.into());
} }
ToggleSelectedHandleMirroring { ToggleSelectedHandleMirroring { layer_path, toggle_angle } => {
layer_path, responses.push_back(DocumentOperation::SetSelectedHandleMirroring { layer_path, toggle_angle }.into());
toggle_distance,
toggle_angle,
} => {
responses.push_back(
DocumentOperation::SetSelectedHandleMirroring {
layer_path,
toggle_distance,
toggle_angle,
}
.into(),
);
} }
Undo => { Undo => {
self.undo_in_progress = true; self.undo_in_progress = true;
@@ -175,12 +175,13 @@ impl ShapeEditor {
} }
/// Move the selected points by dragging the mouse. /// Move the selected points by dragging the mouse.
pub fn move_selected_points(&self, delta: DVec2, responses: &mut VecDeque<Message>) { pub fn move_selected_points(&self, delta: DVec2, mirror_distance: bool, responses: &mut VecDeque<Message>) {
for layer_path in &self.selected_layers { for layer_path in &self.selected_layers {
responses.push_back( responses.push_back(
DocumentMessage::MoveSelectedManipulatorPoints { DocumentMessage::MoveSelectedManipulatorPoints {
layer_path: layer_path.clone(), layer_path: layer_path.clone(),
delta: (delta.x, delta.y), delta: (delta.x, delta.y),
mirror_distance,
} }
.into(), .into(),
); );
@@ -193,13 +194,12 @@ impl ShapeEditor {
} }
/// Toggle if the handles should mirror angle across the anchor position. /// Toggle if the handles should mirror angle across the anchor position.
pub fn toggle_handle_mirroring_on_selected(&self, toggle_angle: bool, toggle_distance: bool, responses: &mut VecDeque<Message>) { pub fn toggle_handle_mirroring_on_selected(&self, toggle_angle: bool, responses: &mut VecDeque<Message>) {
for layer_path in &self.selected_layers { for layer_path in &self.selected_layers {
responses.push_back( responses.push_back(
DocumentMessage::ToggleSelectedHandleMirroring { DocumentMessage::ToggleSelectedHandleMirroring {
layer_path: layer_path.clone(), layer_path: layer_path.clone(),
toggle_angle, toggle_angle,
toggle_distance,
} }
.into(), .into(),
); );
@@ -391,7 +391,6 @@ impl ShapeEditor {
Operation::SetManipulatorHandleMirroring { Operation::SetManipulatorHandleMirroring {
layer_path: layer_path.to_vec(), layer_path: layer_path.to_vec(),
id: bezier_id, id: bezier_id,
mirror_distance: false,
mirror_angle: true, mirror_angle: true,
} }
.into(), .into(),
@@ -131,7 +131,6 @@ struct PathToolData {
drag_start_pos: DVec2, drag_start_pos: DVec2,
alt_debounce: bool, alt_debounce: bool,
shift_debounce: bool,
} }
impl Fsm for PathToolFsmState { impl Fsm for PathToolFsmState {
@@ -248,20 +247,16 @@ impl Fsm for PathToolFsmState {
tool_data.alt_debounce = alt_pressed; tool_data.alt_debounce = alt_pressed;
// Only on alt down // Only on alt down
if alt_pressed { if alt_pressed {
tool_data.shape_editor.toggle_handle_mirroring_on_selected(true, false, responses); tool_data.shape_editor.toggle_handle_mirroring_on_selected(true, responses);
} }
} }
// Determine when shift state changes // Determine when shift state changes
let shift_pressed = input.keyboard.get(shift_mirror_distance as usize); let shift_pressed = input.keyboard.get(shift_mirror_distance as usize);
if shift_pressed != tool_data.shift_debounce {
tool_data.shift_debounce = shift_pressed;
tool_data.shape_editor.toggle_handle_mirroring_on_selected(false, true, responses);
}
// Move the selected points by the mouse position // Move the selected points by the mouse position
let snapped_position = tool_data.snap_manager.snap_position(responses, document, input.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, responses); tool_data.shape_editor.move_selected_points(snapped_position - tool_data.drag_start_pos, shift_pressed, responses);
tool_data.drag_start_pos = snapped_position; tool_data.drag_start_pos = snapped_position;
PathToolFsmState::Dragging PathToolFsmState::Dragging
} }
@@ -234,7 +234,6 @@ impl Fsm for PenToolFsmState {
let op = Operation::SetManipulatorHandleMirroring { let op = Operation::SetManipulatorHandleMirroring {
layer_path: layer.to_vec(), layer_path: layer.to_vec(),
id, id,
mirror_distance: false,
mirror_angle: false, mirror_angle: false,
}; };
responses.push_back(op.into()); responses.push_back(op.into());
@@ -328,7 +327,6 @@ impl Fsm for PenToolFsmState {
let op = Operation::SetManipulatorHandleMirroring { let op = Operation::SetManipulatorHandleMirroring {
layer_path: layer_path.clone(), layer_path: layer_path.clone(),
id: previous_id, id: previous_id,
mirror_distance: false,
mirror_angle: false, mirror_angle: false,
}; };
responses.push_back(op.into()); responses.push_back(op.into());
@@ -386,7 +384,6 @@ impl Fsm for PenToolFsmState {
let op = Operation::SetManipulatorHandleMirroring { let op = Operation::SetManipulatorHandleMirroring {
layer_path: layer_path.clone(), layer_path: layer_path.clone(),
id: first_id, id: first_id,
mirror_distance: false,
mirror_angle: false, mirror_angle: false,
}; };
responses.push_back(op.into()); responses.push_back(op.into());
@@ -475,7 +472,6 @@ impl Fsm for PenToolFsmState {
let op = Operation::SetManipulatorHandleMirroring { let op = Operation::SetManipulatorHandleMirroring {
layer_path: layer_path.clone(), layer_path: layer_path.clone(),
id: last_id, id: last_id,
mirror_distance: should_mirror,
mirror_angle: should_mirror, mirror_angle: should_mirror,
}; };
responses.push_back(op.into()); responses.push_back(op.into());
@@ -105,9 +105,8 @@ impl ManipulatorGroup {
} }
/// Move the selected points by the provided transform. /// Move the selected points by the provided transform.
pub fn move_selected_points(&mut self, delta: DVec2) { pub fn move_selected_points(&mut self, delta: DVec2, mirror_distance: bool) {
let mirror_angle = self.editor_state.mirror_angle_between_handles; let mirror_angle = self.editor_state.mirror_angle_between_handles;
let mirror_distance = self.editor_state.mirror_distance_between_handles;
// Move the point absolutely or relatively depending on if the point is under the cursor (the last selected point) // 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| { let move_point = |point: &mut ManipulatorPoint, delta: DVec2| {
@@ -270,10 +269,7 @@ impl ManipulatorGroup {
} }
/// Set the mirroring state /// Set the mirroring state
pub fn toggle_mirroring(&mut self, toggle_distance: bool, toggle_angle: bool) { pub fn toggle_mirroring(&mut self, toggle_angle: bool) {
if toggle_distance {
self.editor_state.mirror_distance_between_handles = !self.editor_state.mirror_distance_between_handles;
}
if toggle_angle { if toggle_angle {
self.editor_state.mirror_angle_between_handles = !self.editor_state.mirror_angle_between_handles; self.editor_state.mirror_angle_between_handles = !self.editor_state.mirror_angle_between_handles;
} }
@@ -301,15 +297,10 @@ impl ManipulatorGroup {
pub struct ManipulatorGroupEditorState { pub struct ManipulatorGroupEditorState {
// Whether the angle between the handles should be maintained // Whether the angle between the handles should be maintained
pub mirror_angle_between_handles: bool, pub mirror_angle_between_handles: bool,
// Whether the distance between the handles should be equidistant to the anchor
pub mirror_distance_between_handles: bool,
} }
impl Default for ManipulatorGroupEditorState { impl Default for ManipulatorGroupEditorState {
fn default() -> Self { fn default() -> Self {
Self { Self { mirror_angle_between_handles: true }
mirror_angle_between_handles: true,
mirror_distance_between_handles: false,
}
} }
} }
+2 -2
View File
@@ -182,9 +182,9 @@ impl Subpath {
} }
/// Move the selected points by the delta vector /// Move the selected points by the delta vector
pub fn move_selected(&mut self, delta: DVec2) { pub fn move_selected(&mut self, delta: DVec2, mirror_distance: bool) {
self.selected_manipulator_groups_any_points_mut() self.selected_manipulator_groups_any_points_mut()
.for_each(|manipulator_group| manipulator_group.move_selected_points(delta)); .for_each(|manipulator_group| manipulator_group.move_selected_points(delta, mirror_distance));
} }
/// Delete the selected points from the [Subpath] /// Delete the selected points from the [Subpath]