@@ -6,7 +6,7 @@ use crate::consts::{
66} ;
77use crate :: messages:: portfolio:: document:: overlays:: utility_functions:: { path_overlays, selected_segments} ;
88use crate :: messages:: portfolio:: document:: overlays:: utility_types:: { DrawHandles , OverlayContext } ;
9- use crate :: messages:: portfolio:: document:: utility_types:: document_metadata:: LayerNodeIdentifier ;
9+ use crate :: messages:: portfolio:: document:: utility_types:: document_metadata:: { DocumentMetadata , LayerNodeIdentifier } ;
1010use crate :: messages:: portfolio:: document:: utility_types:: network_interface:: NodeNetworkInterface ;
1111use crate :: messages:: portfolio:: document:: utility_types:: transformation:: Axis ;
1212use crate :: messages:: preferences:: SelectionMode ;
@@ -392,13 +392,13 @@ impl PathToolData {
392392 self . saved_points_before_anchor_select_toggle . clear ( ) ;
393393 }
394394
395- pub fn selection_quad ( & self ) -> Quad {
396- let bbox = self . selection_box ( ) ;
395+ pub fn selection_quad ( & self , metadata : & DocumentMetadata ) -> Quad {
396+ let bbox = self . selection_box ( metadata ) ;
397397 Quad :: from_box ( bbox)
398398 }
399399
400- pub fn calculate_selection_mode_from_direction ( & mut self ) -> SelectionMode {
401- let bbox = self . selection_box ( ) ;
400+ pub fn calculate_selection_mode_from_direction ( & mut self , metadata : & DocumentMetadata ) -> SelectionMode {
401+ let bbox = self . selection_box ( metadata ) ;
402402 let above_threshold = bbox[ 1 ] . distance_squared ( bbox[ 0 ] ) > DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD . powi ( 2 ) ;
403403
404404 if self . selection_mode . is_none ( ) && above_threshold {
@@ -414,12 +414,15 @@ impl PathToolData {
414414 self . selection_mode . unwrap_or ( SelectionMode :: Touched )
415415 }
416416
417- pub fn selection_box ( & self ) -> [ DVec2 ; 2 ] {
418- if self . previous_mouse_position == self . drag_start_pos {
417+ pub fn selection_box ( & self , metadata : & DocumentMetadata ) -> [ DVec2 ; 2 ] {
418+ // Convert previous mouse position to viewport space first
419+ let document_to_viewport = metadata. document_to_viewport ;
420+ let previous_mouse = document_to_viewport. transform_point2 ( self . previous_mouse_position ) ;
421+ if previous_mouse == self . drag_start_pos {
419422 let tolerance = DVec2 :: splat ( SELECTION_TOLERANCE ) ;
420423 [ self . drag_start_pos - tolerance, self . drag_start_pos + tolerance]
421424 } else {
422- [ self . drag_start_pos , self . previous_mouse_position ]
425+ [ self . drag_start_pos , previous_mouse ]
423426 }
424427 }
425428
@@ -464,6 +467,7 @@ impl PathToolData {
464467
465468 // Check if the point is already selected; if not, select the first point within the threshold (in pixels)
466469 if let Some ( ( already_selected, mut selection_info) ) = shape_editor. get_point_selection_state ( & document. network_interface , input. mouse . position , SELECTION_THRESHOLD ) {
470+ log:: info!( "entered the part where tool identifies a near point" ) ;
467471 responses. add ( DocumentMessage :: StartTransaction ) ;
468472
469473 self . last_clicked_point_was_selected = already_selected;
@@ -1129,11 +1133,11 @@ impl Fsm for PathToolFsmState {
11291133 let fill_color = Some ( fill_color. as_str ( ) ) ;
11301134
11311135 let selection_mode = match tool_action_data. preferences . get_selection_mode ( ) {
1132- SelectionMode :: Directional => tool_data. calculate_selection_mode_from_direction ( ) ,
1136+ SelectionMode :: Directional => tool_data. calculate_selection_mode_from_direction ( document . metadata ( ) ) ,
11331137 selection_mode => selection_mode,
11341138 } ;
11351139
1136- let quad = tool_data. selection_quad ( ) ;
1140+ let quad = tool_data. selection_quad ( document . metadata ( ) ) ;
11371141 let polygon = & tool_data. lasso_polygon ;
11381142
11391143 match ( selection_shape, selection_mode) {
@@ -1207,7 +1211,7 @@ impl Fsm for PathToolFsmState {
12071211 delete_segment,
12081212 } ,
12091213 ) => {
1210- tool_data. previous_mouse_position = input. mouse . position ;
1214+ tool_data. previous_mouse_position = document . metadata ( ) . document_to_viewport . inverse ( ) . transform_point2 ( input. mouse . position ) ;
12111215
12121216 if selection_shape == SelectionShapeType :: Lasso {
12131217 extend_lasso ( & mut tool_data. lasso_polygon , input. mouse . position ) ;
@@ -1435,12 +1439,14 @@ impl Fsm for PathToolFsmState {
14351439 SelectionChange :: Clear
14361440 } ;
14371441
1438- if tool_data. drag_start_pos == tool_data. previous_mouse_position {
1442+ let document_to_viewport = document. metadata ( ) . document_to_viewport ;
1443+ let previous_mouse = document_to_viewport. transform_point2 ( tool_data. previous_mouse_position ) ;
1444+ if tool_data. drag_start_pos == previous_mouse {
14391445 responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ ] } ) ;
14401446 } else {
14411447 match selection_shape {
14421448 SelectionShapeType :: Box => {
1443- let bbox = [ tool_data. drag_start_pos , tool_data . previous_mouse_position ] ;
1449+ let bbox = [ tool_data. drag_start_pos , previous_mouse ] ;
14441450 shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Box ( bbox) , selection_change) ;
14451451 }
14461452 SelectionShapeType :: Lasso => shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Lasso ( & tool_data. lasso_polygon ) , selection_change) ,
@@ -1481,12 +1487,14 @@ impl Fsm for PathToolFsmState {
14811487 SelectionChange :: Clear
14821488 } ;
14831489
1484- if tool_data. drag_start_pos == tool_data. previous_mouse_position {
1490+ let document_to_viewport = document. metadata ( ) . document_to_viewport ;
1491+ let previous_mouse = document_to_viewport. transform_point2 ( tool_data. previous_mouse_position ) ;
1492+ if tool_data. drag_start_pos == previous_mouse {
14851493 responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ ] } ) ;
14861494 } else {
14871495 match selection_shape {
14881496 SelectionShapeType :: Box => {
1489- let bbox = [ tool_data. drag_start_pos , tool_data . previous_mouse_position ] ;
1497+ let bbox = [ tool_data. drag_start_pos , previous_mouse ] ;
14901498 shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Box ( bbox) , select_kind) ;
14911499 }
14921500 SelectionShapeType :: Lasso => shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Lasso ( & tool_data. lasso_polygon ) , select_kind) ,
0 commit comments