-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVisualNodeSocket.h
More file actions
147 lines (111 loc) · 3.46 KB
/
Copy pathVisualNodeSocket.h
File metadata and controls
147 lines (111 loc) · 3.46 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
#pragma once
#include "VisualNodeCore.h"
namespace VisNodeSys
{
#define NODE_SOCKET_SIZE 5.0f
#define DEFAULT_NODE_SOCKET_COLOR ImColor(150, 150, 150)
#define DEFAULT_CONNECTION_COLOR ImColor(200, 200, 200)
#define DEFAULT_NODE_SOCKET_MOUSE_HOVERED_CONNECTION_COLOR ImColor(220, 220, 220)
class Node;
class VISUAL_NODE_SYSTEM_API NodeSocket
{
public:
enum class SocketFlow : uint8_t
{
Input = 0,
Output = 1
};
private:
friend class NodeSystem;
friend class NodeArea;
friend class SocketMirrorNode;
friend Node;
~NodeSocket() = default;
std::string ID;
SocketFlow Flow;
std::vector<std::string> AllowedTypes;
std::string Name;
std::vector<NodeSocket*> ConnectedSockets;
static std::unordered_map<std::string, ImColor> SocketTypeToColorAssociations;
std::function<void* ()> OutputData = []() { return nullptr; };
bool bCanBeDeletedByUser = true;
static void StripEmptyTypes(std::vector<std::string>& Types);
protected:
Node* Parent = nullptr;
public:
NodeSocket(Node* Parent, std::string Type, std::string Name, SocketFlow Flow = SocketFlow::Input, std::function<void* ()> OutputDataFunction = []() { return nullptr; });
NodeSocket(Node* Parent, std::vector<std::string> Types, std::string Name, SocketFlow Flow = SocketFlow::Input, std::function<void* ()> OutputDataFunction = []() { return nullptr; });
Node* GetParent() const;
const std::vector<NodeSocket*>& GetConnectedSockets() const;
std::string GetID() const;
std::string GetName() const;
void SetName(std::string NewValue);
SocketFlow GetFlowDirection() const;
const std::vector<std::string>& GetAllowedTypes() const;
// Returns true if change did not trigger disconnection of already connected sockets.
bool SetAllowedTypes(std::vector<std::string> NewTypes);
void SetFunctionToOutputData(std::function<void* ()> NewFunction);
void* GetData();
bool CanBeDeletedByUser() const;
void SetCanBeDeletedByUser(bool NewValue);
};
inline NodeSocket::SocketFlow operator!(NodeSocket::SocketFlow Direction)
{
return Direction == NodeSocket::SocketFlow::Input ? NodeSocket::SocketFlow::Output : NodeSocket::SocketFlow::Input;
}
struct ConnectionStyle
{
ImColor ForceColor = DEFAULT_CONNECTION_COLOR;
bool bMarchingAntsEffect = false;
float MarchingAntsSpeed = 1.0f;
bool bMarchingAntsReverseDirection = false;
bool bPulseEffect = false;
float PulseSpeed = 1.0f;
float PulseMin = 0.1f;
float PulseMax = 1.0f;
};
class NodeArea;
class Connection;
class RerouteNode
{
friend class NodeSystem;
friend class NodeArea;
friend class Connection;
friend Node;
std::string ID;
Connection* Parent = nullptr;
ImVec2 Position;
NodeSocket* BeginSocket = nullptr;
RerouteNode* BeginReroute = nullptr;
NodeSocket* EndSocket = nullptr;
RerouteNode* EndReroute = nullptr;
bool bHovered = false;
bool bSelected = false;
RerouteNode() {};
public:
std::string GetID() const { return ID; }
};
struct ConnectionSegment
{
ImVec2 Begin;
ImVec2 End;
NodeSocket* BeginSocket = nullptr;
RerouteNode* BeginReroute = nullptr;
NodeSocket* EndSocket = nullptr;
RerouteNode* EndReroute = nullptr;
};
class Connection
{
friend class NodeSystem;
friend class NodeArea;
friend Node;
NodeSocket* Out = nullptr;
NodeSocket* In = nullptr;
bool bHovered = false;
bool bSelected = false;
ConnectionStyle Style;
std::vector<RerouteNode*> RerouteNodes;
Connection(NodeSocket* Out, NodeSocket* In);
~Connection();
};
}