Skip to content
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

Add transform cage to textbox while using Text tool #2176

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
54a1807
Fix abortion while dragging
Nitish-bot Jan 2, 2025
984dee1
Create function for text bounding box
Nitish-bot Jan 2, 2025
41ee2f5
Reorder arms of text tool FSM
Nitish-bot Jan 2, 2025
0aaa0ae
add transform cage to textbox pt.1
Nitish-bot Jan 3, 2025
9867941
add transform cage pt.2
Nitish-bot Jan 8, 2025
5a77366
Merge branch 'master' of https://github.com/GraphiteEditor/Graphite i…
Nitish-bot Jan 8, 2025
c2cac57
Fix minor issue after merge
Nitish-bot Jan 8, 2025
a75f2b9
Merge branch 'master' into follow-up
Nitish-bot Jan 16, 2025
a137b9c
Get bounding box working in place without action keys
Nitish-bot Jan 24, 2025
0790608
Add max_height and disable pivot drag
Nitish-bot Jan 26, 2025
93fe1a8
Cleanup code and write doco for new utility function
Nitish-bot Jan 26, 2025
59d5de3
Merge branch 'master' into follow-up
Nitish-bot Jan 26, 2025
1c8d060
Minor change due to merge
Nitish-bot Jan 26, 2025
84f2b19
Add bottom overlay
Nitish-bot Jan 27, 2025
72d3f9e
Merge branch 'master' of https://github.com/GraphiteEditor/Graphite i…
Nitish-bot Jan 27, 2025
43012e5
Merge branch 'master' into follow-up
Keavon Jan 29, 2025
94c7209
Get modifier keys to work pt.1
Nitish-bot Feb 3, 2025
9fc28ff
Merge branch 'master' of https://github.com/GraphiteEditor/Graphite i…
Nitish-bot Feb 3, 2025
b99707a
Merge branch 'follow-up' of github.com:Nitish-bot/Graphite into follo…
Nitish-bot Feb 3, 2025
a27807b
Merge branch 'master' into follow-up
Keavon Feb 6, 2025
ead74f4
Code cleanup
Keavon Feb 6, 2025
7b1f4de
cleanup
Nitish-bot Feb 7, 2025
62a5ee2
Merge branch 'follow-up' of github.com:Nitish-bot/Graphite into follo…
Nitish-bot Feb 7, 2025
9fdfaff
Fix transform
0HyperCube Feb 7, 2025
2f20d05
Minor improvements
Nitish-bot Feb 9, 2025
42b577d
Undo debug statement!
Nitish-bot Feb 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ pub fn input_mappings() -> Mapping {
entry!(PointerMove; refresh_keys=[Alt, Shift], action_dispatch=TextToolMessage::PointerMove { center: Alt, lock_ratio: Shift }),
entry!(KeyDown(MouseLeft); action_dispatch=TextToolMessage::DragStart),
entry!(KeyUp(MouseLeft); action_dispatch=TextToolMessage::DragStop),
entry!(KeyDown(MouseRight); action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(MouseRight); action_dispatch=TextToolMessage::Abort),
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::Abort),
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::Abort),
//
// GradientToolMessage
entry!(KeyDown(MouseLeft); action_dispatch=GradientToolMessage::PointerDown),
Expand Down
Keavon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,6 @@ impl NodeNetworkInterface {
log::error!("Cannot connect a network to an export, see https://github.com/GraphiteEditor/Graphite/issues/1762");
return;
}

let Some(previous_input) = self.input_from_connector(input_connector, network_path).cloned() else {
log::error!("Could not get previous input in set_input");
return;
Expand Down
10 changes: 10 additions & 0 deletions editor/src/messages/tool/common_functionality/pivot.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a function that updates pivot for any input value for the normalized pivot instead of calculating it from transform. pretty similar code to the recalculate_pivot function above, implementing the transformation cage for the text tool felt awkward, I feel like I could refactor a lot of code here and there. Some direction would help in that.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ impl Pivot {
}
}

