Skip to content

Commit

Permalink
grab_scale_path and backspace for pen
Browse files Browse the repository at this point in the history
  • Loading branch information
0SlowPoke0 committed Jan 6, 2025
1 parent 6635754 commit 780ddf5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions editor/src/messages/tool/tool_messages/pen_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub enum PenToolMessage {
Undo,
UpdateOptions(PenOptionsUpdate),
RecalculateLatestPointsPosition,
RemovePreviousHandle,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -175,6 +176,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PenTool
PointerMove,
Confirm,
Abort,
RemovePreviousHandle
),
}
}
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,24 @@ impl MessageHandler<TransformLayerMessage, TransformData<'_>> 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::<DVec2>() / 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::<DVec2>() / point_count as f64;
}
}
}
} else {
*selected.pivot = selected_points.iter().filter_map(|point| get_location(point)).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64;
}
}
} else {
*selected.pivot = selected.mean_average_of_pivots();
Expand Down
7 changes: 7 additions & 0 deletions node-graph/gcore/src/vector/vector_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ impl ManipulatorPointId {
}
}

pub fn get_anchor_position(&self, vector_data: &VectorData) -> Option<DVec2> {
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]> {
Expand Down

0 comments on commit 780ddf5

Please sign in to comment.