-
-
Notifications
You must be signed in to change notification settings - Fork 986
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.
+180
−15
Open
Changes from 1 commit
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
102 changes: 102 additions & 0 deletions
102
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,102 @@ | ||
| use super::shape_utility::ShapeToolModifierKey; | ||
| use super::*; | ||
| 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::NodeTemplate; | ||
| use crate::messages::prelude::*; | ||
| use glam::DVec2; | ||
| use graphene_std::vector::{PointId, SegmentId, VectorModificationType}; | ||
| use std::collections::VecDeque; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct Arrow; | ||
|
|
||
| impl Arrow { | ||
| pub fn create_node() -> NodeTemplate { | ||
| let node_type = resolve_document_node_type("Path").expect("Path node does not exist"); | ||
| node_type.default_node_template() | ||
| } | ||
|
|
||
| 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; | ||
|
|
||
| // Work in viewport space like Line does | ||
| let start_viewport = tool_data.data.viewport_drag_start(document); | ||
| let end_viewport = input.mouse.position; | ||
|
|
||
| let delta = end_viewport - start_viewport; | ||
| let length = delta.length(); | ||
| if length < 1e-6 { | ||
| return; | ||
| } | ||
|
|
||
| let direction = delta.normalize(); | ||
| let perpendicular = DVec2::new(-direction.y, direction.x); | ||
|
|
||
| let shaft_thickness = length * 0.05; | ||
| let head_width = length * 0.15; | ||
| let head_length = length * 0.2; | ||
|
|
||
| // Build arrow in viewport space | ||
| let viewport_anchors = vec![ | ||
| start_viewport, | ||
| start_viewport + direction * head_length - perpendicular * (head_width * 0.5), | ||
| start_viewport + direction * head_length - perpendicular * (shaft_thickness * 0.5), | ||
| end_viewport - perpendicular * (shaft_thickness * 0.5), | ||
| end_viewport + perpendicular * (shaft_thickness * 0.5), | ||
| start_viewport + direction * head_length + perpendicular * (shaft_thickness * 0.5), | ||
| start_viewport + direction * head_length + perpendicular * (head_width * 0.5), | ||
| ]; | ||
|
|
||
| let vector = document.network_interface.compute_modified_vector(layer); | ||
| let existing_point_ids: Vec<PointId> = vector.as_ref().map(|v| v.point_domain.ids().to_vec()).unwrap_or_default(); | ||
| let existing_segment_ids: Vec<SegmentId> = vector.as_ref().map(|v| v.segment_domain.ids().to_vec()).unwrap_or_default(); | ||
|
|
||
| for point_id in existing_point_ids { | ||
| responses.add(GraphOperationMessage::Vector { | ||
| layer, | ||
| modification_type: VectorModificationType::RemovePoint { id: point_id }, | ||
| }); | ||
| } | ||
|
|
||
| for segment_id in existing_segment_ids { | ||
| responses.add(GraphOperationMessage::Vector { | ||
| layer, | ||
| modification_type: VectorModificationType::RemoveSegment { id: segment_id }, | ||
| }); | ||
| } | ||
|
|
||
| let point_ids: Vec<PointId> = viewport_anchors | ||
| .iter() | ||
| .map(|&pos| { | ||
| let id = PointId::generate(); | ||
| responses.add(GraphOperationMessage::Vector { | ||
| layer, | ||
| modification_type: VectorModificationType::InsertPoint { id, position: pos }, | ||
| }); | ||
| id | ||
| }) | ||
| .collect(); | ||
|
|
||
| for i in 0..point_ids.len() { | ||
| let id = SegmentId::generate(); | ||
| let points = [point_ids[i], point_ids[(i + 1) % point_ids.len()]]; | ||
| responses.add(GraphOperationMessage::Vector { | ||
| layer, | ||
| modification_type: VectorModificationType::InsertSegment { id, points, handles: [None, None] }, | ||
| }); | ||
| } | ||
|
|
||
| responses.add(NodeGraphMessage::RunDocumentGraph); | ||
| } | ||
|
|
||
| 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
Oops, something went wrong.
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.
Note that this inserts the point in layer space. You said above that you
Build arrow in viewport space.To convert between the viewport and the layer space, you can do something like:
Alternatively you can set the transform on the layer itself:
Note that the line tool is broken and produces offset lines when inside a transformed parent layer. I would recommend that you avoid implementing this bug into you new tool.
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.
Thanks for the help, i have modified it accordingly.