forked from Nelarius/imnodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimnodes.h
More file actions
157 lines (132 loc) · 5.19 KB
/
imnodes.h
File metadata and controls
157 lines (132 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#include <stddef.h>
struct ImVec2;
namespace imnodes
{
enum ColorStyle
{
ColorStyle_NodeBackground = 0,
ColorStyle_NodeBackgroundHovered,
ColorStyle_NodeBackgroundSelected,
ColorStyle_NodeOutline,
ColorStyle_TitleBar,
ColorStyle_TitleBarHovered,
ColorStyle_TitleBarSelected,
ColorStyle_Link,
ColorStyle_LinkHovered,
ColorStyle_LinkSelected,
ColorStyle_Pin,
ColorStyle_PinHovered,
ColorStyle_PinOutline,
ColorStyle_GridBackground,
ColorStyle_GridLine,
ColorStyle_Count
};
// Flags for controlling how the nodes are rendered.
enum Flags
{
Flags_None = 0,
Flags_NodeOutline = 1 << 0,
Flags_PinOutline = 1 << 1
};
struct Style
{
// by default, set to Flags_NodeOutline | Flags_PinOutline
Flags flags;
// Set these mid-frame using Push/PopColorStyle. You can index this color
// array with with a ColorStyle enum value.
unsigned int colors[ColorStyle_Count];
};
// An editor context corresponds to a set of nodes in a single workspace
// (created with a single Begin/EndNodeEditor pair)
//
// By default, the library creates an editor context behind the scenes, so
// using any of the imnodes functions doesn't require you to explicitly create a
// context.
struct EditorContext;
EditorContext* EditorContextCreate();
void EditorContextFree(EditorContext*);
void EditorContextSet(EditorContext*);
// Initialize the node editor system.
void Initialize();
void Shutdown();
// Returns the global style struct. See the struct declaration for default
// values.
Style& GetStyle();
// Style presets matching the dear imgui styles of the same name.
void StyleColorsDark(); // on by default
void StyleColorsClassic();
void StyleColorsLight();
// The top-level function call. Call this before calling BeginNode/EndNode.
// Calling this function will result the node editor grid workspace being
// rendered.
void BeginNodeEditor();
void EndNodeEditor();
// Use PushColorStyle and PopColorStyle to modify Style::colors mid-frame.
void PushColorStyle(ColorStyle item, unsigned int color);
void PopColorStyle();
void BeginNode(int id);
void EndNode();
// Attributes are ImGui UI elements embedded within the node. Attributes have
// circular pins rendered next to them. Links are created between pins.
//
// Input and output attributes are otherwise the same, except that pins are
// rendered on the left of the node for input attributes, and on the right side
// for output attributes.
//
// The attribute ids must be unique.
void BeginInputAttribute(int id);
void BeginOutputAttribute(int id);
void EndAttribute();
// Render a link between attributes.
// The attributes ids used here must match the ids used in
// Begin(Input|Output)Attribute function calls. The order of start_attr and
// end_attr doesn't make a difference for rendering the link.
void Link(int id, int start_attr, int end_attr);
// Set's the node's position corresponding to the node id. You can even set the
// position before the node has been created with BeginNode().
void SetNodePos(int node_id, const ImVec2& pos);
// Set the node name corresponding to the node id. The node name is displayed in
// the node's title bar.
void SetNodeName(int node_id, const char* name);
// The following functions return true if a UI element is being hovered over by
// the mouse cursor. Assigns the id of the UI element being hovered over to the
// function argument. Use these functions after EndNodeEditor() has been called.
bool IsNodeHovered(int* node_id);
bool IsLinkHovered(int* link_id);
bool IsPinHovered(int* attribute_id);
// The following two functions return true if the UI element has been clicked.
// Use these functions after calling EndNodeEditor().
bool IsNodeSelected(int* node_id);
bool IsLinkSelected(int* link_id);
// Was the previous attribute active? This will continuously return true while
// the left mouse button is being pressed over the UI content of the attribute.
bool IsAttributeActive();
// Was any attribute active? If so, sets the active attribute id to the output
// function argument.
bool IsAnyAttributeActive(int* attribute_id = 0);
// The following functions should be used after calling EndNodeEditor().
//
// Is the user dragging a new link?
bool IsLinkStarted(int* started_at_attr);
// Did the user drop the new link before connecting it to a second attribute?
bool IsLinkDropped();
// Did the user create a new link?
bool IsLinkCreated(int* started_at_attr, int* ended_at_attr);
// Use the following functions to write the editor context's state to a string,
// or directly to a file. The editor context is serialized in the INI file
// format.
const char* SaveCurrentEditorStateToMemory(size_t* data_size = NULL);
const char* SaveEditorStateToMemory(
const EditorContext* editor,
size_t* data_size = NULL);
void LoadCurrentEditorStateFromMemory(const char* data, size_t data_size);
void LoadEditorStateFromMemory(
EditorContext* editor,
const char* data,
size_t data_size);
void SaveCurrentEditorStateToDisk(const char* file_name);
void SaveEditorStateToDisk(const EditorContext* editor, const char* file_name);
void LoadCurrentEditorStateFromDisk(const char* file_name);
void LoadEditorStateFromDisk(EditorContext* editor, const char* file_name);
} // namespace imnodes