2
0

graph_node.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /*************************************************************************/
  2. /* graph_node.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/method_bind_ext.gen.inc"
  32. bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
  33. if (!p_name.operator String().begins_with("slot/"))
  34. return false;
  35. int idx = p_name.operator String().get_slice("/", 1).to_int();
  36. String what = p_name.operator String().get_slice("/", 2);
  37. Slot si;
  38. if (slot_info.has(idx))
  39. si = slot_info[idx];
  40. if (what == "left_enabled")
  41. si.enable_left = p_value;
  42. else if (what == "left_type")
  43. si.type_left = p_value;
  44. else if (what == "left_color")
  45. si.color_left = p_value;
  46. else if (what == "right_enabled")
  47. si.enable_right = p_value;
  48. else if (what == "right_type")
  49. si.type_right = p_value;
  50. else if (what == "right_color")
  51. si.color_right = p_value;
  52. else
  53. return false;
  54. set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
  55. update();
  56. return true;
  57. }
  58. bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
  59. if (!p_name.operator String().begins_with("slot/")) {
  60. return false;
  61. }
  62. int idx = p_name.operator String().get_slice("/", 1).to_int();
  63. String what = p_name.operator String().get_slice("/", 2);
  64. Slot si;
  65. if (slot_info.has(idx))
  66. si = slot_info[idx];
  67. if (what == "left_enabled")
  68. r_ret = si.enable_left;
  69. else if (what == "left_type")
  70. r_ret = si.type_left;
  71. else if (what == "left_color")
  72. r_ret = si.color_left;
  73. else if (what == "right_enabled")
  74. r_ret = si.enable_right;
  75. else if (what == "right_type")
  76. r_ret = si.type_right;
  77. else if (what == "right_color")
  78. r_ret = si.color_right;
  79. else
  80. return false;
  81. return true;
  82. }
  83. void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
  84. int idx = 0;
  85. for (int i = 0; i < get_child_count(); i++) {
  86. Control *c = Object::cast_to<Control>(get_child(i));
  87. if (!c || c->is_set_as_toplevel())
  88. continue;
  89. String base = "slot/" + itos(idx) + "/";
  90. p_list->push_back(PropertyInfo(Variant::BOOL, base + "left_enabled"));
  91. p_list->push_back(PropertyInfo(Variant::INT, base + "left_type"));
  92. p_list->push_back(PropertyInfo(Variant::COLOR, base + "left_color"));
  93. p_list->push_back(PropertyInfo(Variant::BOOL, base + "right_enabled"));
  94. p_list->push_back(PropertyInfo(Variant::INT, base + "right_type"));
  95. p_list->push_back(PropertyInfo(Variant::COLOR, base + "right_color"));
  96. idx++;
  97. }
  98. }
  99. void GraphNode::_resort() {
  100. int sep = get_constant("separation");
  101. Ref<StyleBox> sb = get_stylebox("frame");
  102. bool first = true;
  103. Size2 minsize;
  104. for (int i = 0; i < get_child_count(); i++) {
  105. Control *c = Object::cast_to<Control>(get_child(i));
  106. if (!c)
  107. continue;
  108. if (c->is_set_as_toplevel())
  109. continue;
  110. Size2i size = c->get_combined_minimum_size();
  111. minsize.y += size.y;
  112. minsize.x = MAX(minsize.x, size.x);
  113. if (first)
  114. first = false;
  115. else
  116. minsize.y += sep;
  117. }
  118. int vofs = 0;
  119. int w = get_size().x - sb->get_minimum_size().x;
  120. cache_y.clear();
  121. for (int i = 0; i < get_child_count(); i++) {
  122. Control *c = Object::cast_to<Control>(get_child(i));
  123. if (!c)
  124. continue;
  125. if (c->is_set_as_toplevel())
  126. continue;
  127. Size2i size = c->get_combined_minimum_size();
  128. Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y);
  129. fit_child_in_rect(c, r);
  130. cache_y.push_back(vofs + size.y * 0.5);
  131. vofs += size.y + sep;
  132. }
  133. update();
  134. connpos_dirty = true;
  135. }
  136. bool GraphNode::has_point(const Point2 &p_point) const {
  137. if (comment) {
  138. Ref<StyleBox> comment = get_stylebox("comment");
  139. Ref<Texture> resizer = get_icon("resizer");
  140. if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
  141. return true;
  142. }
  143. if (Rect2(0, 0, get_size().width, comment->get_margin(MARGIN_TOP)).has_point(p_point)) {
  144. return true;
  145. }
  146. return false;
  147. } else {
  148. return Control::has_point(p_point);
  149. }
  150. }
  151. void GraphNode::_notification(int p_what) {
  152. switch (p_what) {
  153. case NOTIFICATION_DRAW: {
  154. Ref<StyleBox> sb;
  155. if (comment) {
  156. sb = get_stylebox(selected ? "commentfocus" : "comment");
  157. } else {
  158. sb = get_stylebox(selected ? "selectedframe" : "frame");
  159. }
  160. //sb=sb->duplicate();
  161. //sb->call("set_modulate",modulate);
  162. Ref<Texture> port = get_icon("port");
  163. Ref<Texture> close = get_icon("close");
  164. Ref<Texture> resizer = get_icon("resizer");
  165. int close_offset = get_constant("close_offset");
  166. int close_h_offset = get_constant("close_h_offset");
  167. Color close_color = get_color("close_color");
  168. Color resizer_color = get_color("resizer_color");
  169. Ref<Font> title_font = get_font("title_font");
  170. int title_offset = get_constant("title_offset");
  171. int title_h_offset = get_constant("title_h_offset");
  172. Color title_color = get_color("title_color");
  173. Point2i icofs = -port->get_size() * 0.5;
  174. int edgeofs = get_constant("port_offset");
  175. icofs.y += sb->get_margin(MARGIN_TOP);
  176. draw_style_box(sb, Rect2(Point2(), get_size()));
  177. switch (overlay) {
  178. case OVERLAY_DISABLED: {
  179. } break;
  180. case OVERLAY_BREAKPOINT: {
  181. draw_style_box(get_stylebox("breakpoint"), Rect2(Point2(), get_size()));
  182. } break;
  183. case OVERLAY_POSITION: {
  184. draw_style_box(get_stylebox("position"), Rect2(Point2(), get_size()));
  185. } break;
  186. }
  187. int w = get_size().width - sb->get_minimum_size().x;
  188. if (show_close)
  189. w -= close->get_width();
  190. draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
  191. if (show_close) {
  192. Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT) + close_h_offset, -close->get_height() + close_offset);
  193. draw_texture(close, cpos, close_color);
  194. close_rect.position = cpos;
  195. close_rect.size = close->get_size();
  196. } else {
  197. close_rect = Rect2();
  198. }
  199. for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
  200. if (E->key() < 0 || E->key() >= cache_y.size())
  201. continue;
  202. if (!slot_info.has(E->key()))
  203. continue;
  204. const Slot &s = slot_info[E->key()];
  205. //left
  206. if (s.enable_left) {
  207. Ref<Texture> p = port;
  208. if (s.custom_slot_left.is_valid()) {
  209. p = s.custom_slot_left;
  210. }
  211. p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
  212. }
  213. if (s.enable_right) {
  214. Ref<Texture> p = port;
  215. if (s.custom_slot_right.is_valid()) {
  216. p = s.custom_slot_right;
  217. }
  218. p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
  219. }
  220. }
  221. if (resizable) {
  222. draw_texture(resizer, get_size() - resizer->get_size(), resizer_color);
  223. }
  224. } break;
  225. case NOTIFICATION_SORT_CHILDREN: {
  226. _resort();
  227. } break;
  228. case NOTIFICATION_THEME_CHANGED: {
  229. minimum_size_changed();
  230. } break;
  231. }
  232. }
  233. void GraphNode::set_slot(int p_idx, 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<Texture> &p_custom_left, const Ref<Texture> &p_custom_right) {
  234. ERR_FAIL_COND(p_idx < 0);
  235. if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) && !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1)) {
  236. slot_info.erase(p_idx);
  237. return;
  238. }
  239. Slot s;
  240. s.enable_left = p_enable_left;
  241. s.type_left = p_type_left;
  242. s.color_left = p_color_left;
  243. s.enable_right = p_enable_right;
  244. s.type_right = p_type_right;
  245. s.color_right = p_color_right;
  246. s.custom_slot_left = p_custom_left;
  247. s.custom_slot_right = p_custom_right;
  248. slot_info[p_idx] = s;
  249. update();
  250. connpos_dirty = true;
  251. emit_signal("slot_updated", p_idx);
  252. }
  253. void GraphNode::clear_slot(int p_idx) {
  254. slot_info.erase(p_idx);
  255. update();
  256. connpos_dirty = true;
  257. }
  258. void GraphNode::clear_all_slots() {
  259. slot_info.clear();
  260. update();
  261. connpos_dirty = true;
  262. }
  263. bool GraphNode::is_slot_enabled_left(int p_idx) const {
  264. if (!slot_info.has(p_idx))
  265. return false;
  266. return slot_info[p_idx].enable_left;
  267. }
  268. int GraphNode::get_slot_type_left(int p_idx) const {
  269. if (!slot_info.has(p_idx))
  270. return 0;
  271. return slot_info[p_idx].type_left;
  272. }
  273. Color GraphNode::get_slot_color_left(int p_idx) const {
  274. if (!slot_info.has(p_idx))
  275. return Color(1, 1, 1, 1);
  276. return slot_info[p_idx].color_left;
  277. }
  278. bool GraphNode::is_slot_enabled_right(int p_idx) const {
  279. if (!slot_info.has(p_idx))
  280. return false;
  281. return slot_info[p_idx].enable_right;
  282. }
  283. int GraphNode::get_slot_type_right(int p_idx) const {
  284. if (!slot_info.has(p_idx))
  285. return 0;
  286. return slot_info[p_idx].type_right;
  287. }
  288. Color GraphNode::get_slot_color_right(int p_idx) const {
  289. if (!slot_info.has(p_idx))
  290. return Color(1, 1, 1, 1);
  291. return slot_info[p_idx].color_right;
  292. }
  293. Size2 GraphNode::get_minimum_size() const {
  294. Ref<Font> title_font = get_font("title_font");
  295. int sep = get_constant("separation");
  296. Ref<StyleBox> sb = get_stylebox("frame");
  297. bool first = true;
  298. Size2 minsize;
  299. minsize.x = title_font->get_string_size(title).x;
  300. if (show_close) {
  301. Ref<Texture> close = get_icon("close");
  302. minsize.x += sep + close->get_width();
  303. }
  304. for (int i = 0; i < get_child_count(); i++) {
  305. Control *c = Object::cast_to<Control>(get_child(i));
  306. if (!c)
  307. continue;
  308. if (c->is_set_as_toplevel())
  309. continue;
  310. Size2i size = c->get_combined_minimum_size();
  311. minsize.y += size.y;
  312. minsize.x = MAX(minsize.x, size.x);
  313. if (first)
  314. first = false;
  315. else
  316. minsize.y += sep;
  317. }
  318. return minsize + sb->get_minimum_size();
  319. }
  320. void GraphNode::set_title(const String &p_title) {
  321. if (title == p_title)
  322. return;
  323. title = p_title;
  324. update();
  325. _change_notify("title");
  326. minimum_size_changed();
  327. }
  328. String GraphNode::get_title() const {
  329. return title;
  330. }
  331. void GraphNode::set_offset(const Vector2 &p_offset) {
  332. offset = p_offset;
  333. emit_signal("offset_changed");
  334. update();
  335. }
  336. Vector2 GraphNode::get_offset() const {
  337. return offset;
  338. }
  339. void GraphNode::set_selected(bool p_selected) {
  340. selected = p_selected;
  341. update();
  342. }
  343. bool GraphNode::is_selected() {
  344. return selected;
  345. }
  346. void GraphNode::set_drag(bool p_drag) {
  347. if (p_drag)
  348. drag_from = get_offset();
  349. else
  350. emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
  351. }
  352. Vector2 GraphNode::get_drag_from() {
  353. return drag_from;
  354. }
  355. void GraphNode::set_show_close_button(bool p_enable) {
  356. show_close = p_enable;
  357. update();
  358. }
  359. bool GraphNode::is_close_button_visible() const {
  360. return show_close;
  361. }
  362. void GraphNode::_connpos_update() {
  363. int edgeofs = get_constant("port_offset");
  364. int sep = get_constant("separation");
  365. Ref<StyleBox> sb = get_stylebox("frame");
  366. conn_input_cache.clear();
  367. conn_output_cache.clear();
  368. int vofs = 0;
  369. int idx = 0;
  370. for (int i = 0; i < get_child_count(); i++) {
  371. Control *c = Object::cast_to<Control>(get_child(i));
  372. if (!c)
  373. continue;
  374. if (c->is_set_as_toplevel())
  375. continue;
  376. Size2i size = c->get_combined_minimum_size();
  377. int y = sb->get_margin(MARGIN_TOP) + vofs;
  378. int h = size.y;
  379. if (slot_info.has(idx)) {
  380. if (slot_info[idx].enable_left) {
  381. ConnCache cc;
  382. cc.pos = Point2i(edgeofs, y + h / 2);
  383. cc.type = slot_info[idx].type_left;
  384. cc.color = slot_info[idx].color_left;
  385. conn_input_cache.push_back(cc);
  386. }
  387. if (slot_info[idx].enable_right) {
  388. ConnCache cc;
  389. cc.pos = Point2i(get_size().width - edgeofs, y + h / 2);
  390. cc.type = slot_info[idx].type_right;
  391. cc.color = slot_info[idx].color_right;
  392. conn_output_cache.push_back(cc);
  393. }
  394. }
  395. vofs += sep;
  396. vofs += size.y;
  397. idx++;
  398. }
  399. connpos_dirty = false;
  400. }
  401. int GraphNode::get_connection_input_count() {
  402. if (connpos_dirty)
  403. _connpos_update();
  404. return conn_input_cache.size();
  405. }
  406. int GraphNode::get_connection_output_count() {
  407. if (connpos_dirty)
  408. _connpos_update();
  409. return conn_output_cache.size();
  410. }
  411. Vector2 GraphNode::get_connection_input_position(int p_idx) {
  412. if (connpos_dirty)
  413. _connpos_update();
  414. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
  415. Vector2 pos = conn_input_cache[p_idx].pos;
  416. pos.x *= get_scale().x;
  417. pos.y *= get_scale().y;
  418. return pos;
  419. }
  420. int GraphNode::get_connection_input_type(int p_idx) {
  421. if (connpos_dirty)
  422. _connpos_update();
  423. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
  424. return conn_input_cache[p_idx].type;
  425. }
  426. Color GraphNode::get_connection_input_color(int p_idx) {
  427. if (connpos_dirty)
  428. _connpos_update();
  429. ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
  430. return conn_input_cache[p_idx].color;
  431. }
  432. Vector2 GraphNode::get_connection_output_position(int p_idx) {
  433. if (connpos_dirty)
  434. _connpos_update();
  435. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
  436. Vector2 pos = conn_output_cache[p_idx].pos;
  437. pos.x *= get_scale().x;
  438. pos.y *= get_scale().y;
  439. return pos;
  440. }
  441. int GraphNode::get_connection_output_type(int p_idx) {
  442. if (connpos_dirty)
  443. _connpos_update();
  444. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
  445. return conn_output_cache[p_idx].type;
  446. }
  447. Color GraphNode::get_connection_output_color(int p_idx) {
  448. if (connpos_dirty)
  449. _connpos_update();
  450. ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
  451. return conn_output_cache[p_idx].color;
  452. }
  453. void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
  454. Ref<InputEventMouseButton> mb = p_ev;
  455. if (mb.is_valid()) {
  456. ERR_FAIL_COND_MSG(get_parent_control() == NULL, "GraphNode must be the child of a GraphEdit node.");
  457. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  458. Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
  459. if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
  460. //send focus to parent
  461. get_parent_control()->grab_focus();
  462. emit_signal("close_request");
  463. accept_event();
  464. return;
  465. }
  466. Ref<Texture> resizer = get_icon("resizer");
  467. if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
  468. resizing = true;
  469. resizing_from = mpos;
  470. resizing_from_size = get_size();
  471. accept_event();
  472. return;
  473. }
  474. emit_signal("raise_request");
  475. }
  476. if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  477. resizing = false;
  478. }
  479. }
  480. Ref<InputEventMouseMotion> mm = p_ev;
  481. if (resizing && mm.is_valid()) {
  482. Vector2 mpos = mm->get_position();
  483. Vector2 diff = mpos - resizing_from;
  484. emit_signal("resize_request", resizing_from_size + diff);
  485. }
  486. }
  487. void GraphNode::set_overlay(Overlay p_overlay) {
  488. overlay = p_overlay;
  489. update();
  490. }
  491. GraphNode::Overlay GraphNode::get_overlay() const {
  492. return overlay;
  493. }
  494. void GraphNode::set_comment(bool p_enable) {
  495. comment = p_enable;
  496. update();
  497. }
  498. bool GraphNode::is_comment() const {
  499. return comment;
  500. }
  501. void GraphNode::set_resizable(bool p_enable) {
  502. resizable = p_enable;
  503. update();
  504. }
  505. bool GraphNode::is_resizable() const {
  506. return resizable;
  507. }
  508. void GraphNode::_bind_methods() {
  509. ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
  510. ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
  511. ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input);
  512. ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture>()), DEFVAL(Ref<Texture>()));
  513. ClassDB::bind_method(D_METHOD("clear_slot", "idx"), &GraphNode::clear_slot);
  514. ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
  515. ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left);
  516. ClassDB::bind_method(D_METHOD("get_slot_type_left", "idx"), &GraphNode::get_slot_type_left);
  517. ClassDB::bind_method(D_METHOD("get_slot_color_left", "idx"), &GraphNode::get_slot_color_left);
  518. ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "idx"), &GraphNode::is_slot_enabled_right);
  519. ClassDB::bind_method(D_METHOD("get_slot_type_right", "idx"), &GraphNode::get_slot_type_right);
  520. ClassDB::bind_method(D_METHOD("get_slot_color_right", "idx"), &GraphNode::get_slot_color_right);
  521. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &GraphNode::set_offset);
  522. ClassDB::bind_method(D_METHOD("get_offset"), &GraphNode::get_offset);
  523. ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment);
  524. ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment);
  525. ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable);
  526. ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable);
  527. ClassDB::bind_method(D_METHOD("set_selected", "selected"), &GraphNode::set_selected);
  528. ClassDB::bind_method(D_METHOD("is_selected"), &GraphNode::is_selected);
  529. ClassDB::bind_method(D_METHOD("get_connection_output_count"), &GraphNode::get_connection_output_count);
  530. ClassDB::bind_method(D_METHOD("get_connection_input_count"), &GraphNode::get_connection_input_count);
  531. ClassDB::bind_method(D_METHOD("get_connection_output_position", "idx"), &GraphNode::get_connection_output_position);
  532. ClassDB::bind_method(D_METHOD("get_connection_output_type", "idx"), &GraphNode::get_connection_output_type);
  533. ClassDB::bind_method(D_METHOD("get_connection_output_color", "idx"), &GraphNode::get_connection_output_color);
  534. ClassDB::bind_method(D_METHOD("get_connection_input_position", "idx"), &GraphNode::get_connection_input_position);
  535. ClassDB::bind_method(D_METHOD("get_connection_input_type", "idx"), &GraphNode::get_connection_input_type);
  536. ClassDB::bind_method(D_METHOD("get_connection_input_color", "idx"), &GraphNode::get_connection_input_color);
  537. ClassDB::bind_method(D_METHOD("set_show_close_button", "show"), &GraphNode::set_show_close_button);
  538. ClassDB::bind_method(D_METHOD("is_close_button_visible"), &GraphNode::is_close_button_visible);
  539. ClassDB::bind_method(D_METHOD("set_overlay", "overlay"), &GraphNode::set_overlay);
  540. ClassDB::bind_method(D_METHOD("get_overlay"), &GraphNode::get_overlay);
  541. ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
  542. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
  543. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_close"), "set_show_close_button", "is_close_button_visible");
  544. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable"), "set_resizable", "is_resizable");
  545. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected");
  546. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "comment"), "set_comment", "is_comment");
  547. ADD_PROPERTY(PropertyInfo(Variant::INT, "overlay", PROPERTY_HINT_ENUM, "Disabled,Breakpoint,Position"), "set_overlay", "get_overlay");
  548. ADD_SIGNAL(MethodInfo("offset_changed"));
  549. ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "idx")));
  550. ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
  551. ADD_SIGNAL(MethodInfo("raise_request"));
  552. ADD_SIGNAL(MethodInfo("close_request"));
  553. ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize")));
  554. BIND_ENUM_CONSTANT(OVERLAY_DISABLED);
  555. BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT);
  556. BIND_ENUM_CONSTANT(OVERLAY_POSITION);
  557. }
  558. GraphNode::GraphNode() {
  559. overlay = OVERLAY_DISABLED;
  560. show_close = false;
  561. connpos_dirty = true;
  562. set_mouse_filter(MOUSE_FILTER_STOP);
  563. comment = false;
  564. resizable = false;
  565. resizing = false;
  566. selected = false;
  567. }