Skip to content

Commit d9a89ab

Browse files
committed
Formatting
1 parent 738f815 commit d9a89ab

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

editor/src/messages/portfolio/document/utility_types/transformation.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::messages::portfolio::document::graph_operation::utility_types::{Modif
55
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
66
use crate::messages::prelude::*;
77
use crate::messages::tool::common_functionality::shape_editor::ShapeState;
8-
use crate::messages::tool::transform_layer::transform_layer_message_handler::OtherUsefulParameters;
8+
use crate::messages::tool::transform_layer::transform_layer_message_handler::TransformationState;
99
use crate::messages::tool::utility_types::ToolType;
1010
use glam::{DAffine2, DMat2, DVec2};
1111
use graphene_std::renderer::Quad;
@@ -156,7 +156,7 @@ pub struct Translation {
156156
}
157157

158158
impl Translation {
159-
pub fn to_dvec(self, state: &OtherUsefulParameters) -> DVec2 {
159+
pub fn to_dvec(self, state: &TransformationState) -> DVec2 {
160160
let displacement = if let Some(value) = self.typed_distance {
161161
match self.constraint {
162162
Axis::X => DVec2::X * value,
@@ -326,7 +326,7 @@ impl TransformType {
326326

327327
impl TransformOperation {
328328
#[allow(clippy::too_many_arguments)]
329-
pub fn apply_transform_operation(&self, selected: &mut Selected, state: &OtherUsefulParameters, document: &DocumentMessageHandler) {
329+
pub fn apply_transform_operation(&self, selected: &mut Selected, state: &TransformationState, document: &DocumentMessageHandler) {
330330
if self != &TransformOperation::None {
331331
let mut transformation = match self {
332332
TransformOperation::Grabbing(translation) => DAffine2::from_translation(translation.to_dvec(state)),
@@ -355,7 +355,7 @@ impl TransformOperation {
355355
}
356356

357357
#[allow(clippy::too_many_arguments)]
358-
pub fn constrain_axis(&mut self, axis: Axis, selected: &mut Selected, state: &OtherUsefulParameters, document: &DocumentMessageHandler) -> bool {
358+
pub fn constrain_axis(&mut self, axis: Axis, selected: &mut Selected, state: &TransformationState, document: &DocumentMessageHandler) -> bool {
359359
let resulting_local;
360360
(*self, resulting_local) = match self {
361361
TransformOperation::Grabbing(translation) => {
@@ -368,12 +368,14 @@ impl TransformOperation {
368368
}
369369
_ => (*self, false),
370370
};
371+
371372
self.apply_transform_operation(selected, state, document);
373+
372374
resulting_local
373375
}
374376

375377
#[allow(clippy::too_many_arguments)]
376-
pub fn grs_typed(&mut self, typed: Option<f64>, selected: &mut Selected, state: &OtherUsefulParameters, document: &DocumentMessageHandler) {
378+
pub fn grs_typed(&mut self, typed: Option<f64>, selected: &mut Selected, state: &TransformationState, document: &DocumentMessageHandler) {
377379
match self {
378380
TransformOperation::None => (),
379381
TransformOperation::Grabbing(translation) => translation.typed_distance = typed,
@@ -464,14 +466,15 @@ impl TransformOperation {
464466
}
465467

466468
#[allow(clippy::too_many_arguments)]
467-
pub fn negate(&mut self, selected: &mut Selected, state: &OtherUsefulParameters, document: &DocumentMessageHandler) {
469+
pub fn negate(&mut self, selected: &mut Selected, state: &TransformationState, document: &DocumentMessageHandler) {
468470
if *self != TransformOperation::None {
469471
*self = match self {
470472
TransformOperation::Scaling(scale) => TransformOperation::Scaling(scale.negate()),
471473
TransformOperation::Rotating(rotation) => TransformOperation::Rotating(rotation.negate()),
472474
TransformOperation::Grabbing(translation) => TransformOperation::Grabbing(translation.negate()),
473475
_ => *self,
474476
};
477+
475478
self.apply_transform_operation(selected, state, document);
476479
}
477480
}

editor/src/messages/tool/tool_messages/select_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl Fsm for SelectToolFsmState {
646646
}
647647
}
648648

649-
let mut transform = create_bounding_box_transform(&document);
649+
let mut transform = create_bounding_box_transform(document);
650650

651651
// Check if the matrix is not invertible
652652
let mut transform_tampered = false;

editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::messages::portfolio::document::utility_types::transformation::{Axis,
77
use crate::messages::prelude::*;
88
use crate::messages::tool::common_functionality::pivot::{PivotGizmo, PivotGizmoType};
99
use crate::messages::tool::common_functionality::shape_editor::ShapeState;
10+
use crate::messages::tool::tool_messages::select_tool;
1011
use crate::messages::tool::tool_messages::tool_prelude::Key;
1112
use crate::messages::tool::utility_types::{ToolData, ToolType};
1213
use glam::{DAffine2, DVec2};
@@ -32,71 +33,66 @@ pub struct TransformLayerMessageContext<'a> {
3233
}
3334

3435
#[derive(Debug, Clone, Default, ExtractField)]
35-
pub struct OtherUsefulParameters {
36+
pub struct TransformationState {
3637
pub is_rounded_to_intervals: bool,
3738
pub is_transforming_in_local_space: bool,
3839
pub local_transform_axes: [DVec2; 2],
39-
4040
pub document_space_pivot: DocumentPosition,
4141
}
4242

43-
impl OtherUsefulParameters {
43+
impl TransformationState {
4444
pub fn pivot_viewport(&self, document: &DocumentMessageHandler) -> DVec2 {
4545
document.metadata().document_to_viewport.transform_point2(self.document_space_pivot)
4646
}
47+
4748
pub fn constraint_axis(&self, axis_constraint: Axis) -> Option<DVec2> {
4849
match axis_constraint {
4950
Axis::X => Some(if self.is_transforming_in_local_space { self.local_transform_axes[0] } else { DVec2::X }),
5051
Axis::Y => Some(if self.is_transforming_in_local_space { self.local_transform_axes[1] } else { DVec2::Y }),
5152
_ => None,
5253
}
5354
}
55+
5456
pub fn project_onto_constrained(&self, vector: DVec2, axis_constraint: Axis) -> DVec2 {
5557
self.constraint_axis(axis_constraint).map_or(vector, |direction| vector.project_onto_normalized(direction))
5658
}
59+
5760
pub fn local_to_viewport_transform(&self) -> DAffine2 {
58-
self.is_transforming_in_local_space
59-
.then(|| DAffine2::from_cols(self.local_transform_axes[0], self.local_transform_axes[1], DVec2::ZERO))
60-
.unwrap_or_default()
61+
if self.is_transforming_in_local_space {
62+
DAffine2::from_cols(self.local_transform_axes[0], self.local_transform_axes[1], DVec2::ZERO)
63+
} else {
64+
DAffine2::IDENTITY
65+
}
6166
}
6267
}
6368

6469
#[derive(Debug, Clone, Default, ExtractField)]
6570
pub struct TransformLayerMessageHandler {
6671
pub transform_operation: TransformOperation,
67-
72+
state: TransformationState,
6873
slow: bool,
6974
layer_bounding_box: Quad,
7075
typing: Typing,
71-
7276
mouse_position: ViewportPosition,
7377
start_mouse: ViewportPosition,
74-
7578
original_transforms: OriginalTransforms,
7679
pivot_gizmo: PivotGizmo,
7780
pivot: ViewportPosition,
78-
7981
path_bounds: Option<[DVec2; 2]>,
80-
8182
local_mouse_start: DocumentPosition,
8283
grab_target: DocumentPosition,
83-
8484
ptz: PTZ,
8585
initial_transform: DAffine2,
86-
8786
operation_count: usize,
87+
was_grabbing: bool,
8888

8989
// Pen tool (outgoing handle GRS manipulation)
9090
handle: DVec2,
9191
last_point: DVec2,
9292
grs_pen_handle: bool,
9393

94-
// Ghost outlines for Path Tool
94+
// Path tool (ghost outlines showing pre-transform geometry)
9595
ghost_outline: Vec<(Vec<ClickTargetType>, DAffine2)>,
96-
97-
state: OtherUsefulParameters,
98-
99-
was_grabbing: bool,
10096
}
10197

10298
#[message_handler_data]
@@ -275,7 +271,8 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for
275271
} else if using_path_tool {
276272
start_mouse - self.state.pivot_viewport(document)
277273
} else {
278-
self.layer_bounding_box.top_right() - self.layer_bounding_box.top_right() // TODO: This is always zero breaking the to_angle below????????
274+
// TODO: This is always zero breaking the `.to_angle()` below?
275+
self.layer_bounding_box.top_right() - self.layer_bounding_box.top_right()
279276
};
280277
let tilt_offset = document.document_ptz.unmodified_tilt();
281278
let offset_angle = offset_angle.to_angle() + tilt_offset;
@@ -349,9 +346,8 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for
349346
TransformType::Scale => TransformOperation::Scaling(Default::default()),
350347
};
351348
self.layer_bounding_box = selected.bounding_box();
352-
let bounding_box = crate::messages::tool::tool_messages::select_tool::create_bounding_box_transform(document);
349+
let bounding_box = select_tool::create_bounding_box_transform(document);
353350
self.state.local_transform_axes = [bounding_box.x_axis, bounding_box.y_axis].map(|axis| axis.normalize_or_zero());
354-
info!("{:?}", self.state.local_transform_axes);
355351
}
356352
TransformLayerMessage::BeginGrabPen { last_point, handle } | TransformLayerMessage::BeginRotatePen { last_point, handle } | TransformLayerMessage::BeginScalePen { last_point, handle } => {
357353
self.typing.clear();

0 commit comments

Comments
 (0)