mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 15:38:11 +08:00
Path tool points manipulation: nudging, drag axis snapping, and G/R/S (#1068)
* issue820: implemented nudging points * nudge points triggered only when the mouse is moved after selecting one point * issue 820 // bullet 1 done * grab working / rotate not * rotate works (sensitive) * G/R/S and Shift/Drag working * Cargo formatted // implemented Hypercubes comments * Refactored G/R/S - need to fix fast transform * Finished refactored G/R/S * Typed Angle needs further touch up * Cargo formatted * Dealt with dangerous unwraps * Cargo fmt (again) - unwraps fixed * Cleaned up * cargo fmt * Ready for Review * Ready for Review- cargo fmt * Code review fixes * Remove duplicate constant for nudging * Fix consts.rs spacing * Apply suggestions from code review Added suggestions Co-authored-by: Keavon Chambers <keavon@keavon.com> * Added typo/grammar suggestions * Nits --------- Co-authored-by: Shiro <shiro@damedane.local> Co-authored-by: hypercube <0hypercube@gmail.com> Co-authored-by: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
Shiro
hypercube
0HyperCube
parent
b83f2c24f1
commit
974a37f127
@@ -24,7 +24,7 @@ pub struct PathTool {
|
||||
|
||||
#[remain::sorted]
|
||||
#[impl_message(Message, ToolMessage, Path)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
pub enum PathToolMessage {
|
||||
// Standard messages
|
||||
#[remain::unsorted]
|
||||
@@ -43,6 +43,10 @@ pub enum PathToolMessage {
|
||||
shift_mirror_distance: Key,
|
||||
},
|
||||
InsertPoint,
|
||||
NudgeSelectedPoints {
|
||||
delta_x: f64,
|
||||
delta_y: f64,
|
||||
},
|
||||
PointerMove {
|
||||
alt_mirror_angle: Key,
|
||||
shift_mirror_distance: Key,
|
||||
@@ -77,6 +81,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
InsertPoint,
|
||||
DragStart,
|
||||
Delete,
|
||||
NudgeSelectedPoints,
|
||||
),
|
||||
Dragging => actions!(PathToolMessageDiscriminant;
|
||||
InsertPoint,
|
||||
@@ -108,7 +113,6 @@ enum PathToolFsmState {
|
||||
#[derive(Default)]
|
||||
struct PathToolData {
|
||||
snap_manager: SnapManager,
|
||||
|
||||
drag_start_pos: DVec2,
|
||||
previous_mouse_position: DVec2,
|
||||
alt_debounce: bool,
|
||||
@@ -203,6 +207,7 @@ impl Fsm for PathToolFsmState {
|
||||
|
||||
let include_handles: Vec<_> = selected_layers.iter().map(|x| x.as_slice()).collect();
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &include_handles, &[], &selected_points.points);
|
||||
|
||||
tool_data.drag_start_pos = input.mouse.position;
|
||||
tool_data.previous_mouse_position = input.mouse.position - selected_points.offset;
|
||||
|
||||
@@ -241,9 +246,11 @@ impl Fsm for PathToolFsmState {
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
}
|
||||
}
|
||||
|
||||
PathToolFsmState::Ready
|
||||
}
|
||||
}
|
||||
|
||||
// Dragging
|
||||
(
|
||||
PathToolFsmState::Dragging,
|
||||
@@ -282,6 +289,7 @@ impl Fsm for PathToolFsmState {
|
||||
tool_data.previous_mouse_position = snapped_position;
|
||||
PathToolFsmState::Dragging
|
||||
}
|
||||
|
||||
// Mouse up
|
||||
(_, PathToolMessage::DragStop { shift_mirror_distance }) => {
|
||||
let nearest_point = shape_editor
|
||||
@@ -335,6 +343,10 @@ impl Fsm for PathToolFsmState {
|
||||
shift_mirror_distance: _,
|
||||
},
|
||||
) => self,
|
||||
(_, PathToolMessage::NudgeSelectedPoints { delta_x, delta_y }) => {
|
||||
shape_editor.move_selected_points(&document.document_legacy, (delta_x, delta_y).into(), true, responses);
|
||||
PathToolFsmState::Ready
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self
|
||||
@@ -346,8 +358,8 @@ impl Fsm for PathToolFsmState {
|
||||
PathToolFsmState::Ready => HintData(vec![
|
||||
HintGroup(vec![HintInfo::mouse(MouseMotion::Lmb, "Select Point"), HintInfo::keys([Key::Shift], "Extend Selection").prepend_plus()]),
|
||||
HintGroup(vec![HintInfo::mouse(MouseMotion::LmbDrag, "Drag Selected")]),
|
||||
HintGroup(vec![HintInfo::arrow_keys("Nudge Selected (coming soon)"), HintInfo::keys([Key::Shift], "10x").prepend_plus()]),
|
||||
HintGroup(vec![HintInfo::keys([Key::KeyG, Key::KeyR, Key::KeyS], "Grab/Rotate/Scale Selected (coming soon)")]),
|
||||
HintGroup(vec![HintInfo::arrow_keys("Nudge Selected"), HintInfo::keys([Key::Shift], "10x").prepend_plus()]),
|
||||
HintGroup(vec![HintInfo::keys([Key::KeyG, Key::KeyR, Key::KeyS], "Grab/Rotate/Scale Selected")]),
|
||||
]),
|
||||
PathToolFsmState::Dragging => HintData(vec![HintGroup(vec![
|
||||
HintInfo::keys([Key::Alt], "Split/Align Handles (Toggle)"),
|
||||
|
||||
@@ -539,7 +539,15 @@ impl Fsm for SelectToolFsmState {
|
||||
let document = &document.document_legacy;
|
||||
|
||||
let selected = &tool_data.layers_dragging.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut bounds.center_of_transformation, selected, responses, document);
|
||||
let mut selected = Selected::new(
|
||||
&mut bounds.original_transforms,
|
||||
&mut bounds.center_of_transformation,
|
||||
selected,
|
||||
responses,
|
||||
document,
|
||||
None,
|
||||
&ToolType::Select,
|
||||
);
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(render_data);
|
||||
}
|
||||
|
||||
@@ -549,7 +557,15 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
if let Some(bounds) = &mut tool_data.bounding_box_overlays {
|
||||
let selected = selected.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut bounds.center_of_transformation, &selected, responses, &document.document_legacy);
|
||||
let mut selected = Selected::new(
|
||||
&mut bounds.original_transforms,
|
||||
&mut bounds.center_of_transformation,
|
||||
&selected,
|
||||
responses,
|
||||
&document.document_legacy,
|
||||
None,
|
||||
&ToolType::Select,
|
||||
);
|
||||
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(render_data);
|
||||
}
|
||||
@@ -650,10 +666,10 @@ impl Fsm for SelectToolFsmState {
|
||||
let snapped_mouse_position = tool_data.snap_manager.snap_position(responses, document, mouse_position);
|
||||
|
||||
let (position, size) = movement.new_size(snapped_mouse_position, bounds.transform, center, bounds.center_of_transformation, axis_align);
|
||||
let (delta, mut pivot) = movement.bounds_to_scale_transform(position, size);
|
||||
let (delta, mut _pivot) = movement.bounds_to_scale_transform(position, size);
|
||||
|
||||
let selected = &tool_data.layers_dragging.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut pivot, selected, responses, &document.document_legacy);
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut _pivot, selected, responses, &document.document_legacy, None, &ToolType::Select);
|
||||
|
||||
selected.update_transforms(delta);
|
||||
}
|
||||
@@ -679,7 +695,15 @@ impl Fsm for SelectToolFsmState {
|
||||
let delta = DAffine2::from_angle(snapped_angle);
|
||||
|
||||
let selected = tool_data.layers_dragging.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut bounds.center_of_transformation, &selected, responses, &document.document_legacy);
|
||||
let mut selected = Selected::new(
|
||||
&mut bounds.original_transforms,
|
||||
&mut bounds.center_of_transformation,
|
||||
&selected,
|
||||
responses,
|
||||
&document.document_legacy,
|
||||
None,
|
||||
&ToolType::Select,
|
||||
);
|
||||
|
||||
selected.update_transforms(delta);
|
||||
}
|
||||
@@ -872,6 +896,8 @@ impl Fsm for SelectToolFsmState {
|
||||
&selected,
|
||||
responses,
|
||||
&document.document_legacy,
|
||||
None,
|
||||
&ToolType::Select,
|
||||
);
|
||||
|
||||
selected.revert_operation();
|
||||
|
||||
Reference in New Issue
Block a user