forked from Azzinoth/VisualNodeSystem-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomNodeStyleDemonstration.cpp
More file actions
133 lines (107 loc) · 4.18 KB
/
Copy pathCustomNodeStyleDemonstration.cpp
File metadata and controls
133 lines (107 loc) · 4.18 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
#include "CustomNodeStyleDemonstration.h"
using namespace VisNodeSys;
bool CustomNodeStyleDemonstration::isRegistered = []()
{
NODE_FACTORY.RegisterNodeType("CustomNodeStyleDemonstration",
[]() -> Node* {
return new CustomNodeStyleDemonstration();
},
[](const Node& CurrentNode) -> Node* {
const CustomNodeStyleDemonstration& NodeToCopy = static_cast<const CustomNodeStyleDemonstration&>(CurrentNode);
return new CustomNodeStyleDemonstration(NodeToCopy);
}
);
return true;
}();
CustomNodeStyleDemonstration::CustomNodeStyleDemonstration() : Node()
{
Type = "CustomNodeStyleDemonstration";
SetStyle(DEFAULT);
SetSize(ImVec2(160, 130));
SetName("Style Demonstration");
TitleBackgroundColor = ImColor(128, 117, 208);
TitleBackgroundColorHovered = ImColor(135, 145, 255);
// Socket type can be associated with color system wide.
NODE_SYSTEM.AssociateSocketTypeToColor("BOOL", ImColor(0,0,225));
NODE_SYSTEM.AssociateSocketTypeToColor("FLOAT", ImColor(0, 225, 0));
NODE_SYSTEM.AssociateSocketTypeToColor("MARCHING_ANT", ImColor(0, 225, 225));
AddSocket(new NodeSocket(this, "BOOL", "bool", false));
AddSocket(new NodeSocket(this, "FLOAT", "float", false));
AddSocket(new NodeSocket(this, "MARCHING_ANT", "ants", false));
AddSocket(new NodeSocket(this, "FADE_OUT", "fade", false));
AddSocket(new NodeSocket(this, "BOOL", "bool", true));
AddSocket(new NodeSocket(this, "FLOAT", "float", true));
AddSocket(new NodeSocket(this, "MARCHING_ANT", "ants", true));
AddSocket(new NodeSocket(this, "FADE_OUT", "fade", true));
}
CustomNodeStyleDemonstration::CustomNodeStyleDemonstration(const CustomNodeStyleDemonstration& Src) : Node(Src)
{
SetStyle(DEFAULT);
// Also individual socket connections could have unique styles.
ConnectionStyle CurrentStyle;
GetParentArea()->GetConnectionStyle(this, true, 2, CurrentStyle);
CurrentStyle.bMarchingAntsEffect = true;
GetParentArea()->SetConnectionStyle(this, true, 2, CurrentStyle);
GetParentArea()->GetConnectionStyle(this, true, 3, CurrentStyle);
CurrentStyle.bPulseEffect = true;
GetParentArea()->SetConnectionStyle(this, true, 3, CurrentStyle);
}
void CustomNodeStyleDemonstration::SetStyle(NODE_STYLE NewValue)
{
// Do nothing. We don't want to change style
}
void CustomNodeStyleDemonstration::Draw()
{
Node::Draw();
float Zoom = ParentArea->GetZoomFactor();
bool LocalBool = CouldBeMoved();
if (GetNodesConnectedToOutput().size() > 0)
{
ImVec2 NodePosition = ImGui::GetCursorScreenPos();
ConnectionStyle CurrentStyle;
GetParentArea()->GetConnectionStyle(this, true, 2, CurrentStyle);
ImGui::SetCursorScreenPos(NodePosition + ImVec2(70.0f, 70.0f) * Zoom);
if (ImGui::Checkbox("Reverse \ndirection", &bReverseDirection))
{
CurrentStyle.bMarchingAntsReverseDirection = bReverseDirection;
}
ImGui::SetCursorScreenPos(NodePosition + ImVec2(70.0f, 100.0f) * Zoom);
ImGui::Text("Speed:");
ImGui::SetCursorScreenPos(NodePosition + ImVec2(70.0f, 120.0f) * Zoom);
ImGui::SetNextItemWidth(70.0f * Zoom);
ImGui::SliderFloat("##Speed", &CurrentStyle.MarchingAntsSpeed, 0.01f, 10.0f);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("Speed of the marching ants effect");
ImGui::EndTooltip();
SetCouldBeMoved(false);
}
else
{
SetCouldBeMoved(true);
}
GetParentArea()->SetConnectionStyle(this, true, 2, CurrentStyle);
}
}
void CustomNodeStyleDemonstration::SocketEvent(NodeSocket* OwnSocket, NodeSocket* ConnectedSocket, NODE_SOCKET_EVENT EventType)
{
Node::SocketEvent(OwnSocket, ConnectedSocket, EventType);
if (EventType == CONNECTED)
{
// Also individual socket connections could have unique styles.
ConnectionStyle CurrentStyle;
GetParentArea()->GetConnectionStyle(this, true, 2, CurrentStyle);
CurrentStyle.bMarchingAntsEffect = true;
GetParentArea()->SetConnectionStyle(this, true, 2, CurrentStyle);
GetParentArea()->GetConnectionStyle(this, true, 3, CurrentStyle);
CurrentStyle.bPulseEffect = true;
GetParentArea()->SetConnectionStyle(this, true, 3, CurrentStyle);
}
}
bool CustomNodeStyleDemonstration::CanConnect(NodeSocket* OwnSocket, NodeSocket* CandidateSocket, char** MsgToUser)
{
if (!Node::CanConnect(OwnSocket, CandidateSocket, nullptr))
return false;
return true;
}