From 0d0b181ebb2446bea72704b7d43c308fb80b88f1 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 15 Feb 2022 21:06:12 +0100 Subject: [PATCH] Unified handling of nodes in editor. --- src/AnimGraphEditor.cc | 116 +++++++++++++---------------------------- 1 file changed, 35 insertions(+), 81 deletions(-) diff --git a/src/AnimGraphEditor.cc b/src/AnimGraphEditor.cc index ccb6fce..de8cb42 100644 --- a/src/AnimGraphEditor.cc +++ b/src/AnimGraphEditor.cc @@ -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& 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( - 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& 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( - 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(); - ImGui::TextUnformatted(node_resource.m_type_name.c_str()); + 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( + 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( + socket_name, + nullptr); + } + } + // Save state in node resource ImVec2 node_pos = ImNodes::GetNodeGridSpacePos(i); node_resource.m_position[0] = node_pos[0];