Skip to content
29 changes: 29 additions & 0 deletions editor/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::dispatcher::Dispatcher;
use crate::messages::portfolio::document::node_graph::generate_node_graph_overlay::generate_node_graph_overlay;
use crate::messages::prelude::*;
use graph_craft::document::{NodeInput, NodeNetwork};
use graphene_std::node_graph_overlay::types::NodeGraphOverlayData;
pub use graphene_std::uuid::*;

// TODO: serialize with serde to save the current editor state
Expand Down Expand Up @@ -30,6 +33,32 @@ impl Editor {
pub fn poll_node_graph_evaluation(&mut self, responses: &mut VecDeque<Message>) -> Result<(), String> {
self.dispatcher.poll_node_graph_evaluation(responses)
}

pub fn generate_node_graph_overlay_network(&mut self) -> Option<NodeNetwork> {
let Some(active_document) = self.dispatcher.message_handlers.portfolio_message_handler.active_document_mut() else {
return None;
};
let breadcrumb_network_path = &active_document.breadcrumb_network_path;
let nodes_to_render = active_document.network_interface.collect_nodes(
&active_document.node_graph_handler.node_graph_errors,
self.dispatcher.message_handlers.preferences_message_handler.graph_wire_style,
breadcrumb_network_path,
);
let previewed_node = active_document.network_interface.previewed_node(breadcrumb_network_path);
let node_graph_render_data = NodeGraphOverlayData {
nodes_to_render,
open: active_document.graph_view_overlay_open,
in_selected_network: &active_document.selection_network_path == breadcrumb_network_path,
previewed_node,
};
let opacity = active_document.graph_fade_artwork_percentage;
let node_graph_overlay_node = generate_node_graph_overlay(node_graph_render_data, opacity);
Some(NodeNetwork {
exports: vec![NodeInput::node(NodeId(0), 0)],
nodes: vec![(NodeId(0), node_graph_overlay_node)].into_iter().collect(),
..Default::default()
})
}
}

