Restore handle length when Shift is released while dragging opposite handle with Path tool (#1009)

* Restore path handle length to previous length when shift is released while dragging

* Reset previous opposing handle length on Delete and Abort messages

* Move the opposing handle length state to the path tool

* Use MoveManipulatorPoint messages instead of modifying MoveSelectedManipulatorPoints + break handle mirroring on dragging both handles without anchor

* Handle alt + improve reset logic + comments

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Shouvik Ghosh
2023-02-21 15:51:46 -08:00
committed by GitHub
co-authored by Keavon Chambers
parent f400d2c9dd
commit 5179e8a829
3 changed files with 126 additions and 0 deletions
@@ -9,6 +9,7 @@ use crate::messages::tool::common_functionality::snapping::SnapManager;
use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, HintData, HintGroup, HintInfo, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
use document_legacy::intersection::Quad;
use document_legacy::LayerId;
use graphene_std::vector::consts::ManipulatorType;
use glam::DVec2;
@@ -112,6 +113,7 @@ struct PathToolData {
drag_start_pos: DVec2,
previous_mouse_position: DVec2,
alt_debounce: bool,
opposing_handle_lengths: Option<HashMap<Vec<LayerId>, HashMap<u64, f64>>>,
}
impl Fsm for PathToolFsmState {
@@ -142,6 +144,7 @@ impl Fsm for PathToolFsmState {
tool_data.overlay_renderer.render_subpath_overlays(&document.document_legacy, layer_path.to_vec(), responses);
}
tool_data.opposing_handle_lengths = None;
// This can happen in any state (which is why we return self)
self
}
@@ -158,6 +161,8 @@ impl Fsm for PathToolFsmState {
(_, PathToolMessage::DragStart { add_to_selection }) => {
let shift_pressed = input.keyboard.get(add_to_selection as usize);
tool_data.opposing_handle_lengths = None;
// Select the first point within the threshold (in pixels)
if let Some(mut selected_points) = tool_data
.shape_editor
@@ -240,6 +245,7 @@ impl Fsm for PathToolFsmState {
tool_data.alt_debounce = alt_pressed;
// Only on alt down
if alt_pressed {
tool_data.opposing_handle_lengths = None;
tool_data.shape_editor.toggle_handle_mirroring_on_selected(true, responses);
}
}
@@ -247,6 +253,17 @@ impl Fsm for PathToolFsmState {
// Determine when shift state changes
let shift_pressed = input.keyboard.get(shift_mirror_distance as usize);
if shift_pressed {
if tool_data.opposing_handle_lengths.is_none() {
tool_data.opposing_handle_lengths = Some(tool_data.shape_editor.opposing_handle_lengths(&document.document_legacy));
}
} else {
if let Some(opposing_handle_lengths) = &tool_data.opposing_handle_lengths {
tool_data.shape_editor.reset_opposing_handle_lengths(&document.document_legacy, opposing_handle_lengths, responses);
tool_data.opposing_handle_lengths = None;
}
}
// Move the selected points by the mouse position
let snapped_position = tool_data.snap_manager.snap_position(responses, document, input.mouse.position);
tool_data