Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeGraphShared.h
Go to the documentation of this file.
1#pragma once
2
3#include "../third_party/imgui/imgui.h"
4#include "../AI/BTGraphLayoutEngine.h"
5#include "../third_party/imnodes/imnodes.h"
6#include "../BlueprintEditor/NodeStyleRegistry.h"
7#include <algorithm>
8#include <string>
9
10namespace Olympe
11{
12 namespace NodeGraphShared
13 {
14 inline ImVec2 ComputePinCenterScreen(int nodeId, const BTNodeLayout* layout, bool isOutput, float pinOffset, float headerPx, float currentZoom)
15 {
16 ImVec2 nPos = ImNodes::GetNodeScreenSpacePos(nodeId);
17 ImVec2 nDim = ImNodes::GetNodeDimensions(nodeId);
18
19 // Clamp headerPx
20 float h = headerPx * currentZoom;
21 h = std::max(4.0f, std::min(h, nDim.y - 4.0f));
22 float pinY = nPos.y + h;
23
24 if (isOutput)
25 {
26 return ImVec2(nPos.x + nDim.x - pinOffset, pinY);
27 }
28 else
29 {
30 return ImVec2(nPos.x + pinOffset, pinY);
31 }
32 }
33
35 {
36 if (!drawList) return;
37 drawList->AddCircleFilled(center, radius + outlineThickness, outlineColor);
38 drawList->AddCircleFilled(center, radius, fillColor);
39 }
40
41 inline void RenderNodeHeader(int nodeId, const NodeStyle& style, const char* icon, const std::string& title, bool isCurrentNode, float pulseTimer)
42 {
43 // NOTE: Do not call BeginNode/BeginNodeTitleBar here. The caller
44 // (`RenderNodeVisual`) is responsible for opening the node and title
45 // bar scopes. Calling them here caused nested/duplicate scope
46 // transitions and assertion failures.
47
48 ImU32 headerColor = style.headerColor;
49 ImU32 headerHoveredColor = style.headerHoveredColor;
50 ImU32 headerSelectedColor = style.headerSelectedColor;
51
52 if (isCurrentNode)
53 {
54 float t = 0.5f + 0.5f * sinf(pulseTimer * 2.0f * 3.14159265f * 2.0f);
55 ImU32 r = static_cast<ImU32>(180 + static_cast<int>(t * 75.0f));
56 ImU32 g = static_cast<ImU32>(140 + static_cast<int>(t * 115.0f));
57 ImU32 b = static_cast<ImU32>(10);
58 headerColor = IM_COL32(r, g, b, 255);
59 headerHoveredColor = IM_COL32(r, g, b, 230);
60 headerSelectedColor = IM_COL32(r, g, b, 210);
61 }
62
63 ImNodes::PushColorStyle(ImNodesCol_TitleBar, headerColor);
64 ImNodes::PushColorStyle(ImNodesCol_TitleBarHovered, headerHoveredColor);
65 ImNodes::PushColorStyle(ImNodesCol_TitleBarSelected, headerSelectedColor);
66
67 if (icon && icon[0] != '\0')
68 ImGui::Text("%s %s", icon, title.c_str());
69 else
70 ImGui::TextUnformatted(title.c_str());
71
72 ImNodes::PopColorStyle();
73 ImNodes::PopColorStyle();
74 ImNodes::PopColorStyle();
75
76 // The caller must call EndNodeTitleBar().
77 }
78 }
79}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void DrawPinCircle(ImDrawList *drawList, const ImVec2 &center, float radius, ImU32 fillColor, ImU32 outlineColor, float outlineThickness)
void RenderNodeHeader(int nodeId, const NodeStyle &style, const char *icon, const std::string &title, bool isCurrentNode, float pulseTimer)
ImVec2 ComputePinCenterScreen(int nodeId, const BTNodeLayout *layout, bool isOutput, float pinOffset, float headerPx, float currentZoom)
Compute the screen-space center position of a pin.
< Provides AssetID and INVALID_ASSET_ID
Layout information for a single behavior tree node.
Visual descriptor for a single node type.
ImU32 headerColor
Title-bar background colour (ImNodes TitleBar colour slot).
ImU32 headerSelectedColor
Title-bar colour when the node is selected.
ImU32 headerHoveredColor
Title-bar colour when the node is hovered.