impl Default for Editor {
Expand Down
4 changes: 2 additions & 2 deletions editor/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub struct DispatcherMessageHandlers {
defer_message_handler: DeferMessageHandler,
dialog_message_handler: DialogMessageHandler,
globals_message_handler: GlobalsMessageHandler,
input_preprocessor_message_handler: InputPreprocessorMessageHandler,
pub input_preprocessor_message_handler: InputPreprocessorMessageHandler,
key_mapping_message_handler: KeyMappingMessageHandler,
layout_message_handler: LayoutMessageHandler,
pub portfolio_message_handler: PortfolioMessageHandler,
preferences_message_handler: PreferencesMessageHandler,
pub preferences_message_handler: PreferencesMessageHandler,
tool_message_handler: ToolMessageHandler,
}

Expand Down
41 changes: 13 additions & 28 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument};
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::node_graph::utility_types::{
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNodeToRender, FrontendNodeType, FrontendXY, Transform,
};
use crate::messages::portfolio::document::node_graph::utility_types::{BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendNodeType};
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
use crate::messages::portfolio::document::utility_types::wires::WirePathInProgress;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::HintData;
use graph_craft::document::NodeId;
use graphene_std::node_graph_overlay::types::{FrontendExports, FrontendImport, FrontendXY, NodeGraphTransform};
use graphene_std::raster::Image;
use graphene_std::raster::color::Color;
use graphene_std::text::{Font, TextAlign};
Expand Down Expand Up @@ -127,9 +126,8 @@ pub enum FrontendMessage {
},
UpdateImportsExports {
/// If the primary import is not visible, then it is None.
imports: Vec<Option<FrontendGraphOutput>>,
/// If the primary export is not visible, then it is None.
exports: Vec<Option<FrontendGraphInput>>,
imports: Vec<Option<FrontendImport>>,
exports: FrontendExports,
/// The primary import location.
#[serde(rename = "importPosition")]
import_position: FrontendXY,
Expand All @@ -140,7 +138,7 @@ pub enum FrontendMessage {
#[serde(rename = "addImportExport")]
add_import_export: bool,
},
UpdateBox {
UpdateNodeGraphSelectionBox {
#[serde(rename = "box")]
box_selection: Option<BoxSelection>,
},
Expand Down Expand Up @@ -271,31 +269,18 @@ pub enum FrontendMessage {
UpdateMouseCursor {
cursor: MouseCursorIcon,
},
UpdateNodeGraphRender {
#[serde(rename = "nodesToRender")]
nodes_to_render: Vec<FrontendNodeToRender>,
open: bool,
opacity: f64,
#[serde(rename = "inSelectedNetwork")]
in_selected_network: bool,
// Displays a dashed border around the node
#[serde(rename = "previewedNode")]
previewed_node: Option<NodeId>,
},
UpdateVisibleNodes {
nodes: Vec<NodeId>,
},
UpdateNodeGraphWires {
wires: Vec<WirePathUpdate>,
RequestNativeNodeGraphRender,
UpdateNativeNodeGraphSVG {
#[serde(rename = "svgString")]
svg_string: String,
},
ClearAllNodeGraphWires,
UpdateNodeGraphControlBarLayout {
#[serde(rename = "layoutTarget")]
layout_target: LayoutTarget,
diff: Vec<WidgetDiff>,
},
UpdateNodeGraphTransform {
transform: Transform,
transform: NodeGraphTransform,
},
UpdateNodeThumbnail {
id: NodeId,
Expand All @@ -321,8 +306,8 @@ pub enum FrontendMessage {
diff: Vec<WidgetDiff>,
},
UpdateWirePathInProgress {
#[serde(rename = "wirePath")]
wire_path: Option<WirePath>,
#[serde(rename = "wirePathInProgress")]
wire_path_in_progress: Option<WirePathInProgress>,
},
UpdateWorkingColorsLayout {
#[serde(rename = "layoutTarget")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageContext> f
self.viewport_bounds = bounds;

responses.add(NavigationMessage::CanvasPan { delta: DVec2::ZERO });
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
responses.add(DeferMessage::AfterGraphRun {
messages: vec![
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
use crate::messages::tool::tool_messages::tool_prelude::WidgetCallback;
use derivative::*;
use graphene_std::node_graph_overlay::types::FrontendGraphDataType;
use graphene_std::vector::style::FillChoice;
use graphite_proc_macros::WidgetBuilder;

Expand Down
27 changes: 5 additions & 22 deletions editor/src/messages/portfolio/document/document_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::node_graph::document_node_definitions;
use super::node_graph::utility_types::Transform;
use super::overlays::utility_types::Pivot;
use super::utility_types::error::EditorError;
use super::utility_types::misc::{GroupFolderType, SNAP_FUNCTIONS_FOR_BOUNDING_BOXES, SNAP_FUNCTIONS_FOR_PATHS, SnappingOptions, SnappingState};
Expand Down Expand Up @@ -31,6 +30,7 @@ use glam::{DAffine2, DVec2, IVec2};
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
use graphene_std::math::quad::Quad;
use graphene_std::node_graph_overlay::types::NodeGraphTransform;
use graphene_std::path_bool::{boolean_intersect, path_bool_lib};
use graphene_std::raster::BlendMode;
use graphene_std::raster_types::Raster;
Expand Down Expand Up @@ -119,10 +119,10 @@ pub struct DocumentMessageHandler {
pub(crate) path: Option<PathBuf>,
/// Path to network currently viewed in the node graph overlay. This will eventually be stored in each panel, so that multiple panels can refer to different networks
#[serde(skip)]
breadcrumb_network_path: Vec<NodeId>,
pub breadcrumb_network_path: Vec<NodeId>,
/// Path to network that is currently selected. Updated based on the most recently clicked panel.
#[serde(skip)]
selection_network_path: Vec<NodeId>,
pub selection_network_path: Vec<NodeId>,
/// Stack of document network snapshots for previous history states.
#[serde(skip)]
document_undo_history: VecDeque<NodeNetworkInterface>,
Expand Down Expand Up @@ -474,10 +474,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
DocumentMessage::EnterNestedNetwork { node_id } => {
self.breadcrumb_network_path.push(node_id);
self.selection_network_path.clone_from(&self.breadcrumb_network_path);
responses.add(NodeGraphMessage::UnloadWires);
responses.add(NodeGraphMessage::SendGraph);
responses.add(DocumentMessage::ZoomCanvasToFitAll);
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
DocumentMessage::Escape => {
if self.node_graph_handler.drag_start.is_some() {
Expand All @@ -494,7 +492,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
responses.add(FrontendMessage::UpdateContextMenuInformation { context_menu_information: None });
self.node_graph_handler.wire_in_progress_from_connector = None;
self.node_graph_handler.wire_in_progress_to_connector = None;
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
} else {
responses.add(DocumentMessage::GraphViewOverlay { open: false });
}
Expand All @@ -504,10 +502,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
self.breadcrumb_network_path.pop();
self.selection_network_path.clone_from(&self.breadcrumb_network_path);
}
responses.add(NodeGraphMessage::UnloadWires);
responses.add(NodeGraphMessage::SendGraph);
responses.add(DocumentMessage::PTZUpdate);
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
DocumentMessage::FlipSelectedLayers { flip_axis } => {
let scale = match flip_axis {
Expand Down Expand Up @@ -557,7 +553,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
}
}
DocumentMessage::GraphViewOverlay { open } => {
let opened = !self.graph_view_overlay_open && open;
self.graph_view_overlay_open = open;

responses.add(FrontendMessage::UpdateGraphViewOverlay { open });
Expand All @@ -567,14 +562,10 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes

responses.add(DocumentMessage::RenderRulers);
responses.add(DocumentMessage::RenderScrollbars);
if opened {
responses.add(NodeGraphMessage::UnloadWires);
}
if open {
responses.add(ToolMessage::DeactivateTools);
responses.add(OverlaysMessage::Draw); // Clear the overlays
responses.add(NavigationMessage::CanvasTiltSet { angle_radians: 0. });
responses.add(NodeGraphMessage::SetGridAlignedEdges);
responses.add(NodeGraphMessage::UpdateGraphBarRight);
responses.add(NodeGraphMessage::UpdateHints);
} else {
Expand Down Expand Up @@ -1495,12 +1486,10 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes

responses.add(DocumentMessage::RenderRulers);
responses.add(DocumentMessage::RenderScrollbars);
responses.add(NodeGraphMessage::UpdateEdges);
responses.add(NodeGraphMessage::UpdateBoxSelection);
responses.add(NodeGraphMessage::UpdateImportsExports);

responses.add(FrontendMessage::UpdateNodeGraphTransform {
transform: Transform {
transform: NodeGraphTransform {
scale: transform.matrix2.x_axis.x,
x: transform.translation.x,
y: transform.translation.y,
Expand Down Expand Up @@ -1948,10 +1937,6 @@ impl DocumentMessageHandler {
responses.add(NodeGraphMessage::SelectedNodesUpdated);
responses.add(NodeGraphMessage::ForceRunDocumentGraph);

// TODO: Remove once the footprint is used to load the imports/export distances from the edge
responses.add(NodeGraphMessage::UnloadWires);
responses.add(NodeGraphMessage::SetGridAlignedEdges);

Some(previous_network)
}
pub fn redo_with_history(&mut self, ipp: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) {
Expand Down Expand Up @@ -1981,8 +1966,6 @@ impl DocumentMessageHandler {
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
responses.add(NodeGraphMessage::SelectedNodesUpdated);
responses.add(NodeGraphMessage::ForceRunDocumentGraph);
responses.add(NodeGraphMessage::UnloadWires);
responses.add(NodeGraphMessage::SendWires);
Some(previous_network)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
NavigationMessage::CanvasPanMouseWheel { use_y_as_x } => {
let delta = if use_y_as_x { (-ipp.mouse.scroll_delta.y, 0.).into() } else { -ipp.mouse.scroll_delta.as_dvec2() } * VIEWPORT_SCROLL_RATE;
responses.add(NavigationMessage::CanvasPan { delta });
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
NavigationMessage::CanvasTiltResetAndZoomTo100Percent => {
let Some(ptz) = get_ptz_mut(document_ptz, network_interface, graph_view_overlay_open, breadcrumb_network_path) else {
Expand All @@ -193,7 +192,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
responses.add(PortfolioMessage::UpdateDocumentWidgets);
}
responses.add(DocumentMessage::PTZUpdate);
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
NavigationMessage::CanvasTiltSet { angle_radians } => {
let Some(ptz) = get_ptz_mut(document_ptz, network_interface, graph_view_overlay_open, breadcrumb_network_path) else {
Expand Down Expand Up @@ -272,7 +270,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
responses.add(PortfolioMessage::UpdateDocumentWidgets);
}
responses.add(DocumentMessage::PTZUpdate);
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
NavigationMessage::CanvasFlip => {
if graph_view_overlay_open {
Expand Down Expand Up @@ -320,7 +317,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
} else {
responses.add(PortfolioMessage::UpdateDocumentWidgets);
}
responses.add(NodeGraphMessage::SetGridAlignedEdges);
// Reset the navigation operation now that it's done
self.navigation_operation = NavigationOperation::None;

Expand Down Expand Up @@ -382,7 +378,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
responses.add(PortfolioMessage::UpdateDocumentWidgets);
}
responses.add(DocumentMessage::PTZUpdate);
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
// Fully zooms in on the selected
NavigationMessage::FitViewportToSelection => {
Expand Down Expand Up @@ -476,7 +471,6 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
};

responses.add(NavigationMessage::CanvasZoomSet { zoom_factor: ptz.zoom() });
responses.add(NodeGraphMessage::SetGridAlignedEdges);
}
}

Expand Down
Loading