Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/graph_node.cpp
9903 views
1
/**************************************************************************/
2
/* graph_node.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "graph_node.h"
32
33
#include "scene/gui/box_container.h"
34
#include "scene/gui/graph_edit.h"
35
#include "scene/gui/label.h"
36
#include "scene/theme/theme_db.h"
37
38
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
39
String str = p_name;
40
41
if (!str.begins_with("slot/")) {
42
return false;
43
}
44
45
int idx = str.get_slicec('/', 1).to_int();
46
String slot_property_name = str.get_slicec('/', 2);
47
48
Slot slot;
49
if (slot_table.has(idx)) {
50
slot = slot_table[idx];
51
}
52
53
if (slot_property_name == "left_enabled") {
54
slot.enable_left = p_value;
55
} else if (slot_property_name == "left_type") {
56
slot.type_left = p_value;
57
} else if (slot_property_name == "left_icon") {
58
slot.custom_port_icon_left = p_value;
59
} else if (slot_property_name == "left_color") {
60
slot.color_left = p_value;
61
} else if (slot_property_name == "right_enabled") {
62
slot.enable_right = p_value;
63
} else if (slot_property_name == "right_type") {
64
slot.type_right = p_value;
65
} else if (slot_property_name == "right_color") {
66
slot.color_right = p_value;
67
} else if (slot_property_name == "right_icon") {
68
slot.custom_port_icon_right = p_value;
69
} else if (slot_property_name == "draw_stylebox") {
70
slot.draw_stylebox = p_value;
71
} else {
72
return false;
73
}
74
75
set_slot(idx,
76
slot.enable_left,
77
slot.type_left,
78
slot.color_left,
79
slot.enable_right,
80
slot.type_right,
81
slot.color_right,
82
slot.custom_port_icon_left,
83
slot.custom_port_icon_right,
84
slot.draw_stylebox);
85
86
queue_redraw();
87
return true;
88
}
89
90
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
91
String str = p_name;
92
93
if (!str.begins_with("slot/")) {
94
return false;
95
}
96
97
int idx = str.get_slicec('/', 1).to_int();
98
StringName slot_property_name = str.get_slicec('/', 2);
99
100
Slot slot;
101
if (slot_table.has(idx)) {
102
slot = slot_table[idx];
103
}
104
105
if (slot_property_name == "left_enabled") {
106
r_ret = slot.enable_left;
107
} else if (slot_property_name == "left_type") {
108
r_ret = slot.type_left;
109
} else if (slot_property_name == "left_color") {
110
r_ret = slot.color_left;
111
} else if (slot_property_name == "left_icon") {
112
r_ret = slot.custom_port_icon_left;
113
} else if (slot_property_name == "right_enabled") {
114
r_ret = slot.enable_right;
115
} else if (slot_property_name == "right_type") {
116
r_ret = slot.type_right;
117
} else if (slot_property_name == "right_color") {
118
r_ret = slot.color_right;
119
} else if (slot_property_name == "right_icon") {
120
r_ret = slot.custom_port_icon_right;
121
} else if (slot_property_name == "draw_stylebox") {
122
r_ret = slot.draw_stylebox;
123
} else {
124
return false;
125
}
126
127
return true;
128
}
129
130
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
131
int idx = 0;
132
for (int i = 0; i < get_child_count(false); i++) {
133
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
134
if (!child) {
135
continue;
136
}
137
138
String base = "slot/" + itos(idx) + "/";
139
140
p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
141
p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
142
p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
143
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "left_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
144
p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
145
p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
146
p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
147
p_list->push_back(PropertyInfo(Variant::OBJECT, base + "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
148
p_list->push_back(PropertyInfo(Variant::BOOL, base + "draw_stylebox"));
149
idx++;
150
}
151
}
152
153
void GraphNode::_resort() {
154
Size2 new_size = get_size();
155
Ref<StyleBox> sb_panel = theme_cache.panel;
156
Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
157
158
// Resort titlebar first.
159
Size2 titlebar_size = Size2(new_size.width, titlebar_hbox->get_size().height);
160
titlebar_size -= sb_titlebar->get_minimum_size();
161
Rect2 titlebar_rect = Rect2(sb_titlebar->get_offset(), titlebar_size);
162
fit_child_in_rect(titlebar_hbox, titlebar_rect);
163
164
// After resort, the children of the titlebar container may have changed their height (e.g. Label autowrap).
165
Size2i titlebar_min_size = titlebar_hbox->get_combined_minimum_size();
166
167
// First pass, determine minimum size AND amount of stretchable elements.
168
Ref<StyleBox> sb_slot = theme_cache.slot;
169
int separation = theme_cache.separation;
170
171
int children_count = 0;
172
int stretch_min = 0;
173
int available_stretch_space = 0;
174
float stretch_ratio_total = 0;
175
HashMap<Control *, _MinSizeCache> min_size_cache;
176
177
for (int i = 0; i < get_child_count(false); i++) {
178
Control *child = as_sortable_control(get_child(i, false));
179
if (!child) {
180
continue;
181
}
182
183
Size2i size = child->get_combined_minimum_size() + (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2());
184
185
stretch_min += size.height;
186
187
_MinSizeCache msc;
188
msc.min_size = size.height;
189
msc.will_stretch = child->get_v_size_flags().has_flag(SIZE_EXPAND);
190
msc.final_size = msc.min_size;
191
min_size_cache[child] = msc;
192
193
if (msc.will_stretch) {
194
available_stretch_space += msc.min_size;
195
stretch_ratio_total += child->get_stretch_ratio();
196
}
197
198
children_count++;
199
}
200
slot_count = children_count;
201
if (selected_slot >= slot_count) {
202
selected_slot = -1;
203
}
204
205
int stretch_max = new_size.height - (children_count - 1) * separation;
206
int stretch_diff = stretch_max - stretch_min;
207
208
// Avoid negative stretch space.
209
stretch_diff = MAX(stretch_diff, 0);
210
211
available_stretch_space += stretch_diff - sb_panel->get_margin(SIDE_BOTTOM) - sb_panel->get_margin(SIDE_TOP) - titlebar_min_size.height - sb_titlebar->get_minimum_size().height;
212
213
// Second pass, discard elements that can't be stretched, this will run while stretchable elements exist.
214
215
while (stretch_ratio_total > 0) {
216
// First of all, don't even be here if no stretchable objects exist.
217
bool refit_successful = true;
218
219
for (int i = 0; i < get_child_count(false); i++) {
220
Control *child = as_sortable_control(get_child(i, false));
221
if (!child) {
222
continue;
223
}
224
225
ERR_FAIL_COND(!min_size_cache.has(child));
226
_MinSizeCache &msc = min_size_cache[child];
227
228
if (msc.will_stretch) {
229
int final_pixel_size = available_stretch_space * child->get_stretch_ratio() / stretch_ratio_total;
230
if (final_pixel_size < msc.min_size) {
231
// If the available stretching area is too small for a Control,
232
// then remove it from stretching area.
233
msc.will_stretch = false;
234
stretch_ratio_total -= child->get_stretch_ratio();
235
refit_successful = false;
236
available_stretch_space -= msc.min_size;
237
msc.final_size = msc.min_size;
238
break;
239
} else {
240
msc.final_size = final_pixel_size;
241
}
242
}
243
}
244
245
if (refit_successful) {
246
break;
247
}
248
}
249
250
// Final pass, draw and stretch elements.
251
252
int ofs_y = sb_panel->get_margin(SIDE_TOP) + titlebar_min_size.height + sb_titlebar->get_minimum_size().height;
253
254
slot_y_cache.clear();
255
int width = new_size.width - sb_panel->get_minimum_size().width;
256
int valid_children_idx = 0;
257
for (int i = 0; i < get_child_count(false); i++) {
258
Control *child = as_sortable_control(get_child(i, false));
259
if (!child) {
260
continue;
261
}
262
263
_MinSizeCache &msc = min_size_cache[child];
264
265
if (valid_children_idx > 0) {
266
ofs_y += separation;
267
}
268
269
int from_y_pos = ofs_y;
270
int to_y_pos = ofs_y + msc.final_size;
271
272
// Adjust so the last valid child always fits perfect, compensating for numerical imprecision.
273
if (msc.will_stretch && valid_children_idx == children_count - 1) {
274
to_y_pos = new_size.height - sb_panel->get_margin(SIDE_BOTTOM);
275
}
276
277
int height = to_y_pos - from_y_pos;
278
float margin = sb_panel->get_margin(SIDE_LEFT) + (slot_table[i].draw_stylebox ? sb_slot->get_margin(SIDE_LEFT) : 0);
279
float final_width = width - (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size().x : 0);
280
Rect2 rect(margin, from_y_pos, final_width, height);
281
fit_child_in_rect(child, rect);
282
283
slot_y_cache.push_back(child->get_rect().position.y + child->get_rect().size.height * 0.5);
284
285
ofs_y = to_y_pos;
286
valid_children_idx++;
287
}
288
289
queue_accessibility_update();
290
queue_redraw();
291
port_pos_dirty = true;
292
emit_signal(SNAME("slot_sizes_changed"));
293
}
294
295
void GraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
296
if (GDVIRTUAL_CALL(_draw_port, p_slot_index, p_pos, p_left, p_color)) {
297
return;
298
}
299
300
Slot slot = slot_table[p_slot_index];
301
Ref<Texture2D> port_icon = p_left ? slot.custom_port_icon_left : slot.custom_port_icon_right;
302
303
Point2 icon_offset;
304
if (port_icon.is_null()) {
305
port_icon = theme_cache.port;
306
}
307
308
icon_offset = -port_icon->get_size() * 0.5;
309
port_icon->draw(get_canvas_item(), p_pos + icon_offset, p_color);
310
}
311
312
void GraphNode::_accessibility_action_slot(const Variant &p_data) {
313
CustomAccessibilityAction action = (CustomAccessibilityAction)p_data.operator int();
314
switch (action) {
315
case ACTION_CONNECT_INPUT: {
316
if (slot_table.has(selected_slot)) {
317
const Slot &slot = slot_table[selected_slot];
318
if (slot.enable_left) {
319
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
320
if (graph) {
321
for (int i = 0; i < left_port_cache.size(); i++) {
322
if (left_port_cache[i].slot_index == selected_slot) {
323
if (graph->is_keyboard_connecting()) {
324
graph->end_keyboard_connecting(this, i, -1);
325
} else {
326
graph->start_keyboard_connecting(this, i, -1);
327
}
328
queue_accessibility_update();
329
queue_redraw();
330
break;
331
}
332
}
333
}
334
}
335
}
336
} break;
337
338
case ACTION_CONNECT_OUTPUT: {
339
if (slot_table.has(selected_slot)) {
340
const Slot &slot = slot_table[selected_slot];
341
if (slot.enable_right) {
342
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
343
if (graph) {
344
for (int i = 0; i < right_port_cache.size(); i++) {
345
if (right_port_cache[i].slot_index == selected_slot) {
346
if (graph->is_keyboard_connecting()) {
347
graph->end_keyboard_connecting(this, -1, i);
348
} else {
349
graph->start_keyboard_connecting(this, -1, i);
350
}
351
queue_accessibility_update();
352
queue_redraw();
353
break;
354
}
355
}
356
}
357
}
358
}
359
} break;
360
361
case ACTION_FOLLOW_INPUT: {
362
if (slot_table.has(selected_slot)) {
363
const Slot &slot = slot_table[selected_slot];
364
if (slot.enable_left) {
365
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
366
if (graph) {
367
for (int i = 0; i < left_port_cache.size(); i++) {
368
if (left_port_cache[i].slot_index == selected_slot) {
369
GraphNode *target = graph->get_input_connection_target(get_name(), i);
370
if (target) {
371
target->grab_focus();
372
break;
373
}
374
}
375
}
376
}
377
}
378
}
379
} break;
380
381
case ACTION_FOLLOW_OUTPUT: {
382
if (slot_table.has(selected_slot)) {
383
const Slot &slot = slot_table[selected_slot];
384
if (slot.enable_right) {
385
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
386
if (graph) {
387
for (int i = 0; i < right_port_cache.size(); i++) {
388
if (right_port_cache[i].slot_index == selected_slot) {
389
GraphNode *target = graph->get_output_connection_target(get_name(), i);
390
if (target) {
391
target->grab_focus();
392
break;
393
}
394
}
395
}
396
}
397
}
398
}
399
} break;
400
}
401
}
402
403
void GraphNode::gui_input(const Ref<InputEvent> &p_event) {
404
ERR_FAIL_COND(p_event.is_null());
405
if (port_pos_dirty) {
406
_port_pos_update();
407
}
408
409
if (p_event->is_pressed() && slot_count > 0) {
410
bool ac_enabled = get_tree() && get_tree()->is_accessibility_enabled();
411
if ((ac_enabled && slots_focus_mode == Control::FOCUS_ACCESSIBILITY) || slots_focus_mode == Control::FOCUS_ALL) {
412
if (p_event->is_action("ui_up", true)) {
413
selected_slot--;
414
if (selected_slot < 0) {
415
selected_slot = -1;
416
} else {
417
accept_event();
418
}
419
} else if (p_event->is_action("ui_down", true)) {
420
selected_slot++;
421
if (selected_slot >= slot_count) {
422
selected_slot = -1;
423
} else {
424
accept_event();
425
}
426
}
427
}
428
if (p_event->is_action("ui_cancel", true)) {
429
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
430
if (graph && graph->is_keyboard_connecting()) {
431
graph->force_connection_drag_end();
432
accept_event();
433
}
434
} else if (p_event->is_action("ui_graph_delete", true)) {
435
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
436
if (graph && graph->is_keyboard_connecting()) {
437
graph->end_keyboard_connecting(this, -1, -1);
438
accept_event();
439
}
440
} else if (p_event->is_action("ui_graph_follow_left", true)) {
441
if (slot_table.has(selected_slot)) {
442
const Slot &slot = slot_table[selected_slot];
443
if (slot.enable_left) {
444
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
445
if (graph) {
446
for (int i = 0; i < left_port_cache.size(); i++) {
447
if (left_port_cache[i].slot_index == selected_slot) {
448
GraphNode *target = graph->get_input_connection_target(get_name(), i);
449
if (target) {
450
target->grab_focus();
451
accept_event();
452
break;
453
}
454
}
455
}
456
}
457
}
458
}
459
} else if (p_event->is_action("ui_graph_follow_right", true)) {
460
if (slot_table.has(selected_slot)) {
461
const Slot &slot = slot_table[selected_slot];
462
if (slot.enable_right) {
463
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
464
if (graph) {
465
for (int i = 0; i < right_port_cache.size(); i++) {
466
if (right_port_cache[i].slot_index == selected_slot) {
467
GraphNode *target = graph->get_output_connection_target(get_name(), i);
468
if (target) {
469
target->grab_focus();
470
accept_event();
471
break;
472
}
473
}
474
}
475
}
476
}
477
}
478
} else if (p_event->is_action("ui_left", true)) {
479
if (slot_table.has(selected_slot)) {
480
const Slot &slot = slot_table[selected_slot];
481
if (slot.enable_left) {
482
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
483
if (graph) {
484
for (int i = 0; i < left_port_cache.size(); i++) {
485
if (left_port_cache[i].slot_index == selected_slot) {
486
if (graph->is_keyboard_connecting()) {
487
graph->end_keyboard_connecting(this, i, -1);
488
} else {
489
graph->start_keyboard_connecting(this, i, -1);
490
}
491
accept_event();
492
break;
493
}
494
}
495
}
496
}
497
}
498
} else if (p_event->is_action("ui_right", true)) {
499
if (slot_table.has(selected_slot)) {
500
const Slot &slot = slot_table[selected_slot];
501
if (slot.enable_right) {
502
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
503
if (graph) {
504
for (int i = 0; i < right_port_cache.size(); i++) {
505
if (right_port_cache[i].slot_index == selected_slot) {
506
if (graph->is_keyboard_connecting()) {
507
graph->end_keyboard_connecting(this, -1, i);
508
} else {
509
graph->start_keyboard_connecting(this, -1, i);
510
}
511
accept_event();
512
break;
513
}
514
}
515
}
516
}
517
}
518
} else if (p_event->is_action("ui_accept", true)) {
519
if (slot_table.has(selected_slot)) {
520
int idx = 0;
521
for (int i = 0; i < get_child_count(false); i++) {
522
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
523
if (!child) {
524
continue;
525
}
526
if (idx == selected_slot) {
527
selected_slot = -1;
528
child->grab_focus();
529
break;
530
}
531
idx++;
532
}
533
accept_event();
534
}
535
}
536
queue_accessibility_update();
537
queue_redraw();
538
}
539
540
GraphElement::gui_input(p_event);
541
}
542
543
void GraphNode::_notification(int p_what) {
544
switch (p_what) {
545
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
546
RID ae = get_accessibility_element();
547
ERR_FAIL_COND(ae.is_null());
548
549
String name = get_accessibility_name();
550
if (name.is_empty()) {
551
name = get_name();
552
}
553
name = vformat(ETR("graph node %s (%s)"), name, get_title());
554
555
if (slot_table.has(selected_slot)) {
556
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
557
Dictionary type_info;
558
if (graph) {
559
type_info = graph->get_type_names();
560
}
561
const Slot &slot = slot_table[selected_slot];
562
name += ", " + vformat(ETR("slot %d of %d"), selected_slot + 1, slot_count);
563
if (slot.enable_left) {
564
if (type_info.has(slot.type_left)) {
565
name += "," + vformat(ETR("input port, type: %s"), type_info[slot.type_left]);
566
} else {
567
name += "," + vformat(ETR("input port, type: %d"), slot.type_left);
568
}
569
if (graph) {
570
for (int i = 0; i < left_port_cache.size(); i++) {
571
if (left_port_cache[i].slot_index == selected_slot) {
572
String cd = graph->get_connections_description(get_name(), i);
573
if (cd.is_empty()) {
574
name += " " + ETR("no connections");
575
} else {
576
name += " " + cd;
577
}
578
break;
579
}
580
}
581
}
582
}
583
if (slot.enable_left) {
584
if (type_info.has(slot.type_right)) {
585
name += "," + vformat(ETR("output port, type: %s"), type_info[slot.type_right]);
586
} else {
587
name += "," + vformat(ETR("output port, type: %d"), slot.type_right);
588
}
589
if (graph) {
590
for (int i = 0; i < right_port_cache.size(); i++) {
591
if (right_port_cache[i].slot_index == selected_slot) {
592
String cd = graph->get_connections_description(get_name(), i);
593
if (cd.is_empty()) {
594
name += " " + ETR("no connections");
595
} else {
596
name += " " + cd;
597
}
598
break;
599
}
600
}
601
}
602
}
603
if (graph && graph->is_keyboard_connecting()) {
604
name += ", " + ETR("currently selecting target port");
605
}
606
} else {
607
name += ", " + vformat(ETR("has %d slots"), slot_count);
608
}
609
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_LIST);
610
DisplayServer::get_singleton()->accessibility_update_set_name(ae, name);
611
DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_CONNECT_INPUT, ETR("Edit Input Port Connection"));
612
DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_CONNECT_OUTPUT, ETR("Edit Output Port Connection"));
613
DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_FOLLOW_INPUT, ETR("Follow Input Port Connection"));
614
DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_FOLLOW_OUTPUT, ETR("Follow Output Port Connection"));
615
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CUSTOM, callable_mp(this, &GraphNode::_accessibility_action_slot));
616
} break;
617
case NOTIFICATION_FOCUS_EXIT: {
618
selected_slot = -1;
619
queue_redraw();
620
} break;
621
case NOTIFICATION_DRAW: {
622
// Used for layout calculations.
623
Ref<StyleBox> sb_panel = theme_cache.panel;
624
Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
625
// Used for drawing.
626
Ref<StyleBox> sb_to_draw_panel = selected ? theme_cache.panel_selected : theme_cache.panel;
627
Ref<StyleBox> sb_to_draw_titlebar = selected ? theme_cache.titlebar_selected : theme_cache.titlebar;
628
629
Ref<StyleBox> sb_slot = theme_cache.slot;
630
Ref<StyleBox> sb_slot_selected = theme_cache.slot_selected;
631
632
int port_h_offset = theme_cache.port_h_offset;
633
634
Rect2 titlebar_rect(Point2(), titlebar_hbox->get_size() + sb_titlebar->get_minimum_size());
635
Size2 body_size = get_size();
636
titlebar_rect.size.width = body_size.width;
637
body_size.height -= titlebar_rect.size.height;
638
Rect2 body_rect(0, titlebar_rect.size.height, body_size.width, body_size.height);
639
640
// Draw body (slots area) stylebox.
641
draw_style_box(sb_to_draw_panel, body_rect);
642
643
// Draw title bar stylebox above.
644
draw_style_box(sb_to_draw_titlebar, titlebar_rect);
645
646
int width = get_size().width - sb_panel->get_minimum_size().x;
647
648
// Take the HboxContainer child into account.
649
if (get_child_count(false) > 0) {
650
int slot_index = 0;
651
for (const KeyValue<int, Slot> &E : slot_table) {
652
if (E.key < 0 || E.key >= slot_y_cache.size()) {
653
continue;
654
}
655
if (!slot_table.has(E.key)) {
656
continue;
657
}
658
const Slot &slot = slot_table[E.key];
659
660
// Left port.
661
if (slot.enable_left) {
662
draw_port(slot_index, Point2i(port_h_offset, slot_y_cache[E.key]), true, slot.color_left);
663
}
664
665
// Right port.
666
if (slot.enable_right) {
667
draw_port(slot_index, Point2i(get_size().x - port_h_offset, slot_y_cache[E.key]), false, slot.color_right);
668
}
669
670
if (slot_index == selected_slot) {
671
Ref<Texture2D> port_icon = slot.custom_port_icon_left;
672
if (port_icon.is_null()) {
673
port_icon = theme_cache.port;
674
}
675
Size2i port_sz = port_icon->get_size() + sb_slot_selected->get_minimum_size();
676
draw_style_box(sb_slot_selected, Rect2i(port_h_offset - port_sz.x * 0.5, slot_y_cache[E.key] - port_sz.y * 0.5, port_sz.x, port_sz.y));
677
port_icon = slot.custom_port_icon_right;
678
if (port_icon.is_null()) {
679
port_icon = theme_cache.port;
680
}
681
port_sz = port_icon->get_size() + sb_slot_selected->get_minimum_size();
682
draw_style_box(sb_slot_selected, Rect2i(get_size().x - port_h_offset - port_sz.x * 0.5, slot_y_cache[E.key] - port_sz.y * 0.5, port_sz.x, port_sz.y));
683
}
684
685
// Draw slot stylebox.
686
if (slot.draw_stylebox) {
687
Control *child = Object::cast_to<Control>(get_child(E.key, false));
688
if (!child || !child->is_visible_in_tree()) {
689
continue;
690
}
691
Rect2 child_rect = child->get_rect();
692
child_rect.position.x = sb_panel->get_margin(SIDE_LEFT);
693
child_rect.size.width = width;
694
draw_style_box(sb_slot, child_rect);
695
}
696
697
slot_index++;
698
}
699
}
700
701
if (resizable) {
702
draw_texture(theme_cache.resizer, get_size() - theme_cache.resizer->get_size(), theme_cache.resizer_color);
703
}
704
} break;
705
}
706
}
707
708
void GraphNode::set_slot(int p_slot_index, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left, const Ref<Texture2D> &p_custom_right, bool p_draw_stylebox) {
709
ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set slot with index (%d) lesser than zero.", p_slot_index));
710
711
if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) &&
712
!p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1) &&
713
p_custom_left.is_null() && p_custom_right.is_null()) {
714
slot_table.erase(p_slot_index);
715
return;
716
}
717
718
Slot slot;
719
slot.enable_left = p_enable_left;
720
slot.type_left = p_type_left;
721
slot.color_left = p_color_left;
722
slot.enable_right = p_enable_right;
723
slot.type_right = p_type_right;
724
slot.color_right = p_color_right;
725
slot.custom_port_icon_left = p_custom_left;
726
slot.custom_port_icon_right = p_custom_right;
727
slot.draw_stylebox = p_draw_stylebox;
728
slot_table[p_slot_index] = slot;
729
730
queue_accessibility_update();
731
queue_redraw();
732
port_pos_dirty = true;
733
734
emit_signal(SNAME("slot_updated"), p_slot_index);
735
}
736
737
void GraphNode::clear_slot(int p_slot_index) {
738
slot_table.erase(p_slot_index);
739
740
queue_accessibility_update();
741
queue_redraw();
742
port_pos_dirty = true;
743
}
744
745
void GraphNode::clear_all_slots() {
746
slot_table.clear();
747
748
queue_accessibility_update();
749
queue_redraw();
750
port_pos_dirty = true;
751
}
752
753
bool GraphNode::is_slot_enabled_left(int p_slot_index) const {
754
if (!slot_table.has(p_slot_index)) {
755
return false;
756
}
757
return slot_table[p_slot_index].enable_left;
758
}
759
760
void GraphNode::set_slot_enabled_left(int p_slot_index, bool p_enable) {
761
ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set enable_left for the slot with index (%d) lesser than zero.", p_slot_index));
762
763
if (slot_table[p_slot_index].enable_left == p_enable) {
764
return;
765
}
766
767
slot_table[p_slot_index].enable_left = p_enable;
768
769
queue_accessibility_update();
770
queue_redraw();
771
port_pos_dirty = true;
772
773
emit_signal(SNAME("slot_updated"), p_slot_index);
774
}
775
776
void GraphNode::set_slot_type_left(int p_slot_index, int p_type) {
777
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set type_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
778
779
if (slot_table[p_slot_index].type_left == p_type) {
780
return;
781
}
782
783
slot_table[p_slot_index].type_left = p_type;
784
785
queue_accessibility_update();
786
queue_redraw();
787
port_pos_dirty = true;
788
789
emit_signal(SNAME("slot_updated"), p_slot_index);
790
}
791
792
int GraphNode::get_slot_type_left(int p_slot_index) const {
793
if (!slot_table.has(p_slot_index)) {
794
return 0;
795
}
796
return slot_table[p_slot_index].type_left;
797
}
798
799
void GraphNode::set_slot_color_left(int p_slot_index, const Color &p_color) {
800
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set color_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
801
802
if (slot_table[p_slot_index].color_left == p_color) {
803
return;
804
}
805
806
slot_table[p_slot_index].color_left = p_color;
807
queue_redraw();
808
port_pos_dirty = true;
809
810
emit_signal(SNAME("slot_updated"), p_slot_index);
811
}
812
813
Color GraphNode::get_slot_color_left(int p_slot_index) const {
814
if (!slot_table.has(p_slot_index)) {
815
return Color(1, 1, 1, 1);
816
}
817
return slot_table[p_slot_index].color_left;
818
}
819
820
void GraphNode::set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
821
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set custom_port_icon_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
822
823
if (slot_table[p_slot_index].custom_port_icon_left == p_custom_icon) {
824
return;
825
}
826
827
slot_table[p_slot_index].custom_port_icon_left = p_custom_icon;
828
queue_redraw();
829
port_pos_dirty = true;
830
831
emit_signal(SNAME("slot_updated"), p_slot_index);
832
}
833
834
Ref<Texture2D> GraphNode::get_slot_custom_icon_left(int p_slot_index) const {
835
if (!slot_table.has(p_slot_index)) {
836
return Ref<Texture2D>();
837
}
838
return slot_table[p_slot_index].custom_port_icon_left;
839
}
840
841
bool GraphNode::is_slot_enabled_right(int p_slot_index) const {
842
if (!slot_table.has(p_slot_index)) {
843
return false;
844
}
845
return slot_table[p_slot_index].enable_right;
846
}
847
848
void GraphNode::set_slot_enabled_right(int p_slot_index, bool p_enable) {
849
ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set enable_right for the slot with index (%d) lesser than zero.", p_slot_index));
850
851
if (slot_table[p_slot_index].enable_right == p_enable) {
852
return;
853
}
854
855
slot_table[p_slot_index].enable_right = p_enable;
856
857
queue_accessibility_update();
858
queue_redraw();
859
port_pos_dirty = true;
860
861
emit_signal(SNAME("slot_updated"), p_slot_index);
862
}
863
864
void GraphNode::set_slot_type_right(int p_slot_index, int p_type) {
865
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set type_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
866
867
if (slot_table[p_slot_index].type_right == p_type) {
868
return;
869
}
870
871
slot_table[p_slot_index].type_right = p_type;
872
873
queue_accessibility_update();
874
queue_redraw();
875
port_pos_dirty = true;
876
877
emit_signal(SNAME("slot_updated"), p_slot_index);
878
}
879
880
int GraphNode::get_slot_type_right(int p_slot_index) const {
881
if (!slot_table.has(p_slot_index)) {
882
return 0;
883
}
884
return slot_table[p_slot_index].type_right;
885
}
886
887
void GraphNode::set_slot_color_right(int p_slot_index, const Color &p_color) {
888
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set color_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
889
890
if (slot_table[p_slot_index].color_right == p_color) {
891
return;
892
}
893
894
slot_table[p_slot_index].color_right = p_color;
895
queue_redraw();
896
port_pos_dirty = true;
897
898
emit_signal(SNAME("slot_updated"), p_slot_index);
899
}
900
901
Color GraphNode::get_slot_color_right(int p_slot_index) const {
902
if (!slot_table.has(p_slot_index)) {
903
return Color(1, 1, 1, 1);
904
}
905
return slot_table[p_slot_index].color_right;
906
}
907
908
void GraphNode::set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
909
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set custom_port_icon_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
910
911
if (slot_table[p_slot_index].custom_port_icon_right == p_custom_icon) {
912
return;
913
}
914
915
slot_table[p_slot_index].custom_port_icon_right = p_custom_icon;
916
queue_redraw();
917
port_pos_dirty = true;
918
919
emit_signal(SNAME("slot_updated"), p_slot_index);
920
}
921
922
Ref<Texture2D> GraphNode::get_slot_custom_icon_right(int p_slot_index) const {
923
if (!slot_table.has(p_slot_index)) {
924
return Ref<Texture2D>();
925
}
926
return slot_table[p_slot_index].custom_port_icon_right;
927
}
928
929
bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const {
930
if (!slot_table.has(p_slot_index)) {
931
return false;
932
}
933
return slot_table[p_slot_index].draw_stylebox;
934
}
935
936
void GraphNode::set_slot_draw_stylebox(int p_slot_index, bool p_enable) {
937
ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set draw_stylebox for the slot with p_index (%d) lesser than zero.", p_slot_index));
938
939
slot_table[p_slot_index].draw_stylebox = p_enable;
940
queue_redraw();
941
port_pos_dirty = true;
942
943
emit_signal(SNAME("slot_updated"), p_slot_index);
944
}
945
946
void GraphNode::set_ignore_invalid_connection_type(bool p_ignore) {
947
ignore_invalid_connection_type = p_ignore;
948
}
949
950
bool GraphNode::is_ignoring_valid_connection_type() const {
951
return ignore_invalid_connection_type;
952
}
953
954
Size2 GraphNode::get_minimum_size() const {
955
Ref<StyleBox> sb_panel = theme_cache.panel;
956
Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
957
Ref<StyleBox> sb_slot = theme_cache.slot;
958
959
int separation = theme_cache.separation;
960
Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size();
961
962
for (int i = 0; i < get_child_count(false); i++) {
963
Control *child = as_sortable_control(get_child(i, false));
964
if (!child) {
965
continue;
966
}
967
968
Size2i size = child->get_combined_minimum_size();
969
size.width += sb_panel->get_minimum_size().width;
970
if (slot_table.has(i)) {
971
size += slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2();
972
}
973
974
minsize.height += size.height;
975
minsize.width = MAX(minsize.width, size.width);
976
977
if (i > 0) {
978
minsize.height += separation;
979
}
980
}
981
982
minsize.height += sb_panel->get_minimum_size().height;
983
984
return minsize;
985
}
986
987
void GraphNode::_port_pos_update() {
988
int edgeofs = theme_cache.port_h_offset;
989
int separation = theme_cache.separation;
990
991
// This helps to immediately achieve the initial y "original point" of the slots, which the sum of the titlebar height and the top margin of the panel.
992
int vertical_ofs = titlebar_hbox->get_size().height + theme_cache.titlebar->get_minimum_size().height + theme_cache.panel->get_margin(SIDE_TOP);
993
994
left_port_cache.clear();
995
right_port_cache.clear();
996
997
slot_count = 0; // Reset the slot count, which is the index of the current slot.
998
999
for (int i = 0; i < get_child_count(false); i++) {
1000
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::VISIBLE_IN_TREE);
1001
if (!child) {
1002
continue;
1003
}
1004
1005
Size2 size = child->get_size();
1006
1007
if (slot_table.has(slot_count)) {
1008
const Slot &slot = slot_table[slot_count];
1009
1010
int port_y;
1011
1012
// Check if it is using resort layout (e.g. Shader Graph nodes slots).
1013
if (slot_y_cache.is_empty()) {
1014
port_y = vertical_ofs + size.height * 0.5; // The y centor is calculated from the widget position.
1015
} else {
1016
port_y = child->get_position().y + size.height * 0.5; // The y centor is calculated from the class object position.
1017
}
1018
1019
if (slot.enable_left) {
1020
PortCache port_cache_left{ Point2i(edgeofs, port_y), slot_count, slot.type_left, slot.color_left };
1021
left_port_cache.push_back(port_cache_left);
1022
}
1023
if (slot.enable_right) {
1024
PortCache port_cache_right{ Point2i(get_size().width - edgeofs, port_y), slot_count, slot.type_right, slot.color_right };
1025
right_port_cache.push_back(port_cache_right);
1026
}
1027
}
1028
vertical_ofs += size.height + separation; // Add the height of the child and the separation to the vertical offset.
1029
slot_count++; // Go to the next slot
1030
}
1031
1032
if (selected_slot >= slot_count) {
1033
selected_slot = -1;
1034
}
1035
1036
port_pos_dirty = false;
1037
}
1038
1039
int GraphNode::get_input_port_count() {
1040
if (port_pos_dirty) {
1041
_port_pos_update();
1042
}
1043
1044
return left_port_cache.size();
1045
}
1046
1047
int GraphNode::get_output_port_count() {
1048
if (port_pos_dirty) {
1049
_port_pos_update();
1050
}
1051
1052
return right_port_cache.size();
1053
}
1054
1055
Vector2 GraphNode::get_input_port_position(int p_port_idx) {
1056
if (port_pos_dirty) {
1057
_port_pos_update();
1058
}
1059
1060
ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Vector2());
1061
Vector2 pos = left_port_cache[p_port_idx].pos;
1062
return pos;
1063
}
1064
1065
int GraphNode::get_input_port_type(int p_port_idx) {
1066
if (port_pos_dirty) {
1067
_port_pos_update();
1068
}
1069
1070
ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), 0);
1071
return left_port_cache[p_port_idx].type;
1072
}
1073
1074
Color GraphNode::get_input_port_color(int p_port_idx) {
1075
if (port_pos_dirty) {
1076
_port_pos_update();
1077
}
1078
1079
ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Color());
1080
return left_port_cache[p_port_idx].color;
1081
}
1082
1083
int GraphNode::get_input_port_slot(int p_port_idx) {
1084
if (port_pos_dirty) {
1085
_port_pos_update();
1086
}
1087
1088
ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), -1);
1089
return left_port_cache[p_port_idx].slot_index;
1090
}
1091
1092
Vector2 GraphNode::get_output_port_position(int p_port_idx) {
1093
if (port_pos_dirty) {
1094
_port_pos_update();
1095
}
1096
1097
ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Vector2());
1098
Vector2 pos = right_port_cache[p_port_idx].pos;
1099
return pos;
1100
}
1101
1102
int GraphNode::get_output_port_type(int p_port_idx) {
1103
if (port_pos_dirty) {
1104
_port_pos_update();
1105
}
1106
1107
ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), 0);
1108
return right_port_cache[p_port_idx].type;
1109
}
1110
1111
Color GraphNode::get_output_port_color(int p_port_idx) {
1112
if (port_pos_dirty) {
1113
_port_pos_update();
1114
}
1115
1116
ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Color());
1117
return right_port_cache[p_port_idx].color;
1118
}
1119
1120
int GraphNode::get_output_port_slot(int p_port_idx) {
1121
if (port_pos_dirty) {
1122
_port_pos_update();
1123
}
1124
1125
ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), -1);
1126
return right_port_cache[p_port_idx].slot_index;
1127
}
1128
1129
String GraphNode::get_accessibility_container_name(const Node *p_node) const {
1130
int idx = 0;
1131
for (int i = 0; i < get_child_count(false); i++) {
1132
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
1133
if (!child) {
1134
continue;
1135
}
1136
if (child == p_node) {
1137
String name = get_accessibility_name();
1138
if (name.is_empty()) {
1139
name = get_name();
1140
}
1141
return vformat(ETR(", in slot %d of graph node %s (%s)"), idx + 1, name, get_title());
1142
}
1143
idx++;
1144
}
1145
return String();
1146
}
1147
1148
void GraphNode::set_title(const String &p_title) {
1149
if (title == p_title) {
1150
return;
1151
}
1152
title = p_title;
1153
if (title_label) {
1154
title_label->set_text(title);
1155
}
1156
update_minimum_size();
1157
}
1158
1159
String GraphNode::get_title() const {
1160
return title;
1161
}
1162
1163
HBoxContainer *GraphNode::get_titlebar_hbox() {
1164
return titlebar_hbox;
1165
}
1166
1167
Control::CursorShape GraphNode::get_cursor_shape(const Point2 &p_pos) const {
1168
if (resizable) {
1169
if (resizing || (p_pos.x > get_size().x - theme_cache.resizer->get_width() && p_pos.y > get_size().y - theme_cache.resizer->get_height())) {
1170
return CURSOR_FDIAGSIZE;
1171
}
1172
}
1173
1174
return Control::get_cursor_shape(p_pos);
1175
}
1176
1177
Vector<int> GraphNode::get_allowed_size_flags_horizontal() const {
1178
Vector<int> flags;
1179
flags.append(SIZE_FILL);
1180
flags.append(SIZE_SHRINK_BEGIN);
1181
flags.append(SIZE_SHRINK_CENTER);
1182
flags.append(SIZE_SHRINK_END);
1183
return flags;
1184
}
1185
1186
Vector<int> GraphNode::get_allowed_size_flags_vertical() const {
1187
Vector<int> flags;
1188
flags.append(SIZE_FILL);
1189
flags.append(SIZE_EXPAND);
1190
flags.append(SIZE_SHRINK_BEGIN);
1191
flags.append(SIZE_SHRINK_CENTER);
1192
flags.append(SIZE_SHRINK_END);
1193
return flags;
1194
}
1195
1196
void GraphNode::set_slots_focus_mode(Control::FocusMode p_focus_mode) {
1197
if (slots_focus_mode == p_focus_mode) {
1198
return;
1199
}
1200
ERR_FAIL_COND((int)p_focus_mode < 1 || (int)p_focus_mode > 3);
1201
1202
slots_focus_mode = p_focus_mode;
1203
if (slots_focus_mode == Control::FOCUS_CLICK && selected_slot > -1) {
1204
selected_slot = -1;
1205
queue_redraw();
1206
}
1207
}
1208
1209
Control::FocusMode GraphNode::get_slots_focus_mode() const {
1210
return slots_focus_mode;
1211
}
1212
1213
void GraphNode::_bind_methods() {
1214
ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
1215
ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
1216
1217
ClassDB::bind_method(D_METHOD("get_titlebar_hbox"), &GraphNode::get_titlebar_hbox);
1218
1219
ClassDB::bind_method(D_METHOD("set_slot", "slot_index", "enable_left_port", "type_left", "color_left", "enable_right_port", "type_right", "color_right", "custom_icon_left", "custom_icon_right", "draw_stylebox"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(true));
1220
ClassDB::bind_method(D_METHOD("clear_slot", "slot_index"), &GraphNode::clear_slot);
1221
ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
1222
1223
ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "slot_index"), &GraphNode::is_slot_enabled_left);
1224
ClassDB::bind_method(D_METHOD("set_slot_enabled_left", "slot_index", "enable"), &GraphNode::set_slot_enabled_left);
1225
1226
ClassDB::bind_method(D_METHOD("set_slot_type_left", "slot_index", "type"), &GraphNode::set_slot_type_left);
1227
ClassDB::bind_method(D_METHOD("get_slot_type_left", "slot_index"), &GraphNode::get_slot_type_left);
1228
1229
ClassDB::bind_method(D_METHOD("set_slot_color_left", "slot_index", "color"), &GraphNode::set_slot_color_left);
1230
ClassDB::bind_method(D_METHOD("get_slot_color_left", "slot_index"), &GraphNode::get_slot_color_left);
1231
1232
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_left", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_left);
1233
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_left", "slot_index"), &GraphNode::get_slot_custom_icon_left);
1234
1235
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
1236
ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
1237
1238
ClassDB::bind_method(D_METHOD("set_slot_type_right", "slot_index", "type"), &GraphNode::set_slot_type_right);
1239
ClassDB::bind_method(D_METHOD("get_slot_type_right", "slot_index"), &GraphNode::get_slot_type_right);
1240
1241
ClassDB::bind_method(D_METHOD("set_slot_color_right", "slot_index", "color"), &GraphNode::set_slot_color_right);
1242
ClassDB::bind_method(D_METHOD("get_slot_color_right", "slot_index"), &GraphNode::get_slot_color_right);
1243
1244
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_right", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_right);
1245
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_right", "slot_index"), &GraphNode::get_slot_custom_icon_right);
1246
1247
ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
1248
ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
1249
1250
ClassDB::bind_method(D_METHOD("set_ignore_invalid_connection_type", "ignore"), &GraphNode::set_ignore_invalid_connection_type);
1251
ClassDB::bind_method(D_METHOD("is_ignoring_valid_connection_type"), &GraphNode::is_ignoring_valid_connection_type);
1252
1253
ClassDB::bind_method(D_METHOD("set_slots_focus_mode", "focus_mode"), &GraphNode::set_slots_focus_mode);
1254
ClassDB::bind_method(D_METHOD("get_slots_focus_mode"), &GraphNode::get_slots_focus_mode);
1255
1256
ClassDB::bind_method(D_METHOD("get_input_port_count"), &GraphNode::get_input_port_count);
1257
ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position);
1258
ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type);
1259
ClassDB::bind_method(D_METHOD("get_input_port_color", "port_idx"), &GraphNode::get_input_port_color);
1260
ClassDB::bind_method(D_METHOD("get_input_port_slot", "port_idx"), &GraphNode::get_input_port_slot);
1261
1262
ClassDB::bind_method(D_METHOD("get_output_port_count"), &GraphNode::get_output_port_count);
1263
ClassDB::bind_method(D_METHOD("get_output_port_position", "port_idx"), &GraphNode::get_output_port_position);
1264
ClassDB::bind_method(D_METHOD("get_output_port_type", "port_idx"), &GraphNode::get_output_port_type);
1265
ClassDB::bind_method(D_METHOD("get_output_port_color", "port_idx"), &GraphNode::get_output_port_color);
1266
ClassDB::bind_method(D_METHOD("get_output_port_slot", "port_idx"), &GraphNode::get_output_port_slot);
1267
1268
GDVIRTUAL_BIND(_draw_port, "slot_index", "position", "left", "color")
1269
1270
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
1271
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type");
1272
ADD_PROPERTY(PropertyInfo(Variant::INT, "slots_focus_mode", PROPERTY_HINT_ENUM, "Click:1,All:2,Accessibility:3"), "set_slots_focus_mode", "get_slots_focus_mode");
1273
1274
ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index")));
1275
ADD_SIGNAL(MethodInfo("slot_sizes_changed"));
1276
1277
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel);
1278
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel_selected);
1279
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel_focus);
1280
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, titlebar);
1281
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, titlebar_selected);
1282
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, slot);
1283
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, slot_selected);
1284
1285
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphNode, separation);
1286
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphNode, port_h_offset);
1287
1288
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphNode, port);
1289
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphNode, resizer);
1290
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphNode, resizer_color);
1291
}
1292
1293
GraphNode::GraphNode() {
1294
titlebar_hbox = memnew(HBoxContainer);
1295
titlebar_hbox->set_h_size_flags(SIZE_EXPAND_FILL);
1296
add_child(titlebar_hbox, false, INTERNAL_MODE_FRONT);
1297
1298
title_label = memnew(Label);
1299
title_label->set_theme_type_variation("GraphNodeTitleLabel");
1300
title_label->set_h_size_flags(SIZE_EXPAND_FILL);
1301
titlebar_hbox->add_child(title_label);
1302
1303
set_mouse_filter(MOUSE_FILTER_STOP);
1304
set_focus_mode(FOCUS_ACCESSIBILITY);
1305
}
1306
1307