-
-
Notifications
You must be signed in to change notification settings - Fork 988
add arrow shape feature in editor #3343
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
Open
krVatsal
wants to merge
6
commits into
GraphiteEditor:master
Choose a base branch
from
krVatsal:add-arrow-shape-feature-cleaned
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
989f4ba
add arrow shape feature in editor
krVatsal f3b1179
fix the arrow tool to show arrow in viewport space
krVatsal 7316f2e
fix the direction of arrow and make the new arrow node
krVatsal 6789df3
Merge branch 'master' into add-arrow-shape-feature-cleaned
krVatsal b21a73d
updated arrow tool to hae start and end points
krVatsal 78cc7d5
Merge branch 'add-arrow-shape-feature-cleaned' of https://github.com/…
krVatsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
editor/src/messages/tool/common_functionality/shapes/arrow_shape.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use super::shape_utility::ShapeToolModifierKey; | ||
| use super::*; | ||
| use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn; | ||
| use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type; | ||
| use crate::messages::portfolio::document::overlays::utility_types::OverlayContext; | ||
| use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier; | ||
| use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeTemplate}; | ||
| use crate::messages::prelude::*; | ||
| use crate::messages::tool::common_functionality::graph_modification_utils; | ||
| use glam::{DAffine2, DVec2}; | ||
| use graph_craft::document::NodeInput; | ||
| use graph_craft::document::value::TaggedValue; | ||
| use std::collections::VecDeque; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct Arrow; | ||
|
|
||
| impl Arrow { | ||
| pub fn create_node() -> NodeTemplate { | ||
| let node_type = resolve_document_node_type("Arrow").expect("Arrow node does not exist"); | ||
| node_type.node_template_input_override([ | ||
| None, | ||
| Some(NodeInput::value(TaggedValue::F64(100.), false)), // length | ||
| Some(NodeInput::value(TaggedValue::F64(10.), false)), // shaft_width | ||
| Some(NodeInput::value(TaggedValue::F64(30.), false)), // head_width | ||
| Some(NodeInput::value(TaggedValue::F64(20.), false)), // head_length | ||
| ]) | ||
| } | ||
|
|
||
| pub fn update_shape( | ||
| document: &DocumentMessageHandler, | ||
| input: &InputPreprocessorMessageHandler, | ||
| layer: LayerNodeIdentifier, | ||
| tool_data: &mut ShapeToolData, | ||
| modifier: ShapeToolModifierKey, | ||
| responses: &mut VecDeque<Message>, | ||
| ) { | ||
| let [center, lock_ratio, _] = modifier; | ||
|
|
||
| let Some([start, end]) = tool_data.data.calculate_points(document, input, center, lock_ratio) else { | ||
| return; | ||
| }; | ||
|
|
||
| let delta = end - start; | ||
| let length = delta.length(); | ||
| if length < 1e-6 { | ||
| return; | ||
| } | ||
|
|
||
| let Some(node_id) = graph_modification_utils::get_arrow_id(layer, &document.network_interface) else { | ||
| return; | ||
| }; | ||
|
|
||
| // Calculate proportional dimensions | ||
| let shaft_width = length * 0.1; | ||
| let head_width = length * 0.3; | ||
| let head_length = length * 0.2; | ||
|
|
||
| // Update Arrow node parameters | ||
| responses.add(NodeGraphMessage::SetInput { | ||
| input_connector: InputConnector::node(node_id, 1), | ||
| input: NodeInput::value(TaggedValue::F64(length), false), | ||
| }); | ||
| responses.add(NodeGraphMessage::SetInput { | ||
| input_connector: InputConnector::node(node_id, 2), | ||
| input: NodeInput::value(TaggedValue::F64(shaft_width), false), | ||
| }); | ||
| responses.add(NodeGraphMessage::SetInput { | ||
| input_connector: InputConnector::node(node_id, 3), | ||
| input: NodeInput::value(TaggedValue::F64(head_width), false), | ||
| }); | ||
| responses.add(NodeGraphMessage::SetInput { | ||
| input_connector: InputConnector::node(node_id, 4), | ||
| input: NodeInput::value(TaggedValue::F64(head_length), false), | ||
| }); | ||
|
|
||
| // Set transform to position and rotate the arrow | ||
| let angle = delta.y.atan2(delta.x); | ||
| responses.add(GraphOperationMessage::TransformSet { | ||
| layer, | ||
| transform: DAffine2::from_scale_angle_translation(DVec2::ONE, angle, start), | ||
| transform_in: TransformIn::Viewport, | ||
| skip_rerender: false, | ||
| }); | ||
| } | ||
|
|
||
| pub fn overlays(_document: &DocumentMessageHandler, _tool_data: &ShapeToolData, _overlay_context: &mut OverlayContext) {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,16 +188,27 @@ fn star<T: AsU64>( | |
|
|
||
| /// Generates a line with endpoints at the two chosen coordinates. | ||
| #[node_macro::node(category("Vector: Shape"))] | ||
| fn line( | ||
| fn arrow( | ||
| _: impl Ctx, | ||
| _primary: (), | ||
| /// Coordinate of the line's initial endpoint. | ||
| #[default(0., 0.)] | ||
| start: PixelSize, | ||
| /// Coordinate of the line's terminal endpoint. | ||
| #[default(100., 100.)] | ||
| end: PixelSize, | ||
| #[unit(" px")] | ||
| #[default(100)] | ||
| length: f64, | ||
| #[unit(" px")] | ||
| #[default(10)] | ||
| shaft_width: f64, | ||
| #[unit(" px")] | ||
| #[default(30)] | ||
| head_width: f64, | ||
| #[unit(" px")] | ||
| #[default(20)] | ||
| head_length: f64, | ||
|
||
| ) -> Table<Vector> { | ||
| Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_arrow(length, shaft_width, head_width, head_length))) | ||
| } | ||
|
|
||
| #[node_macro::node(category("Vector: Shape"))] | ||
| fn line(_: impl Ctx, _primary: (), #[default(0., 0.)] start: PixelSize, #[default(100., 100.)] end: PixelSize) -> Table<Vector> { | ||
| Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_line(start, end))) | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why remove theses from the line node?