graph_node.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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. #include "graph_node.h"
  31. #include "scene/gui/box_container.h"
  32. #include "scene/gui/graph_edit.h"
  33. #include "scene/gui/label.h"
  34. #include "scene/theme/theme_db.h"
  35. bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
  36. String str = p_name;
  37. if (!str.begins_with("slot/")) {
  38. return false;
  39. }
  40. int idx = str.get_slicec('/', 1).to_int();
  41. String slot_property_name = str.get_slicec('/', 2);
  42. Slot slot;
  43. if (slot_table.has(idx)) {
  44. slot = slot_table[idx];
  45. }
  46. if (slot_property_name == "left_enabled") {
  47. slot.enable_left = p_value;
  48. } else if (slot_property_name == "left_type") {
  49. slot.type_left = p_value;
  50. } else if (slot_property_name == "left_icon") {
  51. slot.custom_port_icon_left = p_value;
  52. } else if (slot_property_name == "left_color") {
  53. slot.color_left = p_value;
  54. } else if (slot_property_name == "right_enabled") {
  55. slot.enable_right = p_value;
  56. } else if (slot_property_name == "right_type") {
  57. slot.type_right = p_value;
  58. } else if (slot_property_name == "right_color") {
  59. slot.color_right = p_value;
  60. } else if (slot_property_name == "right_icon") {
  61. slot.custom_port_icon_right = p_value;
  62. } else if (slot_property_name == "draw_stylebox") {
  63. slot.draw_stylebox = p_value;
  64. } else {
  65. return false;
  66. }
  67. set_slot(idx,
  68. slot.enable_left,
  69. slot.type_left,
  70. slot.color_left,
  71. slot.enable_right,
  72. slot.type_right,
  73. slot.color_right,
  74. slot.custom_port_icon_left,
  75. slot.custom_port_icon_right,
  76. slot.draw_stylebox);
  77. queue_redraw();
  78. return true;
  79. }
  80. bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
  81. String str = p_name;
  82. if (!str.begins_with("slot/")) {
  83. return false;
  84. }
  85. int idx = str.get_slicec('/', 1).to_int();
  86. StringName slot_property_name = str.get_slicec('/', 2);
  87. Slot slot;
  88. if (slot_table.has(idx)) {
  89. slot = slot_table[idx];
  90. }
  91. if (slot_property_name == "left_enabled") {
  92. r_ret = slot.enable_left;
  93. } else if (slot_property_name == "left_type") {
  94. r_ret = slot.type_left;
  95. } else if (slot_property_name == "left_color") {
  96. r_ret = slot.color_left;
  97. } else if (slot_property_name == "left_icon") {
  98. r_ret = slot.custom_port_icon_left;
  99. } else if (slot_property_name == "right_enabled") {
  100. r_ret = slot.enable_right;
  101. } else if (slot_property_name == "right_type") {
  102. r_ret = slot.type_right;
  103. } else if (slot_property_name == "right_color") {
  104. r_ret = slot.color_right;
  105. } else if (slot_property_name == "right_icon") {
  106. r_ret = slot.custom_port_icon_right;
  107. } else if (slot_property_name == "draw_stylebox") {
  108. r_ret = slot.draw_stylebox;
  109. } else {
  110. return false;
  111. }
  112. return true;
  113. }
  114. void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
  115. int idx = 0;
  116. for (int i = 0; i < get_child_count(false); i++) {
  117. Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
  118. if (!child) {
  119. continue;
  120. }
  121. String base = "slot/" + itos(idx) + "/";
  122. p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
  123. p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
  124. p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
  125. p_list->push_back(PropertyInfo(Variant::OBJECT, base + "left_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
  126. p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
  127. p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
  128. p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
  129. p_list->push_back(PropertyInfo(Variant::OBJECT, base + "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL));
  130. p_list->push_back(PropertyInfo(Variant::BOOL, base + "draw_stylebox"));
  131. idx++;
  132. }
  133. }
  134. void GraphNode::_resort() {
  135. Size2 new_size = get_size();
  136. Ref<StyleBox> sb_panel = theme_cache.panel;
  137. Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
  138. // Resort titlebar first.
  139. Size2 titlebar_size = Size2(new_size.width, titlebar_hbox->get_size().height);
  140. titlebar_size -= sb_titlebar->get_minimum_size();
  141. Rect2 titlebar_rect = Rect2(sb_titlebar->get_offset(), titlebar_size);
  142. fit_child_in_rect(titlebar_hbox, titlebar_rect);
  143. // After resort, the children of the titlebar container may have changed their height (e.g. Label autowrap).
  144. Size2i titlebar_min_size = titlebar_hbox->get_combined_minimum_size();
  145. // First pass, determine minimum size AND amount of stretchable elements.
  146. Ref<StyleBox> sb_slot = theme_cache.slot;
  147. int separation = theme_cache.separation;
  148. int children_count = 0;
  149. int stretch_min = 0;
  150. int available_stretch_space = 0;
  151. float stretch_ratio_total = 0;
  152. HashMap<Control *, _MinSizeCache> min_size_cache;
  153. for (int i = 0; i < get_child_count(false); i++) {
  154. Control *child = as_sortable_control(get_child(i, false));
  155. if (!child) {
  156. continue;
  157. }
  158. Size2i size = child->get_combined_minimum_size() + (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2());
  159. stretch_min += size.height;
  160. _MinSizeCache msc;
  161. msc.min_size = size.height;
  162. msc.will_stretch = child->get_v_size_flags().has_flag(SIZE_EXPAND);
  163. msc.final_size = msc.min_size;
  164. min_size_cache[child] = msc;
  165. if (msc.will_stretch) {
  166. available_stretch_space += msc.min_size;
  167. stretch_ratio_total += child->get_stretch_ratio();
  168. }
  169. children_count++;
  170. }
  171. slot_count = children_count;
  172. if (selected_slot >= slot_count) {
  173. selected_slot = -1;
  174. }
  175. if (children_count == 0) {
  176. return;
  177. }
  178. int stretch_max = new_size.height - (children_count - 1) * separation;
  179. int stretch_diff = stretch_max - stretch_min;
  180. // Avoid negative stretch space.
  181. stretch_diff = MAX(stretch_diff, 0);
  182. 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;
  183. // Second pass, discard elements that can't be stretched, this will run while stretchable elements exist.
  184. while (stretch_ratio_total > 0) {
  185. // First of all, don't even be here if no stretchable objects exist.
  186. bool refit_successful = true;
  187. for (int i = 0; i < get_child_count(false); i++) {
  188. Control *child = as_sortable_control(get_child(i, false));
  189. if (!child) {
  190. continue;
  191. }
  192. ERR_FAIL_COND(!min_size_cache.has(child));
  193. _MinSizeCache &msc = min_size_cache[child];
  194. if (msc.will_stretch) {
  195. int final_pixel_size = available_stretch_space * child->get_stretch_ratio() / stretch_ratio_total;
  196. if (final_pixel_size < msc.min_size) {
  197. // If the available stretching area is too small for a Control,
  198. // then remove it from stretching area.
  199. msc.will_stretch = false;
  200. stretch_ratio_total -= child->get_stretch_ratio();
  201. refit_successful = false;
  202. available_stretch_space -= msc.min_size;
  203. msc.final_size = msc.min_size;
  204. break;
  205. } else {
  206. msc.final_size = final_pixel_size;
  207. }
  208. }
  209. }
  210. if (refit_successful) {
  211. break;
  212. }
  213. }
  214. // Final pass, draw and stretch elements.
  215. int ofs_y = sb_panel->get_margin(SIDE_TOP) + titlebar_min_size.height + sb_titlebar->get_minimum_size().height;
  216. slot_y_cache.clear();
  217. int width = new_size.width - sb_panel->get_minimum_size().width;
  218. int valid_children_idx = 0;
  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. _MinSizeCache &msc = min_size_cache[child];
  225. if (valid_children_idx > 0) {
  226. ofs_y += separation;
  227. }
  228. int from_y_pos = ofs_y;
  229. int to_y_pos = ofs_y + msc.final_size;
  230. // Adjust so the last valid child always fits perfect, compensating for numerical imprecision.
  231. if (msc.will_stretch && valid_children_idx == children_count - 1) {
  232. to_y_pos = new_size.height - sb_panel->get_margin(SIDE_BOTTOM);
  233. }
  234. int height = to_y_pos - from_y_pos;
  235. float margin = sb_panel->get_margin(SIDE_LEFT) + (slot_table[i].draw_stylebox ? sb_slot->get_margin(SIDE_LEFT) : 0);
  236. float final_width = width - (slot_table[i].draw_stylebox ? sb_slot->get_minimum_size().x : 0);
  237. Rect2 rect(margin, from_y_pos, final_width, height);
  238. fit_child_in_rect(child, rect);
  239. slot_y_cache.push_back(child->get_rect().position.y + child->get_rect().size.height * 0.5);
  240. ofs_y = to_y_pos;
  241. valid_children_idx++;
  242. }
  243. queue_accessibility_update();
  244. queue_redraw();
  245. port_pos_dirty = true;
  246. }
  247. void GraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
  248. if (GDVIRTUAL_CALL(_draw_port, p_slot_index, p_pos, p_left, p_color)) {
  249. return;
  250. }
  251. Slot slot = slot_table[p_slot_index];
  252. Ref<Texture2D> port_icon = p_left ? slot.custom_port_icon_left : slot.custom_port_icon_right;
  253. Point2 icon_offset;
  254. if (port_icon.is_null()) {
  255. port_icon = theme_cache.port;
  256. }
  257. icon_offset = -port_icon->get_size() * 0.5;
  258. port_icon->draw(get_canvas_item(), p_pos + icon_offset, p_color);
  259. }
  260. void GraphNode::_accessibility_action_slot(const Variant &p_data) {
  261. CustomAccessibilityAction action = (CustomAccessibilityAction)p_data.operator int();
  262. switch (action) {
  263. case ACTION_CONNECT_INPUT: {
  264. if (slot_table.has(selected_slot)) {
  265. const Slot &slot = slot_table[selected_slot];
  266. if (slot.enable_left) {
  267. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  268. if (graph) {
  269. for (int i = 0; i < left_port_cache.size(); i++) {
  270. if (left_port_cache[i].slot_index == selected_slot) {
  271. if (graph->is_keyboard_connecting()) {
  272. graph->end_keyboard_connecting(this, i, -1);
  273. } else {
  274. graph->start_keyboard_connecting(this, i, -1);
  275. }
  276. queue_accessibility_update();
  277. queue_redraw();
  278. break;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. } break;
  285. case ACTION_CONNECT_OUTPUT: {
  286. if (slot_table.has(selected_slot)) {
  287. const Slot &slot = slot_table[selected_slot];
  288. if (slot.enable_right) {
  289. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  290. if (graph) {
  291. for (int i = 0; i < right_port_cache.size(); i++) {
  292. if (right_port_cache[i].slot_index == selected_slot) {
  293. if (graph->is_keyboard_connecting()) {
  294. graph->end_keyboard_connecting(this, -1, i);
  295. } else {
  296. graph->start_keyboard_connecting(this, -1, i);
  297. }
  298. queue_accessibility_update();
  299. queue_redraw();
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. } break;
  307. case ACTION_FOLLOW_INPUT: {
  308. if (slot_table.has(selected_slot)) {
  309. const Slot &slot = slot_table[selected_slot];
  310. if (slot.enable_left) {
  311. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  312. if (graph) {
  313. for (int i = 0; i < left_port_cache.size(); i++) {
  314. if (left_port_cache[i].slot_index == selected_slot) {
  315. GraphNode *target = graph->get_input_connection_target(get_name(), i);
  316. if (target) {
  317. target->grab_focus();
  318. break;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. } break;
  326. case ACTION_FOLLOW_OUTPUT: {
  327. if (slot_table.has(selected_slot)) {
  328. const Slot &slot = slot_table[selected_slot];
  329. if (slot.enable_right) {
  330. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  331. if (graph) {
  332. for (int i = 0; i < right_port_cache.size(); i++) {
  333. if (right_port_cache[i].slot_index == selected_slot) {
  334. GraphNode *target = graph->get_output_connection_target(get_name(), i);
  335. if (target) {
  336. target->grab_focus();
  337. break;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. } break;
  345. }
  346. }
  347. void GraphNode::gui_input(const Ref<InputEvent> &p_event) {
  348. if (port_pos_dirty) {
  349. _port_pos_update();
  350. }
  351. if (p_event->is_pressed() && slot_count > 0) {
  352. if (p_event->is_action("ui_up", true)) {
  353. selected_slot--;
  354. if (selected_slot < 0) {
  355. selected_slot = -1;
  356. } else {
  357. accept_event();
  358. }
  359. } else if (p_event->is_action("ui_down", true)) {
  360. selected_slot++;
  361. if (selected_slot >= slot_count) {
  362. selected_slot = -1;
  363. } else {
  364. accept_event();
  365. }
  366. } else if (p_event->is_action("ui_cancel", true)) {
  367. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  368. if (graph && graph->is_keyboard_connecting()) {
  369. graph->force_connection_drag_end();
  370. accept_event();
  371. }
  372. } else if (p_event->is_action("ui_graph_delete", true)) {
  373. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  374. if (graph && graph->is_keyboard_connecting()) {
  375. graph->end_keyboard_connecting(this, -1, -1);
  376. accept_event();
  377. }
  378. } else if (p_event->is_action("ui_graph_follow_left", true)) {
  379. if (slot_table.has(selected_slot)) {
  380. const Slot &slot = slot_table[selected_slot];
  381. if (slot.enable_left) {
  382. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  383. if (graph) {
  384. for (int i = 0; i < left_port_cache.size(); i++) {
  385. if (left_port_cache[i].slot_index == selected_slot) {
  386. GraphNode *target = graph->get_input_connection_target(get_name(), i);
  387. if (target) {
  388. target->grab_focus();
  389. accept_event();
  390. break;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. } else if (p_event->is_action("ui_graph_follow_right", true)) {
  398. if (slot_table.has(selected_slot)) {
  399. const Slot &slot = slot_table[selected_slot];
  400. if (slot.enable_right) {
  401. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  402. if (graph) {
  403. for (int i = 0; i < right_port_cache.size(); i++) {
  404. if (right_port_cache[i].slot_index == selected_slot) {
  405. GraphNode *target = graph->get_output_connection_target(get_name(), i);
  406. if (target) {
  407. target->grab_focus();
  408. accept_event();
  409. break;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. }
  416. } else if (p_event->is_action("ui_left", true)) {
  417. if (slot_table.has(selected_slot)) {
  418. const Slot &slot = slot_table[selected_slot];
  419. if (slot.enable_left) {
  420. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  421. if (graph) {
  422. for (int i = 0; i < left_port_cache.size(); i++) {
  423. if (left_port_cache[i].slot_index == selected_slot) {
  424. if (graph->is_keyboard_connecting()) {
  425. graph->end_keyboard_connecting(this, i, -1);
  426. } else {
  427. graph->start_keyboard_connecting(this, i, -1);
  428. }
  429. accept_event();
  430. break;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. } else if (p_event->is_action("ui_right", true)) {
  437. if (slot_table.has(selected_slot)) {
  438. const Slot &slot = slot_table[selected_slot];
  439. if (slot.enable_right) {
  440. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  441. if (graph) {
  442. for (int i = 0; i < right_port_cache.size(); i++) {
  443. if (right_port_cache[i].slot_index == selected_slot) {
  444. if (graph->is_keyboard_connecting()) {
  445. graph->end_keyboard_connecting(this, -1, i);
  446. } else {
  447. graph->start_keyboard_connecting(this, -1, i);
  448. }
  449. accept_event();
  450. break;
  451. }
  452. }
  453. }
  454. }
  455. }
  456. } else if (p_event->is_action("ui_accept", true)) {
  457. if (slot_table.has(selected_slot)) {
  458. int idx = 0;
  459. for (int i = 0; i < get_child_count(false); i++) {
  460. Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
  461. if (!child) {
  462. continue;
  463. }
  464. if (idx == selected_slot) {
  465. selected_slot = -1;
  466. child->grab_focus();
  467. break;
  468. }
  469. idx++;
  470. }
  471. accept_event();
  472. }
  473. }
  474. queue_accessibility_update();
  475. queue_redraw();
  476. }
  477. }
  478. void GraphNode::_notification(int p_what) {
  479. switch (p_what) {
  480. case NOTIFICATION_ACCESSIBILITY_UPDATE: {
  481. RID ae = get_accessibility_element();
  482. ERR_FAIL_COND(ae.is_null());
  483. String name = get_accessibility_name();
  484. if (name.is_empty()) {
  485. name = get_name();
  486. }
  487. name = vformat(ETR("graph node %s (%s)"), name, get_title());
  488. if (slot_table.has(selected_slot)) {
  489. GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
  490. Dictionary type_info;
  491. if (graph) {
  492. type_info = graph->get_type_names();
  493. }
  494. const Slot &slot = slot_table[selected_slot];
  495. name += ", " + vformat(ETR("slot %d of %d"), selected_slot + 1, slot_count);
  496. if (slot.enable_left) {
  497. if (type_info.has(slot.type_left)) {
  498. name += "," + vformat(ETR("input port, type: %s"), type_info[slot.type_left]);
  499. } else {
  500. name += "," + vformat(ETR("input port, type: %d"), slot.type_left);
  501. }
  502. if (graph) {
  503. for (int i = 0; i < left_port_cache.size(); i++) {
  504. if (left_port_cache[i].slot_index == selected_slot) {
  505. String cd = graph->get_connections_description(get_name(), i);
  506. if (cd.is_empty()) {
  507. name += " " + ETR("no connections");
  508. } else {
  509. name += " " + cd;
  510. }
  511. break;
  512. }
  513. }
  514. }
  515. }
  516. if (slot.enable_left) {
  517. if (type_info.has(slot.type_right)) {
  518. name += "," + vformat(ETR("output port, type: %s"), type_info[slot.type_right]);
  519. } else {
  520. name += "," + vformat(ETR("output port, type: %d"), slot.type_right);
  521. }
  522. if (graph) {
  523. for (int i = 0; i < right_port_cache.size(); i++) {
  524. if (right_port_cache[i].slot_index == selected_slot) {
  525. String cd = graph->get_connections_description(get_name(), i);
  526. if (cd.is_empty()) {
  527. name += " " + ETR("no connections");
  528. } else {
  529. name += " " + cd;
  530. }
  531. break;
  532. }
  533. }
  534. }
  535. }
  536. if (graph && graph->is_keyboard_connecting()) {
  537. name += ", " + ETR("currently selecting target port");
  538. }
  539. } else {
  540. name += ", " + vformat(ETR("has %d slots"), slot_count);
  541. }
  542. DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_LIST);
  543. DisplayServer::get_singleton()->accessibility_update_set_name(ae, name);
  544. DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_CONNECT_INPUT, ETR("Edit Input Port Connection"));
  545. DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_CONNECT_OUTPUT, ETR("Edit Output Port Connection"));
  546. DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_FOLLOW_INPUT, ETR("Follow Input Port Connection"));
  547. DisplayServer::get_singleton()->accessibility_update_add_custom_action(ae, CustomAccessibilityAction::ACTION_FOLLOW_OUTPUT, ETR("Follow Output Port Connection"));
  548. DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CUSTOM, callable_mp(this, &GraphNode::_accessibility_action_slot));
  549. } break;
  550. case NOTIFICATION_FOCUS_EXIT: {
  551. selected_slot = -1;
  552. queue_redraw();
  553. } break;
  554. case NOTIFICATION_DRAW: {
  555. // Used for layout calculations.
  556. Ref<StyleBox> sb_panel = theme_cache.panel;
  557. Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
  558. // Used for drawing.
  559. Ref<StyleBox> sb_to_draw_panel = selected ? theme_cache.panel_selected : theme_cache.panel;
  560. Ref<StyleBox> sb_to_draw_titlebar = selected ? theme_cache.titlebar_selected : theme_cache.titlebar;
  561. Ref<StyleBox> sb_slot = theme_cache.slot;
  562. Ref<StyleBox> sb_slot_selected = theme_cache.slot_selected;
  563. int port_h_offset = theme_cache.port_h_offset;
  564. Rect2 titlebar_rect(Point2(), titlebar_hbox->get_size() + sb_titlebar->get_minimum_size());
  565. Size2 body_size = get_size();
  566. titlebar_rect.size.width = body_size.width;
  567. body_size.height -= titlebar_rect.size.height;
  568. Rect2 body_rect(0, titlebar_rect.size.height, body_size.width, body_size.height);
  569. // Draw body (slots area) stylebox.
  570. draw_style_box(sb_to_draw_panel, body_rect);
  571. if (has_focus()) {
  572. draw_style_box(theme_cache.panel_focus, body_rect);
  573. }
  574. // Draw title bar stylebox above.
  575. draw_style_box(sb_to_draw_titlebar, titlebar_rect);
  576. int width = get_size().width - sb_panel->get_minimum_size().x;
  577. // Take the HboxContainer child into account.
  578. if (get_child_count(false) > 0) {
  579. int slot_index = 0;
  580. for (const KeyValue<int, Slot> &E : slot_table) {
  581. if (E.key < 0 || E.key >= slot_y_cache.size()) {
  582. continue;
  583. }
  584. if (!slot_table.has(E.key)) {
  585. continue;
  586. }
  587. const Slot &slot = slot_table[E.key];
  588. // Left port.
  589. if (slot.enable_left) {
  590. draw_port(slot_index, Point2i(port_h_offset, slot_y_cache[E.key]), true, slot.color_left);
  591. }
  592. // Right port.
  593. if (slot.enable_right) {
  594. draw_port(slot_index, Point2i(get_size().x - port_h_offset, slot_y_cache[E.key]), false, slot.color_right);
  595. }
  596. if (slot_index == selected_slot) {
  597. Size2i port_sz = theme_cache.port->get_size();
  598. draw_style_box(sb_slot_selected, Rect2i(port_h_offset - port_sz.x, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP) - port_sz.y, port_sz.x * 2, port_sz.y * 2));
  599. draw_style_box(sb_slot_selected, Rect2i(get_size().x - port_h_offset - port_sz.x, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP) - port_sz.y, port_sz.x * 2, port_sz.y * 2));
  600. }
  601. // Draw slot stylebox.
  602. if (slot.draw_stylebox) {
  603. Control *child = Object::cast_to<Control>(get_child(E.key, false));
  604. if (!child || !child->is_visible_in_tree()) {
  605. continue;
  606. }
  607. Rect2 child_rect = child->get_rect();
  608. child_rect.position.x = sb_panel->get_margin(SIDE_LEFT);
  609. child_rect.size.width = width;
  610. draw_style_box(sb_slot, child_rect);
  611. }
  612. slot_index++;
  613. }
  614. }
  615. if (resizable) {
  616. draw_texture(theme_cache.resizer, get_size() - theme_cache.resizer->get_size(), theme_cache.resizer_color);
  617. }
  618. } break;
  619. }
  620. }
  621. 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) {
  622. ERR_FAIL_COND_MSG(p_slot_index < 0, vformat("Cannot set slot with index (%d) lesser than zero.", p_slot_index));
  623. if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) &&
  624. !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1) &&
  625. p_custom_left.is_null() && p_custom_right.is_null()) {
  626. slot_table.erase(p_slot_index);
  627. return;
  628. }
  629. Slot slot;
  630. slot.enable_left = p_enable_left;
  631. slot.type_left = p_type_left;
  632. slot.color_left = p_color_left;
  633. slot.enable_right = p_enable_right;
  634. slot.type_right = p_type_right;
  635. slot.color_right = p_color_right;
  636. slot.custom_port_icon_left = p_custom_left;
  637. slot.custom_port_icon_right = p_custom_right;
  638. slot.draw_stylebox = p_draw_stylebox;
  639. slot_table[p_slot_index] = slot;
  640. queue_accessibility_update();
  641. queue_redraw();
  642. port_pos_dirty = true;
  643. emit_signal(SNAME("slot_updated"), p_slot_index);
  644. }
  645. void GraphNode::clear_slot(int p_slot_index) {
  646. slot_table.erase(p_slot_index);
  647. queue_accessibility_update();
  648. queue_redraw();
  649. port_pos_dirty = true;
  650. }
  651. void GraphNode::clear_all_slots() {
  652. slot_table.clear();
  653. queue_accessibility_update();
  654. queue_redraw();
  655. port_pos_dirty = true;
  656. }
  657. bool GraphNode::is_slot_enabled_left(int p_slot_index) const {
  658. if (!slot_table.has(p_slot_index)) {
  659. return false;
  660. }
  661. return slot_table[p_slot_index].enable_left;
  662. }
  663. void GraphNode::set_slot_enabled_left(int p_slot_index, bool p_enable) {
  664. 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));
  665. if (slot_table[p_slot_index].enable_left == p_enable) {
  666. return;
  667. }
  668. slot_table[p_slot_index].enable_left = p_enable;
  669. queue_accessibility_update();
  670. queue_redraw();
  671. port_pos_dirty = true;
  672. emit_signal(SNAME("slot_updated"), p_slot_index);
  673. }
  674. void GraphNode::set_slot_type_left(int p_slot_index, int p_type) {
  675. 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));
  676. if (slot_table[p_slot_index].type_left == p_type) {
  677. return;
  678. }
  679. slot_table[p_slot_index].type_left = p_type;
  680. queue_accessibility_update();
  681. queue_redraw();
  682. port_pos_dirty = true;
  683. emit_signal(SNAME("slot_updated"), p_slot_index);
  684. }
  685. int GraphNode::get_slot_type_left(int p_slot_index) const {
  686. if (!slot_table.has(p_slot_index)) {
  687. return 0;
  688. }
  689. return slot_table[p_slot_index].type_left;
  690. }
  691. void GraphNode::set_slot_color_left(int p_slot_index, const Color &p_color) {
  692. 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));
  693. if (slot_table[p_slot_index].color_left == p_color) {
  694. return;
  695. }
  696. slot_table[p_slot_index].color_left = p_color;
  697. queue_redraw();
  698. port_pos_dirty = true;
  699. emit_signal(SNAME("slot_updated"), p_slot_index);
  700. }
  701. Color GraphNode::get_slot_color_left(int p_slot_index) const {
  702. if (!slot_table.has(p_slot_index)) {
  703. return Color(1, 1, 1, 1);
  704. }
  705. return slot_table[p_slot_index].color_left;
  706. }
  707. void GraphNode::set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
  708. 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));
  709. if (slot_table[p_slot_index].custom_port_icon_left == p_custom_icon) {
  710. return;
  711. }
  712. slot_table[p_slot_index].custom_port_icon_left = p_custom_icon;
  713. queue_redraw();
  714. port_pos_dirty = true;
  715. emit_signal(SNAME("slot_updated"), p_slot_index);
  716. }
  717. Ref<Texture2D> GraphNode::get_slot_custom_icon_left(int p_slot_index) const {
  718. if (!slot_table.has(p_slot_index)) {
  719. return Ref<Texture2D>();
  720. }
  721. return slot_table[p_slot_index].custom_port_icon_left;
  722. }
  723. bool GraphNode::is_slot_enabled_right(int p_slot_index) const {
  724. if (!slot_table.has(p_slot_index)) {
  725. return false;
  726. }
  727. return slot_table[p_slot_index].enable_right;
  728. }
  729. void GraphNode::set_slot_enabled_right(int p_slot_index, bool p_enable) {
  730. 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));
  731. if (slot_table[p_slot_index].enable_right == p_enable) {
  732. return;
  733. }
  734. slot_table[p_slot_index].enable_right = p_enable;
  735. queue_accessibility_update();
  736. queue_redraw();
  737. port_pos_dirty = true;
  738. emit_signal(SNAME("slot_updated"), p_slot_index);
  739. }
  740. void GraphNode::set_slot_type_right(int p_slot_index, int p_type) {
  741. 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));
  742. if (slot_table[p_slot_index].type_right == p_type) {
  743. return;
  744. }
  745. slot_table[p_slot_index].type_right = p_type;
  746. queue_accessibility_update();
  747. queue_redraw();
  748. port_pos_dirty = true;
  749. emit_signal(SNAME("slot_updated"), p_slot_index);
  750. }
  751. int GraphNode::get_slot_type_right(int p_slot_index) const {
  752. if (!slot_table.has(p_slot_index)) {
  753. return 0;
  754. }
  755. return slot_table[p_slot_index].type_right;
  756. }
  757. void GraphNode::set_slot_color_right(int p_slot_index, const Color &p_color) {
  758. 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));
  759. if (slot_table[p_slot_index].color_right == p_color) {
  760. return;
  761. }
  762. slot_table[p_slot_index].color_right = p_color;
  763. queue_redraw();
  764. port_pos_dirty = true;
  765. emit_signal(SNAME("slot_updated"), p_slot_index);
  766. }
  767. Color GraphNode::get_slot_color_right(int p_slot_index) const {
  768. if (!slot_table.has(p_slot_index)) {
  769. return Color(1, 1, 1, 1);
  770. }
  771. return slot_table[p_slot_index].color_right;
  772. }
  773. void GraphNode::set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
  774. 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));
  775. if (slot_table[p_slot_index].custom_port_icon_right == p_custom_icon) {
  776. return;
  777. }
  778. slot_table[p_slot_index].custom_port_icon_right = p_custom_icon;
  779. queue_redraw();
  780. port_pos_dirty = true;
  781. emit_signal(SNAME("slot_updated"), p_slot_index);
  782. }
  783. Ref<Texture2D> GraphNode::get_slot_custom_icon_right(int p_slot_index) const {
  784. if (!slot_table.has(p_slot_index)) {
  785. return Ref<Texture2D>();
  786. }
  787. return slot_table[p_slot_index].custom_port_icon_right;
  788. }
  789. bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const {
  790. if (!slot_table.has(p_slot_index)) {
  791. return false;
  792. }
  793. return slot_table[p_slot_index].draw_stylebox;
  794. }
  795. void GraphNode::set_slot_draw_stylebox(int p_slot_index, bool p_enable) {
  796. 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));
  797. slot_table[p_slot_index].draw_stylebox = p_enable;
  798. queue_redraw();
  799. port_pos_dirty = true;
  800. emit_signal(SNAME("slot_updated"), p_slot_index);
  801. }
  802. void GraphNode::set_ignore_invalid_connection_type(bool p_ignore) {
  803. ignore_invalid_connection_type = p_ignore;
  804. }
  805. bool GraphNode::is_ignoring_valid_connection_type() const {
  806. return ignore_invalid_connection_type;
  807. }
  808. Size2 GraphNode::get_minimum_size() const {
  809. Ref<StyleBox> sb_panel = theme_cache.panel;
  810. Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
  811. Ref<StyleBox> sb_slot = theme_cache.slot;
  812. int separation = theme_cache.separation;
  813. Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size();
  814. for (int i = 0; i < get_child_count(false); i++) {
  815. Control *child = as_sortable_control(get_child(i, false));
  816. if (!child) {
  817. continue;
  818. }
  819. Size2i size = child->get_combined_minimum_size();
  820. size.width += sb_panel->get_minimum_size().width;
  821. if (slot_table.has(i)) {
  822. size += slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2();
  823. }
  824. minsize.height += size.height;
  825. minsize.width = MAX(minsize.width, size.width);
  826. if (i > 0) {
  827. minsize.height += separation;
  828. }
  829. }
  830. minsize.height += sb_panel->get_minimum_size().height;
  831. return minsize;
  832. }
  833. void GraphNode::_port_pos_update() {
  834. int edgeofs = theme_cache.port_h_offset;
  835. left_port_cache.clear();
  836. right_port_cache.clear();
  837. int slot_index = 0;
  838. for (int i = 0; i < get_child_count(false); i++) {
  839. Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
  840. if (!child) {
  841. continue;
  842. }
  843. Size2i size = child->get_rect().size;
  844. Point2 pos = child->get_position();
  845. if (slot_table.has(slot_index)) {
  846. if (slot_table[slot_index].enable_left) {
  847. PortCache port_cache;
  848. port_cache.pos = Point2i(edgeofs, pos.y + size.height / 2);
  849. port_cache.type = slot_table[slot_index].type_left;
  850. port_cache.color = slot_table[slot_index].color_left;
  851. port_cache.slot_index = slot_index;
  852. left_port_cache.push_back(port_cache);
  853. }
  854. if (slot_table[slot_index].enable_right) {
  855. PortCache port_cache;
  856. port_cache.pos = Point2i(get_size().width - edgeofs, pos.y + size.height / 2);
  857. port_cache.type = slot_table[slot_index].type_right;
  858. port_cache.color = slot_table[slot_index].color_right;
  859. port_cache.slot_index = slot_index;
  860. right_port_cache.push_back(port_cache);
  861. }
  862. }
  863. slot_index++;
  864. }
  865. slot_count = slot_index;
  866. if (selected_slot >= slot_count) {
  867. selected_slot = -1;
  868. }
  869. port_pos_dirty = false;
  870. }
  871. int GraphNode::get_input_port_count() {
  872. if (port_pos_dirty) {
  873. _port_pos_update();
  874. }
  875. return left_port_cache.size();
  876. }
  877. int GraphNode::get_output_port_count() {
  878. if (port_pos_dirty) {
  879. _port_pos_update();
  880. }
  881. return right_port_cache.size();
  882. }
  883. Vector2 GraphNode::get_input_port_position(int p_port_idx) {
  884. if (port_pos_dirty) {
  885. _port_pos_update();
  886. }
  887. ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Vector2());
  888. Vector2 pos = left_port_cache[p_port_idx].pos;
  889. return pos;
  890. }
  891. int GraphNode::get_input_port_type(int p_port_idx) {
  892. if (port_pos_dirty) {
  893. _port_pos_update();
  894. }
  895. ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), 0);
  896. return left_port_cache[p_port_idx].type;
  897. }
  898. Color GraphNode::get_input_port_color(int p_port_idx) {
  899. if (port_pos_dirty) {
  900. _port_pos_update();
  901. }
  902. ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), Color());
  903. return left_port_cache[p_port_idx].color;
  904. }
  905. int GraphNode::get_input_port_slot(int p_port_idx) {
  906. if (port_pos_dirty) {
  907. _port_pos_update();
  908. }
  909. ERR_FAIL_INDEX_V(p_port_idx, left_port_cache.size(), -1);
  910. return left_port_cache[p_port_idx].slot_index;
  911. }
  912. Vector2 GraphNode::get_output_port_position(int p_port_idx) {
  913. if (port_pos_dirty) {
  914. _port_pos_update();
  915. }
  916. ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Vector2());
  917. Vector2 pos = right_port_cache[p_port_idx].pos;
  918. return pos;
  919. }
  920. int GraphNode::get_output_port_type(int p_port_idx) {
  921. if (port_pos_dirty) {
  922. _port_pos_update();
  923. }
  924. ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), 0);
  925. return right_port_cache[p_port_idx].type;
  926. }
  927. Color GraphNode::get_output_port_color(int p_port_idx) {
  928. if (port_pos_dirty) {
  929. _port_pos_update();
  930. }
  931. ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), Color());
  932. return right_port_cache[p_port_idx].color;
  933. }
  934. int GraphNode::get_output_port_slot(int p_port_idx) {
  935. if (port_pos_dirty) {
  936. _port_pos_update();
  937. }
  938. ERR_FAIL_INDEX_V(p_port_idx, right_port_cache.size(), -1);
  939. return right_port_cache[p_port_idx].slot_index;
  940. }
  941. String GraphNode::get_accessibility_container_name(const Node *p_node) const {
  942. int idx = 0;
  943. for (int i = 0; i < get_child_count(false); i++) {
  944. Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
  945. if (!child) {
  946. continue;
  947. }
  948. if (child == p_node) {
  949. String name = get_accessibility_name();
  950. if (name.is_empty()) {
  951. name = get_name();
  952. }
  953. return vformat(ETR(", in slot %d of graph node %s (%s)"), idx + 1, name, get_title());
  954. }
  955. idx++;
  956. }
  957. return String();
  958. }
  959. void GraphNode::set_title(const String &p_title) {
  960. if (title == p_title) {
  961. return;
  962. }
  963. title = p_title;
  964. if (title_label) {
  965. title_label->set_text(title);
  966. }
  967. update_minimum_size();
  968. }
  969. String GraphNode::get_title() const {
  970. return title;
  971. }
  972. HBoxContainer *GraphNode::get_titlebar_hbox() {
  973. return titlebar_hbox;
  974. }
  975. Control::CursorShape GraphNode::get_cursor_shape(const Point2 &p_pos) const {
  976. if (resizable) {
  977. if (resizing || (p_pos.x > get_size().x - theme_cache.resizer->get_width() && p_pos.y > get_size().y - theme_cache.resizer->get_height())) {
  978. return CURSOR_FDIAGSIZE;
  979. }
  980. }
  981. return Control::get_cursor_shape(p_pos);
  982. }
  983. Vector<int> GraphNode::get_allowed_size_flags_horizontal() const {
  984. Vector<int> flags;
  985. flags.append(SIZE_FILL);
  986. flags.append(SIZE_SHRINK_BEGIN);
  987. flags.append(SIZE_SHRINK_CENTER);
  988. flags.append(SIZE_SHRINK_END);
  989. return flags;
  990. }
  991. Vector<int> GraphNode::get_allowed_size_flags_vertical() const {
  992. Vector<int> flags;
  993. flags.append(SIZE_FILL);
  994. flags.append(SIZE_EXPAND);
  995. flags.append(SIZE_SHRINK_BEGIN);
  996. flags.append(SIZE_SHRINK_CENTER);
  997. flags.append(SIZE_SHRINK_END);
  998. return flags;
  999. }
  1000. void GraphNode::_bind_methods() {
  1001. ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
  1002. ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
  1003. ClassDB::bind_method(D_METHOD("get_titlebar_hbox"), &GraphNode::get_titlebar_hbox);
  1004. 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));
  1005. ClassDB::bind_method(D_METHOD("clear_slot", "slot_index"), &GraphNode::clear_slot);
  1006. ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
  1007. ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "slot_index"), &GraphNode::is_slot_enabled_left);
  1008. ClassDB::bind_method(D_METHOD("set_slot_enabled_left", "slot_index", "enable"), &GraphNode::set_slot_enabled_left);
  1009. ClassDB::bind_method(D_METHOD("set_slot_type_left", "slot_index", "type"), &GraphNode::set_slot_type_left);
  1010. ClassDB::bind_method(D_METHOD("get_slot_type_left", "slot_index"), &GraphNode::get_slot_type_left);
  1011. ClassDB::bind_method(D_METHOD("set_slot_color_left", "slot_index", "color"), &GraphNode::set_slot_color_left);
  1012. ClassDB::bind_method(D_METHOD("get_slot_color_left", "slot_index"), &GraphNode::get_slot_color_left);
  1013. ClassDB::bind_method(D_METHOD("set_slot_custom_icon_left", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_left);
  1014. ClassDB::bind_method(D_METHOD("get_slot_custom_icon_left", "slot_index"), &GraphNode::get_slot_custom_icon_left);
  1015. ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
  1016. ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
  1017. ClassDB::bind_method(D_METHOD("set_slot_type_right", "slot_index", "type"), &GraphNode::set_slot_type_right);
  1018. ClassDB::bind_method(D_METHOD("get_slot_type_right", "slot_index"), &GraphNode::get_slot_type_right);
  1019. ClassDB::bind_method(D_METHOD("set_slot_color_right", "slot_index", "color"), &GraphNode::set_slot_color_right);
  1020. ClassDB::bind_method(D_METHOD("get_slot_color_right", "slot_index"), &GraphNode::get_slot_color_right);
  1021. ClassDB::bind_method(D_METHOD("set_slot_custom_icon_right", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_right);
  1022. ClassDB::bind_method(D_METHOD("get_slot_custom_icon_right", "slot_index"), &GraphNode::get_slot_custom_icon_right);
  1023. ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
  1024. ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
  1025. ClassDB::bind_method(D_METHOD("set_ignore_invalid_connection_type", "ignore"), &GraphNode::set_ignore_invalid_connection_type);
  1026. ClassDB::bind_method(D_METHOD("is_ignoring_valid_connection_type"), &GraphNode::is_ignoring_valid_connection_type);
  1027. ClassDB::bind_method(D_METHOD("get_input_port_count"), &GraphNode::get_input_port_count);
  1028. ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position);
  1029. ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type);
  1030. ClassDB::bind_method(D_METHOD("get_input_port_color", "port_idx"), &GraphNode::get_input_port_color);
  1031. ClassDB::bind_method(D_METHOD("get_input_port_slot", "port_idx"), &GraphNode::get_input_port_slot);
  1032. ClassDB::bind_method(D_METHOD("get_output_port_count"), &GraphNode::get_output_port_count);
  1033. ClassDB::bind_method(D_METHOD("get_output_port_position", "port_idx"), &GraphNode::get_output_port_position);
  1034. ClassDB::bind_method(D_METHOD("get_output_port_type", "port_idx"), &GraphNode::get_output_port_type);
  1035. ClassDB::bind_method(D_METHOD("get_output_port_color", "port_idx"), &GraphNode::get_output_port_color);
  1036. ClassDB::bind_method(D_METHOD("get_output_port_slot", "port_idx"), &GraphNode::get_output_port_slot);
  1037. GDVIRTUAL_BIND(_draw_port, "slot_index", "position", "left", "color")
  1038. ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
  1039. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type");
  1040. ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index")));
  1041. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel);
  1042. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel_selected);
  1043. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel_focus);
  1044. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, titlebar);
  1045. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, titlebar_selected);
  1046. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, slot);
  1047. BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, slot_selected);
  1048. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphNode, separation);
  1049. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphNode, port_h_offset);
  1050. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphNode, port);
  1051. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphNode, resizer);
  1052. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphNode, resizer_color);
  1053. }
  1054. GraphNode::GraphNode() {
  1055. titlebar_hbox = memnew(HBoxContainer);
  1056. titlebar_hbox->set_h_size_flags(SIZE_EXPAND_FILL);
  1057. add_child(titlebar_hbox, false, INTERNAL_MODE_FRONT);
  1058. title_label = memnew(Label);
  1059. title_label->set_theme_type_variation("GraphNodeTitleLabel");
  1060. title_label->set_h_size_flags(SIZE_EXPAND_FILL);
  1061. title_label->set_focus_mode(Control::FOCUS_NONE);
  1062. titlebar_hbox->add_child(title_label);
  1063. set_mouse_filter(MOUSE_FILTER_STOP);
  1064. set_focus_mode(FOCUS_ACCESSIBILITY);
  1065. }