-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pen/Freehand/Splines tool set its origin to the first drawn point #3795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,7 @@ impl<'a> ModifyInputsContext<'a> { | |
| } | ||
|
|
||
| pub fn insert_vector(&mut self, subpaths: Vec<Subpath<PointId>>, layer: LayerNodeIdentifier, include_transform: bool, include_fill: bool, include_stroke: bool) { | ||
| let first_anchor = subpaths.first().and_then(|subpath| subpath.manipulator_groups().first().map(|group| group.anchor)); | ||
| let vector = Table::new_from_element(Vector::from_subpaths(subpaths, true)); | ||
|
|
||
| let shape = resolve_network_node_type("Path") | ||
|
|
@@ -164,7 +165,13 @@ impl<'a> ModifyInputsContext<'a> { | |
| self.network_interface.move_node_to_chain_start(&shape_id, layer, &[]); | ||
|
|
||
| if include_transform { | ||
| let transform = resolve_network_node_type("Transform").expect("Transform node does not exist").default_node_template(); | ||
| let mut transform = resolve_network_node_type("Transform").expect("Transform node does not exist").default_node_template(); | ||
| if let Some(anchor) = first_anchor { | ||
| const TRANSLATION_INDEX: usize = 1; | ||
| if let Some(translation) = transform.document_node.inputs.get_mut(TRANSLATION_INDEX) { | ||
| *translation = NodeInput::value(TaggedValue::DVec2(anchor), false); | ||
| } | ||
|
Comment on lines
168
to
173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| let transform_id = NodeId::new(); | ||
| self.network_interface.insert_node(transform_id, transform, &[]); | ||
| self.network_interface.move_node_to_chain_start(&transform_id, layer, &[]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,15 @@ pub fn new_svg_layer(svg: String, transform: glam::DAffine2, id: NodeId, parent: | |
| } | ||
|
|
||
| pub fn new_custom(id: NodeId, nodes: Vec<(NodeId, NodeTemplate)>, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier { | ||
| let transform_node_id = NodeId::new(); | ||
| let mut nodes = nodes; | ||
|
|
||
| // Insert a Transform node | ||
| let transform_node = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_network_node_type("Transform") | ||
| .expect("Transform node does not exist") | ||
| .default_node_template(); | ||
| nodes.push((transform_node_id, transform_node)); | ||
|
Comment on lines
+246
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new section introduces a |
||
|
|
||
| responses.add(GraphOperationMessage::NewCustomLayer { id, nodes, parent, insert_index: 0 }); | ||
| responses.add(GraphOperationMessage::SetUpstreamToChain { | ||
| layer: LayerNodeIdentifier::new_unchecked(id), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ use crate::messages::tool::common_functionality::color_selector::{ToolColorOptio | |
| use crate::messages::tool::common_functionality::graph_modification_utils; | ||
| use crate::messages::tool::common_functionality::utility_functions::should_extend; | ||
| use glam::DVec2; | ||
| use graph_craft::document::NodeId; | ||
| use graph_craft::document::{NodeId, NodeInput}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| use graphene_std::Color; | ||
| use graphene_std::vector::VectorModificationType; | ||
| use graphene_std::vector::{PointId, SegmentId}; | ||
|
|
@@ -285,9 +285,17 @@ impl Fsm for FreehandToolFsmState { | |
|
|
||
| let parent = document.new_layer_bounding_artboard(input, viewport); | ||
|
|
||
| let document_space_position = document.metadata().document_to_viewport.inverse().transform_point2(input.mouse.position); | ||
|
|
||
| let node_type = resolve_network_node_type("Path").expect("Path node does not exist"); | ||
| let node = node_type.default_node_template(); | ||
| let nodes = vec![(NodeId(0), node)]; | ||
| let mut transform_node = resolve_network_node_type("Transform").expect("Transform node does not exist").default_node_template(); | ||
| if let Some(input) = transform_node.document_node.inputs.get_mut(0) { | ||
| *input = NodeInput::node(NodeId(1), 0); | ||
| } | ||
| if let Some(translation) = transform_node.document_node.inputs.get_mut(1) { | ||
| *translation = NodeInput::value(graph_craft::document::value::TaggedValue::DVec2(document_space_position), false); | ||
| } | ||
|
Comment on lines
291
to
297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let nodes = vec![(NodeId(0), transform_node), (NodeId(1), node_type.default_node_template())]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses); | ||
| tool_options.stroke.apply_stroke(tool_data.weight, layer, responses); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ use crate::messages::tool::common_functionality::graph_modification_utils::{self | |
| use crate::messages::tool::common_functionality::shape_editor::ShapeState; | ||
| use crate::messages::tool::common_functionality::snapping::{SnapCache, SnapCandidatePoint, SnapConstraint, SnapData, SnapManager, SnapTypeConfiguration}; | ||
| use crate::messages::tool::common_functionality::utility_functions::{calculate_segment_angle, closest_point, should_extend}; | ||
| use graph_craft::document::NodeId; | ||
| use graph_craft::document::value::TaggedValue; | ||
| use graph_craft::document::{NodeId, NodeInput}; | ||
|
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| use graphene_std::Color; | ||
| use graphene_std::subpath::pathseg_points; | ||
| use graphene_std::vector::misc::{HandleId, ManipulatorPointId, dvec2_to_point}; | ||
|
|
@@ -1283,7 +1284,15 @@ impl PenToolData { | |
|
|
||
| // New path layer | ||
| let node_type = resolve_network_node_type("Path").expect("Path node does not exist"); | ||
| let nodes = vec![(NodeId(0), node_type.default_node_template())]; | ||
| let mut transform_node = resolve_network_node_type("Transform").expect("Transform node does not exist").default_node_template(); | ||
| if let Some(input) = transform_node.document_node.inputs.get_mut(0) { | ||
| *input = NodeInput::node(NodeId(1), 0); | ||
| } | ||
| const TRANSLATION_INDEX: usize = 1; | ||
| if let Some(translation) = transform_node.document_node.inputs.get_mut(TRANSLATION_INDEX) { | ||
| *translation = NodeInput::value(TaggedValue::DVec2(snapped.snapped_point_document), false); | ||
| } | ||
|
Comment on lines
1287
to
1294
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let nodes = vec![(NodeId(0), transform_node), (NodeId(1), node_type.default_node_template())]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| let parent = document.new_layer_bounding_artboard(input, viewport); | ||
| let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ use crate::messages::tool::common_functionality::shapes::{Ellipse, Line, Rectang | |
| use crate::messages::tool::common_functionality::snapping::{self, SnapCandidatePoint, SnapData, SnapTypeConfiguration}; | ||
| use crate::messages::tool::common_functionality::transformation_cage::{BoundingBoxManager, EdgeBool}; | ||
| use crate::messages::tool::common_functionality::utility_functions::{closest_point, resize_bounds, rotate_bounds, skew_bounds, transforming_transform_cage}; | ||
| use graph_craft::document::NodeId; | ||
| use graph_craft::document::value::TaggedValue; | ||
| use graph_craft::document::{NodeId, NodeInput}; | ||
|
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| use graphene_std::Color; | ||
| use graphene_std::renderer::Quad; | ||
| use graphene_std::vector::misc::{ArcType, GridType, SpiralType}; | ||
|
|
@@ -936,7 +937,17 @@ impl Fsm for ShapeToolFsmState { | |
| ShapeType::Line => Line::create_node(document, tool_data.data.drag_start), | ||
| }; | ||
|
|
||
| let nodes = vec![(NodeId(0), node)]; | ||
| let mut transform_node = crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_network_node_type("Transform") | ||
| .expect("Transform node does not exist") | ||
| .default_node_template(); | ||
| if let Some(input) = transform_node.document_node.inputs.get_mut(0) { | ||
| *input = NodeInput::node(NodeId(1), 0); | ||
| } | ||
| const TRANSLATION_INDEX: usize = 1; | ||
| if let Some(translation) = transform_node.document_node.inputs.get_mut(TRANSLATION_INDEX) { | ||
| *translation = NodeInput::value(TaggedValue::DVec2(tool_data.data.drag_start), false); | ||
| } | ||
|
Comment on lines
940
to
949
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let nodes = vec![(NodeId(0), transform_node), (NodeId(1), node)]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input, viewport), responses); | ||
|
|
||
| let defered_responses = &mut VecDeque::new(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use crate::messages::tool::common_functionality::color_selector::{ToolColorOptio | |
| use crate::messages::tool::common_functionality::graph_modification_utils::{self, find_spline, merge_layers, merge_points}; | ||
| use crate::messages::tool::common_functionality::snapping::{SnapCandidatePoint, SnapData, SnapManager, SnapTypeConfiguration, SnappedPoint}; | ||
| use crate::messages::tool::common_functionality::utility_functions::{closest_point, should_extend}; | ||
| use graph_craft::document::value::TaggedValue; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| use graph_craft::document::{NodeId, NodeInput}; | ||
| use graphene_std::Color; | ||
| use graphene_std::vector::{PointId, SegmentId, VectorModificationType}; | ||
|
|
@@ -391,8 +392,17 @@ impl Fsm for SplineToolFsmState { | |
| let path_node_type = resolve_network_node_type("Path").expect("Path node does not exist"); | ||
| let path_node = path_node_type.default_node_template(); | ||
| let spline_node_type = resolve_proto_node_type(graphene_std::vector::spline::IDENTIFIER).expect("Spline node does not exist"); | ||
| let spline_node = spline_node_type.node_template_input_override([Some(NodeInput::node(NodeId(1), 0))]); | ||
| let nodes = vec![(NodeId(1), path_node), (NodeId(0), spline_node)]; | ||
| let spline_node = spline_node_type.node_template_input_override([Some(NodeInput::node(NodeId(2), 0))]); | ||
|
|
||
| let mut transform_node = resolve_network_node_type("Transform").expect("Transform node does not exist").default_node_template(); | ||
| if let Some(input) = transform_node.document_node.inputs.get_mut(0) { | ||
| *input = NodeInput::node(NodeId(1), 0); | ||
| } | ||
| if let Some(translation) = transform_node.document_node.inputs.get_mut(1) { | ||
| *translation = NodeInput::value(TaggedValue::DVec2(snapped.snapped_point_document), false); | ||
| } | ||
|
Comment on lines
397
to
403
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| let nodes = vec![(NodeId(0), transform_node), (NodeId(1), spline_node), (NodeId(2), path_node)]; | ||
|
|
||
| let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses); | ||
| tool_options.stroke.apply_stroke(tool_data.weight, layer, responses); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line correctly captures the first anchor point from the subpaths, which is then used to set the origin offset for the transform node. This is a good approach to ensure the tool's origin is anchored to the initial drawing point.