119 ax::NodeEditor::SetCurrentEditor(
context);
123 if (ImGui::ArrowButton(
"Play button", ImGuiDir_Right))
130 if (ImGui::Button(
"##Pause button", ImVec2(ImGui::GetFrameHeight(), ImGui::GetFrameHeight())))
135 const ImVec2 button_min_rect = ImGui::GetItemRectMin();
136 const ImVec2 button_size = ImGui::GetItemRectSize();
138 ImDrawList* draw_list = ImGui::GetWindowDrawList();
139 draw_list->AddRectFilled(
140 ImVec2(button_min_rect.x + 0.2f * button_size.x, button_min_rect.y + 0.1f * button_size.y),
141 ImVec2(button_min_rect.x + 0.4f * button_size.x, button_min_rect.y + 0.9f * button_size.y),
142 ImGui::GetColorU32(ImGuiCol_Text)
144 draw_list->AddRectFilled(
145 ImVec2(button_min_rect.x + 0.6f * button_size.x, button_min_rect.y + 0.1f * button_size.y),
146 ImVec2(button_min_rect.x + 0.8f * button_size.x, button_min_rect.y + 0.9f * button_size.y),
147 ImGui::GetColorU32(ImGuiCol_Text)
150 const bool disabled = !
paused;
153 ImGui::BeginDisabled();
156 if (ImGui::Button(
"##Step button", ImVec2(ImGui::GetFrameHeight(), ImGui::GetFrameHeight())))
162 const ImVec2 button_min_rect = ImGui::GetItemRectMin();
163 const ImVec2 button_size = ImGui::GetItemRectSize();
164 ImDrawList* draw_list = ImGui::GetWindowDrawList();
165 draw_list->AddRectFilled(
166 ImVec2(button_min_rect.x + 0.15f * button_size.x, button_min_rect.y + 0.2f * button_size.y),
167 ImVec2(button_min_rect.x + 0.3f * button_size.x, button_min_rect.y + 0.8f * button_size.y),
168 ImGui::GetColorU32(ImGuiCol_Text)
171 const ImVec2 triangle_center = ImVec2(button_min_rect.x + 0.7f * button_size.x, button_min_rect.y + 0.5f * button_size.y);
173 draw_list->AddTriangleFilled(
174 ImVec2(triangle_center.x + 0.205f * button_size.x, triangle_center.y),
175 ImVec2(triangle_center.x - 0.205f * button_size.x, triangle_center.y + 0.237f * button_size.y),
176 ImVec2(triangle_center.x - 0.205f * button_size.x, triangle_center.y - 0.237f * button_size.y),
177 ImGui::GetColorU32(ImGuiCol_Text)
181 ImGui::EndDisabled();
184 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_FlowDuration, 0.5f);
185 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_SelectedNodeBorderWidth, 10.0f);
188 ax::NodeEditor::PushStyleColor(ax::NodeEditor::StyleColor_PinRect, ImColor(0, 0, 0, 0));
189 ax::NodeEditor::PushStyleColor(ax::NodeEditor::StyleColor_Bg, ImColor(60, 60, 70, 100));
191 ax::NodeEditor::Begin(
"Behaviour");
194 for (
size_t i = 0; i <
nodes.size(); ++i)
200 if (
nodes[i]->width == 0.0f &&
nodes[i]->height == 0.0f)
202 const ImVec2 size = ax::NodeEditor::GetNodeSize(
nodes[i]->
id);
203 nodes[i]->width = size.x;
204 nodes[i]->height = size.y;
210 if (
nodes.size() > 1)
218 int current_link_id = 0;
219 for (
const std::unique_ptr<ImNode>& node :
nodes)
221 for (
size_t i = 0; i < node->out_attr_ids.size(); ++i)
223 if (!node->children[i]->visible)
227 ax::NodeEditor::Link(current_link_id++, node->out_attr_ids[i], node->children[i]->in_attr_id,
GetStatusColor(node->children[i]->status),
LINK_THICKNESS);
230 ax::NodeEditor::Flow(current_link_id - 1);
235 ax::NodeEditor::End();
238 const ImVec2 node_editor_min_rect = ImGui::GetItemRectMin();
239 const ImVec2 node_editor_max_rect = ImGui::GetItemRectMax();
240 ImDrawList* draw_list = ImGui::GetWindowDrawList();
242 node_editor_min_rect,
243 node_editor_max_rect,
248 ax::NodeEditor::PopStyleColor();
249 ax::NodeEditor::PopStyleColor();
250 ax::NodeEditor::PopStyleColor();
251 ax::NodeEditor::PopStyleColor();
252 ax::NodeEditor::PopStyleVar();
253 ax::NodeEditor::PopStyleVar();
255 if (
paused && ImGui::IsKeyPressed(ImGuiKey_F5))
260 if (
paused && ImGui::IsKeyPressed(ImGuiKey_F10))
266 ax::NodeEditor::SetCurrentEditor(
nullptr);
451 const ImVec2 mouse_pos = ImGui::GetMousePos();
452 const bool mouse_left_click = ImGui::IsMouseClicked(ImGuiMouseButton_Left);
454 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar::StyleVar_NodePadding, ImVec4(0, 4, 0, 8));
455 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar::StyleVar_NodeRounding, 4.0f);
456 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar::StyleVar_NodeBorderWidth, 0.0f);
458 ax::NodeEditor::BeginNode(node->
id);
462 ImGui::Dummy(ImVec2(1, 0));
464 ImGui::TextUnformatted(node->
name.c_str());
466 ImGui::Dummy(ImVec2(1, 0));
467 ImGui::Dummy(ImVec2(0, ax::NodeEditor::GetStyle().NodePadding.y));
469 const float title_bar_max_y = ImGui::GetItemRectMax().y;
470 const float title_bar_width = ImGui::GetItemRectSize().x;
476 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_PivotAlignment, ImVec2(0.0f, 0.5f));
477 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_PivotSize, ImVec2(0, 0));
478 ax::NodeEditor::BeginPin(node->
in_attr_id, ax::NodeEditor::PinKind::Input);
480 ImGui::Dummy(ImVec2(1, ImGui::GetTextLineHeight()));
482 const ImVec2 size = ImGui::GetItemRectSize();
483 ImDrawList* draw_list = ImGui::GetWindowDrawList();
484 const ImVec2 p = ImGui::GetCursorScreenPos();
487 ax::NodeEditor::EndPin();
488 ax::NodeEditor::PopStyleVar();
489 ax::NodeEditor::PopStyleVar();
492 float pins_width = ImGui::GetItemRectSize().x;
495 ImGui::TextUnformatted(node->
classname.c_str());
497 pins_width += ImGui::GetItemRectSize().x;
503 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_PivotAlignment, ImVec2(1.0f, 0.5f));
504 ax::NodeEditor::PushStyleVar(ax::NodeEditor::StyleVar_PivotSize, ImVec2(0, 0));
505 ax::NodeEditor::BeginPin(node->
out_attr_ids[i], ax::NodeEditor::PinKind::Output);
507 ImGui::Dummy(ImVec2(std::max(1.0f, std::max(
MIN_NODE_WIDTH - pins_width, title_bar_width - pins_width)), ImGui::GetTextLineHeight()));
508 const ImVec2 size = ImGui::GetItemRectSize();
510 ImDrawList* draw_list = ImGui::GetWindowDrawList();
511 ImVec2 p = ImGui::GetCursorScreenPos();
512 const ImVec2 circle_center(p.x + size.x, p.y - size.y + 0.5f *
PIN_RADIUS);
514 if (mouse_left_click &&
516 (mouse_pos.x - circle_center.x) * (mouse_pos.x - circle_center.x) +
517 (mouse_pos.y - circle_center.y) * (mouse_pos.y - circle_center.y)
533 ax::NodeEditor::EndPin();
534 ax::NodeEditor::PopStyleVar();
535 ax::NodeEditor::PopStyleVar();
539 ImGui::Dummy(ImVec2(std::max(1.0f, std::max(
MIN_NODE_WIDTH - pins_width, title_bar_width - pins_width)), ImGui::GetTextLineHeight()));
543 ax::NodeEditor::EndNode();
545 ImVec2 node_rect_min = ImGui::GetItemRectMin();
546 ImVec2 node_rect_max = ImGui::GetItemRectMax();
549 ImDrawList* draw_list = ax::NodeEditor::GetNodeBackgroundDrawList(node->
id);
551 draw_list->AddRectFilled(
552 ImVec2(node_rect_min.x, node_rect_min.y),
553 ImVec2(node_rect_max.x, title_bar_max_y),
555 ax::NodeEditor::GetStyle().NodeRounding,
556 ImDrawFlags_RoundCornersTop);
563 ax::NodeEditor::GetStyle().NodeRounding,
564 ImDrawFlags_RoundCornersAll,
568 ax::NodeEditor::PopStyleVar();
569 ax::NodeEditor::PopStyleVar();
570 ax::NodeEditor::PopStyleVar();
572 ax::NodeEditor::SetNodePosition(node->
id, ImVec2(node->
x, node->
y));
578 std::vector<ax::NodeEditor::NodeId> selected_nodes;
579 std::vector<ax::NodeEditor::LinkId> selected_links;
581 selected_nodes.resize(ax::NodeEditor::GetSelectedObjectCount());
582 selected_links.resize(ax::NodeEditor::GetSelectedObjectCount());
584 const int node_count = ax::NodeEditor::GetSelectedNodes(selected_nodes.data(),
static_cast<int>(selected_nodes.size()));
585 const int link_count = ax::NodeEditor::GetSelectedLinks(selected_links.data(),
static_cast<int>(selected_links.size()));
587 selected_nodes.resize(node_count);
588 selected_links.resize(link_count);
591 for (
const auto& nid : selected_nodes)
593 ax::NodeEditor::DeselectNode(nid);
595 for (
const auto& lid : selected_links)
597 ax::NodeEditor::DeselectLink(lid);
602 ax::NodeEditor::NavigateToSelection();
606 for (
const auto& nid : selected_nodes)
608 ax::NodeEditor::SelectNode(nid,
true);
610 for (
const auto& lid : selected_links)
612 ax::NodeEditor::SelectLink(lid,
true);
619 std::vector<std::unique_ptr<ImNode>> output;
626 int current_index = index;
633 output.back()->in_attr_id = current_index++;
638 const size_t this_node_index = output.size() - 1;
646 current_index +=
static_cast<int>(child_tree.size());
647 for (
size_t j = 0; j < child_tree.size(); ++j)
649 current_index += 1 +
static_cast<int>(child_tree[j]->children.size());
653 output[this_node_index]->out_attr_ids.push_back(current_index++);
656 child_tree.front()->parent = output[this_node_index].get();
657 output[this_node_index]->children.push_back(child_tree.front().get());
662 std::make_move_iterator(child_tree.begin()),
663 std::make_move_iterator(child_tree.end())