@@ -7,6 +7,7 @@ use crate::messages::portfolio::document::utility_types::transformation::{Axis,
77use crate :: messages:: prelude:: * ;
88use crate :: messages:: tool:: common_functionality:: pivot:: { PivotGizmo , PivotGizmoType } ;
99use crate :: messages:: tool:: common_functionality:: shape_editor:: ShapeState ;
10+ use crate :: messages:: tool:: tool_messages:: select_tool;
1011use crate :: messages:: tool:: tool_messages:: tool_prelude:: Key ;
1112use crate :: messages:: tool:: utility_types:: { ToolData , ToolType } ;
1213use 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 ) ]
6570pub 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