Unified handling of nodes in editor.

AnimGraphEditor
Martin Felis 2022-02-15 21:06:12 +01:00
parent 9b743fd081
commit 0d0b181ebb
1 changed files with 35 additions and 81 deletions

View File

@ -101,93 +101,20 @@ void AnimGraphEditorUpdate() {
ImGui::PopStyleVar(ImGuiStyleVar_WindowPadding);
}
// Graph Output and Inputs
if (graph_resource.m_nodes.size() > 0) {
// Graph Output
AnimNodeResource& graph_output_node = graph_resource.getGraphOutputNode();
ImNodes::BeginNode(0);
// Header
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("Graph Output");
ImNodes::EndNodeTitleBar();
// Graph Outputs = Graph Node inputs
const std::vector<Socket>& graph_outputs =
graph_output_node.m_socket_accessor->m_inputs;
for (size_t j = 0, ni = graph_outputs.size(); j < ni; j++) {
const Socket& socket = graph_outputs[j];
ImNodes::BeginInputAttribute(
GenerateInputAttributeId(0, j),
sGetSocketShapeFromSocketType(socket.m_type),
ImColor(255, 255, 255, 255));
ImGui::Text(socket.m_name.c_str());
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
ImNodes::EndInputAttribute();
}
if (ImGui::Button("+Output")) {
static float bla = 0.f;
std::string socket_name = "Output";
socket_name +=
std::to_string(graph_output_node.m_socket_accessor->m_inputs.size());
graph_output_node.m_socket_accessor->RegisterInput<float>(
socket_name,
nullptr);
}
ImVec2 node_pos = ImNodes::GetNodeGridSpacePos(0);
graph_output_node.m_position[0] = node_pos[0];
graph_output_node.m_position[1] = node_pos[1];
ImNodes::EndNode();
// Graph Input
AnimNodeResource& graph_input_node = graph_resource.getGraphInputNode();
ImNodes::BeginNode(1);
// Header
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("Graph Input");
ImNodes::EndNodeTitleBar();
// Graph Input = Graph Node outputs
const std::vector<Socket>& graph_inputs =
graph_input_node.m_socket_accessor->m_outputs;
for (size_t j = 0, ni = graph_inputs.size(); j < ni; j++) {
const Socket& socket = graph_inputs[j];
ImNodes::BeginOutputAttribute(
GenerateOutputAttributeId(1, j),
sGetSocketShapeFromSocketType(socket.m_type),
ImColor(255, 255, 255, 255));
ImGui::Text(socket.m_name.c_str());
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
ImNodes::EndInputAttribute();
}
if (ImGui::Button("+Input")) {
static float bla = 0.f;
std::string socket_name = "Input";
socket_name +=
std::to_string(graph_input_node.m_socket_accessor->m_outputs.size());
graph_input_node.m_socket_accessor->RegisterOutput<float>(
socket_name,
nullptr);
}
node_pos = ImNodes::GetNodeGridSpacePos(1);
graph_input_node.m_position[0] = node_pos[0];
graph_input_node.m_position[1] = node_pos[1];
ImNodes::EndNode();
}
for (size_t i = 2, n = graph_resource.m_nodes.size(); i < n; i++) {
for (size_t i = 0, n = graph_resource.m_nodes.size(); i < n; i++) {
AnimNodeResource& node_resource = graph_resource.m_nodes[i];
ImNodes::BeginNode(i);
// Header
ImNodes::BeginNodeTitleBar();
if (i == 0) {
ImGui::TextUnformatted("Graph Outputs");
} else if (i == 1) {
ImGui::TextUnformatted("Graph Inputs");
} else {
ImGui::TextUnformatted(node_resource.m_type_name.c_str());
}
ImNodes::EndNodeTitleBar();
// Inputs
@ -219,6 +146,33 @@ void AnimGraphEditorUpdate() {
ImNodes::EndInputAttribute();
}
// Graph output node
if (i == 0) {
if (ImGui::Button("+Output")) {
AnimNodeResource& graph_output_node = graph_resource.getGraphOutputNode();
static float bla = 0.f;
std::string socket_name = "Output";
socket_name +=
std::to_string(graph_output_node.m_socket_accessor->m_inputs.size());
graph_output_node.m_socket_accessor->RegisterInput<float>(
socket_name,
nullptr);
}
} else if (i == 1) {
if (ImGui::Button("+Input")) {
AnimNodeResource& graph_input_node = graph_resource.getGraphInputNode();
static float bla = 0.f;
std::string socket_name = "Input";
socket_name +=
std::to_string(graph_input_node.m_socket_accessor->m_outputs.size());
graph_input_node.m_socket_accessor->RegisterOutput<float>(
socket_name,
nullptr);
}
}
// Save state in node resource
ImVec2 node_pos = ImNodes::GetNodeGridSpacePos(i);
node_resource.m_position[0] = node_pos[0];