0.4.1
Loading...
Searching...
No Matches
BlueprintNodeBuilder.hpp
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// LICENSE
3// This software is dual-licensed to the public domain and under the following
4// license: you are granted a perpetual, irrevocable license to copy, modify,
5// publish, and distribute this file as you see fit.
6//
7// CREDITS
8// Written by Michal Cichon
9//------------------------------------------------------------------------------
10#pragma once
11
12//------------------------------------------------------------------------------
13#include <imgui_node_editor.h>
14
15//------------------------------------------------------------------------------
17{
18//------------------------------------------------------------------------------
19
20/// @brief Node Builder class
22{
23 public:
24 /// @brief Constructor
25 /// @param[in] texture Pointer to the texture to use for the node
26 /// @param[in] textureWidth Width of the provided texture
27 /// @param[in] textureHeight Height of the provided texture
28 explicit BlueprintNodeBuilder(ImTextureID texture = nullptr, int textureWidth = 0, int textureHeight = 0);
29
30 /// @brief Begins building a node
31 /// @param[in] id Id of the node to build
32 void Begin(ax::NodeEditor::NodeId id);
33
34 /// @brief Ends building a node
35 void End();
36
37 /// @brief Begins building the header
38 /// @param[in] color Color of the header
39 void Header(const ImVec4& color = ImVec4(1, 1, 1, 1));
40
41 /// @brief Ends building the header
42 void EndHeader();
43
44 /// @brief Begins building an input pin
45 /// @param[in] id Id of the pin to build
46 void Input(ax::NodeEditor::PinId id);
47 /// @brief Ends building the input pin
48 static void EndInput();
49
50 /// @brief Begins building of the middle of the node
51 void Middle();
52
53 /// @brief Begins building an output pin
54 /// @param[in] id Id of the pin to build
55 void Output(ax::NodeEditor::PinId id);
56 /// @brief Ends building the output pin
57 static void EndOutput();
58
59 private:
60 /// @brief Stages in the build process
61 enum class Stage : uint8_t
62 {
63 Invalid, ///< Invalid stage
64 Begin, ///< Beginning of node construction
65 Header, ///< Currently building the header
66 Content, ///< Currently building the content
67 Input, ///< Currently building an input pin
68 Output, ///< Currently building an output pin
69 Middle, ///< Currently building the middle
70 End ///< End of node construction
71 };
72
73 /// @brief Set the stage of the node build process. Takes care of all the Layout elements
74 /// @param[in] stage Stage to set
75 /// @return True if stage was set correctly
76 bool SetStage(Stage stage);
77
78 /// @brief Begins building a pin
79 /// @param[in] id Id of the pin to build
80 /// @param[in] kind Kind of the pin (input/output)
81 static void Pin(ax::NodeEditor::PinId id, ax::NodeEditor::PinKind kind);
82 /// @brief Ends building the pin
83 static void EndPin();
84
85 ImTextureID HeaderTextureId; ///< @brief Pointer to the texture to use for the header
86 int HeaderTextureWidth; ///< Width of the header texture
87 int HeaderTextureHeight; ///< Height of the header texture
88 NodeId CurrentNodeId = 0; ///< Id of the node currently built
89 Stage CurrentStage = Stage::Invalid; ///< Current stage of the build process
90 ImU32 HeaderColor = IM_COL32(255, 255, 255, 0); ///< Color of the header
91 ImVec2 NodeMin; ///< Minimum size of the node
92 ImVec2 NodeMax; ///< Maximum size of the node
93 ImVec2 HeaderMin; ///< Minimum size of the header
94 ImVec2 HeaderMax; ///< Maximum size of the header
95 ImVec2 ContentMin; ///< Minimum size of the content
96 ImVec2 ContentMax; ///< Maximum size of the content
97 bool HasHeader = false; ///< Flag whether the node has a header
98};
99
100//------------------------------------------------------------------------------
101} // namespace ax::NodeEditor::Utilities
static void EndOutput()
Ends building the output pin.
NodeId CurrentNodeId
Id of the node currently built.
ImTextureID HeaderTextureId
Pointer to the texture to use for the header.
bool SetStage(Stage stage)
Set the stage of the node build process. Takes care of all the Layout elements.
void Output(ax::NodeEditor::PinId id)
Begins building an output pin.
void Begin(ax::NodeEditor::NodeId id)
Begins building a node.
void Middle()
Begins building of the middle of the node.
void Input(ax::NodeEditor::PinId id)
Begins building an input pin.
Stage CurrentStage
Current stage of the build process.
static void Pin(ax::NodeEditor::PinId id, ax::NodeEditor::PinKind kind)
Begins building a pin.
BlueprintNodeBuilder(ImTextureID texture=nullptr, int textureWidth=0, int textureHeight=0)
Constructor.
bool HasHeader
Flag whether the node has a header.
void Header(const ImVec4 &color=ImVec4(1, 1, 1, 1))
Begins building the header.
static void EndInput()
Ends building the input pin.