-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Artboard Grab/Scale #4053
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
atchamwa
wants to merge
7
commits into
GraphiteEditor:master
Choose a base branch
from
atchamwa:artboard-gsr
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.
+187
−9
Open
Add Artboard Grab/Scale #4053
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f00df2f
Artboard now supports G/S transformation
Eugenehwng a3576df
Clarification Changes
atchamwa 5f0c228
should fix the errors given in the PR
oliverhgraham 951b888
Gemini Fix Clarification Comments
atchamwa 37e3180
Added Testing For Artboard G/S
atchamwa 07eada0
Merge branch 'master' into artboard-gsr
atchamwa a405294
Merge branch 'master' into artboard-gsr
oliverhgraham 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
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 |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ use crate::messages::tool::common_functionality::shape_editor::ShapeState; | |
| use crate::messages::tool::tool_messages::select_tool; | ||
| use crate::messages::tool::tool_messages::tool_prelude::Key; | ||
| use crate::messages::tool::utility_types::{ToolData, ToolType}; | ||
| use glam::{DAffine2, DVec2}; | ||
| use glam::{DAffine2, DVec2, IVec2}; | ||
| use graphene_std::renderer::Quad; | ||
| use graphene_std::vector::click_target::ClickTargetType; | ||
| use graphene_std::vector::misc::ManipulatorPointId; | ||
|
|
@@ -94,6 +94,8 @@ pub struct TransformLayerMessageHandler { | |
|
|
||
| // Path tool (ghost outlines showing pre-transform geometry) | ||
| ghost_outline: Vec<(Vec<ClickTargetType>, DAffine2)>, | ||
|
|
||
| original_artboard_bounds: HashMap<LayerNodeIdentifier, [DVec2; 2]>, | ||
|
Contributor
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. I think this should probably be stored inside |
||
| } | ||
|
|
||
| #[message_handler_data] | ||
|
|
@@ -111,15 +113,21 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| let using_select_tool = tool_data.active_tool_type == ToolType::Select; | ||
| let using_pen_tool = tool_data.active_tool_type == ToolType::Pen; | ||
| let using_shape_tool = tool_data.active_tool_type == ToolType::Shape; | ||
| let using_artboard_tool = tool_data.active_tool_type == ToolType::Artboard; | ||
|
|
||
| // TODO: Add support for transforming layer not in the document network | ||
| let selected_layers = document | ||
| let mut selected_layers = document | ||
| .network_interface | ||
| .selected_nodes() | ||
| .selected_layers(document.metadata()) | ||
| .filter(|&layer| document.network_interface.is_visible(&layer.to_node(), &[]) && !document.network_interface.is_locked(&layer.to_node(), &[])) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| // Ensure only artboard layers are transformed when using the Artboard tool | ||
| if using_artboard_tool { | ||
| selected_layers.retain(|layer| document.network_interface.is_artboard(&layer.to_node(), &[])); | ||
| } | ||
|
|
||
| let mut selected = Selected::new( | ||
| &mut self.original_transforms, | ||
| &mut self.pivot, | ||
|
|
@@ -312,6 +320,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| if final_transform { | ||
| self.transform_operation = TransformOperation::None; | ||
| self.operation_count = 0; | ||
| self.original_artboard_bounds.clear(); | ||
| } | ||
|
|
||
| if using_pen_tool { | ||
|
|
@@ -390,13 +399,32 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| }); | ||
| } | ||
| TransformLayerMessage::BeginGRS { operation: transform_type } => { | ||
| // Artboards don't support rotation yet | ||
| if using_artboard_tool && transform_type == TransformType::Rotate { | ||
| return; | ||
| } | ||
| if using_artboard_tool && selected_layers.is_empty() { | ||
| return; | ||
| } | ||
| // Prepare artboard bounds | ||
| if using_artboard_tool { | ||
| self.original_artboard_bounds.clear(); | ||
| for &layer in &selected_layers { | ||
| if !document.network_interface.is_artboard(&layer.to_node(), &[]) { | ||
| continue; | ||
| } | ||
| if let Some(bounds) = document.metadata().bounding_box_document(layer) { | ||
| self.original_artboard_bounds.insert(layer, bounds); | ||
| } | ||
| } | ||
| } | ||
|
atchamwa marked this conversation as resolved.
|
||
| let selected_points: Vec<&ManipulatorPointId> = shape_editor.selected_points().collect(); | ||
| let selected_segments = shape_editor.selected_segments().collect::<Vec<_>>(); | ||
|
|
||
| if using_path_tool { | ||
| Self::set_ghost_outline(&mut self.ghost_outline, shape_editor, document); | ||
| if (selected_points.is_empty() && selected_segments.is_empty()) | ||
| || (!using_path_tool && !using_select_tool && !using_pen_tool && !using_shape_tool) | ||
| || (!using_path_tool && !using_select_tool && !using_pen_tool && !using_shape_tool && !using_artboard_tool) | ||
| || selected_layers.is_empty() | ||
| || (transform_type.equivalent_to(self.transform_operation) && !self.was_grabbing) | ||
| { | ||
|
|
@@ -497,6 +525,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| responses.add(ToolMessage::UpdateHints); | ||
| } else { | ||
| selected.original_transforms.clear(); | ||
| self.original_artboard_bounds.clear(); | ||
| self.typing.clear(); | ||
| self.transform_operation = TransformOperation::None; | ||
|
|
||
|
|
@@ -580,6 +609,30 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| }; | ||
| } | ||
|
|
||
| if using_artboard_tool && !self.original_artboard_bounds.is_empty() && self.transform_operation != TransformOperation::None { | ||
| // Compute the full transform | ||
| let inner = match self.transform_operation { | ||
| TransformOperation::Grabbing(translation) => DAffine2::from_translation(translation.to_dvec(&self.state, document)), | ||
| TransformOperation::Scaling(scale) => DAffine2::from_scale(scale.to_dvec(self.state.is_rounded_to_intervals)), | ||
| _ => DAffine2::IDENTITY, | ||
| }; | ||
| let normalized_transform = self.state.local_to_viewport_transform(); | ||
| let local_viewport_transform = normalized_transform * inner * normalized_transform.inverse(); | ||
| let pivot_translation = DAffine2::from_translation(self.state.pivot_viewport(document)); | ||
| let viewport_transform = pivot_translation * local_viewport_transform * pivot_translation.inverse(); | ||
| let document_to_viewport = document.metadata().document_to_viewport; | ||
| let document_transform = document_to_viewport.inverse() * viewport_transform * document_to_viewport; | ||
|
|
||
| // Resize artboards based on transformed bounds | ||
| for (&layer, &original_bounds) in &self.original_artboard_bounds { | ||
| let new_top_left = document_transform.transform_point2(original_bounds[0]); | ||
| let new_bottom_right = document_transform.transform_point2(original_bounds[1]); | ||
| let location = new_top_left.min(new_bottom_right).round().as_ivec2(); | ||
| let dimensions = (new_bottom_right - new_top_left).abs().round().as_ivec2().max(IVec2::ONE); | ||
| responses.add(GraphOperationMessage::ResizeArtboard { layer, location, dimensions }); | ||
| } | ||
| } | ||
|
|
||
| self.mouse_position = input.mouse.position; | ||
| } | ||
| TransformLayerMessage::SelectionChanged => { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.