forked from jhergel/icesl-nodes
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnode.cpp
More file actions
116 lines (99 loc) · 3.77 KB
/
Copy pathnode.cpp
File metadata and controls
116 lines (99 loc) · 3.77 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
#include <LibSL/LibSL.h>
#include <LibSL/LibSL_gl.h>
#include "node.h"
#include "node_lua.h"
#include "imgui/imgui.h"
using namespace std;
void NodeWindow::displayNode(NodeSelecter& ns,bool mouseDown){
ImVec2 offsetGUI = ImVec2(size[0],size[1]);
ImGui::Begin(name.c_str(), &show,offsetGUI );
ImDrawList* draw_list = ImGui::GetWindowDrawList();
if(isNew){
ImVec2 posVec2 = ImVec2(pos[0],pos[1]);
ImVec2 sizeVec2 = ImVec2(size[0],size[1]);
ImGui::SetWindowPos(posVec2);
ImGui::SetWindowSize(sizeVec2);
isNew =false;
}
pos = v2i(ImGui::GetWindowPos().x,ImGui::GetWindowPos().y);
size = v2i(ImGui::GetWindowSize().x,ImGui::GetWindowSize().y);
for(auto st: node->getTweaks()){
st.second->drawUi();
}
ImGui::End();
ImColor color = ImColor(150,150,150,150);
v2i Mpos = v2i(ImGui::GetMousePos().x,ImGui::GetMousePos().y);
ForIndex(i,node->getInputName().size()){
v2i Cpos = v2i(GetInputSlotPos(i).x,GetInputSlotPos(i).y);
if(sqLength(Cpos-Mpos) < 100){
color =ImColor(150,0,0,150);
if(mouseDown){
if(!ns.inputHasBeenPicked){
ns.nodePickedInput.nodeWindow = this;
ns.nodePickedInput.pos = i;
ns.inputHasBeenPicked = true;
}
}
}
if(ns.nodePickedInput.nodeWindow == this && ns.nodePickedInput.pos == i)color =ImColor(0,150,0,150);
draw_list->AddCircleFilled(GetInputSlotPos(i), 10, color,64);
color = ImColor(150,150,150,150);
}
ForIndex(i,node->getoutputName().size()){
v2i Cpos = v2i(GetOutputSlotPos(i).x,GetOutputSlotPos(i).y);
if(sqLength(Cpos-Mpos) < 100){
color =ImColor(150,0,0,150);
if(mouseDown){
if(!ns.outputHasBeenPicked){
ns.nodePickedOutput.nodeWindow = this;
ns.nodePickedOutput.pos = i;
ns.outputHasBeenPicked = true;
}
}
}
if(ns.nodePickedOutput.nodeWindow == this && ns.nodePickedOutput.pos == i)color =ImColor(0,150,0,150);
draw_list->AddCircleFilled(GetOutputSlotPos(i), 10, color,64);
color = ImColor(150,150,150,150);
}
//Node* n = node;
ForIndex(i,previousConnectedWindow.size()){
NodeWindow* w= previousConnectedWindow[i];
if(w == nullptr)continue;
string s = node->getPrevNamed()[node->getInputName()[i]].second;
Node* n = w->node;
int outputSlot = n->getIndiceOutByName(s);
ImVec2 p1 = w->GetOutputSlotPos(outputSlot);//TODO
ImVec2 p2 = GetInputSlotPos(i);
ImVec2 p3 = ImVec2(p1.x+50,p1.y);
ImVec2 p4 = ImVec2(p2.x-50,p2.y);
draw_list->AddBezierCurve(p1, p3, p4, p2, ImColor(200,200,100), 3.0f);
}
if(ns.nodePickedInput.nodeWindow == this){
int pos = ns.nodePickedInput.pos;
ImVec2 p1 = GetInputSlotPos(pos);//TODO
ImVec2 p2 = ImGui::GetMousePos();
ImVec2 p3 = ImVec2(p1.x-50,p1.y);
ImVec2 p4 = ImVec2(p2.x+50,p2.y);
draw_list->AddBezierCurve(p1, p3, p4, p2, ImColor(200,200,100), 3.0f);
}
if(ns.nodePickedOutput.nodeWindow == this){
int pos = ns.nodePickedInput.pos;
ImVec2 p1 = GetOutputSlotPos(pos);//TODO
ImVec2 p2 = ImGui::GetMousePos();
ImVec2 p3 = ImVec2(p1.x+50,p1.y);
ImVec2 p4 = ImVec2(p2.x-50,p2.y);
draw_list->AddBezierCurve(p1, p3, p4, p2, ImColor(200,200,100), 3.0f);
}
}
void NodeWindow::connectPreviousWindow(NodeWindow* prev,int inpos,int outpos){
if(prev->node->isAscendent(node))return;
previousConnectedWindow[inpos] = prev;
Node* n = prev->node;
n->onChange();
node->connect(n,n->getoutputName()[outpos],inpos);
}
void NodeWindow::connectPreviousWindow(NodeWindow* prev,string in,string out){
int outpos = prev->node->getIndiceOutByName(out);
int inpos = this->node->getIndiceInByName(in);
connectPreviousWindow(prev,inpos,outpos);
}