Fix Pen and Freehand tool path extension (#1809)
Improve path tool extend
This commit is contained in:
parent
4cd11448a0
commit
97616e8019
|
|
@ -5,7 +5,7 @@ use graphene_std::vector::PointId;
|
|||
|
||||
use glam::DVec2;
|
||||
|
||||
/// Determines if a path should be extended. Returns the path and if it is extending from the start, if applicable.
|
||||
/// Determines if a path should be extended. Goal in viewport space. Returns the path and if it is extending from the start, if applicable.
|
||||
pub fn should_extend(document: &DocumentMessageHandler, goal: DVec2, tolerance: f64) -> Option<(LayerNodeIdentifier, PointId, DVec2)> {
|
||||
let mut best = None;
|
||||
let mut best_distance_squared = tolerance * tolerance;
|
||||
|
|
|
|||
|
|
@ -175,7 +175,6 @@ impl ToolTransition for FreehandTool {
|
|||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct FreehandToolData {
|
||||
extend_from_start: bool,
|
||||
end_point: Option<(DVec2, PointId)>,
|
||||
dragged: bool,
|
||||
weight: f64,
|
||||
|
|
@ -208,12 +207,13 @@ impl Fsm for FreehandToolFsmState {
|
|||
responses.add(DocumentMessage::StartTransaction);
|
||||
|
||||
tool_data.dragged = false;
|
||||
tool_data.extend_from_start = false;
|
||||
tool_data.end_point = None;
|
||||
tool_data.weight = tool_options.line_weight;
|
||||
|
||||
// Extend an endpoint of the selected path
|
||||
if let Some((layer, _, position)) = should_extend(document, input.mouse.position, crate::consts::SNAP_POINT_TOLERANCE) {
|
||||
if let Some((layer, point, position)) = should_extend(document, input.mouse.position, crate::consts::SNAP_POINT_TOLERANCE) {
|
||||
tool_data.layer = Some(layer);
|
||||
tool_data.end_point = Some((position, point));
|
||||
|
||||
extend_path_with_next_segment(tool_data, position, responses);
|
||||
|
||||
|
|
@ -260,6 +260,7 @@ impl Fsm for FreehandToolFsmState {
|
|||
responses.add(DocumentMessage::DocumentHistoryBackward);
|
||||
}
|
||||
|
||||
tool_data.end_point = None;
|
||||
tool_data.layer = None;
|
||||
|
||||
FreehandToolFsmState::Ready
|
||||
|
|
@ -267,6 +268,7 @@ impl Fsm for FreehandToolFsmState {
|
|||
(FreehandToolFsmState::Drawing, FreehandToolMessage::Abort) => {
|
||||
responses.add(DocumentMessage::AbortTransaction);
|
||||
tool_data.layer = None;
|
||||
tool_data.end_point = None;
|
||||
|
||||
FreehandToolFsmState::Ready
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,8 +508,12 @@ impl Fsm for PenToolFsmState {
|
|||
(PenToolFsmState::Ready, PenToolMessage::DragStart) => {
|
||||
responses.add(DocumentMessage::StartTransaction);
|
||||
|
||||
let point = SnapCandidatePoint::handle(document.metadata.document_to_viewport.inverse().transform_point2(input.mouse.position));
|
||||
let snapped = tool_data.snap_manager.free_snap(&SnapData::new(document, input), &point, None, false);
|
||||
let viewport = document.metadata.document_to_viewport.transform_point2(snapped.snapped_point_document);
|
||||
|
||||
// Perform extension of an existing path
|
||||
if let Some((layer, point, position)) = should_extend(document, input.mouse.position, crate::consts::SNAP_POINT_TOLERANCE) {
|
||||
if let Some((layer, point, position)) = should_extend(document, viewport, crate::consts::SNAP_POINT_TOLERANCE) {
|
||||
tool_data.add_point(LastPoint {
|
||||
id: point,
|
||||
pos: position,
|
||||
|
|
@ -535,8 +539,6 @@ impl Fsm for PenToolFsmState {
|
|||
// Generate first point
|
||||
let id = PointId::generate();
|
||||
let transform = document.metadata().transform_to_document(parent);
|
||||
let point = SnapCandidatePoint::handle(document.metadata.document_to_viewport.inverse().transform_point2(input.mouse.position));
|
||||
let snapped = tool_data.snap_manager.free_snap(&SnapData::new(document, input), &point, None, false);
|
||||
let pos = transform.inverse().transform_point2(snapped.snapped_point_document);
|
||||
let modification_type = VectorModificationType::InsertPoint { id, position: pos };
|
||||
responses.add(GraphOperationMessage::Vector { layer, modification_type });
|
||||
|
|
|
|||
Loading…
Reference in New Issue