pub fn update_box_pivot(&mut self, normalized_pivot: DVec2, layer_transform: DAffine2, bounds_transform: DAffine2, overlay_context: &mut OverlayContext) {
self.normalized_pivot = normalized_pivot;
self.transform_from_normalized = layer_transform * bounds_transform;

self.pivot = Some(self.transform_from_normalized.transform_point2(normalized_pivot));
if let Some(pivot) = self.pivot {
overlay_context.pivot(pivot);
}
}

pub fn update_pivot(&mut self, document: &DocumentMessageHandler, overlay_context: &mut OverlayContext) {
self.recalculate_pivot(document);
if let Some(pivot) = self.pivot {
Expand Down
13 changes: 13 additions & 0 deletions editor/src/messages/tool/common_functionality/utility_functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::prelude::*;
use crate::messages::tool::common_functionality::graph_modification_utils::get_text;

use graphene_core::renderer::Quad;
use graphene_core::text::{load_face, FontCache};
use graphene_std::vector::PointId;

use glam::DVec2;
Expand Down Expand Up @@ -53,3 +56,13 @@ where

best
}

/// Calculates the bounding box of the layer's text, based on the settings for max width and height specified in the typesetting config.
pub fn text_bounding_box(layer: LayerNodeIdentifier, document: &DocumentMessageHandler, font_cache: &FontCache) -> Quad {
let (text, font, typesetting) = get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool");

let buzz_face = font_cache.get(font).map(|data| load_face(data));
let far = graphene_core::text::bounding_box(text, buzz_face.as_ref(), typesetting);

Quad::from_box([DVec2::ZERO, far])
}
14 changes: 4 additions & 10 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use crate::messages::portfolio::document::utility_types::network_interface::{Flo
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
use crate::messages::portfolio::document::utility_types::transformation::Selected;
use crate::messages::preferences::SelectionMode;
use crate::messages::tool::common_functionality::graph_modification_utils::{get_text, is_layer_fed_by_node_of_name};
use crate::messages::tool::common_functionality::graph_modification_utils::is_layer_fed_by_node_of_name;
use crate::messages::tool::common_functionality::pivot::Pivot;
use crate::messages::tool::common_functionality::shape_editor::SelectionShapeType;
use crate::messages::tool::common_functionality::snapping::{self, SnapCandidatePoint, SnapData, SnapManager};
use crate::messages::tool::common_functionality::transformation_cage::*;
use crate::messages::tool::common_functionality::utility_functions::text_bounding_box;
use crate::messages::tool::common_functionality::{auto_panning::AutoPanning, measure};

use bezier_rs::Subpath;
use graph_craft::document::NodeId;
use graphene_core::renderer::Quad;
use graphene_core::text::load_face;
use graphene_std::renderer::Rect;
use graphene_std::vector::misc::BooleanOperation;

Expand Down Expand Up @@ -494,14 +494,8 @@ impl Fsm for SelectToolFsmState {
overlay_context.outline(document.metadata().layer_outline(layer), document.metadata().transform_to_viewport(layer));

if is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text") {
let (text, font, typesetting) = get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool in `interact()`");

let buzz_face = font_cache.get(font).map(|data| load_face(data));
let far = graphene_core::text::bounding_box(text, buzz_face, typesetting);
let quad = Quad::from_box([DVec2::ZERO, far]);
let transformed_quad = document.metadata().transform_to_viewport(layer) * quad;

overlay_context.dashed_quad(transformed_quad, None, Some(4.), Some(4.), Some(0.5));
let transformed_quad = document.metadata().transform_to_viewport(layer) * text_bounding_box(layer, document, font_cache);
overlay_context.dashed_quad(transformed_quad, None, Some(7.), Some(5.), None);
}
}

Expand Down
Loading
Loading