@@ -4,6 +4,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::{Doc
4
4
use crate :: messages:: portfolio:: document:: utility_types:: misc:: { GeometrySnapSource , SnapSource } ;
5
5
use crate :: messages:: portfolio:: document:: utility_types:: network_interface:: NodeNetworkInterface ;
6
6
use crate :: messages:: prelude:: * ;
7
+ use crate :: messages:: tool:: tool_messages:: path_tool:: PointSelectState ;
7
8
8
9
use bezier_rs:: { Bezier , BezierHandles , TValue } ;
9
10
use graphene_core:: transform:: Transform ;
@@ -12,8 +13,9 @@ use graphene_core::vector::{ManipulatorPointId, PointId, VectorData, VectorModif
12
13
use glam:: DVec2 ;
13
14
use graphene_std:: vector:: { HandleId , SegmentId } ;
14
15
15
- #[ derive( Debug , PartialEq , Copy , Clone ) ]
16
+ #[ derive( Debug , PartialEq , Eq , Copy , Clone , Default ) ]
16
17
pub enum ManipulatorAngle {
18
+ #[ default]
17
19
Colinear ,
18
20
Free ,
19
21
Mixed ,
@@ -161,9 +163,9 @@ impl ClosestSegment {
161
163
midpoint
162
164
}
163
165
164
- pub fn adjusted_insert_and_select ( & self , shape_editor : & mut ShapeState , responses : & mut VecDeque < Message > , add_to_selection : bool ) {
166
+ pub fn adjusted_insert_and_select ( & self , shape_editor : & mut ShapeState , responses : & mut VecDeque < Message > , extend_selection : bool ) {
165
167
let id = self . adjusted_insert ( responses) ;
166
- shape_editor. select_anchor_point_by_id ( self . layer , id, add_to_selection )
168
+ shape_editor. select_anchor_point_by_id ( self . layer , id, extend_selection )
167
169
}
168
170
}
169
171
@@ -221,7 +223,7 @@ impl ShapeState {
221
223
222
224
/// Select/deselect the first point within the selection threshold.
223
225
/// Returns a tuple of the points if found and the offset, or `None` otherwise.
224
- pub fn change_point_selection ( & mut self , network_interface : & NodeNetworkInterface , mouse_position : DVec2 , select_threshold : f64 , add_to_selection : bool ) -> Option < Option < SelectedPointsInfo > > {
226
+ pub fn change_point_selection ( & mut self , network_interface : & NodeNetworkInterface , mouse_position : DVec2 , select_threshold : f64 , extend_selection : bool ) -> Option < Option < SelectedPointsInfo > > {
225
227
if self . selected_shape_state . is_empty ( ) {
226
228
return None ;
227
229
}
@@ -234,14 +236,14 @@ impl ShapeState {
234
236
let already_selected = selected_shape_state. is_selected ( manipulator_point_id) ;
235
237
236
238
// Should we select or deselect the point?
237
- let new_selected = if already_selected { !add_to_selection } else { true } ;
239
+ let new_selected = if already_selected { !extend_selection } else { true } ;
238
240
239
241
// Offset to snap the selected point to the cursor
240
242
let offset = mouse_position - network_interface. document_metadata ( ) . transform_to_viewport ( layer) . transform_point2 ( point_position) ;
241
243
242
244
// This is selecting the manipulator only for now, next to generalize to points
243
245
if new_selected {
244
- let retain_existing_selection = add_to_selection || already_selected;
246
+ let retain_existing_selection = extend_selection || already_selected;
245
247
if !retain_existing_selection {
246
248
self . deselect_all_points ( ) ;
247
249
}
@@ -267,8 +269,8 @@ impl ShapeState {
267
269
None
268
270
}
269
271
270
- pub fn select_anchor_point_by_id ( & mut self , layer : LayerNodeIdentifier , id : PointId , add_to_selection : bool ) {
271
- if !add_to_selection {
272
+ pub fn select_anchor_point_by_id ( & mut self , layer : LayerNodeIdentifier , id : PointId , extend_selection : bool ) {
273
+ if !extend_selection {
272
274
self . deselect_all_points ( ) ;
273
275
}
274
276
let point = ManipulatorPointId :: Anchor ( id) ;
@@ -1060,6 +1062,71 @@ impl ShapeState {
1060
1062
_ => self . sorted_selected_layers ( network_interface. document_metadata ( ) ) . find_map ( closest_seg) ,
1061
1063
}
1062
1064
}
1065
+ pub fn get_dragging_state ( & self , network_interface : & NodeNetworkInterface ) -> PointSelectState {
1066
+ for & layer in self . selected_shape_state . keys ( ) {
1067
+ let Some ( vector_data) = network_interface. compute_modified_vector ( layer) else { continue } ;
1068
+
1069
+ for point in self . selected_points ( ) {
1070
+ if point. as_anchor ( ) . is_some ( ) {
1071
+ return PointSelectState :: Anchor ;
1072
+ }
1073
+ if point. get_handle_pair ( & vector_data) . is_some ( ) {
1074
+ return PointSelectState :: HandleWithPair ;
1075
+ }
1076
+ }
1077
+ }
1078
+ PointSelectState :: HandleNoPair
1079
+ }
1080
+
1081
+ /// Returns true if at least one handle with pair is selected
1082
+ pub fn handle_with_pair_selected ( & mut self , network_interface : & NodeNetworkInterface ) -> bool {
1083
+ for & layer in self . selected_shape_state . keys ( ) {
1084
+ let Some ( vector_data) = network_interface. compute_modified_vector ( layer) else { continue } ;
1085
+
1086
+ for point in self . selected_points ( ) {
1087
+ if point. as_anchor ( ) . is_some ( ) {
1088
+ return false ;
1089
+ }
1090
+ if point. get_handle_pair ( & vector_data) . is_some ( ) {
1091
+ return true ;
1092
+ }
1093
+ }
1094
+ }
1095
+
1096
+ false
1097
+ }
1098
+
1099
+ /// Alternate selected handles to mirrors
1100
+ pub fn alternate_selected_handles ( & mut self , network_interface : & NodeNetworkInterface ) {
1101
+ let mut handles_to_update = Vec :: new ( ) ;
1102
+
1103
+ for & layer in self . selected_shape_state . keys ( ) {
1104
+ let Some ( vector_data) = network_interface. compute_modified_vector ( layer) else { continue } ;
1105
+
1106
+ for point in self . selected_points ( ) {
1107
+ if point. as_anchor ( ) . is_some ( ) {
1108
+ continue ;
1109
+ }
1110
+ if let Some ( handles) = point. get_handle_pair ( & vector_data) {
1111
+ // handle[0] is selected, handle[1] is opposite / mirror handle
1112
+ handles_to_update. push ( ( layer, handles[ 0 ] . to_manipulator_point ( ) , handles[ 1 ] . to_manipulator_point ( ) ) ) ;
1113
+ }
1114
+ }
1115
+ }
1116
+
1117
+ for ( layer, handle_to_deselect, handle_to_select) in handles_to_update {
1118
+ if let Some ( state) = self . selected_shape_state . get_mut ( & layer) {
1119
+ let points = & state. selected_points ;
1120
+ let both_selected = points. contains ( & handle_to_deselect) && points. contains ( & handle_to_select) ;
1121
+ if both_selected {
1122
+ continue ;
1123
+ }
1124
+
1125
+ state. deselect_point ( handle_to_deselect) ;
1126
+ state. select_point ( handle_to_select) ;
1127
+ }
1128
+ }
1129
+ }
1063
1130
1064
1131
/// Selects handles and anchor connected to current handle
1065
1132
pub fn select_handles_and_anchor_connected_to_current_handle ( & mut self , network_interface : & NodeNetworkInterface ) {
0 commit comments