diff --git a/include/sight_node_graph.h b/include/sight_node_graph.h index 7cb2d34..7923d4a 100644 --- a/include/sight_node_graph.h +++ b/include/sight_node_graph.h @@ -295,7 +295,7 @@ namespace sight { bool broken = false; // real nodes - SightArray nodes{ LITTLE_ARRAY_SIZE }; + SightArray nodes{ LITTLE_ARRAY_SIZE * 2 }; // real connections. SightArray connections{ MEDIUM_ARRAY_SIZE }; diff --git a/src/sight_node_graph.cpp b/src/sight_node_graph.cpp index 0b90e72..9e04919 100644 --- a/src/sight_node_graph.cpp +++ b/src/sight_node_graph.cpp @@ -98,6 +98,7 @@ namespace sight { // nodes auto nodeRoot = root["nodes"]; + auto connectionRoot = root["connections"]; logDebug(nodeRoot.size()); int loadNodeStatus = CODE_OK; @@ -119,7 +120,6 @@ namespace sight { } // connections - auto connectionRoot = root["connections"]; for (const auto& item : connectionRoot) { SightNodeConnection tmpConnection; tmpConnection.graph = this; diff --git a/src/sight_ui_node_editor.cpp b/src/sight_ui_node_editor.cpp index 2c92b26..a4e62a7 100644 --- a/src/sight_ui_node_editor.cpp +++ b/src/sight_ui_node_editor.cpp @@ -76,6 +76,11 @@ static struct { uint lastMarkedNodeId = 0; uint lastClickedNodeId = 0; + uint lastMarkedPortId = 0; + // both means invalid port type + sight::NodePortType lastMarkedPortType = sight::NodePortType::Both; + + bool lastMarkNodeIsManually = false; bool isNextNodePositionEmpty() { @@ -173,6 +178,11 @@ namespace sight { g_ContextStatus->lastMarkedNodeId = 0; g_ContextStatus->lastMarkNodeIsManually = false; } + + void tryMarkPort(SightNodePort const& port) { + g_ContextStatus->lastMarkedPortId = port.getId(); + g_ContextStatus->lastMarkedPortType = port.kind; + } // node editor functions @@ -269,11 +279,21 @@ namespace sight { ed::Flow(item->connectionId); logDebug(item->connectionId); } + } else if (ImGui::MenuItem("MarkPort")) { + tryMarkPort(*port); } ImGui::EndPopup(); } if (ImGui::BeginPopup(LINK_CONTEXT_MENU)) { + auto connection = graph->findConnection(linkId); + if (!connection) { + logError("can't find connection: $0", linkId); + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + return; + } + auto markedNodeId = g_ContextStatus->lastMarkedNodeId; if (ImGui::MenuItem("insertAtMiddle", nullptr, false, markedNodeId != 0)) { if (graph->insertNodeAtConnectionMid(markedNodeId, linkId)) { @@ -282,6 +302,25 @@ namespace sight { clearMarkNodeInfo(); } } + // + auto lastMarkedPortId = g_ContextStatus->lastMarkedPortId; + if (lastMarkedPortId > 0) { + auto lastMarkedPortType = g_ContextStatus->lastMarkedPortType; + if (lastMarkedPortType == NodePortType::Input || lastMarkedPortType == NodePortType::Output) { + bool changed = false; + if (ImGui::MenuItem("ChangeLeftToMark")) { + changed = connection->changeLeft(lastMarkedPortId); + } else if (ImGui::MenuItem("ChangeRightToMark")) { + changed = connection->changeRight(lastMarkedPortId); + } + + if (changed) { + g_ContextStatus->lastMarkedPortId = 0; + g_ContextStatus->lastMarkedPortType = NodePortType::Both; + } + } + } + ImGui::EndPopup(); } if (ImGui::BeginPopup(BACKGROUND_CONTEXT_MENU)) {