mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 17:08:11 +08:00
Fix Pen and Freehand tool path extension (#1809)
Improve path tool extend
This commit is contained in:
@@ -5,7 +5,7 @@ use graphene_std::vector::PointId;
|
|||||||
|
|
||||||
use glam::DVec2;
|
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)> {
|
pub fn should_extend(document: &DocumentMessageHandler, goal: DVec2, tolerance: f64) -> Option<(LayerNodeIdentifier, PointId, DVec2)> {
|
||||||
let mut best = None;
|
let mut best = None;
|
||||||
let mut best_distance_squared = tolerance * tolerance;
|
let mut best_distance_squared = tolerance * tolerance;
|
||||||
|
|||||||
@@ -175,7 +175,6 @@ impl ToolTransition for FreehandTool {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct FreehandToolData {
|
struct FreehandToolData {
|
||||||
extend_from_start: bool,
|
|
||||||
end_point: Option<(DVec2, PointId)>,
|
end_point: Option<(DVec2, PointId)>,
|
||||||
dragged: bool,
|
dragged: bool,
|
||||||
weight: f64,
|
weight: f64,
|
||||||
@@ -208,12 +207,13 @@ impl Fsm for FreehandToolFsmState {
|
|||||||
responses.add(DocumentMessage::StartTransaction);
|
responses.add(DocumentMessage::StartTransaction);
|
||||||
|
|
||||||
tool_data.dragged = false;
|
tool_data.dragged = false;
|
||||||
tool_data.extend_from_start = false;
|
tool_data.end_point = None;
|
||||||
tool_data.weight = tool_options.line_weight;
|
tool_data.weight = tool_options.line_weight;
|
||||||
|
|
||||||
// Extend an endpoint of the selected path
|
// 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.layer = Some(layer);
|
||||||
|
tool_data.end_point = Some((position, point));
|
||||||
|
|
||||||
extend_path_with_next_segment(tool_data, position, responses);
|
extend_path_with_next_segment(tool_data, position, responses);
|
||||||
|
|
||||||
@@ -260,6 +260,7 @@ impl Fsm for FreehandToolFsmState {
|
|||||||
responses.add(DocumentMessage::DocumentHistoryBackward);
|
responses.add(DocumentMessage::DocumentHistoryBackward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tool_data.end_point = None;
|
||||||
tool_data.layer = None;
|
tool_data.layer = None;
|
||||||
|
|
||||||
FreehandToolFsmState::Ready
|
FreehandToolFsmState::Ready
|
||||||
@@ -267,6 +268,7 @@ impl Fsm for FreehandToolFsmState {
|
|||||||
(FreehandToolFsmState::Drawing, FreehandToolMessage::Abort) => {
|
(FreehandToolFsmState::Drawing, FreehandToolMessage::Abort) => {
|
||||||
responses.add(DocumentMessage::AbortTransaction);
|
responses.add(DocumentMessage::AbortTransaction);
|
||||||
tool_data.layer = None;
|
tool_data.layer = None;
|
||||||
|
tool_data.end_point = None;
|
||||||
|
|
||||||
FreehandToolFsmState::Ready
|
FreehandToolFsmState::Ready
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -508,8 +508,12 @@ impl Fsm for PenToolFsmState {
|
|||||||
(PenToolFsmState::Ready, PenToolMessage::DragStart) => {
|
(PenToolFsmState::Ready, PenToolMessage::DragStart) => {
|
||||||
responses.add(DocumentMessage::StartTransaction);
|
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
|
// 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 {
|
tool_data.add_point(LastPoint {
|
||||||
id: point,
|
id: point,
|
||||||
pos: position,
|
pos: position,
|
||||||
@@ -535,8 +539,6 @@ impl Fsm for PenToolFsmState {
|
|||||||
// Generate first point
|
// Generate first point
|
||||||
let id = PointId::generate();
|
let id = PointId::generate();
|
||||||
let transform = document.metadata().transform_to_document(parent);
|
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 pos = transform.inverse().transform_point2(snapped.snapped_point_document);
|
||||||
let modification_type = VectorModificationType::InsertPoint { id, position: pos };
|
let modification_type = VectorModificationType::InsertPoint { id, position: pos };
|
||||||
responses.add(GraphOperationMessage::Vector { layer, modification_type });
|
responses.add(GraphOperationMessage::Vector { layer, modification_type });
|
||||||
|
|||||||
Reference in New Issue
Block a user