@@ -6,7 +6,7 @@ use crate::consts::{
6
6
} ;
7
7
use crate :: messages:: portfolio:: document:: overlays:: utility_functions:: { path_overlays, selected_segments} ;
8
8
use 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 } ;
10
10
use crate :: messages:: portfolio:: document:: utility_types:: network_interface:: NodeNetworkInterface ;
11
11
use crate :: messages:: portfolio:: document:: utility_types:: transformation:: Axis ;
12
12
use crate :: messages:: preferences:: SelectionMode ;
@@ -392,13 +392,13 @@ impl PathToolData {
392
392
self . saved_points_before_anchor_select_toggle . clear ( ) ;
393
393
}
394
394
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 ) ;
397
397
Quad :: from_box ( bbox)
398
398
}
399
399
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 ) ;
402
402
let above_threshold = bbox[ 1 ] . distance_squared ( bbox[ 0 ] ) > DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD . powi ( 2 ) ;
403
403
404
404
if self . selection_mode . is_none ( ) && above_threshold {
@@ -414,12 +414,15 @@ impl PathToolData {
414
414
self . selection_mode . unwrap_or ( SelectionMode :: Touched )
415
415
}
416
416
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 {
419
422
let tolerance = DVec2 :: splat ( SELECTION_TOLERANCE ) ;
420
423
[ self . drag_start_pos - tolerance, self . drag_start_pos + tolerance]
421
424
} else {
422
- [ self . drag_start_pos , self . previous_mouse_position ]
425
+ [ self . drag_start_pos , previous_mouse ]
423
426
}
424
427
}
425
428
@@ -464,6 +467,7 @@ impl PathToolData {
464
467
465
468
// Check if the point is already selected; if not, select the first point within the threshold (in pixels)
466
469
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" ) ;
467
471
responses. add ( DocumentMessage :: StartTransaction ) ;
468
472
469
473
self . last_clicked_point_was_selected = already_selected;
@@ -1129,11 +1133,11 @@ impl Fsm for PathToolFsmState {
1129
1133
let fill_color = Some ( fill_color. as_str ( ) ) ;
1130
1134
1131
1135
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 ( ) ) ,
1133
1137
selection_mode => selection_mode,
1134
1138
} ;
1135
1139
1136
- let quad = tool_data. selection_quad ( ) ;
1140
+ let quad = tool_data. selection_quad ( document . metadata ( ) ) ;
1137
1141
let polygon = & tool_data. lasso_polygon ;
1138
1142
1139
1143
match ( selection_shape, selection_mode) {
@@ -1207,7 +1211,7 @@ impl Fsm for PathToolFsmState {
1207
1211
delete_segment,
1208
1212
} ,
1209
1213
) => {
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 ) ;
1211
1215
1212
1216
if selection_shape == SelectionShapeType :: Lasso {
1213
1217
extend_lasso ( & mut tool_data. lasso_polygon , input. mouse . position ) ;
@@ -1435,12 +1439,14 @@ impl Fsm for PathToolFsmState {
1435
1439
SelectionChange :: Clear
1436
1440
} ;
1437
1441
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 {
1439
1445
responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ ] } ) ;
1440
1446
} else {
1441
1447
match selection_shape {
1442
1448
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 ] ;
1444
1450
shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Box ( bbox) , selection_change) ;
1445
1451
}
1446
1452
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 {
1481
1487
SelectionChange :: Clear
1482
1488
} ;
1483
1489
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 {
1485
1493
responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ ] } ) ;
1486
1494
} else {
1487
1495
match selection_shape {
1488
1496
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 ] ;
1490
1498
shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Box ( bbox) , select_kind) ;
1491
1499
}
1492
1500
SelectionShapeType :: Lasso => shape_editor. select_all_in_shape ( & document. network_interface , SelectionShape :: Lasso ( & tool_data. lasso_polygon ) , select_kind) ,
0 commit comments