From 780ddf58782f3de8a58a79b98ed8078cfe80c71d Mon Sep 17 00:00:00 2001 From: 0SlowPoke0 Date: Mon, 6 Jan 2025 22:19:56 +0530 Subject: [PATCH] grab_scale_path and backspace for pen --- .../messages/input_mapper/input_mappings.rs | 2 ++ .../messages/tool/tool_messages/pen_tool.rs | 11 ++++++++++ .../transform_layer_message_handler.rs | 20 +++++++++++++++++-- node-graph/gcore/src/vector/vector_data.rs | 7 +++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/editor/src/messages/input_mapper/input_mappings.rs b/editor/src/messages/input_mapper/input_mappings.rs index f29c0fb2be..a684eba092 100644 --- a/editor/src/messages/input_mapper/input_mappings.rs +++ b/editor/src/messages/input_mapper/input_mappings.rs @@ -258,6 +258,8 @@ pub fn input_mappings() -> Mapping { entry!(KeyDown(MouseRight); action_dispatch=PenToolMessage::Confirm), entry!(KeyDown(Escape); action_dispatch=PenToolMessage::Confirm), entry!(KeyDown(Enter); action_dispatch=PenToolMessage::Confirm), + entry!(KeyDown(Delete); action_dispatch=PenToolMessage::RemovePreviousHandle), + entry!(KeyDown(Backspace); action_dispatch=PenToolMessage::RemovePreviousHandle), // // FreehandToolMessage entry!(PointerMove; action_dispatch=FreehandToolMessage::PointerMove), diff --git a/editor/src/messages/tool/tool_messages/pen_tool.rs b/editor/src/messages/tool/tool_messages/pen_tool.rs index ca601ec012..0a2ff4ec1f 100644 --- a/editor/src/messages/tool/tool_messages/pen_tool.rs +++ b/editor/src/messages/tool/tool_messages/pen_tool.rs @@ -62,6 +62,7 @@ pub enum PenToolMessage { Undo, UpdateOptions(PenOptionsUpdate), RecalculateLatestPointsPosition, + RemovePreviousHandle, } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -175,6 +176,7 @@ impl<'a> MessageHandler> for PenTool PointerMove, Confirm, Abort, + RemovePreviousHandle ), } } @@ -663,6 +665,15 @@ impl Fsm for PenToolFsmState { PenToolFsmState::PlacingAnchor } } + (PenToolFsmState::PlacingAnchor, PenToolMessage::RemovePreviousHandle) => { + if let Some(last_point) = tool_data.latest_points.last_mut() { + last_point.handle_start = last_point.pos; + responses.add(OverlaysMessage::Draw); + } else { + log::warn!("No latest point available to modify handle_start."); + } + self + } (PenToolFsmState::DraggingHandle, PenToolMessage::DragStop) => tool_data .finish_placing_handle(SnapData::new(document, input), transform, responses) .unwrap_or(PenToolFsmState::PlacingAnchor), diff --git a/editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs b/editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs index 6b2f3ac525..0581aa9da0 100644 --- a/editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs +++ b/editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs @@ -77,8 +77,24 @@ impl MessageHandler> for TransformLayer let mut point_count: usize = 0; let get_location = |point: &ManipulatorPointId| point.get_position(&vector_data).map(|position| viewspace.transform_point2(position)); let points = shape_editor.selected_points(); - - *selected.pivot = points.filter_map(get_location).inspect(|_| point_count += 1).sum::() / point_count as f64; + let selected_points: Vec<&ManipulatorPointId> = points.collect(); + + if selected_points.len() == 1 { + if let Some(point) = selected_points.first() { + match point { + ManipulatorPointId::PrimaryHandle(_) | ManipulatorPointId::EndHandle(_) => { + if let Some(anchor_position) = point.get_anchor_position(&vector_data) { + *selected.pivot = viewspace.transform_point2(anchor_position); + } + } + _ => { + *selected.pivot = selected_points.iter().filter_map(|point| get_location(point)).inspect(|_| point_count += 1).sum::() / point_count as f64; + } + } + } + } else { + *selected.pivot = selected_points.iter().filter_map(|point| get_location(point)).inspect(|_| point_count += 1).sum::() / point_count as f64; + } } } else { *selected.pivot = selected.mean_average_of_pivots(); diff --git a/node-graph/gcore/src/vector/vector_data.rs b/node-graph/gcore/src/vector/vector_data.rs index 35fc1db0c7..61928fb862 100644 --- a/node-graph/gcore/src/vector/vector_data.rs +++ b/node-graph/gcore/src/vector/vector_data.rs @@ -306,6 +306,13 @@ impl ManipulatorPointId { } } + pub fn get_anchor_position(&self, vector_data: &VectorData) -> Option { + match self { + ManipulatorPointId::EndHandle(_) | ManipulatorPointId::PrimaryHandle(_) => self.get_anchor(vector_data).and_then(|id| vector_data.point_domain.position_from_id(id)), + _ => self.get_position(vector_data), + } + } + /// Attempt to get a pair of handles. For an anchor this is the first two handles connected. For a handle it is self and the first opposing handle. #[must_use] pub fn get_handle_pair(self, vector_data: &VectorData) -> Option<[HandleId; 2]> {