1
1
#![ allow( clippy:: too_many_arguments) ]
2
2
3
3
use super :: tool_prelude:: * ;
4
- use crate :: consts:: { DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD , ROTATE_INCREMENT , SELECTION_TOLERANCE } ;
4
+ use crate :: consts:: { COLOR_OVERLAY_GREEN , COLOR_OVERLAY_RED , DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD , ROTATE_INCREMENT , SELECTION_TOLERANCE } ;
5
5
use crate :: messages:: input_mapper:: utility_types:: input_mouse:: ViewportPosition ;
6
6
use crate :: messages:: portfolio:: document:: graph_operation:: utility_types:: TransformIn ;
7
7
use crate :: messages:: portfolio:: document:: overlays:: utility_types:: OverlayContext ;
@@ -12,7 +12,7 @@ use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
12
12
use crate :: messages:: portfolio:: document:: utility_types:: transformation:: Selected ;
13
13
use crate :: messages:: preferences:: SelectionMode ;
14
14
use crate :: messages:: tool:: common_functionality:: graph_modification_utils:: { get_text, is_layer_fed_by_node_of_name} ;
15
- use crate :: messages:: tool:: common_functionality:: pivot:: { CompassRoseState , Pivot } ;
15
+ use crate :: messages:: tool:: common_functionality:: pivot:: { Axis , Pivot } ;
16
16
use crate :: messages:: tool:: common_functionality:: shape_editor:: SelectionShapeType ;
17
17
use crate :: messages:: tool:: common_functionality:: snapping:: { self , SnapCandidatePoint , SnapData , SnapManager } ;
18
18
use crate :: messages:: tool:: common_functionality:: transformation_cage:: * ;
@@ -270,14 +270,6 @@ impl ToolTransition for SelectTool {
270
270
}
271
271
}
272
272
273
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , Default ) ]
274
- pub enum Axis {
275
- #[ default]
276
- None ,
277
- X ,
278
- Y ,
279
- }
280
-
281
273
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
282
274
enum SelectToolFsmState {
283
275
Ready { selection : NestedSelectionBehavior } ,
@@ -555,8 +547,30 @@ impl Fsm for SelectToolFsmState {
555
547
. map ( |bounds| transform * Quad :: from_box ( bounds) )
556
548
. map_or ( 0. , |quad| ( quad. top_left ( ) - quad. top_right ( ) ) . to_angle ( ) ) ;
557
549
let mouse_position = input. mouse . position ;
550
+ let compass_rose_state = tool_data. pivot . compass_rose_state ( mouse_position, angle) ;
551
+ let show_hover_ring = compass_rose_state. is_ring ( ) ;
558
552
// Update pivot
559
- tool_data. pivot . update_pivot ( document, & mut overlay_context, angle, mouse_position) ;
553
+ tool_data. pivot . update_pivot ( document, & mut overlay_context, angle, show_hover_ring) ;
554
+ if let SelectToolFsmState :: Dragging { axis } = self {
555
+ if axis. is_constraint ( ) {
556
+ let e0 = tool_data
557
+ . bounding_box_manager
558
+ . as_ref ( )
559
+ . map ( |man| man. transform * Quad :: from_box ( man. bounds ) )
560
+ . map_or ( DVec2 :: X , |quad| ( quad. top_left ( ) - quad. top_right ( ) ) . normalize_or ( DVec2 :: X ) ) ;
561
+
562
+ let origin = tool_data. pivot . get_position ( ) . unwrap_or ( tool_data. drag_start ) ;
563
+ let ( direction, color) = match axis {
564
+ Axis :: X => ( e0, COLOR_OVERLAY_RED ) ,
565
+ Axis :: Y => ( e0. perp ( ) , COLOR_OVERLAY_GREEN ) ,
566
+ _ => unreachable ! ( ) ,
567
+ } ;
568
+
569
+ let viewport_diagonal = input. viewport_bounds . size ( ) . length ( ) ;
570
+
571
+ overlay_context. line ( origin - direction * viewport_diagonal, origin + direction * viewport_diagonal, Some ( color) ) ;
572
+ }
573
+ }
560
574
561
575
// Check if the tool is in selection mode
562
576
if let Self :: Drawing { selection_shape } = self {
@@ -693,11 +707,11 @@ impl Fsm for SelectToolFsmState {
693
707
. as_ref ( )
694
708
. map ( |man| man. transform * Quad :: from_box ( man. bounds ) )
695
709
. map_or ( 0. , |quad| ( quad. top_left ( ) - quad. top_right ( ) ) . to_angle ( ) ) ;
696
- let compass_ross_state = tool_data. pivot . is_over ( input. mouse . position , angle) ;
710
+ let compass_rose_state = tool_data. pivot . compass_rose_state ( input. mouse . position , angle) ;
697
711
698
712
let state =
699
713
// Dragging the pivot
700
- if compass_ross_state . is_pivot ( ) {
714
+ if compass_rose_state . is_pivot ( ) {
701
715
responses. add ( DocumentMessage :: StartTransaction ) ;
702
716
703
717
// tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(), true, true);
@@ -775,7 +789,7 @@ impl Fsm for SelectToolFsmState {
775
789
SelectToolFsmState :: RotatingBounds
776
790
}
777
791
// Dragging the selected layers around to transform them
778
- else if compass_ross_state . can_grab ( ) || intersection. is_some_and ( |intersection| selected. iter ( ) . any ( |selected_layer| intersection. starts_with ( * selected_layer, document. metadata ( ) ) ) ) {
792
+ else if compass_rose_state . can_grab ( ) || intersection. is_some_and ( |intersection| selected. iter ( ) . any ( |selected_layer| intersection. starts_with ( * selected_layer, document. metadata ( ) ) ) ) {
779
793
responses. add ( DocumentMessage :: StartTransaction ) ;
780
794
781
795
if input. keyboard . key ( select_deepest) || tool_data. nested_selection_behavior == NestedSelectionBehavior :: Deepest {
@@ -787,13 +801,7 @@ impl Fsm for SelectToolFsmState {
787
801
tool_data. layers_dragging = selected;
788
802
789
803
tool_data. get_snap_candidates ( document, input) ;
790
- let axis = match compass_ross_state{
791
- CompassRoseState :: AxisX => Axis :: X ,
792
- CompassRoseState :: AxisY => Axis :: Y ,
793
- CompassRoseState :: HoverRing => Axis :: None ,
794
- _ => unreachable ! ( )
795
- } ;
796
-
804
+ let axis = compass_rose_state. axis_type ( ) ;
797
805
SelectToolFsmState :: Dragging { axis}
798
806
}
799
807
// Dragging a selection box
@@ -1042,7 +1050,7 @@ impl Fsm for SelectToolFsmState {
1042
1050
. map ( |man| man. transform * Quad :: from_box ( man. bounds ) )
1043
1051
. map_or ( 0. , |quad| ( quad. top_left ( ) - quad. top_right ( ) ) . to_angle ( ) ) ;
1044
1052
// Dragging the pivot overrules the other operations
1045
- if tool_data. pivot . is_over ( input. mouse . position , angle) . is_pivot ( ) {
1053
+ if tool_data. pivot . compass_rose_state ( input. mouse . position , angle) . is_pivot ( ) {
1046
1054
cursor = MouseCursorIcon :: Move ;
1047
1055
}
1048
1056
0 commit comments