Skip to content

Commit

Permalink
mark port
Browse files Browse the repository at this point in the history
  • Loading branch information
Aincvy committed Nov 15, 2023
1 parent fc7d3c2 commit e79c05a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/sight_node_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ namespace sight {
bool broken = false;

// real nodes
SightArray<SightNode> nodes{ LITTLE_ARRAY_SIZE };
SightArray<SightNode> nodes{ LITTLE_ARRAY_SIZE * 2 };
// real connections.
SightArray<SightNodeConnection> connections{ MEDIUM_ARRAY_SIZE };

Expand Down
2 changes: 1 addition & 1 deletion src/sight_node_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace sight {

// nodes
auto nodeRoot = root["nodes"];
auto connectionRoot = root["connections"];
logDebug(nodeRoot.size());

int loadNodeStatus = CODE_OK;
Expand All @@ -119,7 +120,6 @@ namespace sight {
}

// connections
auto connectionRoot = root["connections"];
for (const auto& item : connectionRoot) {
SightNodeConnection tmpConnection;
tmpConnection.graph = this;
Expand Down
39 changes: 39 additions & 0 deletions src/sight_ui_node_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit e79c05a

Please sign in to comment.