82 inline const static ImColor Colors[COUNT] = {
83 ImColor(0xB9, 0xF5, 0x94)
84 , ImColor(0x8C, 0xC0, 0x8C)
85 , ImColor(0x37, 0x95, 0x85)
86 , ImColor(0xE3, 0x7D, 0xDC)
88 , ImColor(0xD2, 0xD5, 0xD3)
91 inline const static std::string TypeNames[COUNT] = {
100 PinDirection Direction;
106 ImVec2 Position = { 0, 0 };
110 std::string Title =
"Node";
111 ImColor Color = Pin::Colors[Pin::VECTOR];
117 std::vector<Pin> Inputs, Outputs;
118 bool DynamicInputs =
false;
129 ,
const std::string& title, ImColor color
130 ,
const std::vector<Pin>& inputs,
bool dyn_inputs
131 ,
const std::vector<Pin>& outputs
132 ,
bool constant =
false);
136 virtual void Inspect() = 0;
145 using Connection = std::pair<const PinPtr, PinPtr>;
146 using ConnectionMap = std::unordered_multimap<PinPtr, PinPtr, PinPtr::Hash>;
155 struct ContextMenuItem
158 ConstructorPtr Constructor;
164 std::vector<Node*> Nodes;
165 std::unordered_set<PinId> Erased;
166 ConnectionMap Connections;
169 GraphState(
const GraphState& other);
172 GraphState& operator=(
const GraphState& other);
175 using ContextMenuHierarchy = ocu::directed_tree<ContextMenuItem>;
176 using ContextID = ContextMenuHierarchy::node;
177 inline static ContextMenuHierarchy ContextMenu;
180 float CalculateWidth(
Node& node);
181 float CalculateHeight(
Node& node);
186 void DrawNode(
Node& node, NodeId
id);
187 void DrawPin(NodeId node_id,
Pin& pin, PinId pin_id, ImVec2 location,
bool input);
188 void DrawContextMenu();
191 void DrawConnections();
193 auto StartConnection(
const PinPtr& ptr) -> void;
194 void StopConnection();
195 void CreateConnection(
const PinPtr& a,
const PinPtr& b);
197 void EraseConnections(
const PinPtr& a);
199 NodeId AddNode(
Node* node);
200 void RemoveNode(NodeId
id);
203 void ClearClipboard();
205 void Paste(
const ImVec2& location);
206 void EraseSelection();
213 float BezierOffset(
const ImVec2& out,
const ImVec2& in);
214 bool AABB(
const ImVec2& a0,
const ImVec2& a1,
const ImVec2& b0,
const ImVec2& b1);
216 ImVec2 GridToScreen(
const ImVec2& position);
217 ImVec2 ScreenToGrid(
const ImVec2& position);
218 ImVec2 SnapToGrid(
const ImVec2& position);
229 static void Register(
const std::filesystem::path& path, ConstructorPtr constructor);
233 std::stack<GraphState> History;
239 ImColor BackgroundColor;
251 Line Border, SelectedBorder;
258 float BorderThickness;
280 float Rate, Smoothing;
287 ImVec2 Location, ScreenLocation, Delta;
289 bool ClickedSomething;
291 ocu::optional<NodeId> FocusedNode;
292 std::unordered_map<NodeId, ImVec2> Locks;
293 std::unordered_set<NodeId> DragSelect;
294 bool LocksDragged, NodeHovered;
295 ocu::optional<PinPtr> NewConnection;
296 std::unordered_set<NodeId> Selected;
307 std::vector<Node*> Nodes;
308 ConnectionMap Connections;
312 ImVec2 ContextMenuPosition;