summaryrefslogtreecommitdiffstats
path: root/scene/gui/graph_node.cpp
blob: 96f8828efccb947061a25b33fa2d6ae00a73ced9 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "graph_node.h"


void GraphNode::_resort() {



	int sep=get_constant("separation");
	Ref<StyleBox> sb=get_stylebox("frame");
	bool first=true;

	Size2 minsize;

	for(int i=0;i<get_child_count();i++) {
		Control *c=get_child(i)->cast_to<Control>();
		if (!c || !c->is_visible())
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size=c->get_combined_minimum_size();

		minsize.y+=size.y;
		minsize.x=MAX(minsize.x,size.x);

		if (first)
			first=false;
		else
			minsize.y+=sep;

	}

	int vofs=0;
	int w = get_size().x - sb->get_minimum_size().x;


	for(int i=0;i<get_child_count();i++) {
		Control *c=get_child(i)->cast_to<Control>();
		if (!c || !c->is_visible())
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size=c->get_combined_minimum_size();

		Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y);

		fit_child_in_rect(c,r);


		if (vofs>0)
			vofs+=sep;
		vofs+=size.y;

	}

}


void GraphNode::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		Ref<StyleBox> sb=get_stylebox("frame");
		draw_style_box(sb,Rect2(Point2(),get_size()));
	}
	if (p_what==NOTIFICATION_SORT_CHILDREN) {

		_resort();
	}

}

void GraphNode::set_title(const String& p_title) {

	title=p_title;
	update();
}

String GraphNode::get_title() const {

	return title;
}

void GraphNode::set_slot(int p_idx,int p_type_left,int p_index_left,const Color& p_color_left, int p_type_right,int p_index_right,const Color& p_color_right) {

	ERR_FAIL_COND(p_idx<0);
	Slot s;
	s.type_left=p_type_left;
	s.color_left=p_color_left;
	s.index_left=p_index_left;
	s.type_right=p_type_right;
	s.color_right=p_color_right;
	s.index_right=p_index_right;
	slot_info[p_idx]=s;
	update();
}

void GraphNode::clear_slot(int p_idx){

	slot_info.erase(p_idx);
	update();
}
void GraphNode::clear_all_slots(){

	slot_info.clear();
	update();
}
int GraphNode::get_slot_type_left(int p_idx) const{

	if (!slot_info.has(p_idx))
		return TYPE_DISABLED;
	return slot_info[p_idx].type_left;

}
int GraphNode::get_slot_index_left(int p_idx) const{

	if (!slot_info.has(p_idx))
		return TYPE_DISABLED;
	return slot_info[p_idx].index_left;

}
Color GraphNode::get_slot_color_left(int p_idx) const{

	if (!slot_info.has(p_idx))
		return Color();
	return slot_info[p_idx].color_left;

}

int GraphNode::get_slot_type_right(int p_idx) const{

	if (!slot_info.has(p_idx))
		return TYPE_DISABLED;
	return slot_info[p_idx].type_right;

}
int GraphNode::get_slot_index_right(int p_idx) const{

	if (!slot_info.has(p_idx))
		return TYPE_DISABLED;
	return slot_info[p_idx].index_right;

}
Color GraphNode::get_slot_color_right(int p_idx) const{

	if (!slot_info.has(p_idx))
		return Color();
	return slot_info[p_idx].color_right;

}

Size2 GraphNode::get_minimum_size() const {

	int sep=get_constant("separation");
	Ref<StyleBox> sb=get_stylebox("frame");
	bool first=true;

	Size2 minsize;

	for(int i=0;i<get_child_count();i++) {

		Control *c=get_child(i)->cast_to<Control>();
		if (!c || !c->is_visible())
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size=c->get_combined_minimum_size();

		minsize.y+=size.y;
		minsize.x=MAX(minsize.x,size.x);

		if (first)
			first=false;
		else
			minsize.y+=sep;
	}

	return minsize+sb->get_minimum_size();
}


void GraphNode::_bind_methods() {


}

GraphNode::GraphNode()
{
}