@@ -10,6 +10,8 @@ use crate::messages::portfolio::document::utility_types::document_metadata::{sel
1010use crate :: messages:: portfolio:: document:: utility_types:: misc:: { AlignAggregate , AlignAxis , FlipAxis } ;
1111use crate :: messages:: portfolio:: document:: utility_types:: network_interface:: { FlowType , NodeNetworkInterface , NodeTemplate } ;
1212use crate :: messages:: portfolio:: document:: utility_types:: transformation:: Selected ;
13+ use crate :: messages:: preferences:: PreferencesMessageHandler ;
14+ use crate :: messages:: preferences:: SelectionMode ;
1315use crate :: messages:: tool:: common_functionality:: graph_modification_utils:: is_layer_fed_by_node_of_name;
1416use crate :: messages:: tool:: common_functionality:: pivot:: Pivot ;
1517use crate :: messages:: tool:: common_functionality:: snapping:: { self , SnapCandidatePoint , SnapData , SnapManager } ;
@@ -77,7 +79,6 @@ pub enum SelectToolMessage {
7779 // Standard messages
7880 Abort ,
7981 Overlays ( OverlayContext ) ,
80-
8182 // Tool-specific messages
8283 DragStart { extend_selection : Key , select_deepest : Key } ,
8384 DragStop { remove_from_selection : Key } ,
@@ -87,6 +88,7 @@ pub enum SelectToolMessage {
8788 PointerOutsideViewport ( SelectToolPointerKeys ) ,
8889 SelectOptions ( SelectOptionsUpdate ) ,
8990 SetPivot { position : PivotPosition } ,
91+ UpdateSelectionMode { selection_mode : SelectionMode } ,
9092}
9193
9294impl ToolMetadata for SelectTool {
@@ -263,6 +265,7 @@ enum SelectToolFsmState {
263265 RotatingBounds ,
264266 DraggingPivot ,
265267}
268+
266269impl Default for SelectToolFsmState {
267270 fn default ( ) -> Self {
268271 let selection = NestedSelectionBehavior :: Deepest ;
@@ -288,6 +291,7 @@ struct SelectToolData {
288291 selected_layers_changed : bool ,
289292 snap_candidates : Vec < SnapCandidatePoint > ,
290293 auto_panning : AutoPanning ,
294+ selection_mode : SelectionMode ,
291295}
292296
293297impl SelectToolData {
@@ -304,12 +308,12 @@ impl SelectToolData {
304308 }
305309 }
306310
307- fn selection_quad ( & self ) -> Quad {
311+ pub fn selection_quad ( & self ) -> Quad {
308312 let bbox = self . selection_box ( ) ;
309313 Quad :: from_box ( bbox)
310314 }
311315
312- fn calculate_direction ( & self ) -> SelectionDirection {
316+ pub fn calculate_direction ( & self ) -> SelectionDirection {
313317 let bbox: [ DVec2 ; 2 ] = self . selection_box ( ) ;
314318 if bbox[ 1 ] . x > bbox[ 0 ] . x {
315319 SelectionDirection :: Rightwards
@@ -320,7 +324,7 @@ impl SelectToolData {
320324 }
321325 }
322326
323- fn selection_box ( & self ) -> [ DVec2 ; 2 ] {
327+ pub fn selection_box ( & self ) -> [ DVec2 ; 2 ] {
324328 if self . drag_current == self . drag_start {
325329 let tolerance = DVec2 :: splat ( SELECTION_TOLERANCE ) ;
326330 [ self . drag_start - tolerance, self . drag_start + tolerance]
@@ -1025,14 +1029,23 @@ impl Fsm for SelectToolFsmState {
10251029 SelectToolFsmState :: Ready { selection }
10261030 }
10271031 ( SelectToolFsmState :: DrawingBox { .. } , SelectToolMessage :: DragStop { .. } | SelectToolMessage :: Enter ) => {
1032+ let mut preferences_handler = PreferencesMessageHandler :: default ( ) ;
1033+ tool_data. selection_mode = preferences_handler. selection_mode . clone ( ) ;
1034+ info ! ( "Setting selection mode to: {:?}" , tool_data. selection_mode) ;
10281035 let quad = tool_data. selection_quad ( ) ;
10291036 let direction = tool_data. calculate_direction ( ) ;
1037+ info ! ( "Using SelectionMode: {:?}" , tool_data. selection_mode) ;
10301038 // let new_selected: HashSet<_> = document.intersect_quad_no_artboards(quad, input).collect();
1031- let new_selected: HashSet < _ > = match direction {
1032- SelectionDirection :: Rightwards => document. intersect_quad_no_artboards ( quad, input) . filter ( |layer| document. is_layer_fully_inside ( layer, quad) ) . collect ( ) ,
1033- SelectionDirection :: Leftwards => document. intersect_quad_no_artboards ( quad, input) . collect ( ) ,
1034- SelectionDirection :: None => HashSet :: new ( ) ,
1039+ let new_selected: HashSet < _ > = match tool_data. selection_mode {
1040+ SelectionMode :: Touched => document. intersect_quad_no_artboards ( quad, input) . collect ( ) ,
1041+ SelectionMode :: Contained => document. intersect_quad_no_artboards ( quad, input) . filter ( |layer| document. is_layer_fully_inside ( layer, quad) ) . collect ( ) ,
1042+ SelectionMode :: ByDragDirection => match direction {
1043+ SelectionDirection :: Rightwards => document. intersect_quad_no_artboards ( quad, input) . filter ( |layer| document. is_layer_fully_inside ( layer, quad) ) . collect ( ) ,
1044+ SelectionDirection :: Leftwards => document. intersect_quad_no_artboards ( quad, input) . collect ( ) ,
1045+ SelectionDirection :: None => HashSet :: new ( ) ,
1046+ } ,
10351047 } ;
1048+
10361049 let current_selected: HashSet < _ > = document. network_interface . selected_nodes ( & [ ] ) . unwrap ( ) . selected_layers ( document. metadata ( ) ) . collect ( ) ;
10371050 if new_selected != current_selected {
10381051 tool_data. layers_dragging = new_selected. into_iter ( ) . collect ( ) ;
0 commit comments