@@ -498,7 +498,10 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
498
498
log:: error!( "Could not get center of selected_nodes" ) ;
499
499
return ;
500
500
} ;
501
- let center_of_selected_nodes_grid_space = IVec2 :: new ( ( center_of_selected_nodes. x / 24. + 0.5 ) . floor ( ) as i32 , ( center_of_selected_nodes. y / 24. + 0.5 ) . floor ( ) as i32 ) ;
501
+ let center_of_selected_nodes_grid_space = IVec2 :: new (
502
+ ( center_of_selected_nodes. x / GRID_SIZE as f64 + 0.5 ) . floor ( ) as i32 ,
503
+ ( center_of_selected_nodes. y / GRID_SIZE as f64 + 0.5 ) . floor ( ) as i32 ,
504
+ ) ;
502
505
default_node_template. persistent_node_metadata . node_type_metadata = NodeTypePersistentMetadata :: node ( center_of_selected_nodes_grid_space - IVec2 :: new ( 3 , 1 ) ) ;
503
506
responses. add ( DocumentMessage :: AddTransaction ) ;
504
507
responses. add ( NodeGraphMessage :: InsertNode {
@@ -603,7 +606,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
603
606
log:: error!( "Could not get network metadata in PointerDown" ) ;
604
607
return ;
605
608
} ;
606
-
609
+ self . disconnecting = None ;
607
610
let click = ipp. mouse . position ;
608
611
609
612
let node_graph_point = network_metadata. persistent_metadata . navigation_metadata . node_graph_to_viewport . inverse ( ) . transform_point2 ( click) ;
@@ -938,8 +941,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
938
941
} ;
939
942
responses. add ( FrontendMessage :: UpdateWirePathInProgress { wire_path : Some ( wire_path) } ) ;
940
943
}
941
- } else if self . disconnecting . is_some ( ) {
942
- // Disconnecting with no upstream node, create new value node.
944
+ }
945
+ // Dragging from an exposed value input
946
+ else if self . disconnecting . is_some ( ) {
943
947
let to_connector = network_interface. input_connector_from_click ( ipp. mouse . position , selection_network_path) ;
944
948
if let Some ( to_connector) = & to_connector {
945
949
let Some ( input_position) = network_interface. input_position ( to_connector, selection_network_path) else {
@@ -948,58 +952,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
948
952
} ;
949
953
self . wire_in_progress_to_connector = Some ( input_position) ;
950
954
}
951
- // Not hovering over a node input or node output, insert the node
952
- else {
953
- // Disconnect if the wire was previously connected to an input
954
- if let Some ( disconnecting) = self . disconnecting . take ( ) {
955
- let mut position = if let Some ( to_connector) = self . wire_in_progress_to_connector { to_connector } else { point } ;
956
- // Offset to drag from center of node
957
- position = position - DVec2 :: new ( 24. * 3. , 24. ) ;
958
-
959
- // Offset to account for division rounding error
960
- if position. x < 0. {
961
- position. x = position. x - 1. ;
962
- }
963
- if position. y < 0. {
964
- position. y = position. y - 1. ;
965
- }
966
-
967
- let Some ( input) = network_interface. take_input ( & disconnecting, breadcrumb_network_path) else {
968
- return ;
969
- } ;
970
-
971
- let drag_start = DragStart {
972
- start_x : point. x ,
973
- start_y : point. y ,
974
- round_x : 0 ,
975
- round_y : 0 ,
976
- } ;
977
-
978
- self . drag_start = Some ( ( drag_start, false ) ) ;
979
- self . node_has_moved_in_drag = false ;
980
- self . update_node_graph_hints ( responses) ;
981
-
982
- let node_id = NodeId :: new ( ) ;
983
- responses. add ( NodeGraphMessage :: CreateNodeFromContextMenu {
984
- node_id : Some ( node_id) ,
985
- node_type : "Identity" . to_string ( ) ,
986
- xy : Some ( ( ( position. x / 24. ) as i32 , ( position. y / 24. ) as i32 ) ) ,
987
- } ) ;
988
-
989
- responses. add ( NodeGraphMessage :: SetInput {
990
- input_connector : InputConnector :: node ( node_id, 0 ) ,
991
- input,
992
- } ) ;
993
-
994
- responses. add ( NodeGraphMessage :: CreateWire {
995
- output_connector : OutputConnector :: Node { node_id, output_index : 0 } ,
996
- input_connector : disconnecting,
997
- } ) ;
998
- responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ node_id] } ) ;
999
- // Update the frontend that the node is disconnected
1000
- responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
1001
- responses. add ( NodeGraphMessage :: SendGraph ) ;
1002
- }
955
+ // Not hovering over a node input or node output, create the value node if alt is pressed
956
+ else if ipp. keyboard . get ( Key :: Alt as usize ) {
957
+ self . preview_on_mouse_up = None ;
958
+ self . create_value_node ( network_interface, point, breadcrumb_network_path, responses) ;
959
+ } else {
960
+ //TODO: Start creating wire
1003
961
}
1004
962
} else if let Some ( ( drag_start, dragged) ) = & mut self . drag_start {
1005
963
if drag_start. start_x != point. x || drag_start. start_y != point. y {
@@ -1020,7 +978,10 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
1020
978
}
1021
979
}
1022
980
1023
- let mut graph_delta = IVec2 :: new ( ( ( point. x - drag_start. start_x ) / 24. ) . round ( ) as i32 , ( ( point. y - drag_start. start_y ) / 24. ) . round ( ) as i32 ) ;
981
+ let mut graph_delta = IVec2 :: new (
982
+ ( ( point. x - drag_start. start_x ) / GRID_SIZE as f64 ) . round ( ) as i32 ,
983
+ ( ( point. y - drag_start. start_y ) / GRID_SIZE as f64 ) . round ( ) as i32 ,
984
+ ) ;
1024
985
let previous_round_x = drag_start. round_x ;
1025
986
let previous_round_y = drag_start. round_y ;
1026
987
@@ -1407,6 +1368,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
1407
1368
let document_bbox: [ DVec2 ; 2 ] = viewport_bbox. map ( |p| network_metadata. persistent_metadata . navigation_metadata . node_graph_to_viewport . inverse ( ) . transform_point2 ( p) ) ;
1408
1369
1409
1370
let mut nodes = Vec :: new ( ) ;
1371
+
1410
1372
for node_id in & self . frontend_nodes {
1411
1373
let Some ( node_bbox) = network_interface. node_bounding_box ( node_id, breadcrumb_network_path) else {
1412
1374
log:: error!( "Could not get bbox for node: {:?}" , node_id) ;
@@ -1418,6 +1380,17 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
1418
1380
}
1419
1381
}
1420
1382
1383
+ // Always send nodes with errors
1384
+ for error in & self . node_graph_errors {
1385
+ let Some ( ( id, path) ) = error. node_path . split_last ( ) else {
1386
+ log:: error!( "Could not get node path in error: {:?}" , error) ;
1387
+ continue ;
1388
+ } ;
1389
+ if breadcrumb_network_path == path {
1390
+ nodes. push ( * id) ;
1391
+ }
1392
+ }
1393
+
1421
1394
responses. add ( FrontendMessage :: UpdateVisibleNodes { nodes } ) ;
1422
1395
}
1423
1396
NodeGraphMessage :: SendGraph => {
@@ -1456,7 +1429,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
1456
1429
input,
1457
1430
} ) ;
1458
1431
responses. add ( PropertiesPanelMessage :: Refresh ) ;
1459
- if ! ( network_interface . reference ( & node_id , selection_network_path ) . is_none ( ) || input_index == 0 ) && network_interface. connected_to_output ( & node_id, selection_network_path) {
1432
+ if network_interface. connected_to_output ( & node_id, selection_network_path) {
1460
1433
responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
1461
1434
}
1462
1435
}
@@ -1538,6 +1511,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
1538
1511
1539
1512
responses. add ( NodeGraphMessage :: SendWires ) ;
1540
1513
}
1514
+ NodeGraphMessage :: SetReference { node_id, reference } => {
1515
+ network_interface. set_reference ( & node_id, breadcrumb_network_path, reference) ;
1516
+ }
1541
1517
NodeGraphMessage :: SetToNodeOrLayer { node_id, is_layer } => {
1542
1518
if is_layer && !network_interface. is_eligible_to_be_layer ( & node_id, selection_network_path) {
1543
1519
return ;
@@ -2217,6 +2193,69 @@ impl NodeGraphMessageHandler {
2217
2193
}
2218
2194
}
2219
2195
2196
+ fn create_value_node ( & mut self , network_interface : & mut NodeNetworkInterface , point : DVec2 , breadcrumb_network_path : & [ NodeId ] , responses : & mut VecDeque < Message > ) {
2197
+ let Some ( disconnecting) = self . disconnecting . take ( ) else {
2198
+ log:: error!( "To connector must be initialized to create a value node" ) ;
2199
+ return ;
2200
+ } ;
2201
+ let Some ( mut position) = self . wire_in_progress_to_connector . take ( ) else {
2202
+ log:: error!( "To connector must be initialized to create a value node" ) ;
2203
+ return ;
2204
+ } ;
2205
+ // Offset node insertion 3 grid spaces left and 1 grid space up so the center of the node is dragged
2206
+ position = position - DVec2 :: new ( GRID_SIZE as f64 * 3. , GRID_SIZE as f64 ) ;
2207
+
2208
+ // Offset to account for division rounding error and place the selected node to the top left of the input
2209
+ if position. x < 0. {
2210
+ position. x = position. x - 1. ;
2211
+ }
2212
+ if position. y < 0. {
2213
+ position. y = position. y - 1. ;
2214
+ }
2215
+
2216
+ let Some ( mut input) = network_interface. take_input ( & disconnecting, breadcrumb_network_path) else {
2217
+ return ;
2218
+ } ;
2219
+
2220
+ match & mut input {
2221
+ NodeInput :: Value { exposed, .. } => * exposed = false ,
2222
+ _ => return ,
2223
+ }
2224
+
2225
+ let drag_start = DragStart {
2226
+ start_x : point. x ,
2227
+ start_y : point. y ,
2228
+ round_x : 0 ,
2229
+ round_y : 0 ,
2230
+ } ;
2231
+
2232
+ self . drag_start = Some ( ( drag_start, false ) ) ;
2233
+ self . node_has_moved_in_drag = false ;
2234
+ self . update_node_graph_hints ( responses) ;
2235
+
2236
+ let node_id = NodeId :: new ( ) ;
2237
+ responses. add ( NodeGraphMessage :: CreateNodeFromContextMenu {
2238
+ node_id : Some ( node_id) ,
2239
+ node_type : "Value" . to_string ( ) ,
2240
+ xy : Some ( ( ( position. x / GRID_SIZE as f64 ) as i32 , ( position. y / GRID_SIZE as f64 ) as i32 ) ) ,
2241
+ add_transaction : false ,
2242
+ } ) ;
2243
+
2244
+ responses. add ( NodeGraphMessage :: SetInput {
2245
+ input_connector : InputConnector :: node ( node_id, 0 ) ,
2246
+ input,
2247
+ } ) ;
2248
+
2249
+ responses. add ( NodeGraphMessage :: CreateWire {
2250
+ output_connector : OutputConnector :: Node { node_id, output_index : 0 } ,
2251
+ input_connector : disconnecting,
2252
+ } ) ;
2253
+ responses. add ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ node_id] } ) ;
2254
+ // Update the frontend that the node is disconnected
2255
+ responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
2256
+ responses. add ( NodeGraphMessage :: SendGraph ) ;
2257
+ }
2258
+
2220
2259
fn collect_wires ( & mut self , network_interface : & mut NodeNetworkInterface , graph_wire_style : GraphWireStyle , breadcrumb_network_path : & [ NodeId ] ) -> Vec < WirePathUpdate > {
2221
2260
let mut added_wires = network_interface
2222
2261
. node_graph_input_connectors ( breadcrumb_network_path)
0 commit comments