Skip to content

Commit 00bc03a

Browse files
0SlowPoke0Keavon
authored andcommitted
grab_scale_path and backspace for pen
1 parent d692538 commit 00bc03a

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

editor/src/messages/input_mapper/input_mappings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ pub fn input_mappings() -> Mapping {
258258
entry!(KeyDown(MouseRight); action_dispatch=PenToolMessage::Confirm),
259259
entry!(KeyDown(Escape); action_dispatch=PenToolMessage::Confirm),
260260
entry!(KeyDown(Enter); action_dispatch=PenToolMessage::Confirm),
261+
entry!(KeyDown(Delete); action_dispatch=PenToolMessage::RemovePreviousHandle),
262+
entry!(KeyDown(Backspace); action_dispatch=PenToolMessage::RemovePreviousHandle),
261263
//
262264
// FreehandToolMessage
263265
entry!(PointerMove; action_dispatch=FreehandToolMessage::PointerMove),

editor/src/messages/tool/tool_messages/pen_tool.rs

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub enum PenToolMessage {
6262
Undo,
6363
UpdateOptions(PenOptionsUpdate),
6464
RecalculateLatestPointsPosition,
65+
RemovePreviousHandle,
6566
}
6667

6768
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -175,6 +176,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PenTool
175176
PointerMove,
176177
Confirm,
177178
Abort,
179+
RemovePreviousHandle
178180
),
179181
}
180182
}
@@ -685,6 +687,15 @@ impl Fsm for PenToolFsmState {
685687
PenToolFsmState::PlacingAnchor
686688
}
687689
}
690+
(PenToolFsmState::PlacingAnchor, PenToolMessage::RemovePreviousHandle) => {
691+
if let Some(last_point) = tool_data.latest_points.last_mut() {
692+
last_point.handle_start = last_point.pos;
693+
responses.add(OverlaysMessage::Draw);
694+
} else {
695+
log::warn!("No latest point available to modify handle_start.");
696+
}
697+
self
698+
}
688699
(PenToolFsmState::DraggingHandle, PenToolMessage::DragStop) => tool_data
689700
.finish_placing_handle(SnapData::new(document, input), transform, responses)
690701
.unwrap_or(PenToolFsmState::PlacingAnchor),

editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,24 @@ impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayer
7777
let mut point_count: usize = 0;
7878
let get_location = |point: &ManipulatorPointId| point.get_position(&vector_data).map(|position| viewspace.transform_point2(position));
7979
let points = shape_editor.selected_points();
80-
81-
*selected.pivot = points.filter_map(get_location).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64;
80+
let selected_points: Vec<&ManipulatorPointId> = points.collect();
81+
82+
if selected_points.len() == 1 {
83+
if let Some(point) = selected_points.first() {
84+
match point {
85+
ManipulatorPointId::PrimaryHandle(_) | ManipulatorPointId::EndHandle(_) => {
86+
if let Some(anchor_position) = point.get_anchor_position(&vector_data) {
87+
*selected.pivot = viewspace.transform_point2(anchor_position);
88+
}
89+
}
90+
_ => {
91+
*selected.pivot = selected_points.iter().filter_map(|point| get_location(point)).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64;
92+
}
93+
}
94+
}
95+
} else {
96+
*selected.pivot = selected_points.iter().filter_map(|point| get_location(point)).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64;
97+
}
8298
}
8399
} else {
84100
*selected.pivot = selected.mean_average_of_pivots();

node-graph/gcore/src/vector/vector_data.rs

+7
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ impl ManipulatorPointId {
306306
}
307307
}
308308

309+
pub fn get_anchor_position(&self, vector_data: &VectorData) -> Option<DVec2> {
310+
match self {
311+
ManipulatorPointId::EndHandle(_) | ManipulatorPointId::PrimaryHandle(_) => self.get_anchor(vector_data).and_then(|id| vector_data.point_domain.position_from_id(id)),
312+
_ => self.get_position(vector_data),
313+
}
314+
}
315+
309316
/// 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.
310317
#[must_use]
311318
pub fn get_handle_pair(self, vector_data: &VectorData) -> Option<[HandleId; 2]> {

0 commit comments

Comments
 (0)